GBase 8s开发与管理 - 使用sqlalchemy-gbasedbt连接GBase 8s数据库 的评论
测试环境：操作系统：CentOS 7.9 64-bit数据库版本：GBase8sV8.8_AEE_3.0.0_1，对应的CSDK版本为3.0.0_11，确认安装python3确认已经安装pyth...
什么叫python版本太高，就是跟着你的文章建的虚拟环境，python==3.6.8
我使用python3.12.10时，连接gabse8s V8.8该使用哪种连接方式，最好还能兼容sqlalchemy
还不支持py3.12。 如果你的数据库是363,可以使用gbase8s-sqlalchemy(依赖gbase8sdb,sqlalchemy~=2.0.0).
连接信息 from sqlalchemy import create_engine from contextlib import contextmanager from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker, scoped_session from sqlalchemy.dialects import registry from config.finalparam import FinalParamfrom utils.Loging import LOGGINGfrom utils.common import get_yaml registry.register("gbasedbt", "sqlalchemy_gbasedbt.dbtdb", "GBasedbtDialect") # DATABASE_CONFIG_YML = "../config/gw_database_config.yaml" DATABASE_CONFIG_YML = "../config/database_config.yaml" DATABASE_CONFIG_YML = FinalParam.DATABASE_CONFIG_YML cfg = get_yaml(DATABASE_CONFIG_YML) # print(type(cfg)) host = cfg['host'] port = cfg['port'] user = cfg['user'] password = cfg['password'] database = cfg['database'] Base = declarative_base() engine = create_engine( "gbasedbt://%s:%s@%s:%s/%s" % (user, password, host, port, database)+";SERVER=gbase01;DB_LOCALE=zh_CN.utf8;CLIENT_LOCALE=zh_CN.utf8;DELIMIDENT=y", # encoding='utf-8', # echo=True, # SQL 语句及其参数到控制台 pool_pre_ping=True, # 检测断开连接 pool_recycle=1800, # 每30分钟重新创建连接，避免超时 pool_size=3, # 连接池中最多可以保持的连接数 max_overflow=4, # 允许在需要时，连接池外再创建最多 4 个额外的连接，超出连接池大小的部分会在使用后关闭 # pool_recycle=7200, # 表示连接在 7200 秒（2 小时）后会被回收，避免因长时间连接而导致的问题（例如，MySQL 的“互动超时”） # pool_timeout=30 # 连接池的超时时间，表示如果在 30 秒内没有获取到可用的连接，将会抛出异常 )Base.metadata.create_all(engine) Session = sessionmaker(bind=engine) 报错信息 File "/work/audioTrace_screenCorrect0605-kylin/dao/screen_correct_mapper.py", line 2, in from dao.databaseConnector import Connector File "/work/audioTrace_screenCorrect0605-kylin/dao/databaseConnector.py", line 23, in engine = create_engine( ^^^^^^^^^^^^^^ File "", line 2, in create_engine File "/usr/local/lib/python3.12/site-packages/sqlalchemy/util/deprecations.py", line 375, in warned return fn(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/sqlalchemy/engine/create.py", line 518, in create_engine entrypoint = u._get_entrypoint() ^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/sqlalchemy/engine/url.py", line 662, in _get_entrypoint cls = registry.load(name) ^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/sqlalchemy/util/langhelpers.py", line 330, in load return self.impls[name]() ^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/sqlalchemy/util/langhelpers.py", line 349, in load mod = compat.import_(modulepath) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/sqlalchemy_gbasedbt/dbtdb.py", line 7, in import DbtPyDbi as Database File "/usr/local/lib/python3.12/site-packages/DbtPyDbi.py", line 44, in import DbtPy ImportError: /usr/local/lib/python3.12/site-packages/DbtPy.cpython-312-x86_64-linux-gnu.so: undefined symbol: PyUnicode_FromUnicode