From d4327ca4d8905509e68e213f5ffb93de19ad6187 Mon Sep 17 00:00:00 2001 From: jaydxn1 Date: Fri, 25 Oct 2024 10:35:42 +0800 Subject: [PATCH 1/4] updated oracle conn with alias option --- connectorx/src/sources/oracle/mod.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/connectorx/src/sources/oracle/mod.rs b/connectorx/src/sources/oracle/mod.rs index 50b58e933..5a924bfbe 100644 --- a/connectorx/src/sources/oracle/mod.rs +++ b/connectorx/src/sources/oracle/mod.rs @@ -1,6 +1,8 @@ mod errors; mod typesystem; +use std::collections::HashMap; + pub use self::errors::OracleSourceError; pub use self::typesystem::OracleTypeSystem; use crate::constants::{DB_BUFFER_SIZE, ORACLE_ARRAY_SIZE}; @@ -56,9 +58,16 @@ pub fn connect_oracle(conn: &Url) -> Connector { let password = decode(conn.password().unwrap_or(""))?.into_owned(); let host = decode(conn.host_str().unwrap_or("localhost"))?.into_owned(); let port = conn.port().unwrap_or(1521); - let path = decode(conn.path())?.into_owned(); - let conn_str = format!("//{}:{}{}", host, port, path); + let params: HashMap = conn.query_pairs().into_owned().collect(); + + let conn_str = if params.get("alias").map_or(false, |v| v == "true") { + decode(conn.path())?.into_owned() + } else { + let path = decode(conn.path())?.into_owned(); + format!("//{}:{}{}", host, port, path) + }; + let mut connector = oracle::Connector::new(user.as_str(), password.as_str(), conn_str.as_str()); if user.is_empty() && password.is_empty() && host == "localhost" { debug!("No username or password provided, assuming system auth."); From 12bcc7e5b8acb7f1832b56e93a17378568439a78 Mon Sep 17 00:00:00 2001 From: jaydxn1 Date: Fri, 25 Oct 2024 11:19:22 +0800 Subject: [PATCH 2/4] use host for oracle alias instead of path --- connectorx/src/sources/oracle/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/connectorx/src/sources/oracle/mod.rs b/connectorx/src/sources/oracle/mod.rs index 5a924bfbe..d55e1724a 100644 --- a/connectorx/src/sources/oracle/mod.rs +++ b/connectorx/src/sources/oracle/mod.rs @@ -57,13 +57,13 @@ pub fn connect_oracle(conn: &Url) -> Connector { let user = decode(conn.username())?.into_owned(); let password = decode(conn.password().unwrap_or(""))?.into_owned(); let host = decode(conn.host_str().unwrap_or("localhost"))?.into_owned(); - let port = conn.port().unwrap_or(1521); let params: HashMap = conn.query_pairs().into_owned().collect(); let conn_str = if params.get("alias").map_or(false, |v| v == "true") { - decode(conn.path())?.into_owned() + host.clone() } else { + let port = conn.port().unwrap_or(1521); let path = decode(conn.path())?.into_owned(); format!("//{}:{}{}", host, port, path) }; From a3877018ae4e36c7791a9b1c944e6cd8e084a9dd Mon Sep 17 00:00:00 2001 From: jaydxn1 Date: Fri, 25 Oct 2024 11:38:11 +0800 Subject: [PATCH 3/4] removed condition for localhost to use sys auth, to account for general use case --- connectorx/src/sources/oracle/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connectorx/src/sources/oracle/mod.rs b/connectorx/src/sources/oracle/mod.rs index d55e1724a..7cf550248 100644 --- a/connectorx/src/sources/oracle/mod.rs +++ b/connectorx/src/sources/oracle/mod.rs @@ -69,7 +69,7 @@ pub fn connect_oracle(conn: &Url) -> Connector { }; let mut connector = oracle::Connector::new(user.as_str(), password.as_str(), conn_str.as_str()); - if user.is_empty() && password.is_empty() && host == "localhost" { + if user.is_empty() && password.is_empty() { debug!("No username or password provided, assuming system auth."); connector.external_auth(true); } From d08f6cee26e1ba1b54ce92dcb3aebb4ffe2c2499 Mon Sep 17 00:00:00 2001 From: jaydxn1 Date: Fri, 25 Oct 2024 11:42:43 +0800 Subject: [PATCH 4/4] updated oracle docs w alias conn & sys auth info --- docs/databases/oracle.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/databases/oracle.md b/docs/databases/oracle.md index f25e05e49..24e603fe6 100644 --- a/docs/databases/oracle.md +++ b/docs/databases/oracle.md @@ -1,5 +1,9 @@ # Oracle +### System Authentication +```{hint} +If you want to use system authentication to access Oracle, username & password should not present in the connection string. +``` ### Oracle Connection ```py @@ -9,6 +13,14 @@ query = 'SELECT * FROM table' # query string cx.read_sql(conn, query) # read data from Oracle ``` +### Oracle TNS Alias (DNS) Connection +```py +import connectorx as cx +conn = 'oracle://username:password@alias_name?alias=true' # connection token +query = 'SELECT * FROM table' # query string +cx.read_sql(conn, query) # read data from Oracle +``` + ### Oracle-Pandas Type Mapping | Oracle Type | Pandas Type | Comment | |:-------------------------:|:---------------------------:|:----------------------------------:|