Skip to content

Commit d958512

Browse files
committed
feat:修复人大金仓接入的 bug
1 parent 568ebd1 commit d958512

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

rookie_text2data.difypkg

29 Bytes
Binary file not shown.

utils/alchemy_db_client.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,22 @@
66
import logging
77
import time
88

9-
# 导入自定义方言以注册到 SQLAlchemy
9+
# 导入自定义方言模块,触发方言注册
10+
# 这些导入是必需的,即使看起来未使用,因为它们会在导入时注册自定义方言
1011
try:
11-
from .gaussdb_dialect import GaussDBDialect
12-
from .kingbase_dialect import KingbaseESDialect
13-
from .dm_dialect import DMDialect
12+
from utils import gaussdb_dialect
1413
except ImportError:
15-
pass # 如果导入失败,使用标准方言
14+
pass
15+
16+
try:
17+
from utils import dm_dialect
18+
except ImportError:
19+
pass
20+
21+
try:
22+
from utils import kingbase_dialect
23+
except ImportError:
24+
pass
1625

1726
# 配置日志
1827
logging.basicConfig(
@@ -265,8 +274,8 @@ def _get_driver(db_type: str) -> str:
265274
'sqlserver': 'pymssql',
266275
'postgresql': 'psycopg2',
267276
'gaussdb': 'psycopg', # 仅 GaussDB 使用 psycopg3,避免版本解析问题
268-
'kingbase': 'psycopg2', # 人大金仓使用 psycopg2 驱动(兼容 PostgreSQL
269-
'dm': 'dmPython' # 达梦数据库使用专用的 dmPython 驱动
277+
'dm': 'oracledb', # 达梦数据库使用 oracledb 驱动(兼容 Oracle 协议
278+
'kingbase': 'psycopg2' # 人大金仓使用 psycopg2 驱动(兼容 PostgreSQL 协议)
270279
}
271280
return drivers.get(db_type.lower(), '')
272281

@@ -285,18 +294,18 @@ def _build_connection_uri(
285294
if db_type == 'sqlserver':
286295
db_type = 'mssql'
287296
elif db_type == 'gaussdb':
288-
# GaussDB 使用自定义方言来处理版本解析问题
297+
# GaussDB 使用 postgresql 协议
289298
# 只禁用 SSL,保留 SCRAM-SHA-256 等认证方式的支持
290-
return f"gaussdb+{driver}://{username}:{password}@{host}:{port}/{database}?sslmode=disable"
299+
db_type = 'postgresql'
300+
return f"{db_type}+{driver}://{username}:{password}@{host}:{port}/{database}?sslmode=disable"
291301
elif db_type == 'kingbase':
292-
# KingbaseES 使用自定义方言来处理版本解析问题
293-
# 人大金仓数据库兼容 PostgreSQL 协议
294-
return f"kingbase+{driver}://{username}:{password}@{host}:{port}/{database}"
302+
# KingbaseES 使用自定义方言(兼容 PostgreSQL 协议)
303+
# 使用已注册的 kingbase 方言
304+
return f"{db_type}+{driver}://{username}:{password}@{host}:{port}/{database}"
295305
elif db_type == 'dm':
296-
# 达梦数据库使用专用的 dmPython 驱动和 dm 方言
297-
# 格式:dm+dmPython://user:pass@host:port/schema
298-
# database 参数在达梦中表示 schema
299-
return f"dm+{driver}://{username}:{password}@{host}:{port}/{database}"
306+
# 达梦数据库使用 Oracle 驱动(兼容 Oracle 协议)
307+
# 格式:oracle+oracledb://user:pass@host:port/?service_name=SYSDBA
308+
return f"oracle+{driver}://{username}:{password}@{host}:{port}/?service_name=SYSDBA"
300309

301310
return f"{db_type}+{driver}://{username}:{password}@{host}:{port}/{database}"
302311

0 commit comments

Comments
 (0)