oceanbase-sqlalchemy 0.5.1__tar.gz → 0.7.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (22) hide show
  1. {oceanbase_sqlalchemy-0.5.1 → oceanbase_sqlalchemy-0.7.0}/PKG-INFO +1 -1
  2. {oceanbase_sqlalchemy-0.5.1 → oceanbase_sqlalchemy-0.7.0}/oceanbase_sqlalchemy/cx_oracle.py +53 -7
  3. {oceanbase_sqlalchemy-0.5.1 → oceanbase_sqlalchemy-0.7.0}/oceanbase_sqlalchemy.egg-info/PKG-INFO +1 -1
  4. {oceanbase_sqlalchemy-0.5.1 → oceanbase_sqlalchemy-0.7.0}/setup.py +1 -1
  5. {oceanbase_sqlalchemy-0.5.1 → oceanbase_sqlalchemy-0.7.0}/LICENSE +0 -0
  6. {oceanbase_sqlalchemy-0.5.1 → oceanbase_sqlalchemy-0.7.0}/README.md +0 -0
  7. {oceanbase_sqlalchemy-0.5.1 → oceanbase_sqlalchemy-0.7.0}/oceanbase_sqlalchemy/__init__.py +0 -0
  8. {oceanbase_sqlalchemy-0.5.1 → oceanbase_sqlalchemy-0.7.0}/oceanbase_sqlalchemy/cx_oceanbase.py +0 -0
  9. {oceanbase_sqlalchemy-0.5.1 → oceanbase_sqlalchemy-0.7.0}/oceanbase_sqlalchemy/requirements.py +0 -0
  10. {oceanbase_sqlalchemy-0.5.1 → oceanbase_sqlalchemy-0.7.0}/oceanbase_sqlalchemy/utils.py +0 -0
  11. {oceanbase_sqlalchemy-0.5.1 → oceanbase_sqlalchemy-0.7.0}/oceanbase_sqlalchemy.egg-info/SOURCES.txt +0 -0
  12. {oceanbase_sqlalchemy-0.5.1 → oceanbase_sqlalchemy-0.7.0}/oceanbase_sqlalchemy.egg-info/dependency_links.txt +0 -0
  13. {oceanbase_sqlalchemy-0.5.1 → oceanbase_sqlalchemy-0.7.0}/oceanbase_sqlalchemy.egg-info/entry_points.txt +0 -0
  14. {oceanbase_sqlalchemy-0.5.1 → oceanbase_sqlalchemy-0.7.0}/oceanbase_sqlalchemy.egg-info/not-zip-safe +0 -0
  15. {oceanbase_sqlalchemy-0.5.1 → oceanbase_sqlalchemy-0.7.0}/oceanbase_sqlalchemy.egg-info/requires.txt +0 -0
  16. {oceanbase_sqlalchemy-0.5.1 → oceanbase_sqlalchemy-0.7.0}/oceanbase_sqlalchemy.egg-info/top_level.txt +0 -0
  17. {oceanbase_sqlalchemy-0.5.1 → oceanbase_sqlalchemy-0.7.0}/setup.cfg +0 -0
  18. {oceanbase_sqlalchemy-0.5.1 → oceanbase_sqlalchemy-0.7.0}/test/__init__.py +0 -0
  19. {oceanbase_sqlalchemy-0.5.1 → oceanbase_sqlalchemy-0.7.0}/test/conftest.py +0 -0
  20. {oceanbase_sqlalchemy-0.5.1 → oceanbase_sqlalchemy-0.7.0}/test/test_basic.py +0 -0
  21. {oceanbase_sqlalchemy-0.5.1 → oceanbase_sqlalchemy-0.7.0}/test/test_optimization.py +0 -0
  22. {oceanbase_sqlalchemy-0.5.1 → oceanbase_sqlalchemy-0.7.0}/test/test_suite.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: oceanbase-sqlalchemy
3
- Version: 0.5.1
3
+ Version: 0.7.0
4
4
  Summary: SQLAlchemy dialect for OceanBase Oracle mode (supports SQLAlchemy 1.3.x and 2.0+)
5
5
  Home-page: https://github.com/oceanbase/ecology-plugins
6
6
  Author: OceanBase Team
@@ -3,7 +3,11 @@
3
3
  OceanBase dialect for cx_oracle driver.
