1
1
import re
2
+ from typing import Any
2
3
from ..base import IRISDialect
3
- from sqlalchemy import text , util
4
4
from ..base import IRISExecutionContext
5
5
from . import dbapi
6
- from .dbapi import connect , Cursor
7
- from .cursor import InterSystemsCursorFetchStrategy
6
+ from .dbapi import connect
8
7
from .dbapi import IntegrityError , OperationalError , DatabaseError
8
+ from sqlalchemy .engine .cursor import CursorFetchStrategy
9
9
10
10
11
11
def remap_exception (func ):
@@ -19,7 +19,7 @@ def wrapper(cursor, *args, **kwargs):
19
19
except RuntimeError as ex :
20
20
# [SQLCODE: <-119>:...
21
21
message = ex .args [0 ]
22
- if ' <LIST ERROR>' in message :
22
+ if " <LIST ERROR>" in message :
23
23
# just random error happens in the driver, try again
24
24
continue
25
25
sqlcode = re .findall (r"^\[SQLCODE: <(-\d+)>:" , message )
@@ -35,6 +35,18 @@ def wrapper(cursor, *args, **kwargs):
35
35
return wrapper
36
36
37
37
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
+
38
50
class InterSystemsExecutionContext (IRISExecutionContext ):
39
51
cursor_fetch_strategy = InterSystemsCursorFetchStrategy ()
40
52
@@ -123,9 +135,13 @@ def on_connect(conn):
123
135
if super_ is not None :
124
136
super_ (conn )
125
137
126
- server_version = dbapi .createIRIS (conn ).classMethodValue ("%SYSTEM.Version" , "GetNumber" )
138
+ server_version = dbapi .createIRIS (conn ).classMethodValue (
139
+ "%SYSTEM.Version" , "GetNumber"
140
+ )
127
141
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
+ )
129
145
130
146
return on_connect
131
147
0 commit comments