7
7
import msgpack
8
8
import hashlib
9
9
10
-
10
+ from tarantool . error import DatabaseError
11
11
from tarantool .const import (
12
12
IPROTO_CODE ,
13
13
IPROTO_SYNC ,
27
27
IPROTO_OPS ,
28
28
# IPROTO_INDEX_BASE,
29
29
IPROTO_SCHEMA_ID ,
30
+ IPROTO_SQL_TEXT ,
31
+ IPROTO_SQL_BIND ,
30
32
REQUEST_TYPE_OK ,
31
33
REQUEST_TYPE_PING ,
32
34
REQUEST_TYPE_SELECT ,
37
39
REQUEST_TYPE_UPSERT ,
38
40
REQUEST_TYPE_CALL16 ,
39
41
REQUEST_TYPE_CALL ,
42
+ REQUEST_TYPE_EXECUTE ,
40
43
REQUEST_TYPE_EVAL ,
41
44
REQUEST_TYPE_AUTHENTICATE ,
42
45
REQUEST_TYPE_JOIN ,
43
46
REQUEST_TYPE_SUBSCRIBE
44
47
)
48
+ from tarantool .response import Response , ResponseExecute
45
49
from tarantool .utils import (
46
50
strxor ,
47
51
binary_types
@@ -64,6 +68,7 @@ def __init__(self, conn):
64
68
self .conn = conn
65
69
self ._sync = None
66
70
self ._body = ''
71
+ self .response_class = Response
67
72
68
73
def __bytes__ (self ):
69
74
return self .header (len (self ._body )) + self ._body
@@ -332,3 +337,24 @@ def __init__(self, conn, sync):
332
337
request_body = msgpack .dumps ({IPROTO_CODE : self .request_type ,
333
338
IPROTO_SYNC : sync })
334
339
self ._body = request_body
340
+
341
+
342
+ class RequestExecute (Request ):
343
+ '''
344
+ Represents EXECUTE request
345
+ '''
346
+ request_type = REQUEST_TYPE_EXECUTE
347
+
348
+ # pylint: disable=W0231
349
+ def __init__ (self , conn , sql , args ):
350
+ super (RequestExecute , self ).__init__ (conn )
351
+ if isinstance (args , dict ):
352
+ args = [{":%s" % name : value } for name , value in args .items ()]
353
+ try :
354
+ request_body = msgpack .dumps ({IPROTO_SQL_TEXT : sql ,
355
+ IPROTO_SQL_BIND : args })
356
+ except ValueError as e :
357
+ raise DatabaseError ("Value error: %s" % e )
358
+
359
+ self ._body = request_body
360
+ self .response_class = ResponseExecute
0 commit comments