11import datetime
22from telnetlib import BINARY
3- from iris .dbapi ._DBAPI import Cursor
4- from iris .dbapi ._Column import _Column
5- from iris .dbapi ._ResultSetRow import _ResultSetRow
6- from iris .dbapi ._DBAPI import SQLType as IRISSQLType
7- import iris ._IRISNative as irisnative
8- import iris .dbapi ._DBAPI as dbapi
3+ import intersystems_iris .dbapi ._DBAPI as dbapi
94from . import information_schema as ischema
105from sqlalchemy import exc
116from sqlalchemy .orm import aliased
@@ -519,63 +514,19 @@ def __init__(self, dialect):
519514 dialect , omit_schema = False )
520515
521516
522- class CursorWrapper (Cursor ):
523- def __init__ (self , connection ):
524- super (CursorWrapper , self ).__init__ (connection )
525-
526- _types = {
527- IRISSQLType .INTEGER : int ,
528- IRISSQLType .BIGINT : int ,
529-
530- IRISSQLType .VARCHAR : str ,
531- }
532-
533- # Workaround for issue, when type of variable not the same as column type
534- def _fix_type (self , value , sql_type : IRISSQLType ):
535- if value is None :
536- return value
537-
538- try :
539- expected_type = self ._types .get (sql_type )
540- if expected_type and not isinstance (value , expected_type ):
541- value = expected_type (value )
542- except Exception :
543- pass
544-
545- return value
546-
547- def fetchone (self ):
548- retval = super (CursorWrapper , self ).fetchone ()
549- if retval is None :
550- return None
551- if not isinstance (retval , _ResultSetRow .DataRow ):
552- return retval
553- # return retval[:]
554-
555- # Workaround for fetchone, which returns values in row not from 0
556- row = []
557- self ._columns : list [_Column ]
558- for c in self ._columns :
559- value = retval [c .name ]
560- if c .tableName != 'None' and c .schema != 'None' :
561- # print('_fix_type', [c.name, value, c.type, type(value), c.isAliased, c.isExpression, c.isKeyColumn, c.isIdentity, c.tableName is None, c.schema])
562- value = self ._fix_type (value , c .type )
563- row .append (value )
564- return row
565-
566-
567517class IRISExecutionContext (default .DefaultExecutionContext ):
568518
569519 def get_lastrowid (self ):
570- cursor = self .create_cursor ()
571- cursor .execute ("SELECT LAST_IDENTITY()" )
572- lastrowid = cursor .fetchone ()[0 ]
573- cursor .close ()
574- return lastrowid
520+ try :
521+ return self .cursor .lastrowid
522+ except Exception :
523+ cursor = self .cursor
524+ cursor .execute ("SELECT LAST_IDENTITY()" )
525+ lastrowid = cursor .fetchone ()[0 ]
526+ return lastrowid
575527
576528 def create_cursor (self ):
577- # cursor = self._dbapi_connection.cursor()
578- cursor = CursorWrapper (self ._dbapi_connection )
529+ cursor = self ._dbapi_connection .cursor ()
579530 return cursor
580531
581532
@@ -700,7 +651,7 @@ def __init__(self, **kwargs):
700651 )
701652
702653 def _get_option (self , connection , option ):
703- cursor = CursorWrapper ( connection )
654+ cursor = connection . cursor ( )
704655 # cursor = connection.cursor()
705656 cursor .execute ('SELECT %SYSTEM_SQL.Util_GetOption(?)' , [option , ])
706657 row = cursor .fetchone ()
@@ -709,7 +660,7 @@ def _get_option(self, connection, option):
709660 return None
710661
711662 def _set_option (self , connection , option , value ):
712- cursor = CursorWrapper ( connection )
663+ cursor = connection . cursor ( )
713664 # cursor = connection.cursor()
714665 cursor .execute ('SELECT %SYSTEM_SQL.Util_SetOption(?, ?)' , [option , value , ])
715666 row = cursor .fetchone ()
0 commit comments