Skip to content

Commit 3776c0d

Browse files
committed
workaround for update and insert
1 parent 6a2851b commit 3776c0d

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

tarantool/connection.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@
5656
InterfaceError,
5757
SchemaError,
5858
NetworkWarning,
59+
OperationalError,
60+
DataError,
61+
IntegrityError,
62+
InternalError,
63+
ProgrammingError,
64+
NotSupportedError,
5965
SchemaReloadException,
6066
warn
6167
)
@@ -78,11 +84,20 @@ class Connection(object):
7884
Also this class provides low-level interface to data manipulation
7985
(insert/delete/update/select).
8086
'''
87+
# DBAPI Extension: supply exceptions as attributes on the connection
8188
Error = tarantool.error
8289
DatabaseError = DatabaseError
8390
InterfaceError = InterfaceError
8491
SchemaError = SchemaError
8592
NetworkError = NetworkError
93+
Warning = Warning
94+
DataError = DataError
95+
OperationalError = OperationalError
96+
IntegrityError = IntegrityError
97+
InternalError = InternalError
98+
ProgrammingError = ProgrammingError
99+
NotSupportedError = NotSupportedError
100+
ImproperlyConfigured = Exception
86101

87102
def __init__(self, host, port,
88103
user=None,

tarantool/dbapi.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"""
22
Supports python 3.6 and above
33
"""
4+
import re
45
from copy import deepcopy
56

67
from tarantool.error import InterfaceError
78

89
from .connection import Connection as BaseConnection
9-
from . import error
1010

1111

1212
class Cursor:
@@ -28,16 +28,27 @@ def close(self):
2828
self._c.close()
2929

3030
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+
3139
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)
3341

42+
print(query)
3443
response = self._c.execute(query)
3544

3645
if len(response.body) > 1:
3746
self.rows = tuple(response.body.values())[1]
3847
else:
3948
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):
4152
try:
4253
self._rowcount = response.rowcount
4354
except InterfaceError:
@@ -46,6 +57,7 @@ def execute(self, query, params=None):
4657
self._rowcount = 1
4758
return response
4859

60+
@property
4961
def lastrowid(self):
5062
return self._lastrowid
5163

@@ -79,19 +91,6 @@ class Connection(BaseConnection):
7991
rows = []
8092
_cursor = None
8193

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-
9594
server_version = 1
9695

9796
def commit(self):

0 commit comments

Comments
 (0)