4
4
  """
5
5
 
6
- from sqlalchemy.dialects.oracle.cx_oracle import OracleDialect_cx_oracle
6
+ from sqlalchemy.dialects.oracle.cx_oracle import (
7
+ OracleDialect_cx_oracle,
8
+ OracleCompiler_cx_oracle,
9
+ )
10
+ from sqlalchemy.dialects.oracle.base import OracleCompiler
7
11
  from sqlalchemy import select, and_, or_, bindparam, sql
8
12
  from functools import lru_cache
9
13
  from sqlalchemy.engine import reflection
@@ -19,6 +23,44 @@ if SA_20_PLUS:
19
23
  from sqlalchemy.dialects.oracle import dictionary
20
24
 
21
25
 
26
+ class OceanBaseCompiler_cx_oracle(OracleCompiler_cx_oracle):
27
+ """
28
+ Custom compiler for OceanBase to handle bind parameter naming.
29
+
30
+ OceanBase does not support quoted bind parameter names (e.g., :"start")
31
+ like Oracle does. This compiler disables bind parameter quoting and
32
+ normalizes numeric-leading parameter names to match SQLAlchemy 2.0 behavior.
33
+ """
34
+
35
+ def bindparam_string(self, name, **kw):
36
+ """
37
+ Override bindparam_string to disable quoting and normalize parameter names.
38
+
39
+ Issues:
40
+ 1. SQLAlchemy's Oracle dialect quotes bind parameter names that are
41
+ reserved words (e.g., :start becomes :"start"). Oracle supports this,
42
+ but OceanBase raises OBE-01036: illegal variable name/number.
43
+ 2. SQLAlchemy 1.3 doesn't handle numeric-leading parameter names
44
+ (e.g., :123start), but SQLAlchemy 2.0+ does (converts to :D123start).
45
+
46
+ Solution:
47
+ 1. Skip the quoting branch entirely (don't quote reserved words)
48
+ 2. Normalize parameter names that start with digits or underscores
49
+ by prefixing with "D" (following SQLAlchemy 2.0 convention)
50
+ """
51
+ # Step 1: Normalize parameter names (handle numeric/underscore prefixes)
52
+ # Only for SQLAlchemy 2.x, as 1.3 doesn't handle this and will cause errors
53
+ if SA_20_PLUS:
54
+ escaped_from = kw.get("escaped_from", None)
55
+ if not escaped_from:
56
+ if name and (name[0].isdigit() or name[0] == "_"):
57
+ new_name = "D" + name
58
+ kw["escaped_from"] = name
59
+ name = new_name
60
+
61
+ return OracleCompiler.bindparam_string(self, name, **kw)
62
+
63
+
22
64
  class OceanBaseDialect_cx_oracle(OracleDialect_cx_oracle):
23
65
  """
24
66
  OceanBase dialect for cx_oracle driver.
@@ -27,6 +69,9 @@ class OceanBaseDialect_cx_oracle(OracleDialect_cx_oracle):
27
69
  name = "oceanbase"
28
70
  driver = "cx_oracle"
29
71
 
72
+ # Use custom compiler that doesn't quote bind parameter names
73
+ statement_compiler = OceanBaseCompiler_cx_oracle
74
+
30
75
  def __init__(self, **kwargs):
31
76
  super().__init__(**kwargs)
32
77
 
@@ -60,17 +105,18 @@ class OceanBaseDialect_cx_oracle(OracleDialect_cx_oracle):
60
105
  """
61
106
  Get OceanBase server version information
62
107
 
63
- Issue: cx_Oceanbase driver returns "0.0.0.0.1" for connection.version,
108
+ Issue1: cx_Oceanbase driver returns "0.0.0.0.1" for connection.version,
64
109
  causing SQLAlchemy to misidentify it as Oracle 8 and set supports_unicode_binds to False,
65
110
  which encodes all string parameters as bytes, resulting in NVARCHAR2 query failures.
66
111
 
67
- Solution: Extract the real OceanBase version number from v$version banner.
112
+ Issue2: Hard-code a pre-12c version so SQLAlchemy will not try to query
113
+ Oracle-only dictionary views such as ALL_TAB_IDENTITY_COLS, which
114
+ OceanBase does not implement. Unicode bind support is forced on in
115
+ initialize(), so we do not rely on the reported version for that.
116
+ _column_query() in base.py will fail with ORA-00942: table or view does not exist.
68
117
  """
69
118
 
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)
119
+ return (11, 2, 0, 0)
74
120
 
75
121
  def initialize(self, connection):
76
122
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: oceanbase-sqlalchemy
3
- Version: 0.5.1
3
+ Version: 0.7.0
4
4
  Summary: SQLAlchemy dialect for OceanBase Oracle mode (supports SQLAlchemy 1.3.x and 2.0+)
5
5
  Home-page: https://github.com/oceanbase/ecology-plugins
6
6
  Author: OceanBase Team
@@ -5,7 +5,7 @@ from setuptools import setup, find_packages
5
5
 
6
6
  setup(
7
7
  name="oceanbase-sqlalchemy",
8
- version="0.5.1",
8
+ version="0.7.0",
9
9
  description="SQLAlchemy dialect for OceanBase Oracle mode (supports SQLAlchemy 1.3.x and 2.0+)",
10
10
  long_description=open("README.md", "r", encoding="utf-8").read(),
11
11
  long_description_content_type="text/markdown",