@@ -27,25 +27,21 @@ def callproc(self, procname, *params):
27
27
def close (self ):
28
28
self ._c .close ()
29
29
30
- def execute (self , query , params = None ):
31
- def convert_param (p ):
32
- print ('PARAM: ' , p )
33
- if isinstance (p , bool ):
34
- return str (p )
35
- elif p is None :
36
- return "NULL"
37
- return "'%s'" % p
30
+ def _convert_param (self , p ):
31
+ if isinstance (p , bool ):
32
+ return str (p )
33
+ elif p is None :
34
+ return "NULL"
35
+ return "'%s'" % p
38
36
37
+ def execute (self , query , params = None ):
39
38
if params :
40
- query = query % tuple (convert_param (param ) for param in params )
39
+ query = query % tuple (self . _convert_param (param ) for param in params )
41
40
42
- print (query )
41
+ # print(query)
43
42
response = self ._c .execute (query )
44
43
45
- if len (response .body ) > 1 :
46
- self .rows = tuple (response .body .values ())[1 ]
47
- else :
48
- self .rows = []
44
+ self .rows = tuple (response .body .values ())[1 ] if len (response .body ) > 1 else []
49
45
50
46
rc_pattern = re .compile (r'^(UPDATE|INSERT)' )
51
47
if rc_pattern .match (query ):
@@ -55,6 +51,17 @@ def convert_param(p):
55
51
pass
56
52
else :
57
53
self ._rowcount = 1
54
+
55
+ def extract_last_row_id (body ): # Need to be checked
56
+ try :
57
+ val = tuple (tuple (body .items ())[0 ][- 1 ].items ())[- 1 ][- 1 ][0 ]
58
+ except TypeError :
59
+ val = 1
60
+ return val
61
+
62
+ u_pattern = re .compile (r'^INSERT' )
63
+ if u_pattern .match (query ):
64
+ self ._lastrowid = extract_last_row_id (response .body )
58
65
return response
59
66
60
67
@property
@@ -72,7 +79,6 @@ def fetchone(self):
72
79
pass
73
80
74
81
def fetchmany (self , size ):
75
- self ._lastrowid += size
76
82
items = deepcopy (self .rows )
77
83
self .rows = []
78
84
return items
0 commit comments