Skip to content

Commit 6a2851b

Browse files
committed
updated connection and response
1 parent 7136373 commit 6a2851b

File tree

4 files changed

+26
-13
lines changed

4 files changed

+26
-13
lines changed

tarantool/connection.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import ctypes
1313
import ctypes.util
14+
1415
try:
1516
from ctypes import c_ssize_t
1617
except ImportError:
@@ -293,13 +294,12 @@ def check(): # Check that connection is alive
293294
retbytes = self._sys_recv(sock_fd, buf, 1, flag)
294295

295296
err = 0
296-
if os.name!= 'nt':
297+
if os.name != 'nt':
297298
err = ctypes.get_errno()
298299
else:
299300
err = ctypes.get_last_error()
300301
self._socket.setblocking(True)
301302

302-
303303
WWSAEWOULDBLOCK = 10035
304304
if (retbytes < 0) and (err == errno.EAGAIN or
305305
err == errno.EWOULDBLOCK or
@@ -791,10 +791,10 @@ def execute(self, query, params=None):
791791
'''
792792
Execute SQL request.
793793
Execute SQL query in database.
794-
795-
:param query: SQL syntax query
794+
795+
:param query: SQL syntax query
796796
:type query: str
797-
797+
798798
:param params: Bind values to use in query
799799
:type params: list, dict
800800

tarantool/dbapi.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
"""
22
Supports python 3.6 and above
33
"""
4+
from copy import deepcopy
5+
6+
from tarantool.error import InterfaceError
47

58
from .connection import Connection as BaseConnection
69
from . import error
@@ -13,6 +16,7 @@ class Cursor:
1316
rows = []
1417
position = 0
1518
autocommit = True
19+
_rowcount = 0
1620

1721
def __init__(self, connection):
1822
self._c = connection
@@ -31,14 +35,23 @@ def execute(self, query, params=None):
3135

3236
if len(response.body) > 1:
3337
self.rows = tuple(response.body.values())[1]
38+
else:
39+
self.rows = []
40+
if 'UPDATE' not in query or 'INSERT' not in query:
41+
try:
42+
self._rowcount = response.rowcount
43+
except InterfaceError:
44+
pass
45+
else:
46+
self._rowcount = 1
3447
return response
3548

3649
def lastrowid(self):
3750
return self._lastrowid
3851

3952
@property
4053
def rowcount(self):
41-
return len(self._c.rows)
54+
return self._rowcount
4255

4356
def executemany(self, query, params):
4457
return self.execute(query, params)
@@ -48,7 +61,7 @@ def fetchone(self):
4861

4962
def fetchmany(self, size):
5063
self._lastrowid += size
51-
items = self.rows.copy()
64+
items = deepcopy(self.rows)
5265
self.rows = []
5366
return items
5467

tarantool/request.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import msgpack
88
import hashlib
99

10-
1110
from tarantool.const import (
1211
IPROTO_CODE,
1312
IPROTO_SYNC,
@@ -50,6 +49,7 @@
5049
binary_types
5150
)
5251

52+
5353
class Request(object):
5454
'''
5555
Represents a single request to the server in compliance with the
@@ -137,7 +137,7 @@ def sha1(values):
137137
request_body = msgpack.dumps({IPROTO_USER_NAME: user,
138138
IPROTO_TUPLE: ("chap-sha1", scramble)})
139139
self._body = request_body
140-
140+
141141
def header(self, length):
142142
self._sync = self.conn.generate_sync()
143143
# Set IPROTO_SCHEMA_ID: 0 to avoid SchemaReloadException

tarantool/response.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Response(Sequence):
3535
and parses binary packet received from the server.
3636
'''
3737

38-
def __init__(self, conn, response):
38+
def __init__(self, conn, response, use_list=False):
3939
'''
4040
Create an instance of `Response` using data received from the server.
4141
@@ -54,11 +54,11 @@ def __init__(self, conn, response):
5454
# Get rid of the following warning.
5555
# > PendingDeprecationWarning: encoding is deprecated,
5656
# > Use raw=False instead.
57-
unpacker = msgpack.Unpacker(use_list=True, raw=False)
57+
unpacker = msgpack.Unpacker(use_list=use_list, raw=False)
5858
elif conn.encoding is not None:
59-
unpacker = msgpack.Unpacker(use_list=True, encoding=conn.encoding)
59+
unpacker = msgpack.Unpacker(use_list=use_list, encoding=conn.encoding)
6060
else:
61-
unpacker = msgpack.Unpacker(use_list=True)
61+
unpacker = msgpack.Unpacker(use_list=use_list)
6262

6363
unpacker.feed(response)
6464
header = unpacker.unpack()

0 commit comments

Comments
 (0)