Skip to content

Commit

Permalink
sql: decode ARRAY and MAP types after SELECT
Browse files Browse the repository at this point in the history
Before this patch MSGPACK received using SELECT statement through
net.box was unpacked. Fixed in this patch.
  • Loading branch information
ImeevMA committed Nov 21, 2018
1 parent 29dde03 commit 8482e0c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/box/execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,21 @@ sql_column_to_messagepack(struct sqlite3_stmt *stmt, int i,
}
case SQLITE_BLOB: {
uint32_t len = sqlite3_column_bytes(stmt, i);
size = mp_sizeof_bin(len);
char *pos = (char *) region_alloc(region, size);
if (pos == NULL)
goto oom;
const char *s;
s = (const char *)sqlite3_column_blob(stmt, i);
mp_encode_bin(pos, s, len);
const char *s =
(const char *)sqlite3_column_blob(stmt, i);
if (sql_column_subtype(stmt, i) == SQL_SUBTYPE_MSGPACK) {
size = len;
char *pos = (char *)region_alloc(region, size);
if (pos == NULL)
goto oom;
memcpy(pos, s, len);
} else {
size = mp_sizeof_bin(len);
char *pos = (char *)region_alloc(region, size);
if (pos == NULL)
goto oom;
mp_encode_bin(pos, s, len);
}
break;
}
case SQLITE_NULL: {
Expand Down
32 changes: 32 additions & 0 deletions test/sql/iproto.result
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,38 @@ cn:execute("PRAGMA TABLE_INFO(test);")
box.sql.execute('DROP TABLE test')
---
...
-- SELECT returns unpacked msgpack.
format = {{name = 'id', type = 'integer'}, {name = 'x', type = 'any'}}
---
...
s = box.schema.space.create('test', {format=format})
---
...
i1 = s:create_index('i1', {parts = {1, 'int'}})
---
...
s:insert({1, {1,2,3}})
---
- [1, [1, 2, 3]]
...
s:insert({2, {a = 3}})
---
- [2, {'a': 3}]
...
cn:execute('select * from "test"')
---
- metadata:
- name: id
type: UNKNOWN
- name: x
type: UNKNOWN
rows:
- [1, [1, 2, 3]]
- [2, {'a': 3}]
...
s:drop()
---
...
cn:close()
---
...
Expand Down
9 changes: 9 additions & 0 deletions test/sql/iproto.test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,15 @@ box.sql.execute('CREATE TABLE test (id INT PRIMARY KEY)')
cn:execute("PRAGMA TABLE_INFO(test);")
box.sql.execute('DROP TABLE test')

-- SELECT returns unpacked msgpack.
format = {{name = 'id', type = 'integer'}, {name = 'x', type = 'any'}}
s = box.schema.space.create('test', {format=format})
i1 = s:create_index('i1', {parts = {1, 'int'}})
s:insert({1, {1,2,3}})
s:insert({2, {a = 3}})
cn:execute('select * from "test"')
s:drop()

cn:close()

box.schema.user.revoke('guest', 'read,write,execute', 'universe')
Expand Down

0 comments on commit 8482e0c

Please sign in to comment.