11import re
2+ from typing import Any
23from ..base import IRISDialect
3- from sqlalchemy import text , util
44from ..base import IRISExecutionContext
55from . import dbapi
6- from .dbapi import connect , Cursor
7- from .cursor import InterSystemsCursorFetchStrategy
6+ from .dbapi import connect
87from .dbapi import IntegrityError , OperationalError , DatabaseError
8+ from sqlalchemy .engine .cursor import CursorFetchStrategy
99
1010
1111def 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+
3850class 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
0 commit comments