|
5 | 5 | from decimal import Decimal |
6 | 6 | from typing import Optional |
7 | 7 |
|
| 8 | +import oracledb |
8 | 9 | import psycopg2 |
9 | 10 | import pymssql |
| 11 | + |
10 | 12 | from apps.db.db_sql import get_table_sql, get_field_sql, get_version_sql |
11 | 13 | from common.error import ParseSQLResultError |
12 | 14 |
|
|
27 | 29 | from common.utils.utils import SQLBotLogUtil, equals_ignore_case |
28 | 30 | from fastapi import HTTPException |
29 | 31 | from apps.db.es_engine import get_es_connect, get_es_index, get_es_fields, get_es_data_by_http |
| 32 | +from common.core.config import settings |
| 33 | + |
| 34 | +try: |
| 35 | + oracledb.init_oracle_client( |
| 36 | + lib_dir=settings.ORACLE_CLIENT_PATH |
| 37 | + ) |
| 38 | + SQLBotLogUtil.info("init oracle client success, use thick mode") |
| 39 | +except Exception: |
| 40 | + SQLBotLogUtil.error("init oracle client failed, use thin mode") |
30 | 41 |
|
31 | 42 |
|
32 | 43 | def get_uri(ds: CoreDatasource) -> str: |
33 | | - conf = DatasourceConf(**json.loads(aes_decrypt(ds.configuration))) if not equals_ignore_case(ds.type, "excel") else get_engine_config() |
| 44 | + conf = DatasourceConf(**json.loads(aes_decrypt(ds.configuration))) if not equals_ignore_case(ds.type, |
| 45 | + "excel") else get_engine_config() |
34 | 46 | return get_uri_from_config(ds.type, conf) |
35 | 47 |
|
36 | 48 |
|
@@ -102,7 +114,8 @@ def get_origin_connect(type: str, conf: DatasourceConf): |
102 | 114 |
|
103 | 115 | # use sqlalchemy |
104 | 116 | def get_engine(ds: CoreDatasource, timeout: int = 0) -> Engine: |
105 | | - conf = DatasourceConf(**json.loads(aes_decrypt(ds.configuration))) if not equals_ignore_case(ds.type, "excel") else get_engine_config() |
| 117 | + conf = DatasourceConf(**json.loads(aes_decrypt(ds.configuration))) if not equals_ignore_case(ds.type, |
| 118 | + "excel") else get_engine_config() |
106 | 119 | if conf.timeout is None: |
107 | 120 | conf.timeout = timeout |
108 | 121 | if timeout > 0: |
@@ -233,7 +246,8 @@ def get_version(ds: CoreDatasource | AssistantOutDsSchema): |
233 | 246 | conf = None |
234 | 247 | if isinstance(ds, CoreDatasource): |
235 | 248 | conf = DatasourceConf( |
236 | | - **json.loads(aes_decrypt(ds.configuration))) if not equals_ignore_case(ds.type, "excel") else get_engine_config() |
| 249 | + **json.loads(aes_decrypt(ds.configuration))) if not equals_ignore_case(ds.type, |
| 250 | + "excel") else get_engine_config() |
237 | 251 | if isinstance(ds, AssistantOutDsSchema): |
238 | 252 | conf = DatasourceConf() |
239 | 253 | conf.host = ds.host |
@@ -319,7 +333,8 @@ def get_schema(ds: CoreDatasource): |
319 | 333 |
|
320 | 334 |
|
321 | 335 | def get_tables(ds: CoreDatasource): |
322 | | - conf = DatasourceConf(**json.loads(aes_decrypt(ds.configuration))) if not equals_ignore_case(ds.type, "excel") else get_engine_config() |
| 336 | + conf = DatasourceConf(**json.loads(aes_decrypt(ds.configuration))) if not equals_ignore_case(ds.type, |
| 337 | + "excel") else get_engine_config() |
323 | 338 | db = DB.get_db(ds.type) |
324 | 339 | sql, sql_param = get_table_sql(ds, conf, get_version(ds)) |
325 | 340 | if db.connect_type == ConnectType.sqlalchemy: |
@@ -369,7 +384,8 @@ def get_tables(ds: CoreDatasource): |
369 | 384 |
|
370 | 385 |
|
371 | 386 | def get_fields(ds: CoreDatasource, table_name: str = None): |
372 | | - conf = DatasourceConf(**json.loads(aes_decrypt(ds.configuration))) if not equals_ignore_case(ds.type, "excel") else get_engine_config() |
| 387 | + conf = DatasourceConf(**json.loads(aes_decrypt(ds.configuration))) if not equals_ignore_case(ds.type, |
| 388 | + "excel") else get_engine_config() |
373 | 389 | db = DB.get_db(ds.type) |
374 | 390 | sql, p1, p2 = get_field_sql(ds, conf, table_name) |
375 | 391 | if db.connect_type == ConnectType.sqlalchemy: |
|
0 commit comments