1
1
import datetime
2
2
from 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
9
4
from . import information_schema as ischema
10
5
from sqlalchemy import exc
11
6
from sqlalchemy .orm import aliased
@@ -519,63 +514,19 @@ def __init__(self, dialect):
519
514
dialect , omit_schema = False )
520
515
521
516
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
-
567
517
class IRISExecutionContext (default .DefaultExecutionContext ):
568
518
569
519
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
575
527
576
528
def create_cursor (self ):
577
- # cursor = self._dbapi_connection.cursor()
578
- cursor = CursorWrapper (self ._dbapi_connection )
529
+ cursor = self ._dbapi_connection .cursor ()
579
530
return cursor
580
531
581
532
@@ -700,7 +651,7 @@ def __init__(self, **kwargs):
700
651
)
701
652
702
653
def _get_option (self , connection , option ):
703
- cursor = CursorWrapper ( connection )
654
+ cursor = connection . cursor ( )
704
655
# cursor = connection.cursor()
705
656
cursor .execute ('SELECT %SYSTEM_SQL.Util_GetOption(?)' , [option , ])
706
657
row = cursor .fetchone ()
@@ -709,7 +660,7 @@ def _get_option(self, connection, option):
709
660
return None
710
661
711
662
def _set_option (self , connection , option , value ):
712
- cursor = CursorWrapper ( connection )
663
+ cursor = connection . cursor ( )
713
664
# cursor = connection.cursor()
714
665
cursor .execute ('SELECT %SYSTEM_SQL.Util_SetOption(?, ?)' , [option , value , ])
715
666
row = cursor .fetchone ()
0 commit comments