@@ -56,7 +56,37 @@ def create_connect_args(self, url):
5656
5757 return super ().create_connect_args (url )
5858
59- @reflection .cache
59+ def _get_server_version_info (self , connection ):
60+ """
61+ Get OceanBase server version information
62+
63+ Issue: cx_Oceanbase driver returns "0.0.0.0.1" for connection.version,
64+ causing SQLAlchemy to misidentify it as Oracle 8 and set supports_unicode_binds to False,
65+ which encodes all string parameters as bytes, resulting in NVARCHAR2 query failures.
66+
67+ Solution: Extract the real OceanBase version number from v$version banner.
68+ """
69+
70+ # Fallback: Return a reasonable default version
71+ # Note: Due to Python tuple comparison (4, x, x) < (9,) evaluates to True
72+ # Use (21, 0, 0, 0, 0) to simulate Oracle 21g, ensuring it won't be misidentified as Oracle 8
73+ return (21 , 0 , 0 , 0 , 0 )
74+
75+ def initialize (self , connection ):
76+ """
77+ Initialize dialect to ensure OceanBase uses Unicode string binding
78+
79+ OceanBase is compatible with Oracle 10g+, supporting Unicode binding.
80+ Even if the version number might be misjudged, force enable supports_unicode_binds.
81+ """
82+ # Call parent class initialization
83+ super ().initialize (connection )
84+
85+ # Force enable Unicode binding support
86+ # OceanBase fully supports Unicode and should not use bytes encoding
87+ self .supports_unicode_binds = True
88+
89+ @reflection .cache ()
6090 def _get_constraint_data (
6191 self , connection , table_name , schema = None , dblink = "" , ** kw
6292 ):
0 commit comments