Skip to content

Commit

Permalink
sql: show value and its type in type mismatch error
Browse files Browse the repository at this point in the history
After this patch value and its type will be shown in description
of type mismatch error
  • Loading branch information
ImeevMA committed Jun 25, 2020
1 parent d87d1ce commit 7aae5f7
Show file tree
Hide file tree
Showing 22 changed files with 867 additions and 881 deletions.
17 changes: 6 additions & 11 deletions src/box/sql/vdbe.c
Expand Up @@ -2327,14 +2327,9 @@ case OP_Ge: { /* same as TK_GE, jump, in1, in3 */
int type_arg1 = flags1 & (MEM_Bool | MEM_Blob);
int type_arg3 = flags3 & (MEM_Bool | MEM_Blob);
if (type_arg1 != type_arg3) {
char *inconsistent_type = type_arg1 != 0 ?
mem_type_to_str(pIn3) :
mem_type_to_str(pIn1);
char *expected_type = type_arg1 != 0 ?
mem_type_to_str(pIn1) :
mem_type_to_str(pIn3);
diag_set(ClientError, ER_SQL_TYPE_MISMATCH,
inconsistent_type, expected_type);
sql_value_to_diag_str(pIn3),
mem_type_to_str(pIn1));
goto abort_due_to_error;
}
res = sqlMemCompare(pIn3, pIn1, NULL);
Expand Down Expand Up @@ -2386,13 +2381,13 @@ case OP_Ge: { /* same as TK_GE, jump, in1, in3 */
} else if (type == FIELD_TYPE_STRING) {
if ((flags1 & MEM_Str) == 0) {
diag_set(ClientError, ER_SQL_TYPE_MISMATCH,
mem_type_to_str(pIn3),
sql_value_to_diag_str(pIn3),
mem_type_to_str(pIn1));
goto abort_due_to_error;
}
if ((flags3 & MEM_Str) == 0) {
diag_set(ClientError, ER_SQL_TYPE_MISMATCH,
mem_type_to_str(pIn1),
sql_value_to_diag_str(pIn1),
mem_type_to_str(pIn3));
goto abort_due_to_error;
}
Expand Down Expand Up @@ -3580,7 +3575,7 @@ case OP_SeekGT: { /* jump, in3 */
goto seek_not_found;
}
diag_set(ClientError, ER_SQL_TYPE_MISMATCH,
field_type_strs[type], mem_type_to_str(mem));
sql_value_to_diag_str(mem), field_type_strs[type]);
goto abort_due_to_error;
}
#ifdef SQL_DEBUG
Expand Down Expand Up @@ -4719,7 +4714,7 @@ case OP_IdxGE: { /* jump */
(mem->flags & (MEM_Real | MEM_Int | MEM_UInt)) != 0)
continue;
diag_set(ClientError, ER_SQL_TYPE_MISMATCH,
field_type_strs[type], mem_type_to_str(mem));
sql_value_to_diag_str(mem), mem_type_to_str(mem));
goto abort_due_to_error;
}
#ifdef SQL_DEBUG
Expand Down
13 changes: 8 additions & 5 deletions src/box/sql/vdbemem.c
Expand Up @@ -1166,12 +1166,15 @@ sqlValueText(sql_value * pVal)
const char *
sql_value_to_diag_str(sql_value *value)
{
if (sql_value_type(value) == MP_BIN) {
if (mem_has_msgpack_subtype(value))
return sqlValueText(value);
if (sql_value_mp_type(value) == MP_BIN)
return "varbinary";
}
return sqlValueText(value);
char *type = mem_type_to_str(value);
char *str = (char *)sqlValueText(value);
if (str == NULL)
return "NULL";
if (strlen(str) < 80)
return tt_sprintf("'%s' (type: %s)", str, type);
return tt_sprintf("'%.80s...' (type: %s)", str, type);
}

/*
Expand Down
4 changes: 2 additions & 2 deletions test/sql-tap/autoinc.test.lua
Expand Up @@ -618,7 +618,7 @@ test:do_catchsql_test(
INSERT INTO t2 VALUES('asd');
]], {
-- <autoinc-10.2>
1, "Type mismatch: can not convert asd to integer"
1, "Type mismatch: can not convert 'asd' (type: text) to integer"
-- </autoinc-10.2>
})

Expand Down Expand Up @@ -811,7 +811,7 @@ test:do_catchsql_test(
INSERT INTO t1 SELECT s2, s2 FROM t1;
]], {
-- <autoinc-gh-3670>
1, "Type mismatch: can not convert a to integer"
1, "Type mismatch: can not convert 'a' (type: text) to integer"
-- </autoinc-gh-3670>
})

Expand Down
16 changes: 8 additions & 8 deletions test/sql-tap/cast.test.lua
Expand Up @@ -450,7 +450,7 @@ test:do_catchsql_test(
SELECT CAST('123abc' AS NUMBER)
]], {
-- <cast-1.45>
1, 'Type mismatch: can not convert 123abc to number'
1, "Type mismatch: can not convert '123abc' (type: text) to number"
-- </cast-1.45>
})

Expand All @@ -470,7 +470,7 @@ test:do_catchsql_test(
SELECT CAST('123abc' AS integer)
]], {
-- <cast-1.49>
1, 'Type mismatch: can not convert 123abc to integer'
1, "Type mismatch: can not convert '123abc' (type: text) to integer"
-- </cast-1.49>
})

Expand All @@ -480,7 +480,7 @@ test:do_catchsql_test(
SELECT CAST('123.5abc' AS NUMBER)
]], {
-- <cast-1.51>
1, 'Type mismatch: can not convert 123.5abc to number'
1, "Type mismatch: can not convert '123.5abc' (type: text) to number"
-- </cast-1.51>
})

Expand All @@ -490,7 +490,7 @@ test:do_catchsql_test(
SELECT CAST('123.5abc' AS integer)
]], {
-- <cast-1.53>
1, 'Type mismatch: can not convert 123.5abc to integer'
1, "Type mismatch: can not convert '123.5abc' (type: text) to integer"
-- </cast-1.53>
})

Expand Down Expand Up @@ -561,7 +561,7 @@ test:do_catchsql_test(
SELECT CAST('abc' AS NUMBER)
]], {
-- <case-1.66>
1, 'Type mismatch: can not convert abc to number'
1, "Type mismatch: can not convert 'abc' (type: text) to number"
-- </case-1.66>
})

Expand Down Expand Up @@ -829,7 +829,7 @@ test:do_test(
]]
end, {
-- <cast-4.1>
1, 'Type mismatch: can not convert abc to integer'
1, "Type mismatch: can not convert 'abc' (type: text) to integer"
-- </cast-4.1>
})

Expand All @@ -841,7 +841,7 @@ test:do_test(
]]
end, {
-- <cast-4.2>
1, 'Type mismatch: can not convert abc to integer'
1, "Type mismatch: can not convert 'abc' (type: text) to integer"
-- </cast-4.2>
})

Expand All @@ -853,7 +853,7 @@ test:do_test(
]]
end, {
-- <cast-4.4>
1, 'Type mismatch: can not convert abc to number'
1, "Type mismatch: can not convert 'abc' (type: text) to number"
-- </cast-4.4>
})

Expand Down

0 comments on commit 7aae5f7

Please sign in to comment.