-
Notifications
You must be signed in to change notification settings - Fork 46
Dbapi2 #161
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
Merged
Merged
Dbapi2 #161
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e99662d
appveyor: Add python 3.8 to environment matrix
artembo c529767
Add sql execute to Connection
artembo 00d315b
Make use_list param configurable
artembo e43e41e
Add pep-249 dbapi module
artembo 5160aaf
Add unit tests for dbapi module
artembo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,8 @@ | |
RequestSubscribe, | ||
RequestUpdate, | ||
RequestUpsert, | ||
RequestAuthenticate | ||
RequestAuthenticate, | ||
RequestExecute | ||
) | ||
from tarantool.space import Space | ||
from tarantool.const import ( | ||
|
@@ -49,13 +50,21 @@ | |
ITERATOR_ALL | ||
) | ||
from tarantool.error import ( | ||
Error, | ||
NetworkError, | ||
DatabaseError, | ||
InterfaceError, | ||
ConfigurationError, | ||
SchemaError, | ||
NetworkWarning, | ||
OperationalError, | ||
DataError, | ||
IntegrityError, | ||
InternalError, | ||
ProgrammingError, | ||
NotSupportedError, | ||
SchemaReloadException, | ||
Warning, | ||
warn | ||
) | ||
from tarantool.schema import Schema | ||
|
@@ -77,12 +86,20 @@ 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 | ||
artembo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Error = Error | ||
DatabaseError = DatabaseError | ||
InterfaceError = InterfaceError | ||
ConfigurationError = ConfigurationError | ||
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, | ||
|
@@ -92,6 +109,7 @@ def __init__(self, host, port, | |
reconnect_delay=RECONNECT_DELAY, | ||
connect_now=True, | ||
encoding=ENCODING_DEFAULT, | ||
use_list=True, | ||
artembo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
call_16=False, | ||
connection_timeout=CONNECTION_TIMEOUT): | ||
''' | ||
|
@@ -131,6 +149,7 @@ def __init__(self, host, port, | |
self.connected = False | ||
self.error = True | ||
self.encoding = encoding | ||
self.use_list = use_list | ||
self.call_16 = call_16 | ||
self.connection_timeout = connection_timeout | ||
if connect_now: | ||
|
@@ -143,6 +162,13 @@ def close(self): | |
self._socket.close() | ||
self._socket = None | ||
|
||
def is_closed(self): | ||
''' | ||
Returns the state of the Connection instance | ||
:rtype: Boolean | ||
''' | ||
return self._socket is None | ||
|
||
artembo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def connect_basic(self): | ||
if self.host == None: | ||
self.connect_unix() | ||
|
@@ -257,7 +283,7 @@ def _read_response(self): | |
|
||
def _send_request_wo_reconnect(self, request): | ||
''' | ||
:rtype: `Response` instance | ||
:rtype: `Response` instance or subclass | ||
|
||
:raise: NetworkError | ||
''' | ||
|
@@ -267,7 +293,7 @@ def _send_request_wo_reconnect(self, request): | |
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) | ||
|
@@ -792,3 +818,36 @@ def generate_sync(self): | |
Need override for async io connection | ||
''' | ||
return 0 | ||
|
||
def execute(self, query, params=None): | ||
artembo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
''' | ||
Execute SQL request. | ||
|
||
Tarantool binary protocol for SQL requests | ||
supports "qmark" and "named" param styles. | ||
Sequence of values can be used for "qmark" style. | ||
A mapping is used for "named" param style | ||
without leading colon in the keys. | ||
|
||
Example for "qmark" arguments: | ||
>>> args = ['[email protected]'] | ||
>>> c.execute('select * from "users" where "email"=?', args) | ||
|
||
Example for "named" arguments: | ||
>>> args = {'email': '[email protected]'} | ||
>>> c.execute('select * from "users" where "email"=:email', args) | ||
|
||
:param query: SQL syntax query | ||
:type query: str | ||
|
||
:param params: Bind values to use in the query. | ||
:type params: list, dict | ||
artembo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
:return: query result data | ||
:rtype: `Response` instance | ||
''' | ||
if not params: | ||
params = [] | ||
request = RequestExecute(self, query, params) | ||
response = self._send_request(request) | ||
return response | ||
artembo marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.