diff --git a/test/box/sql.result b/test/box/sql.result index 93c819eb2507348d38919d0272b6b151a81f2613..947d4b4cd3a44d6f2b97cb02fd6e4ab547e5494f 100644 --- a/test/box/sql.result +++ b/test/box/sql.result @@ -23,3 +23,7 @@ Found 1 tuple: select * from t0 where k0 = 1 Found 1 tuple: [1, 'I am a tuple'] +delete from t0 where k0 = 1 +Delete OK, 1 row affected +select * from t0 where k0 = 1 +No match diff --git a/test/box/sql.test b/test/box/sql.test index ba955f39de372a1b3f64ae1a00b0c45407eab346..3353e832ecb582e7d09ba973550e209ddd848499 100644 --- a/test/box/sql.test +++ b/test/box/sql.test @@ -14,5 +14,7 @@ exec admin "save snapshot" exec sql 'select * from t0 where k0 = 1' server.restart() exec sql 'select * from t0 where k0 = 1' +exec sql 'delete from t0 where k0 = 1' +exec sql 'select * from t0 where k0 = 1' # vim: syntax=python diff --git a/test/lib/sql_ast.py b/test/lib/sql_ast.py index bfe70ab3dcf1b6f3d05828a4d7419864a5537c24..da08a3537f647dccca38a35423f2fc3b9cfb5683 100644 --- a/test/lib/sql_ast.py +++ b/test/lib/sql_ast.py @@ -6,6 +6,7 @@ import ctypes # command code, length, request id IPROTO_HEADER_LEN = 12 INSERT_REQUEST_FIXED_LEN = 8 +DELETE_REQUEST_FIXED_LEN = 4 SELECT_REQUEST_FIXED_LEN = 20 PACKET_BUF_LEN = 2048 @@ -93,6 +94,10 @@ def opt_resize_buf(buf, newsize): def pack_tuple(value_list, buf, offset): + """Represents <tuple> rule in tarantool protocol description. + Pack tuple into a binary representation. + buf and offset are in-out parameters, offset is advanced + to the amount of bytes that it took to pack the tuple""" # length of int field: 1 byte - field len (is always 4), 4 bytes - data INT_FIELD_LEN = 4 # max length of compressed integer @@ -172,7 +177,23 @@ class StatementDelete(StatementPing): def __init__(self, table_name, where): self.namespace_no = int(object_no_re.sub("", table_name)) - self.where = where + key_no = int(object_no_re.sub("", where[0])) + if key_no != 0: + raise RuntimeError("DELETE can only be made by the primary key (#0)") + self.value_list = where[1:] + + def pack(self): + buf = ctypes.create_string_buffer(PACKET_BUF_LEN) + (buf, offset) = pack_tuple(self.value_list, buf, DELETE_REQUEST_FIXED_LEN) + struct.pack_into("<L", buf, 0, self.namespace_no) + return buf[:offset] + + def unpack(self, response): + (return_code,) = struct.unpack("<L", response[:4]) + if return_code: + return format_error(return_code) + (result_code, row_count) = struct.unpack("<LL", response) + return "Delete OK, {0} row affected".format(row_count) class StatementSelect(StatementPing): reqeust_type = SELECT_REQUEST_TYPE