adapting raw data retrieval for Oracle DB

This commit is contained in:
2025-12-02 12:21:06 +01:00
parent 37ac00a502
commit 547d924f31
3 changed files with 594 additions and 12 deletions

View File

@@ -2,8 +2,11 @@
from pathlib import Path
import oracledb
import sqlalchemy as sql
from dopt_basics import configs, io
from umbreit import db
# %%
p_cfg = io.search_file_iterative(
starting_path=Path.cwd(),
@@ -20,23 +23,54 @@ USER_PASS = CFG["user"]["pass"]
# %%
# !! init thick mode
p_oracle_client = Path(r"C:\Databases\Oracle\instantclient_19_29")
assert p_oracle_client.exists()
assert p_oracle_client.is_dir()
oracledb.init_oracle_client(lib_dir=str(p_oracle_client))
# p_oracle_client = Path(r"C:\Databases\Oracle\instantclient_19_29")
# assert p_oracle_client.exists()
# assert p_oracle_client.is_dir()
# oracledb.init_oracle_client(lib_dir=str(p_oracle_client))
# %%
# conn = oracledb.connect(user=USER_NAME, password=USER_PASS, dsn=f"{HOST}:{PORT}/{SERVICE}")
# conn = oracledb.connect(user=USER_NAME, password=USER_PASS, dsn=f"{HOST}/{SERVICE}")
# conn = oracledb.connect(user=USER_NAME, password=USER_PASS, dsn="10.50.4.82:1521/TS4")
# conn = oracledb.connect(user=USER_NAME, password=USER_PASS, dsn="ts4db:1521/?TS4")
conn_string = (
f"oracle+oracledb://{USER_NAME}:{USER_PASS}@{HOST}:{PORT}?service_name={SERVICE}"
)
engine = sql.create_engine(conn_string)
# %%
# stmt = sql.select(db.EXT_BESPBES_INFO).limit(10)
stmt = sql.text("SELECT * FROM ext_bedpbed FETCH FIRST 30 ROWS ONLY")
compiled = stmt.compile(dialect=engine.dialect, compile_kwargs={"literal_binds": True})
print(str(compiled))
# conn = oracledb.connect(user=USER_NAME, password=USER_PASS, dsn="ts4db.umbreit.local:1521/TS4")
# conn = oracledb.connect(user=USER_NAME, password=USER_PASS, dsn="10.50.4.82:1521/TS4")
# %%
with engine.connect() as conn:
res = conn.execute(stmt)
res = tuple(res.all())
# %%
len(res[0])
# %%
res
# %%
engine.dispose()
# # %%
# stmt = sql.text("SELECT * FROM ALL_TAB_COLUMNS WHERE TABLE_NAME = 'ext_bedpbed' AND COLUMN_NAME = 'BEDARFNR'")
# with engine.connect() as conn:
# res = conn.execute(stmt)
# # %%
# res.all()
# %%
conn = oracledb.connect(
user=USER_NAME,
password=USER_PASS,
host=HOST,
port=PORT,
service_name="TS4",
service_name=SERVICE,
)
# %%
cursor = conn.cursor()
cursor.execute("select * from ext_bedpbed limit 3")
# %%
print(cursor.fetchone())
# %%
conn.close()
# %%