1
1
"""
2
2
Supports python 3.6 and above
3
3
"""
4
+ import re
4
5
from copy import deepcopy
5
6
6
7
from tarantool .error import InterfaceError
7
8
8
9
from .connection import Connection as BaseConnection
9
- from . import error
10
10
11
11
12
12
class Cursor :
@@ -28,16 +28,27 @@ def close(self):
28
28
self ._c .close ()
29
29
30
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
38
+
31
39
if params :
32
- query = query % tuple (str (param ) if isinstance ( param , bool ) else "'%s'" % param for param in params )
40
+ query = query % tuple (convert_param (param ) for param in params )
33
41
42
+ print (query )
34
43
response = self ._c .execute (query )
35
44
36
45
if len (response .body ) > 1 :
37
46
self .rows = tuple (response .body .values ())[1 ]
38
47
else :
39
48
self .rows = []
40
- if 'UPDATE' not in query or 'INSERT' not in query :
49
+
50
+ rc_pattern = re .compile (r'^(UPDATE|INSERT)' )
51
+ if rc_pattern .match (query ):
41
52
try :
42
53
self ._rowcount = response .rowcount
43
54
except InterfaceError :
@@ -46,6 +57,7 @@ def execute(self, query, params=None):
46
57
self ._rowcount = 1
47
58
return response
48
59
60
+ @property
49
61
def lastrowid (self ):
50
62
return self ._lastrowid
51
63
@@ -79,19 +91,6 @@ class Connection(BaseConnection):
79
91
rows = []
80
92
_cursor = None
81
93
82
- # DBAPI Extension: supply exceptions as attributes on the connection
83
- Warning = Warning
84
- Error = error .Error
85
- InterfaceError = error .InterfaceError
86
- DataError = error .DataError
87
- DatabaseError = error .DatabaseError
88
- OperationalError = error .OperationalError
89
- IntegrityError = error .IntegrityError
90
- InternalError = error .InternalError
91
- ProgrammingError = error .ProgrammingError
92
- NotSupportedError = error .NotSupportedError
93
- ImproperlyConfigured = Exception
94
-
95
94
server_version = 1
96
95
97
96
def commit (self ):
0 commit comments