New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sql: wrong types on concatenation w/ RANDOMBLOB() #3544
Comments
Ok, this bug turns out to be severe: zeroblob() usage leads to assertion (sic!):
I'm not going to open new issue, let's fix it in scope of current problem. |
For the record: according to ANSI, if one of concatenation operands is of TEXT type, then the rest must have the same type. Otherwise, error is raised. The same for binary-like types. Now concatenation operator ('||') accepts even numeric types. I suggest to re-work concatenation operator to allow only string-like types and validate their type equivalence. |
Accidentally, mask which is used to map type of VDBE memory cell into outer API types was replaced with MEM_TypeMask. But value of the latter is larger then possible values of VDBE memory cells types. Hence, if it is applied to memory cell, not only pure types is taken into consideration, but some additional flags (such as MEM_Zero) as well. Overall, it results in wrong type calculation for zeroed blobs, for instance. Lets return back previous mask. Follow-up #3698 Needed for #3544
Original SQLite operator of concatenation accepts all types of arguments. If type of parameter is not TEXT, it is implicitly converted to TEXT (except for NULLs). That contradicts ANSI (it is regulated by [1]), so lets allow only TEXT and BLOB as argument type for concatenation. Moreover, they both must be of the same type at the same time (i.e. both TEXT or BLOB). [1] SQL ANSI 2013, 9.5 Result of data type combination Part of #3544
Before this patch, resulting type of concatenation operator always was TEXT (i.e. type of memory cell containing result - MEM_Str). Lets fix it and return type depending on type of concatenation arguments: if both arguments are TEXT, then resulting type is TEXT; BLOB otherwise. Note that other options of combining types of arguments are illegal. Closes #3544
Accidentally, mask which is used to map type of VDBE memory cell into outer API types was replaced with MEM_TypeMask. But value of the latter is larger then possible values of VDBE memory cells types. Hence, if it is applied to memory cell, not only pure types is taken into consideration, but some additional flags (such as MEM_Zero) as well. Overall, it results in wrong type calculation for zeroed blobs, for instance. Lets return back previous mask. Follow-up #3698 Needed for #3544
Original SQLite operator of concatenation accepts all types of arguments. If type of parameter is not TEXT, it is implicitly converted to TEXT (except for NULLs). That contradicts ANSI (it is regulated by [1]), so lets allow only TEXT and BLOB as argument type for concatenation. Moreover, they both must be of the same type at the same time (i.e. both TEXT or BLOB). [1] SQL ANSI 2013, 9.5 Result of data type combination Part of #3544
TYPEOF(randomblob(5) || zeroblob(5)) is 'text'.
This is SQLite behaviour -- || always causes text
or null results -- but once again it seems to be a
rule that depends on the operator, not the operands.
Result = 'text'
This is a part of #2347
The text was updated successfully, but these errors were encountered: