Skip to content

Add use_list param to Connection init #168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ environment:
- PYTHON: "C:\\Python36-x64"
- PYTHON: "C:\\Python37"
- PYTHON: "C:\\Python37-x64"
- PYTHON: "C:\\Python38"
- PYTHON: "C:\\Python38-x64"

install:
# install runtime dependencies
- "%PYTHON%\\python.exe -m pip install -r requirements.txt"
# install testing dependencies
- "%PYTHON%\\python.exe -m pip install pyyaml%PYYAML%"
- "%PYTHON%\\python.exe -m pip install pyyaml%PYYAML% dbapi-compliance==1.15.0"

build: off

Expand Down
2 changes: 1 addition & 1 deletion tarantool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ def connectmesh(addrs=({'host': 'localhost', 'port': 3301},), user=None,

__all__ = ['connect', 'Connection', 'connectmesh', 'MeshConnection', 'Schema',
'Error', 'DatabaseError', 'NetworkError', 'NetworkWarning',
'SchemaError']
'SchemaError', 'dbapi']
57 changes: 52 additions & 5 deletions tarantool/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
RequestSubscribe,
RequestUpdate,
RequestUpsert,
RequestAuthenticate
RequestAuthenticate,
RequestExecute
)
from tarantool.space import Space
from tarantool.const import (
Expand All @@ -49,12 +50,20 @@
ITERATOR_ALL
)
from tarantool.error import (
Error,
NetworkError,
DatabaseError,
InterfaceError,
SchemaError,
NetworkWarning,
OperationalError,
DataError,
IntegrityError,
InternalError,
ProgrammingError,
NotSupportedError,
SchemaReloadException,
Warning,
warn
)
from tarantool.schema import Schema
Expand All @@ -76,11 +85,19 @@ class Connection(object):
Also this class provides low-level interface to data manipulation
(insert/delete/update/select).
'''
Error = tarantool.error
# DBAPI Extension: supply exceptions as attributes on the connection
Error = Error
DatabaseError = DatabaseError
InterfaceError = InterfaceError
SchemaError = SchemaError
NetworkError = NetworkError
Warning = Warning
DataError = DataError
OperationalError = OperationalError
IntegrityError = IntegrityError
InternalError = InternalError
ProgrammingError = ProgrammingError
NotSupportedError = NotSupportedError

def __init__(self, host, port,
user=None,
Expand All @@ -91,6 +108,7 @@ def __init__(self, host, port,
connect_now=True,
encoding=ENCODING_DEFAULT,
call_16=False,
use_list=True,
connection_timeout=CONNECTION_TIMEOUT):
'''
Initialize a connection to the server.
Expand Down Expand Up @@ -125,6 +143,7 @@ def __init__(self, host, port,
self.error = True
self.encoding = encoding
self.call_16 = call_16
self.use_list = use_list
self.connection_timeout = connection_timeout
if connect_now:
self.connect()
Expand All @@ -136,6 +155,13 @@ def close(self):
self._socket.close()
self._socket = None

def is_closed(self):
self._check_not_closed()

def _check_not_closed(self, error=None):
if self._socket is None:
raise DatabaseError(error or "The connector is closed")

def connect_basic(self):
if self.host == None:
self.connect_unix()
Expand Down Expand Up @@ -250,17 +276,18 @@ def _read_response(self):

def _send_request_wo_reconnect(self, request):
'''
:rtype: `Response` instance
:rtype: `Response` instance or subclass

:raise: NetworkError
'''
assert isinstance(request, Request)
if not issubclass(type(request), Request):
raise NetworkError

response = None
while True:
try:
self._socket.sendall(bytes(request))
response = Response(self, self._read_response())
response = request.response_class(self, self._read_response())
break
except SchemaReloadException as e:
self.update_schema(e.schema_version)
Expand Down Expand Up @@ -785,3 +812,23 @@ def generate_sync(self):
Need override for async io connection
'''
return 0

def execute(self, query, params=None):
'''
Execute SQL request.

:param query: SQL syntax query
:type query: str

:param params: Bind values to use in query
:type params: list, dict

:return: query result data
:rtype: list
'''
self._check_not_closed()
if not params:
params = []
request = RequestExecute(self, query, params)
response = self._send_request(request)
return response
8 changes: 8 additions & 0 deletions tarantool/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
#
IPROTO_DATA = 0x30
IPROTO_ERROR = 0x31
#
IPROTO_METADATA = 0x32
IPROTO_SQL_TEXT = 0x40
IPROTO_SQL_BIND = 0x41
IPROTO_SQL_INFO = 0x42
IPROTO_SQL_INFO_ROW_COUNT = 0x00
IPROTO_SQL_INFO_AUTOINCREMENT_IDS = 0x01

IPROTO_GREETING_SIZE = 128
IPROTO_BODY_MAX_LEN = 2147483648
Expand All @@ -44,6 +51,7 @@
REQUEST_TYPE_EVAL = 8
REQUEST_TYPE_UPSERT = 9
REQUEST_TYPE_CALL = 10
REQUEST_TYPE_EXECUTE = 11
REQUEST_TYPE_PING = 64
REQUEST_TYPE_JOIN = 65
REQUEST_TYPE_SUBSCRIBE = 66
Expand Down
Loading