Skip to content
Snippets Groups Projects
Commit a281c742 authored by Andrey Saranchin's avatar Andrey Saranchin Committed by Vladimir Davydov
Browse files

memtx: raise an error if argument of select() is a "clear" dict

Currently, select/pairs/get look at an :array part of passed table,
that is why different problems occurs when passed to select() table
is not a regular array.

Now we will check if passed table is not "clear dict"
(not empty table without array part). Invalid queries
like s:select{key = 'value'} will fail with an appropriate
error, but the problems with dicts containing array part
still remain (for example, s:select{1, key = 'value'} is
the same as s:select{1}).

Closes #6167
parent 0315c2db
No related branches found
No related tags found
No related merge requests found
## bugfix/memtx
* Now memtx will raise an error if "clear" dictionary was passed to s:select() (gh-6167)
......@@ -79,8 +79,13 @@ local tuple_encode = function(tmpbuf, obj)
elseif is_tuple(obj) then
encode_r(tmpbuf, obj, 1)
elseif type(obj) == "table" then
encode_array(tmpbuf, #obj)
for i = 1, #obj, 1 do
local obj_size = #obj
if obj_size == 0 and not rawequal(next(obj), nil) then
-- dictionary cannot represent a tuple
return box.error(box.error.TUPLE_NOT_ARRAY)
end
encode_array(tmpbuf, obj_size)
for i = 1, obj_size, 1 do
encode_r(tmpbuf, obj[i], 1)
end
else
......
-- test-run result file version 2
s = box.schema.create_space('test')
| ---
| ...
_ = s:create_index('pk')
| ---
| ...
dict = {key = 'value'}
| ---
| ...
-- There must be errors saying tuple must be array
s:select(dict)
| ---
| - error: Tuple/Key must be MsgPack array
| ...
s:pairs(dict)
| ---
| - error: Tuple/Key must be MsgPack array
| ...
s:get(dict)
| ---
| - error: Tuple/Key must be MsgPack array
| ...
s:drop()
| ---
| ...
s = box.schema.create_space('test')
_ = s:create_index('pk')
dict = {key = 'value'}
-- There must be errors saying tuple must be array
s:select(dict)
s:pairs(dict)
s:get(dict)
s:drop()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment