Skip to content

Commit cfde76a

Browse files
committed
some more fixes for official driver
1 parent 27fb25b commit cfde76a

File tree

4 files changed

+36
-33
lines changed

4 files changed

+36
-33
lines changed

sqlalchemy_iris/intersystems/__init__.py

+22-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import re
2+
from typing import Any
23
from ..base import IRISDialect
3-
from sqlalchemy import text, util
44
from ..base import IRISExecutionContext
55
from . import dbapi
6-
from .dbapi import connect, Cursor
7-
from .cursor import InterSystemsCursorFetchStrategy
6+
from .dbapi import connect
87
from .dbapi import IntegrityError, OperationalError, DatabaseError
8+
from sqlalchemy.engine.cursor import CursorFetchStrategy
99

1010

1111
def remap_exception(func):
@@ -19,7 +19,7 @@ def wrapper(cursor, *args, **kwargs):
1919
except RuntimeError as ex:
2020
# [SQLCODE: <-119>:...
2121
message = ex.args[0]
22-
if '<LIST ERROR>' in message:
22+
if "<LIST ERROR>" in message:
2323
# just random error happens in the driver, try again
2424
continue
2525
sqlcode = re.findall(r"^\[SQLCODE: <(-\d+)>:", message)
@@ -35,6 +35,18 @@ def wrapper(cursor, *args, **kwargs):
3535
return wrapper
3636

3737

38+
class InterSystemsCursorFetchStrategy(CursorFetchStrategy):
39+
40+
def fetchone(
41+
self,
42+
result,
43+
dbapi_cursor,
44+
hard_close: bool = False,
45+
) -> Any:
46+
row = dbapi_cursor.fetchone()
47+
return tuple(row) if row else None
48+
49+
3850
class InterSystemsExecutionContext(IRISExecutionContext):
3951
cursor_fetch_strategy = InterSystemsCursorFetchStrategy()
4052

@@ -123,9 +135,13 @@ def on_connect(conn):
123135
if super_ is not None:
124136
super_(conn)
125137

126-
server_version = dbapi.createIRIS(conn).classMethodValue("%SYSTEM.Version", "GetNumber")
138+
server_version = dbapi.createIRIS(conn).classMethodValue(
139+
"%SYSTEM.Version", "GetNumber"
140+
)
127141
server_version = server_version.split(".")
128-
self.server_version = tuple([int("".join(filter(str.isdigit, v))) for v in server_version])
142+
self.server_version = tuple(
143+
[int("".join(filter(str.isdigit, v))) for v in server_version]
144+
)
129145

130146
return on_connect
131147

sqlalchemy_iris/intersystems/cursor.py

-17
This file was deleted.

sqlalchemy_iris/requirements.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -960,8 +960,8 @@ def datetime_literals(self):
960960
literal string, e.g. via the TypeEngine.literal_processor() method.
961961
962962
"""
963-
964-
return exclusions.open()
963+
# works stable only on Community driver
964+
return self.community_driver
965965

966966
@property
967967
def datetime(self):

tests/test_alembic.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,18 @@ def define_tables(cls, metadata):
9393
@classmethod
9494
def insert_data(cls, connection):
9595
connection.execute(
96-
text(
97-
"""
98-
insert into tab (col) values
99-
('some data 1'),
100-
('some data 2'),
101-
('some data 3')
102-
"""
103-
)
96+
cls.tables.tab.insert(),
97+
[
98+
{
99+
"col": "some data 1",
100+
},
101+
{
102+
"col": "some data 2",
103+
},
104+
{
105+
"col": "some data 3",
106+
},
107+
],
104108
)
105109

106110
def test_str_to_blob(self, connection, ops_context):

0 commit comments

Comments
 (0)