Skip to content

Commit

Permalink
sql: introduce uuid to quote()
Browse files Browse the repository at this point in the history
Prior to this patch, built-in SQL function quote() could not work with
uuid. It now returns a string representation of the received uuid.

Part of #6164
  • Loading branch information
ImeevMA authored and yanshtunder committed Oct 4, 2021
1 parent 8364df2 commit bc64f46
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/box/sql/func.c
Expand Up @@ -1095,8 +1095,8 @@ quoteFunc(sql_context * context, int argc, sql_value ** argv)
{
assert(argc == 1);
UNUSED_PARAMETER(argc);
switch (sql_value_type(argv[0])) {
case MP_DOUBLE:{
switch (argv[0]->type) {
case MEM_TYPE_DOUBLE:{
double r1, r2;
char zBuf[50];
r1 = mem_get_double_unsafe(argv[0]);
Expand All @@ -1110,14 +1110,20 @@ quoteFunc(sql_context * context, int argc, sql_value ** argv)
SQL_TRANSIENT);
break;
}
case MP_UINT:
case MP_INT:{
case MEM_TYPE_UUID: {
char buf[UUID_STR_LEN + 1];
tt_uuid_to_string(&argv[0]->u.uuid, &buf[0]);
sql_result_text(context, buf, UUID_STR_LEN, SQL_TRANSIENT);
break;
}
case MEM_TYPE_UINT:
case MEM_TYPE_INT: {
sql_result_value(context, argv[0]);
break;
}
case MP_BIN:
case MP_ARRAY:
case MP_MAP: {
case MEM_TYPE_BIN:
case MEM_TYPE_ARRAY:
case MEM_TYPE_MAP: {
char *zText = 0;
char const *zBlob = mem_as_bin(argv[0]);
int nBlob = mem_len_unsafe(argv[0]);
Expand All @@ -1143,7 +1149,7 @@ quoteFunc(sql_context * context, int argc, sql_value ** argv)
}
break;
}
case MP_STR:{
case MEM_TYPE_STR: {
int i, j;
u64 n;
const unsigned char *zArg = mem_as_ustr(argv[0]);
Expand Down Expand Up @@ -1171,7 +1177,7 @@ quoteFunc(sql_context * context, int argc, sql_value ** argv)
}
break;
}
case MP_BOOL: {
case MEM_TYPE_BOOL: {
sql_result_text(context,
SQL_TOKEN_BOOLEAN(mem_get_bool_unsafe(argv[0])),
-1, SQL_TRANSIENT);
Expand Down
3 changes: 3 additions & 0 deletions test/sql-tap/engine.cfg
Expand Up @@ -20,6 +20,9 @@
"gh-3332-tuple-format-leak.test.lua": {
"memtx": {"engine": "memtx"}
},
"gh-6164-uuid-follow-ups.test.lua": {
"memtx": {"engine": "memtx"}
},
"gh-4077-iproto-execute-no-bind.test.lua": {},
"*": {
"memtx": {"engine": "memtx"},
Expand Down
14 changes: 14 additions & 0 deletions test/sql-tap/gh-6164-uuid-follow-ups.test.lua
@@ -0,0 +1,14 @@
#!/usr/bin/env tarantool
local test = require("sqltester")
test:plan(1)

-- Make sure that function quote() can work with uuid.
test:do_execsql_test(
"gh-6164-1",
[[
SELECT quote(cast('11111111-1111-1111-1111-111111111111' as uuid));
]], {
'11111111-1111-1111-1111-111111111111'
})

test:finish_test()

0 comments on commit bc64f46

Please sign in to comment.