|
38 | 38 | from sqlalchemy.pool import NullPool |
39 | 39 | from pyhive import hive |
40 | 40 |
|
41 | | - |
42 | 41 | try: |
43 | 42 | if os.path.exists(settings.ORACLE_CLIENT_PATH): |
44 | 43 | oracledb.init_oracle_client( |
@@ -159,9 +158,10 @@ def get_engine(ds: CoreDatasource, timeout: int = 0) -> Engine: |
159 | 158 | poolclass=NullPool) |
160 | 159 | elif equals_ignore_case(ds.type, 'oracle'): |
161 | 160 | engine = create_engine(get_uri(ds), poolclass=NullPool) |
162 | | - elif equals_ignore_case(ds.type, 'mysql'): # mysql |
| 161 | + elif equals_ignore_case(ds.type, 'mysql'): # mysql |
163 | 162 | ssl_mode = {"require": True} if conf.ssl else None |
164 | | - engine = create_engine(get_uri(ds), connect_args={"connect_timeout": conf.timeout, "ssl": ssl_mode}, poolclass=NullPool) |
| 163 | + engine = create_engine(get_uri(ds), connect_args={"connect_timeout": conf.timeout, "ssl": ssl_mode}, |
| 164 | + poolclass=NullPool) |
165 | 165 | elif equals_ignore_case(ds.type, 'sqlite'): |
166 | 166 | engine = create_engine(get_uri(ds), connect_args={"check_same_thread": False}, poolclass=NullPool) |
167 | 167 | else: # ck |
@@ -271,7 +271,7 @@ def check_connection(trans: Optional[Trans], ds: CoreDatasource | AssistantOutDs |
271 | 271 | if is_raise: |
272 | 272 | raise HTTPException(status_code=500, detail=trans('i18n_ds_invalid') + f': {e.args}') |
273 | 273 | return False |
274 | | - |
| 274 | + |
275 | 275 | elif equals_ignore_case(ds.type, 'es'): |
276 | 276 | es_conn = get_es_connect(conf) |
277 | 277 | if es_conn.ping(): |
@@ -314,7 +314,7 @@ def get_version(ds: CoreDatasource | AssistantOutDsSchema): |
314 | 314 | # conf.timeout = 10 |
315 | 315 | db = DB.get_db(ds.type) |
316 | 316 | sql = get_version_sql(ds, conf) |
317 | | - if equals_ignore_case(ds.type, 'sqlite'): |
| 317 | + if not sql: |
318 | 318 | return '' |
319 | 319 | try: |
320 | 320 | if db.connect_type == ConnectType.sqlalchemy: |
@@ -397,30 +397,6 @@ def get_schema(ds: CoreDatasource): |
397 | 397 | res = cursor.fetchall() |
398 | 398 | res_list = [item[0] for item in res] |
399 | 399 | return res_list |
400 | | - elif equals_ignore_case(ds.type, 'hive'): |
401 | | - conn = hive.connect(host=conf.host, port=conf.port, username=conf.username, |
402 | | - database=conf.database, **extra_config_dict) |
403 | | - cursor = conn.cursor() |
404 | | - cursor.execute('SHOW DATABASES') |
405 | | - res = cursor.fetchall() |
406 | | - res_list = [item[0] for item in res] |
407 | | - cursor.close() |
408 | | - conn.close() |
409 | | - return res_list |
410 | | - elif equals_ignore_case(ds.type, 'doris', 'starrocks'): |
411 | | - with pymysql.connect(user=conf.username, passwd=conf.password, host=conf.host, |
412 | | - port=conf.port, db=conf.database, connect_timeout=10, |
413 | | - read_timeout=10, **extra_config_dict) as conn, conn.cursor() as cursor: |
414 | | - cursor.execute('SHOW DATABASES') |
415 | | - res = cursor.fetchall() |
416 | | - res_list = [item[0] for item in res] |
417 | | - return res_list |
418 | | - elif equals_ignore_case(ds.type, 'ck'): |
419 | | - with get_session(ds) as session: |
420 | | - with session.execute(text('SHOW DATABASES')) as result: |
421 | | - res = result.fetchall() |
422 | | - res_list = [item[0] for item in res] |
423 | | - return res_list |
424 | 400 |
|
425 | 401 |
|
426 | 402 | def get_tables(ds: CoreDatasource): |
@@ -456,7 +432,8 @@ def get_tables(ds: CoreDatasource): |
456 | 432 | ssl_args = {'ssl': {'ssl_mode': 'REQUIRE'}} if conf.ssl else {} |
457 | 433 | with pymysql.connect(user=conf.username, passwd=conf.password, host=conf.host, |
458 | 434 | port=conf.port, db=conf.database, connect_timeout=conf.timeout, |
459 | | - read_timeout=conf.timeout, **extra_config_dict, **ssl_args) as conn, conn.cursor() as cursor: |
| 435 | + read_timeout=conf.timeout, **extra_config_dict, |
| 436 | + **ssl_args) as conn, conn.cursor() as cursor: |
460 | 437 | cursor.execute(sql, (sql_param,)) |
461 | 438 | res = cursor.fetchall() |
462 | 439 | res_list = [TableSchema(*item) for item in res] |
@@ -527,7 +504,8 @@ def get_fields(ds: CoreDatasource, table_name: str = None): |
527 | 504 | ssl_args = {'ssl': {'ssl_mode': 'REQUIRE'}} if conf.ssl else {} |
528 | 505 | with pymysql.connect(user=conf.username, passwd=conf.password, host=conf.host, |
529 | 506 | port=conf.port, db=conf.database, connect_timeout=conf.timeout, |
530 | | - read_timeout=conf.timeout, **extra_config_dict, **ssl_args) as conn, conn.cursor() as cursor: |
| 507 | + read_timeout=conf.timeout, **extra_config_dict, |
| 508 | + **ssl_args) as conn, conn.cursor() as cursor: |
531 | 509 | cursor.execute(sql, (p1, p2)) |
532 | 510 | res = cursor.fetchall() |
533 | 511 | res_list = [ColumnSchema(*item) for item in res] |
@@ -684,7 +662,8 @@ def exec_sql(ds: CoreDatasource | AssistantOutDsSchema, sql: str, origin_column= |
684 | 662 | ssl_args = {'ssl': {'ssl_mode': 'REQUIRE'}} if conf.ssl else {} |
685 | 663 | with pymysql.connect(user=conf.username, passwd=conf.password, host=conf.host, |
686 | 664 | port=conf.port, db=conf.database, connect_timeout=conf.timeout, |
687 | | - read_timeout=conf.timeout, **extra_config_dict, **ssl_args) as conn, conn.cursor() as cursor: |
| 665 | + read_timeout=conf.timeout, **extra_config_dict, |
| 666 | + **ssl_args) as conn, conn.cursor() as cursor: |
688 | 667 | try: |
689 | 668 | cursor.execute(sql) |
690 | 669 | res = cursor.fetchall() |
|
0 commit comments