diff --git a/connectorx/src/sources/oracle/mod.rs b/connectorx/src/sources/oracle/mod.rs index 50b58e933..7cf550248 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}; @@ -55,12 +57,19 @@ 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 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") { + host.clone() + } else { + let port = conn.port().unwrap_or(1521); + 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" { + if user.is_empty() && password.is_empty() { debug!("No username or password provided, assuming system auth."); connector.external_auth(true); } 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 | |:-------------------------:|:---------------------------:|:----------------------------------:|