Skip to content

Instantly share code, notes, and snippets.

@germanviscuso
Last active November 3, 2023 12:35
Show Gist options
  • Save germanviscuso/e0659bdaa4787cd4577bea06997fa752 to your computer and use it in GitHub Desktop.
Save germanviscuso/e0659bdaa4787cd4577bea06997fa752 to your computer and use it in GitHub Desktop.
Code for Sibyl to ADB
[package]
name = "adb_rust_s"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
sibyl = {version = "0.6.16", features = ["blocking"]}
[package]
name = "adb_rust_s"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
actix-web = "4"
sibyl = { version = "0.6.16", features = ["nonblocking", "actix"] }
#!/bin/sh
# This example script sets up Oracle environment variables.
# Set TNS_ADMIN
export TNS_ADMIN='/Users/gviscuso/.oci/Wallet_IQRYYGS7ID28DBNW'
# Set Oracle user
export ORACLE_USER='ADMIN'
# Set Oracle password
# Note: If your password contains special characters, they need to be escaped or quoted.
export ORACLE_PASSWORD='Webinar1234!'
# Set Oracle TNS name
export ORACLE_TNSNAME='iqryygs7id28dbnw_high'
use sibyl as oracle;
use std::env;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Ensure that the TNS_ADMIN environment variable is set
let _tns_admin = env::var("TNS_ADMIN").expect("TNS_ADMIN environment variable is not set. Please configure it to point to your wallet.");
// Retrieve connection parameters from environment variables
let user = env::var("ORACLE_USER").expect("Expected ORACLE_USER environment variable not found.");
let password = env::var("ORACLE_PASSWORD").expect("Expected ORACLE_PASSWORD environment variable not found.");
let tnsname = env::var("ORACLE_TNSNAME").expect("Expected ORACLE_TNSNAME environment variable not found.");
// Initialize the Oracle environment
let oracle = oracle::env()?;
// Establish the Oracle session/connection using the retrieved environment variables
let session = oracle.connect(&tnsname, &user, &password)?; // TNS profile is in tnsnames.ora
// Get and display the Oracle client version
let (major, minor, update, patch, sub_patch) = oracle::client_version();
println!("Client Version: {}.{}.{}.{}.{}", major, minor, update, patch, sub_patch);
// Prepare and execute the SQL statement to get Oracle server version
let stmt = session.prepare("SELECT * FROM v$version WHERE banner LIKE 'Oracle%'")?;
let rows = stmt.query(1)?; // Placeholder argument since query expects one
// Fetch and display the Oracle server version
while let Some(row) = rows.next()? {
let banner: &str = row.get(0)?;
println!("Server Version: {}", banner);
}
Ok(())
}
use sibyl as oracle;
use std::env;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Ensure that the TNS_ADMIN environment variable is set
let _tns_admin = env::var("TNS_ADMIN").expect("TNS_ADMIN environment variable is not set. Please configure it to point to your wallet.");
// Retrieve connection parameters from environment variables
let user = env::var("ORACLE_USER").expect("Expected ORACLE_USER environment variable not found.");
let password = env::var("ORACLE_PASSWORD").expect("Expected ORACLE_PASSWORD environment variable not found.");
let tnsname = env::var("ORACLE_TNSNAME").expect("Expected ORACLE_TNSNAME environment variable not found.");
// Initialize the Oracle environment
let oracle = oracle::env()?;
// Establish the Oracle session/connection using the retrieved environment variables
let session = oracle.connect(&tnsname, &user, &password)?; // TNS profile is in tnsnames.ora
// Get and display the Oracle client version
let (major, minor, update, patch, sub_patch) = oracle::client_version();
println!("Client Version: {}.{}.{}.{}.{}", major, minor, update, patch, sub_patch);
// Prepare and execute the SQL statement to get Oracle server version
let filter = "Oracle%";
let stmt = session.prepare("SELECT * FROM v$version WHERE banner LIKE :filter")?;
let rows = stmt.query(&filter)?;
// Fetch and display the Oracle server version
while let Some(row) = rows.next()? {
let banner: &str = row.get(0)?;
println!("Server Version: {}", banner);
}
Ok(())
}
use sibyl as oracle;
use std::env;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Ensure that the TNS_ADMIN environment variable is set
let _tns_admin = env::var("TNS_ADMIN").expect("TNS_ADMIN environment variable is not set. Please configure it to point to your wallet.");
// Retrieve connection parameters from environment variables
let user = env::var("ORACLE_USER").expect("Expected ORACLE_USER environment variable not found.");
let password = env::var("ORACLE_PASSWORD").expect("Expected ORACLE_PASSWORD environment variable not found.");
let tnsname = env::var("ORACLE_TNSNAME").expect("Expected ORACLE_TNSNAME environment variable not found.");
// Initialize the Oracle environment
let oracle = oracle::env()?;
// Establish the Oracle session/connection using the retrieved environment variables
let session = oracle.connect(&tnsname, &user, &password)?; // TNS profile is in tnsnames.ora
let stmt = session.prepare("
SELECT
NAME,
ROUND(SUM(ACTUAL_PRICE), 0) AS SALES
FROM CUSTSALES C, GENRE G
WHERE C.GENRE_ID = G.GENRE_ID
GROUP BY NAME
ORDER BY SALES DESC
FETCH FIRST :TOP_SALES ROWS ONLY
")?;
let rows = stmt.query(5)?;
while let Some(row) = rows.next()? {
let name : &str = row.get(0)?;
let sales : u32 = row.get(1)?;
println!("{:10}: {:>5}", name, sales);
}
Ok(())
}
use sibyl as oracle;
use std::env;
fn main() -> Result<(),Box<dyn std::error::Error>> {
oracle::block_on(async {
// Ensure that the TNS_ADMIN environment variable is set
let _tns_admin = env::var("TNS_ADMIN").expect("TNS_ADMIN environment variable is not set. Please configure it to point to your wallet.");
// Retrieve connection parameters from environment variables
let user = env::var("ORACLE_USER").expect("Expected ORACLE_USER environment variable not found.");
let password = env::var("ORACLE_PASSWORD").expect("Expected ORACLE_PASSWORD environment variable not found.");
let tnsname = env::var("ORACLE_TNSNAME").expect("Expected ORACLE_TNSNAME environment variable not found.");
// Initialize the Oracle environment
let oracle = oracle::env()?;
// Establish the Oracle session/connection using the retrieved environment variables
let session = oracle.connect(&tnsname, &user, &password).await?; // TNS profile is in tnsnames.ora
let stmt = session.prepare("
SELECT
NAME,
ROUND(SUM(ACTUAL_PRICE),0) AS SALES
FROM CUSTSALES C, GENRE G
WHERE C.GENRE_ID = G.GENRE_ID
GROUP BY NAME
ORDER BY SALES DESC
FETCH FIRST :TOP_SALES ROWS ONLY
").await?;
let rows = stmt.query(5).await?;
while let Some(row) = rows.next().await? {
let name : &str = row.get(0)?;
let sales : u32 = row.get(1)?;
println!("{:10}: {:>5}", name, sales);
}
Ok(())
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment