dmpython-jdbc 2.5.32__tar.gz → 2.5.32.post1__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 (21) hide show
  1. {dmpython_jdbc-2.5.32 → dmpython_jdbc-2.5.32.post1}/MANIFEST.in +3 -0
  2. dmpython_jdbc-2.5.32.post1/PKG-INFO +116 -0
  3. dmpython_jdbc-2.5.32.post1/README.md +93 -0
  4. dmpython_jdbc-2.5.32/dmpython_jdbc.egg-info/PKG-INFO → dmpython_jdbc-2.5.32.post1/README.zh-CN.md +38 -23
  5. {dmpython_jdbc-2.5.32 → dmpython_jdbc-2.5.32.post1}/_dmPython_jdbc/__init__.py +52 -48
  6. dmpython_jdbc-2.5.32.post1/_dmpython_metadata.py +27 -0
  7. {dmpython_jdbc-2.5.32 → dmpython_jdbc-2.5.32.post1}/dmPython.py +5 -2
  8. dmpython_jdbc-2.5.32.post1/dmpython-2.5.32.dist-info/METADATA +4 -0
  9. dmpython_jdbc-2.5.32.post1/dmpython_jdbc.egg-info/PKG-INFO +116 -0
  10. {dmpython_jdbc-2.5.32 → dmpython_jdbc-2.5.32.post1}/dmpython_jdbc.egg-info/SOURCES.txt +4 -0
  11. {dmpython_jdbc-2.5.32 → dmpython_jdbc-2.5.32.post1}/dmpython_jdbc.egg-info/top_level.txt +1 -0
  12. {dmpython_jdbc-2.5.32 → dmpython_jdbc-2.5.32.post1}/pyproject.toml +2 -2
  13. dmpython_jdbc-2.5.32.post1/setup.py +15 -0
  14. dmpython_jdbc-2.5.32/PKG-INFO +0 -78
  15. dmpython_jdbc-2.5.32/README.md +0 -55
  16. {dmpython_jdbc-2.5.32 → dmpython_jdbc-2.5.32.post1}/LICENSE +0 -0
  17. {dmpython_jdbc-2.5.32 → dmpython_jdbc-2.5.32.post1}/NOTICE +0 -0
  18. {dmpython_jdbc-2.5.32 → dmpython_jdbc-2.5.32.post1}/_dmPython_jdbc/DmJdbcDriver18-8.1.3.140.jar +0 -0
  19. {dmpython_jdbc-2.5.32 → dmpython_jdbc-2.5.32.post1}/dmpython_jdbc.egg-info/dependency_links.txt +0 -0
  20. {dmpython_jdbc-2.5.32 → dmpython_jdbc-2.5.32.post1}/dmpython_jdbc.egg-info/requires.txt +0 -0
  21. {dmpython_jdbc-2.5.32 → dmpython_jdbc-2.5.32.post1}/setup.cfg +0 -0
@@ -1,5 +1,8 @@
1
1
  include README.md
2
+ include README.zh-CN.md
2
3
  include LICENSE
3
4
  include NOTICE
4
5
  include pyproject.toml
5
6
  recursive-include _dmPython_jdbc *.jar
7
+ recursive-include dmpython-2.5.32.dist-info *
8
+ include setup.py
@@ -0,0 +1,116 @@
1
+ Metadata-Version: 2.4
2
+ Name: dmpython-jdbc
3
+ Version: 2.5.32.post1
4
+ Summary: macOS dmPython compatibility shim backed by JayDeBeApi
5
+ Author-email: Darley <darley.wey@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/Darley-Wey/dmpython-jdbc
8
+ Project-URL: Repository, https://github.com/Darley-Wey/dmpython-jdbc
9
+ Project-URL: Issues, https://github.com/Darley-Wey/dmpython-jdbc/issues
10
+ Keywords: dameng,dmPython,jdbc,macos
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: MacOS
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Topic :: Database
18
+ Requires-Python: >=3.12
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: JayDeBeApi>=1.2.3
22
+ Dynamic: license-file
23
+
24
+ # dmpython-jdbc
25
+
26
+ [English](README.md) | [简体中文](README.zh-CN.md)
27
+
28
+ macOS compatibility layer for Dameng `dmPython`. Dameng does not ship a macOS driver, so this package implements a DBAPI subset with JayDeBeApi + Dameng JDBC and makes dmSQLAlchemy's `dm+dmPython://` dialect work locally.
29
+
30
+ **The distribution name is `dmpython-jdbc`; the import name remains `dmPython`.** Application code does not need to change.
31
+
32
+ - macOS: use this package's JDBC shim
33
+ - Other platforms: forward `import dmPython` to the official driver
34
+
35
+ ## Install
36
+
37
+ PyPI:
38
+
39
+ ```bash
40
+ pip install dmpython-jdbc
41
+ ```
42
+
43
+ Cross-platform projects (official driver on Linux/Windows, this package on macOS):
44
+
45
+ ```toml
46
+ [project]
47
+ dependencies = [
48
+ "dmpython>=2.5.32; sys_platform != 'darwin'",
49
+ "dmpython-jdbc>=2.5.32; sys_platform == 'darwin'",
50
+ ]
51
+ ```
52
+
53
+ If the project also depends on `dmSQLAlchemy`, see [Using with dmSQLAlchemy](#using-with-dmsqlalchemy). That package pulls official `dmpython` unconditionally.
54
+
55
+ From GitHub:
56
+
57
+ ```bash
58
+ pip install "dmpython-jdbc @ git+https://github.com/Darley-Wey/dmpython-jdbc.git"
59
+ ```
60
+
61
+ uv:
62
+
63
+ ```toml
64
+ [tool.uv.sources]
65
+ dmpython-jdbc = { git = "https://github.com/Darley-Wey/dmpython-jdbc.git" }
66
+ ```
67
+
68
+ Pin a commit or tag by appending `@<ref>`, for example `@main` or `@v2.5.32`.
69
+
70
+ ## Runtime requirements
71
+
72
+ - Python >= 3.12
73
+ - JDK (`brew install openjdk` on macOS). `JAVA_HOME` is probed at `/opt/homebrew/opt/openjdk` and `/usr/local/opt/openjdk`
74
+ - The Dameng JDBC driver is bundled in the wheel; override it with `DM_JDBC_JAR`
75
+
76
+
77
+ ## Using with dmSQLAlchemy
78
+
79
+ `dmSQLAlchemy` unconditionally depends on official `dmpython` (`Requires-Dist: dmPython`). That package has no macOS wheel, so `pip install dmSQLAlchemy` on a Mac will try to install Dameng's driver and fail.
80
+
81
+ Keep `dmSQLAlchemy`, prevent the resolver from installing official `dmpython` on macOS, and install `dmpython-jdbc` instead. The import name stays `dmPython`.
82
+
83
+ ### uv
84
+
85
+ ```toml
86
+ [project]
87
+ dependencies = [
88
+ "dmsqlalchemy",
89
+ "dmpython>=2.5.32; sys_platform != 'darwin'",
90
+ "dmpython-jdbc>=2.5.32; sys_platform == 'darwin'",
91
+ ]
92
+
93
+ [tool.uv]
94
+ override-dependencies = [
95
+ "dmpython ; sys_platform != 'darwin'",
96
+ ]
97
+ ```
98
+
99
+ `override-dependencies` rewrites `dmSQLAlchemy`'s `dmpython` requirement so it is skipped on macOS. `dmpython-jdbc` then provides the `dmPython` module.
100
+
101
+ `dmSQLAlchemy.extensions` calls `importlib.metadata.version("dmPython")`. This package installs a `.pth` hook so that lookup returns the shim version `2.5.32` without needing setuptools/`pkg_resources`.
102
+
103
+ ### pip on macOS
104
+
105
+ ```bash
106
+ pip install "dmSQLAlchemy" --no-deps
107
+ pip install "SQLAlchemy>1.4.54" dmpython-jdbc
108
+ ```
109
+
110
+ ## Limits
111
+
112
+ Stored-procedure OUT binds (`cursor.var`) and streaming LOB I/O are not supported. ORM CRUD is covered.
113
+
114
+ ## License
115
+
116
+ The Python shim is MIT. `DmJdbcDriver18-*.jar` is Dameng's official JDBC driver and is not covered by MIT.
@@ -0,0 +1,93 @@
1
+ # dmpython-jdbc
2
+
3
+ [English](README.md) | [简体中文](README.zh-CN.md)
4
+
5
+ macOS compatibility layer for Dameng `dmPython`. Dameng does not ship a macOS driver, so this package implements a DBAPI subset with JayDeBeApi + Dameng JDBC and makes dmSQLAlchemy's `dm+dmPython://` dialect work locally.
6
+
7
+ **The distribution name is `dmpython-jdbc`; the import name remains `dmPython`.** Application code does not need to change.
8
+
9
+ - macOS: use this package's JDBC shim
10
+ - Other platforms: forward `import dmPython` to the official driver
11
+
12
+ ## Install
13
+
14
+ PyPI:
15
+
16
+ ```bash
17
+ pip install dmpython-jdbc
18
+ ```
19
+
20
+ Cross-platform projects (official driver on Linux/Windows, this package on macOS):
21
+
22
+ ```toml
23
+ [project]
24
+ dependencies = [
25
+ "dmpython>=2.5.32; sys_platform != 'darwin'",
26
+ "dmpython-jdbc>=2.5.32; sys_platform == 'darwin'",
27
+ ]
28
+ ```
29
+
30
+ If the project also depends on `dmSQLAlchemy`, see [Using with dmSQLAlchemy](#using-with-dmsqlalchemy). That package pulls official `dmpython` unconditionally.
31
+
32
+ From GitHub:
33
+
34
+ ```bash
35
+ pip install "dmpython-jdbc @ git+https://github.com/Darley-Wey/dmpython-jdbc.git"
36
+ ```
37
+
38
+ uv:
39
+
40
+ ```toml
41
+ [tool.uv.sources]
42
+ dmpython-jdbc = { git = "https://github.com/Darley-Wey/dmpython-jdbc.git" }
43
+ ```
44
+
45
+ Pin a commit or tag by appending `@<ref>`, for example `@main` or `@v2.5.32`.
46
+
47
+ ## Runtime requirements
48
+
49
+ - Python >= 3.12
50
+ - JDK (`brew install openjdk` on macOS). `JAVA_HOME` is probed at `/opt/homebrew/opt/openjdk` and `/usr/local/opt/openjdk`
51
+ - The Dameng JDBC driver is bundled in the wheel; override it with `DM_JDBC_JAR`
52
+
53
+
54
+ ## Using with dmSQLAlchemy
55
+
56
+ `dmSQLAlchemy` unconditionally depends on official `dmpython` (`Requires-Dist: dmPython`). That package has no macOS wheel, so `pip install dmSQLAlchemy` on a Mac will try to install Dameng's driver and fail.
57
+
58
+ Keep `dmSQLAlchemy`, prevent the resolver from installing official `dmpython` on macOS, and install `dmpython-jdbc` instead. The import name stays `dmPython`.
59
+
60
+ ### uv
61
+
62
+ ```toml
63
+ [project]
64
+ dependencies = [
65
+ "dmsqlalchemy",
66
+ "dmpython>=2.5.32; sys_platform != 'darwin'",
67
+ "dmpython-jdbc>=2.5.32; sys_platform == 'darwin'",
68
+ ]
69
+
70
+ [tool.uv]
71
+ override-dependencies = [
72
+ "dmpython ; sys_platform != 'darwin'",
73
+ ]
74
+ ```
75
+
76
+ `override-dependencies` rewrites `dmSQLAlchemy`'s `dmpython` requirement so it is skipped on macOS. `dmpython-jdbc` then provides the `dmPython` module.
77
+
78
+ `dmSQLAlchemy.extensions` calls `importlib.metadata.version("dmPython")`. This package installs a `.pth` hook so that lookup returns the shim version `2.5.32` without needing setuptools/`pkg_resources`.
79
+
80
+ ### pip on macOS
81
+
82
+ ```bash
83
+ pip install "dmSQLAlchemy" --no-deps
84
+ pip install "SQLAlchemy>1.4.54" dmpython-jdbc
85
+ ```
86
+
87
+ ## Limits
88
+
89
+ Stored-procedure OUT binds (`cursor.var`) and streaming LOB I/O are not supported. ORM CRUD is covered.
90
+
91
+ ## License
92
+
93
+ The Python shim is MIT. `DmJdbcDriver18-*.jar` is Dameng's official JDBC driver and is not covered by MIT.
@@ -1,28 +1,7 @@
1
- Metadata-Version: 2.4
2
- Name: dmpython-jdbc
3
- Version: 2.5.32
4
- Summary: macOS dmPython compatibility shim backed by JayDeBeApi
5
- Author-email: Darley <darley.wey@gmail.com>
6
- License-Expression: MIT
7
- Project-URL: Homepage, https://github.com/Darley-Wey/dmpython-jdbc
8
- Project-URL: Repository, https://github.com/Darley-Wey/dmpython-jdbc
9
- Project-URL: Issues, https://github.com/Darley-Wey/dmpython-jdbc/issues
10
- Keywords: dameng,dmPython,jdbc,macos
11
- Classifier: Development Status :: 4 - Beta
12
- Classifier: Intended Audience :: Developers
13
- Classifier: Operating System :: MacOS
14
- Classifier: Programming Language :: Python :: 3
15
- Classifier: Programming Language :: Python :: 3.12
16
- Classifier: Programming Language :: Python :: 3.13
17
- Classifier: Topic :: Database
18
- Requires-Python: >=3.12
19
- Description-Content-Type: text/markdown
20
- License-File: LICENSE
21
- Requires-Dist: JayDeBeApi>=1.2.3
22
- Dynamic: license-file
23
-
24
1
  # dmpython-jdbc
25
2
 
3
+ [English](README.md) | [简体中文](README.zh-CN.md)
4
+
26
5
  macOS 上的达梦 `dmPython` 兼容层。官方驱动没有 macOS 版,这里用 JayDeBeApi + 达梦 JDBC 实现 DBAPI 子集,让 `dmSQLAlchemy` 的 `dm+dmPython://` 方言能在本机跑起来。
27
6
 
28
7
  **发行名是 `dmpython-jdbc`,import 名仍是 `dmPython`。** 业务代码不用改。
@@ -48,6 +27,8 @@ dependencies = [
48
27
  ]
49
28
  ```
50
29
 
30
+ 如果项目还依赖 `dmSQLAlchemy`,见 [配合 dmSQLAlchemy](#配合-dmsqlalchemy)。该包会无条件拉取官方 `dmpython`。
31
+
51
32
  从 GitHub 安装:
52
33
 
53
34
  ```bash
@@ -69,6 +50,40 @@ dmpython-jdbc = { git = "https://github.com/Darley-Wey/dmpython-jdbc.git" }
69
50
  - JDK(macOS 可用 `brew install openjdk`)。`JAVA_HOME` 会自动探测 `/opt/homebrew/opt/openjdk` 和 `/usr/local/opt/openjdk`
70
51
  - 达梦 JDBC 驱动已打包进 wheel;也可用环境变量 `DM_JDBC_JAR` 覆盖
71
52
 
53
+
54
+ ## 配合 dmSQLAlchemy
55
+
56
+ `dmSQLAlchemy` 无条件依赖官方 `dmpython`(`Requires-Dist: dmPython`)。该包没有 macOS wheel,所以在 Mac 上 `pip install dmSQLAlchemy` 会尝试装达梦官方驱动并失败。
57
+
58
+ 要保留 `dmSQLAlchemy`,又阻止解析器在 macOS 上装官方 `dmpython`,改装 `dmpython-jdbc`。import 名仍是 `dmPython`。
59
+
60
+ ### uv
61
+
62
+ ```toml
63
+ [project]
64
+ dependencies = [
65
+ "dmsqlalchemy",
66
+ "dmpython>=2.5.32; sys_platform != 'darwin'",
67
+ "dmpython-jdbc>=2.5.32; sys_platform == 'darwin'",
68
+ ]
69
+
70
+ [tool.uv]
71
+ override-dependencies = [
72
+ "dmpython ; sys_platform != 'darwin'",
73
+ ]
74
+ ```
75
+
76
+ `override-dependencies` 会改写 `dmSQLAlchemy` 对 `dmpython` 的依赖,让它在 macOS 上被跳过;然后由 `dmpython-jdbc` 提供 `dmPython` 模块。
77
+
78
+ `dmSQLAlchemy.extensions` 会调用 `importlib.metadata.version("dmPython")`。本包会安装 `.pth` 钩子,让这次查询返回 shim 版本 `2.5.32`,不依赖 setuptools/`pkg_resources`。
79
+
80
+ ### macOS 上的 pip
81
+
82
+ ```bash
83
+ pip install "dmSQLAlchemy" --no-deps
84
+ pip install "SQLAlchemy>1.4.54" dmpython-jdbc
85
+ ```
86
+
72
87
  ## 限制
73
88
 
74
89
  不支持存储过程出参(`cursor.var`)、LOB 流式读写等高级特性,覆盖 ORM CRUD 即可。
@@ -1,16 +1,16 @@
1
1
  """
2
- dmPython 兼容 shim(仅 macOS 本地开发用)。
2
+ dmPython-compatible shim for local macOS development.
3
3
 
4
- 达梦官方没有 macOS 版 dmPython(缺少 libdmdpi 闭源库无法本地编译),
5
- 本模块用 JayDeBeApi + DmJdbcDriver 实现 dmPython 的 DBAPI 子集,
6
- 让 dmSQLAlchemy 的 `dm+dmPython://` 方言在 mac 上可用。
4
+ Dameng does not ship a macOS dmPython build (libdmdpi is closed-source),
5
+ so this module implements a DBAPI subset with JayDeBeApi + DmJdbcDriver
6
+ and makes dmSQLAlchemy's `dm+dmPython://` dialect usable on Mac.
7
7
 
8
- 依赖:
9
- - pip/uv 安装本包时会自动拉 JayDeBeApi(jpype1 会一并安装)
10
- - brew install openjdk (JAVA_HOME 自动探测 /opt/homebrew/opt/openjdk)
11
- - 达梦 JDBC 驱动 jar 已随包发布;可用环境变量 DM_JDBC_JAR 覆盖
8
+ Dependencies:
9
+ - JayDeBeApi is installed with this package (JPype1 comes with it)
10
+ - brew install openjdk (JAVA_HOME is probed at /opt/homebrew/opt/openjdk)
11
+ - Dameng JDBC driver JAR is packaged; override with DM_JDBC_JAR
12
12
 
13
- 限制: 不支持存储过程出参(cursor.var)、LOB 流式读写等高级特性, 满足 ORM CRUD 即可。
13
+ Limits: no cursor.var / OUT binds, no streaming LOB I/O. ORM CRUD is enough.
14
14
  """
15
15
  import datetime as _datetime
16
16
  import glob
@@ -18,13 +18,13 @@ import os
18
18
  import re
19
19
  import sys
20
20
 
21
- version = "2.5.32" # 伪装成官方版本号, dmSQLAlchemy 会解析它
21
+ version = "2.5.32" # spoof the official version; dmSQLAlchemy parses it
22
22
  apilevel = "2.0"
23
23
  threadsafety = 1
24
- paramstyle = "qmark" # 编译成 ? 占位符, 与 JDBC 原生一致; dialect do_execute 也按位置索引参数
24
+ paramstyle = "qmark" # compiled to JDBC `?`; dialect do_execute uses positional binds
25
25
 
26
26
 
27
- # ---------------------------------------------------------------- 异常体系
27
+ # ---------------------------------------------------------------- exceptions
28
28
  class Warning(Exception): pass
29
29
  class Error(Exception): pass
30
30
  class InterfaceError(Error): pass
@@ -37,9 +37,9 @@ class ProgrammingError(DatabaseError): pass
37
37
  class NotSupportedError(DatabaseError): pass
38
38
 
39
39
 
40
- # ---------------------------------------------------------------- 类型哨兵
41
- # 官方 dmPython 中这些符号本身是类, dmSQLAlchemy 会拿来做 isinstance 判断
42
- # (如 isinstance(value, dialect.dbapi.LOB)), 所以必须是类而不是实例。
40
+ # ---------------------------------------------------------------- type sentinels
41
+ # Official dmPython exposes these as classes; dmSQLAlchemy uses isinstance
42
+ # (e.g. isinstance(value, dialect.dbapi.LOB)), so they must be types, not instances.
43
43
  class _DBType:
44
44
  def __init__(self, name):
45
45
  self.name = name
@@ -78,7 +78,7 @@ TupleCursor = _make_type("TupleCursor")
78
78
 
79
79
 
80
80
  def _jdbc_timestamp_to_datetime(result_set, column):
81
- """将 JDBC TIMESTAMP 转为与官方 dmPython 一致的 Python datetime。"""
81
+ """Convert a JDBC TIMESTAMP to the datetime shape official dmPython returns."""
82
82
  value = result_set.getTimestamp(column)
83
83
  if value is None:
84
84
  return None
@@ -100,7 +100,7 @@ def _find_jar():
100
100
  or sorted(glob.glob(os.path.join(base, "DmJdbcDriver*.jar")))
101
101
  if hits:
102
102
  return hits[-1]
103
- raise InterfaceError("找不到达梦 JDBC 驱动 jar, 请设置环境变量 DM_JDBC_JAR")
103
+ raise InterfaceError("Dameng JDBC driver JAR not found; set DM_JDBC_JAR")
104
104
 
105
105
 
106
106
  def _ensure_java_home():
@@ -112,7 +112,7 @@ def _ensure_java_home():
112
112
  return
113
113
 
114
114
 
115
- # :name 占位符 → JDBC '?' 占位符。跳过字符串字面量与 :: 转换。
115
+ # Rewrite :name binds to JDBC `?`, skipping string literals and `::` casts.
116
116
  _BIND_RE = re.compile(r"(?<![:\w]):([A-Za-z_][A-Za-z0-9_]*)")
117
117
 
118
118
 
@@ -123,12 +123,12 @@ def _named_to_qmark(sql):
123
123
  in_str = False
124
124
  i = 0
125
125
  buf = sql
126
- # 简单状态机: 单引号字符串内不做替换
126
+ # Skip replacements inside single-quoted string literals.
127
127
  result = []
128
128
  last = 0
129
129
  for m in _BIND_RE.finditer(sql):
130
130
  seg = sql[last:m.start()]
131
- # 统计该占位符之前未闭合的单引号数
131
+ # Odd number of quotes before this match means we are inside a string.
132
132
  if (sql[:m.start()].count("'") % 2) == 1:
133
133
  continue
134
134
  result.append(seg)
@@ -152,8 +152,9 @@ class Cursor:
152
152
  self._closed = False
153
153
 
154
154
  def _check_conn_open(self):
155
- # dmSQLAlchemy.is_disconnect 只把 InterfaceError("not connected") 判成断线;
156
- # 把 JDBC 的“连接尚未建立或已经关闭”映射成这一形态, 连接池才能自动丢弃旧连接并重建。
155
+ # dmSQLAlchemy.is_disconnect only treats InterfaceError("not connected")
156
+ # as a dropped connection. Map Dameng JDBC closed-connection errors to
157
+ # that shape so the pool can discard and reconnect.
157
158
  if self._closed or getattr(self._conn, "_closed", False):
158
159
  raise InterfaceError("not connected")
159
160
 
@@ -163,10 +164,10 @@ class Cursor:
163
164
  desc = self._cur.description
164
165
  if not desc:
165
166
  return desc
166
- # jaydebeapi 用 getColumnName(底层列名)而非 getColumnLabel(SQL 别名),
167
- # 会丢掉 `id as "tab_id"` 这类别名; 这里用 label 修正。
168
- # 另: DM 服务端把未加引号的标识符统一大写返回, 官方 dmPython 返回小写,
169
- # dmSQLAlchemy 反射代码按小写取列, 全大写时转小写保持一致。
167
+ # jaydebeapi uses getColumnName (physical name) instead of getColumnLabel
168
+ # (SQL alias), dropping aliases such as `id as "tab_id"`. Fix via label.
169
+ # Dameng also uppercases unquoted identifiers; official dmPython returns
170
+ # lowercase, and dmSQLAlchemy reflection looks up columns in lowercase.
170
171
  meta = getattr(self._cur, "_meta", None)
171
172
  names = []
172
173
  for i, d in enumerate(desc):
@@ -190,7 +191,7 @@ class Cursor:
190
191
  return operation, None
191
192
  if isinstance(parameters, (list, tuple)):
192
193
  return operation, list(parameters)
193
- # dict → named 转 qmark
194
+ # dict -> named binds rewritten as qmark
194
195
  sql, names = _named_to_qmark(operation)
195
196
  return sql, [parameters.get(n) for n in names]
196
197
 
@@ -201,6 +202,7 @@ class Cursor:
201
202
  self._cur.execute(sql, params)
202
203
  except Exception as e:
203
204
  msg = str(e)
205
+ # Dameng JDBC uses these Chinese phrases for a closed connection.
204
206
  if "尚未建立" in msg or "已经关闭" in msg or "not connected" in msg.lower() or "connection closed" in msg.lower():
205
207
  raise InterfaceError("not connected") from e
206
208
  raise DatabaseError(msg) from e
@@ -219,13 +221,14 @@ class Cursor:
219
221
  self._cur.executemany(sql, rows)
220
222
  except Exception as e:
221
223
  msg = str(e)
224
+ # Dameng JDBC uses these Chinese phrases for a closed connection.
222
225
  if "尚未建立" in msg or "已经关闭" in msg or "not connected" in msg.lower() or "connection closed" in msg.lower():
223
226
  raise InterfaceError("not connected") from e
224
227
  raise DatabaseError(msg) from e
225
228
  return self
226
229
 
227
230
  def _capture_identity(self, sql):
228
- # 仅 INSERT 后按需取自增值(get_lastrowid 会读取)
231
+ # Capture identity only after INSERT; lastrowid reads it lazily.
229
232
  self._lastrowid = None
230
233
  if re.match(r"\s*insert\b", sql, re.I):
231
234
  self._pending_identity = True
@@ -248,13 +251,13 @@ class Cursor:
248
251
  return self._lastrowid
249
252
 
250
253
  def _convert_row(self, row):
251
- """jaydebeapi 把 CLOB/BLOB 列返回为 java.sql.Clob/Blob 对象,
252
- 官方 dmPython 返回 str/bytes, 这里统一转换避免 ORM 赋值时报错。"""
254
+ """jaydebeapi returns java.sql.Clob/Blob; official dmPython returns str/bytes.
255
+ Normalize so ORM assignment does not fail."""
253
256
  if row is None:
254
257
  return None
255
258
  items = []
256
259
  for v in row:
257
- # jpype1 代理对象的类名形如 _jp_java.sql.Clob, 或是接口类型 java.sql.Clob
260
+ # JPype proxies look like _jp_java.sql.Clob or java.sql.Clob
258
261
  cls_name = type(v).__name__
259
262
  if not isinstance(v, (str, bytes, int, float, bool, type(None))):
260
263
  try:
@@ -293,7 +296,7 @@ class Cursor:
293
296
  pass
294
297
 
295
298
  def var(self, *args, **kw):
296
- raise NotSupportedError("JDBC shim 不支持 cursor.var/出参")
299
+ raise NotSupportedError("JDBC shim does not support cursor.var / OUT binds")
297
300
 
298
301
  def close(self):
299
302
  try:
@@ -323,8 +326,8 @@ class Connection:
323
326
  self.inputtypehandler = None
324
327
  self.autocommit = False
325
328
  self.server_version = "8.1.3.140"
326
- self.current_schema = schema # dmSQLAlchemy 取默认 schema 用
327
- self.local_code = 1 # 1 = utf-8, dmSQLAlchemy 会读取
329
+ self.current_schema = schema # dmSQLAlchemy reads the default schema here
330
+ self.local_code = 1 # 1 = utf-8; dmSQLAlchemy reads this
328
331
  self._closed = False
329
332
  try:
330
333
  cur = self._jconn.cursor()
@@ -378,8 +381,8 @@ class Connection:
378
381
 
379
382
 
380
383
  def _patch_dialect_no_returning():
381
- """RETURNING 依赖 cursor.var 出参, JDBC shim 不支持;
382
- 关闭方言的 returning 能力, 让 SQLAlchemy 回退到 lastrowid 取自增主键。"""
384
+ """RETURNING needs cursor.var OUT binds, which this shim does not support.
385
+ Disable dialect returning so SQLAlchemy falls back to lastrowid."""
383
386
  mod = sys.modules.get("dmSQLAlchemy.dmpython")
384
387
  if mod is None:
385
388
  return
@@ -392,8 +395,9 @@ def _patch_dialect_no_returning():
392
395
  cls.insert_executemany_returning = False
393
396
  cls.favor_returning_over_lastrowid = False
394
397
 
395
- # JDBC 的 SCOPE_IDENTITY() 返回单列自增主键值;dmSQLAlchemy 官方驱动
396
- # 则将 lastrowid 视为物理 ROWID 再查询。为 JDBC shim 直接回填该主键值。
398
+ # JDBC SCOPE_IDENTITY() returns a single identity column value. Official
399
+ # dmSQLAlchemy treats lastrowid as a physical ROWID and queries it back.
400
+ # For this shim, fill the PK directly from that identity value.
397
401
  def _get_cols_from_lastrowid(self, table, primary_columns, lastrowid):
398
402
  if len(primary_columns) == 1:
399
403
  return (lastrowid,)
@@ -403,9 +407,9 @@ def _patch_dialect_no_returning():
403
407
 
404
408
  cls.execution_ctx_cls.get_cols_from_lastrowid = _get_cols_from_lastrowid
405
409
 
406
- # 官方 do_executemany 会拼 `RETURNING ... INTO ?` 出参取回自增主键,
407
- # JDBC 无此机制; 改为普通 executemany, 主键由服务端自增, ORM 批量插入
408
- # 后如需主键请单条 add + flush。
410
+ # Official do_executemany appends `RETURNING ... INTO ?` to fetch identity.
411
+ # JDBC cannot do that; use plain executemany and let the server assign PKs.
412
+ # If the ORM needs those keys, insert one row at a time and flush.
409
413
  import datetime as _dt
410
414
  import json as _json
411
415
 
@@ -424,7 +428,7 @@ def _patch_dialect_no_returning():
424
428
 
425
429
 
426
430
  def connect(*args, **kw):
427
- """兼容 dmPython.connect(user=..., password=..., dsn='host:port', schema=..., ...)"""
431
+ """Compatible with dmPython.connect(user=..., password=..., dsn='host:port', schema=..., ...)."""
428
432
  import jaydebeapi
429
433
 
430
434
  _patch_dialect_no_returning()
@@ -442,7 +446,7 @@ def connect(*args, **kw):
442
446
  if schema:
443
447
  props["schema"] = schema
444
448
  if kw.get("local_code") is not None:
445
- pass # 编码由 JDBC 自动处理
449
+ pass # JDBC handles encoding
446
450
  if props:
447
451
  url += "?" + "&".join(f"{k}={v}" for k, v in props.items())
448
452
  try:
@@ -452,7 +456,7 @@ def connect(*args, **kw):
452
456
  timestamp_type = jaydebeapi._jdbc_name_to_const["TIMESTAMP"]
453
457
  jconn._converters[timestamp_type] = _jdbc_timestamp_to_datetime
454
458
  except Exception as e:
455
- raise OperationalError(f"达梦 JDBC 连接失败: {e}") from e
459
+ raise OperationalError(f"Dameng JDBC connection failed: {e}") from e
456
460
  autocommit = kw.get("autoCommit", kw.get("autocommit", False))
457
461
  jconn.jconn.setAutoCommit(bool(autocommit))
458
462
  conn = Connection(jconn, schema=schema)
@@ -469,14 +473,14 @@ def connect(*args, **kw):
469
473
  return conn
470
474
 
471
475
 
472
- # dmSQLAlchemy 反射用到的可选符号, 提供占位实现
476
+ # Optional symbols used by dmSQLAlchemy reflection; provide stubs.
473
477
  def parse_mysql_stmt(*a, **kw):
474
- raise NotSupportedError("shim 不支持 parse_mysql_stmt")
478
+ raise NotSupportedError("shim does not support parse_mysql_stmt")
475
479
 
476
480
 
477
481
  def parse_tsql_stmt(*a, **kw):
478
- raise NotSupportedError("shim 不支持 parse_tsql_stmt")
482
+ raise NotSupportedError("shim does not support parse_tsql_stmt")
479
483
 
480
484
 
481
- class objedctvar: # dmSQLAlchemy 引用了这个拼写
485
+ class objedctvar: # dmSQLAlchemy uses this misspelling
482
486
  pass
@@ -0,0 +1,27 @@
1
+ """Make importlib.metadata.version("dmPython") resolve to this shim."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import importlib.metadata as metadata
6
+
7
+ _DRIVER_VERSION = "2.5.32"
8
+
9
+
10
+ def _is_dmpython(name: str) -> bool:
11
+ normalized = name.lower().replace("-", "").replace("_", "").replace(".", "")
12
+ return normalized == "dmpython"
13
+
14
+
15
+ if not getattr(metadata, "_dmpython_jdbc_alias", False):
16
+ _orig_distribution = metadata.distribution
17
+
18
+ def version(distribution_name: str) -> str:
19
+ try:
20
+ return _orig_distribution(distribution_name).version
21
+ except metadata.PackageNotFoundError:
22
+ if _is_dmpython(distribution_name):
23
+ return _DRIVER_VERSION
24
+ raise
25
+
26
+ metadata.version = version
27
+ metadata._dmpython_jdbc_alias = True
@@ -1,4 +1,6 @@
1
- """按平台选择达梦官方驱动或 macOS JDBC 兼容实现。"""
1
+ """Pick the official Dameng driver or the macOS JDBC shim."""
2
+
3
+ import _dmpython_metadata # noqa: F401
2
4
 
3
5
  import importlib.machinery
4
6
  import importlib.util
@@ -18,7 +20,8 @@ else:
18
20
  spec = importlib.machinery.PathFinder.find_spec(__name__, search_paths)
19
21
  if spec is None or spec.loader is None:
20
22
  raise ImportError(
21
- "当前平台需要安装达梦官方 dmPython 驱动,但未在虚拟环境中找到"
23
+ "This platform requires the official Dameng dmPython driver, "
24
+ "which was not found on sys.path"
22
25
  )
23
26
 
24
27
  native_module = importlib.util.module_from_spec(spec)
@@ -0,0 +1,4 @@
1
+ Metadata-Version: 2.1
2
+ Name: dmPython
3
+ Version: 2.5.32
4
+ Summary: Metadata alias so importlib.metadata.version("dmPython") resolves to dmpython-jdbc
@@ -0,0 +1,116 @@
1
+ Metadata-Version: 2.4
2
+ Name: dmpython-jdbc
3
+ Version: 2.5.32.post1
4
+ Summary: macOS dmPython compatibility shim backed by JayDeBeApi
5
+ Author-email: Darley <darley.wey@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/Darley-Wey/dmpython-jdbc
8
+ Project-URL: Repository, https://github.com/Darley-Wey/dmpython-jdbc
9
+ Project-URL: Issues, https://github.com/Darley-Wey/dmpython-jdbc/issues
10
+ Keywords: dameng,dmPython,jdbc,macos
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: MacOS
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Topic :: Database
18
+ Requires-Python: >=3.12
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: JayDeBeApi>=1.2.3
22
+ Dynamic: license-file
23
+
24
+ # dmpython-jdbc
25
+
26
+ [English](README.md) | [简体中文](README.zh-CN.md)
27
+
28
+ macOS compatibility layer for Dameng `dmPython`. Dameng does not ship a macOS driver, so this package implements a DBAPI subset with JayDeBeApi + Dameng JDBC and makes dmSQLAlchemy's `dm+dmPython://` dialect work locally.
29
+
30
+ **The distribution name is `dmpython-jdbc`; the import name remains `dmPython`.** Application code does not need to change.
31
+
32
+ - macOS: use this package's JDBC shim
33
+ - Other platforms: forward `import dmPython` to the official driver
34
+
35
+ ## Install
36
+
37
+ PyPI:
38
+
39
+ ```bash
40
+ pip install dmpython-jdbc
41
+ ```
42
+
43
+ Cross-platform projects (official driver on Linux/Windows, this package on macOS):
44
+
45
+ ```toml
46
+ [project]
47
+ dependencies = [
48
+ "dmpython>=2.5.32; sys_platform != 'darwin'",
49
+ "dmpython-jdbc>=2.5.32; sys_platform == 'darwin'",
50
+ ]
51
+ ```
52
+
53
+ If the project also depends on `dmSQLAlchemy`, see [Using with dmSQLAlchemy](#using-with-dmsqlalchemy). That package pulls official `dmpython` unconditionally.
54
+
55
+ From GitHub:
56
+
57
+ ```bash
58
+ pip install "dmpython-jdbc @ git+https://github.com/Darley-Wey/dmpython-jdbc.git"
59
+ ```
60
+
61
+ uv:
62
+
63
+ ```toml
64
+ [tool.uv.sources]
65
+ dmpython-jdbc = { git = "https://github.com/Darley-Wey/dmpython-jdbc.git" }
66
+ ```
67
+
68
+ Pin a commit or tag by appending `@<ref>`, for example `@main` or `@v2.5.32`.
69
+
70
+ ## Runtime requirements
71
+
72
+ - Python >= 3.12
73
+ - JDK (`brew install openjdk` on macOS). `JAVA_HOME` is probed at `/opt/homebrew/opt/openjdk` and `/usr/local/opt/openjdk`
74
+ - The Dameng JDBC driver is bundled in the wheel; override it with `DM_JDBC_JAR`
75
+
76
+
77
+ ## Using with dmSQLAlchemy
78
+
79
+ `dmSQLAlchemy` unconditionally depends on official `dmpython` (`Requires-Dist: dmPython`). That package has no macOS wheel, so `pip install dmSQLAlchemy` on a Mac will try to install Dameng's driver and fail.
80
+
81
+ Keep `dmSQLAlchemy`, prevent the resolver from installing official `dmpython` on macOS, and install `dmpython-jdbc` instead. The import name stays `dmPython`.
82
+
83
+ ### uv
84
+
85
+ ```toml
86
+ [project]
87
+ dependencies = [
88
+ "dmsqlalchemy",
89
+ "dmpython>=2.5.32; sys_platform != 'darwin'",
90
+ "dmpython-jdbc>=2.5.32; sys_platform == 'darwin'",
91
+ ]
92
+
93
+ [tool.uv]
94
+ override-dependencies = [
95
+ "dmpython ; sys_platform != 'darwin'",
96
+ ]
97
+ ```
98
+
99
+ `override-dependencies` rewrites `dmSQLAlchemy`'s `dmpython` requirement so it is skipped on macOS. `dmpython-jdbc` then provides the `dmPython` module.
100
+
101
+ `dmSQLAlchemy.extensions` calls `importlib.metadata.version("dmPython")`. This package installs a `.pth` hook so that lookup returns the shim version `2.5.32` without needing setuptools/`pkg_resources`.
102
+
103
+ ### pip on macOS
104
+
105
+ ```bash
106
+ pip install "dmSQLAlchemy" --no-deps
107
+ pip install "SQLAlchemy>1.4.54" dmpython-jdbc
108
+ ```
109
+
110
+ ## Limits
111
+
112
+ Stored-procedure OUT binds (`cursor.var`) and streaming LOB I/O are not supported. ORM CRUD is covered.
113
+
114
+ ## License
115
+
116
+ The Python shim is MIT. `DmJdbcDriver18-*.jar` is Dameng's official JDBC driver and is not covered by MIT.
@@ -2,10 +2,14 @@ LICENSE
2
2
  MANIFEST.in
3
3
  NOTICE
4
4
  README.md
5
+ README.zh-CN.md
6
+ _dmpython_metadata.py
5
7
  dmPython.py
6
8
  pyproject.toml
9
+ setup.py
7
10
  _dmPython_jdbc/DmJdbcDriver18-8.1.3.140.jar
8
11
  _dmPython_jdbc/__init__.py
12
+ dmpython-2.5.32.dist-info/METADATA
9
13
  dmpython_jdbc.egg-info/PKG-INFO
10
14
  dmpython_jdbc.egg-info/SOURCES.txt
11
15
  dmpython_jdbc.egg-info/dependency_links.txt
@@ -1,2 +1,3 @@
1
1
  _dmPython_jdbc
2
+ _dmpython_metadata
2
3
  dmPython
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "dmpython-jdbc"
7
- version = "2.5.32"
7
+ version = "2.5.32.post1"
8
8
  description = "macOS dmPython compatibility shim backed by JayDeBeApi"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"
@@ -33,7 +33,7 @@ Repository = "https://github.com/Darley-Wey/dmpython-jdbc"
33
33
  Issues = "https://github.com/Darley-Wey/dmpython-jdbc/issues"
34
34
 
35
35
  [tool.setuptools]
36
- py-modules = ["dmPython"]
36
+ py-modules = ["dmPython", "_dmpython_metadata"]
37
37
  packages = ["_dmPython_jdbc"]
38
38
  include-package-data = true
39
39
 
@@ -0,0 +1,15 @@
1
+ from pathlib import Path
2
+
3
+ from setuptools import setup
4
+ from setuptools.command.build_py import build_py as _build_py
5
+
6
+
7
+ class build_py(_build_py):
8
+ def run(self):
9
+ super().run()
10
+ Path(self.build_lib, "dmpython_jdbc.pth").write_text(
11
+ "import _dmpython_metadata\n", encoding="utf-8"
12
+ )
13
+
14
+
15
+ setup(cmdclass={"build_py": build_py})
@@ -1,78 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: dmpython-jdbc
3
- Version: 2.5.32
4
- Summary: macOS dmPython compatibility shim backed by JayDeBeApi
5
- Author-email: Darley <darley.wey@gmail.com>
6
- License-Expression: MIT
7
- Project-URL: Homepage, https://github.com/Darley-Wey/dmpython-jdbc
8
- Project-URL: Repository, https://github.com/Darley-Wey/dmpython-jdbc
9
- Project-URL: Issues, https://github.com/Darley-Wey/dmpython-jdbc/issues
10
- Keywords: dameng,dmPython,jdbc,macos
11
- Classifier: Development Status :: 4 - Beta
12
- Classifier: Intended Audience :: Developers
13
- Classifier: Operating System :: MacOS
14
- Classifier: Programming Language :: Python :: 3
15
- Classifier: Programming Language :: Python :: 3.12
16
- Classifier: Programming Language :: Python :: 3.13
17
- Classifier: Topic :: Database
18
- Requires-Python: >=3.12
19
- Description-Content-Type: text/markdown
20
- License-File: LICENSE
21
- Requires-Dist: JayDeBeApi>=1.2.3
22
- Dynamic: license-file
23
-
24
- # dmpython-jdbc
25
-
26
- macOS 上的达梦 `dmPython` 兼容层。官方驱动没有 macOS 版,这里用 JayDeBeApi + 达梦 JDBC 实现 DBAPI 子集,让 `dmSQLAlchemy` 的 `dm+dmPython://` 方言能在本机跑起来。
27
-
28
- **发行名是 `dmpython-jdbc`,import 名仍是 `dmPython`。** 业务代码不用改。
29
-
30
- - macOS:使用本包的 JDBC shim
31
- - 其它平台:把 `import dmPython` 转发给已安装的官方驱动
32
-
33
- ## 安装
34
-
35
- PyPI:
36
-
37
- ```bash
38
- pip install dmpython-jdbc
39
- ```
40
-
41
- 跨平台项目(Linux/Windows 用官方驱动,macOS 用本包):
42
-
43
- ```toml
44
- [project]
45
- dependencies = [
46
- "dmpython>=2.5.32; sys_platform != 'darwin'",
47
- "dmpython-jdbc>=2.5.32; sys_platform == 'darwin'",
48
- ]
49
- ```
50
-
51
- 从 GitHub 安装:
52
-
53
- ```bash
54
- pip install "dmpython-jdbc @ git+https://github.com/Darley-Wey/dmpython-jdbc.git"
55
- ```
56
-
57
- uv:
58
-
59
- ```toml
60
- [tool.uv.sources]
61
- dmpython-jdbc = { git = "https://github.com/Darley-Wey/dmpython-jdbc.git" }
62
- ```
63
-
64
- 需要钉到某个提交或 tag 时,在 URL 后加 `@<ref>`,例如 `@main` 或 `@v2.5.32`。
65
-
66
- ## 运行依赖
67
-
68
- - Python >= 3.12
69
- - JDK(macOS 可用 `brew install openjdk`)。`JAVA_HOME` 会自动探测 `/opt/homebrew/opt/openjdk` 和 `/usr/local/opt/openjdk`
70
- - 达梦 JDBC 驱动已打包进 wheel;也可用环境变量 `DM_JDBC_JAR` 覆盖
71
-
72
- ## 限制
73
-
74
- 不支持存储过程出参(`cursor.var`)、LOB 流式读写等高级特性,覆盖 ORM CRUD 即可。
75
-
76
- ## 许可证
77
-
78
- Python 兼容层使用 MIT。仓库中的 `DmJdbcDriver18-*.jar` 是达梦官方 JDBC 驱动,版权归达梦数据库所有,不受 MIT 覆盖。
@@ -1,55 +0,0 @@
1
- # dmpython-jdbc
2
-
3
- macOS 上的达梦 `dmPython` 兼容层。官方驱动没有 macOS 版,这里用 JayDeBeApi + 达梦 JDBC 实现 DBAPI 子集,让 `dmSQLAlchemy` 的 `dm+dmPython://` 方言能在本机跑起来。
4
-
5
- **发行名是 `dmpython-jdbc`,import 名仍是 `dmPython`。** 业务代码不用改。
6
-
7
- - macOS:使用本包的 JDBC shim
8
- - 其它平台:把 `import dmPython` 转发给已安装的官方驱动
9
-
10
- ## 安装
11
-
12
- PyPI:
13
-
14
- ```bash
15
- pip install dmpython-jdbc
16
- ```
17
-
18
- 跨平台项目(Linux/Windows 用官方驱动,macOS 用本包):
19
-
20
- ```toml
21
- [project]
22
- dependencies = [
23
- "dmpython>=2.5.32; sys_platform != 'darwin'",
24
- "dmpython-jdbc>=2.5.32; sys_platform == 'darwin'",
25
- ]
26
- ```
27
-
28
- 从 GitHub 安装:
29
-
30
- ```bash
31
- pip install "dmpython-jdbc @ git+https://github.com/Darley-Wey/dmpython-jdbc.git"
32
- ```
33
-
34
- uv:
35
-
36
- ```toml
37
- [tool.uv.sources]
38
- dmpython-jdbc = { git = "https://github.com/Darley-Wey/dmpython-jdbc.git" }
39
- ```
40
-
41
- 需要钉到某个提交或 tag 时,在 URL 后加 `@<ref>`,例如 `@main` 或 `@v2.5.32`。
42
-
43
- ## 运行依赖
44
-
45
- - Python >= 3.12
46
- - JDK(macOS 可用 `brew install openjdk`)。`JAVA_HOME` 会自动探测 `/opt/homebrew/opt/openjdk` 和 `/usr/local/opt/openjdk`
47
- - 达梦 JDBC 驱动已打包进 wheel;也可用环境变量 `DM_JDBC_JAR` 覆盖
48
-
49
- ## 限制
50
-
51
- 不支持存储过程出参(`cursor.var`)、LOB 流式读写等高级特性,覆盖 ORM CRUD 即可。
52
-
53
- ## 许可证
54
-
55
- Python 兼容层使用 MIT。仓库中的 `DmJdbcDriver18-*.jar` 是达梦官方 JDBC 驱动,版权归达梦数据库所有,不受 MIT 覆盖。