|Title:||replace function works on blobs|
|Last Modified:||2009-11-16 20:59:45|
|Version Found In:||3.4.2|
http://www.sqlite.org/cvstrac/tktview?tn=2613 (plus other discussion)
The replace documentation states that it works on strings. However it also accepts blobs for any of the parameters and coerces the the result to a string.
It should really error when provided with blobs.
If blobs are going to be supported then it should be required that all parameters are either string or blobs (ie all 3 the same type) and the output type be the same as the parameters type. cast can be used on the parameters to clarify if this is a byte based or character based operation.
The code is fairly complicated already. Being able to mix and match bytes with characters is likely to lead to bugs related to encodings (eg different results depending on utf16 or or utf8) and the possibility of producing invalidly encoded result strings by replacing the wrong bytes.
drh added on 2009-11-16 12:36:30:
rogerb added on 2009-11-16 19:18:34:
It is also an application error to be mixing bytes/blobs with text.
drh added on 2009-11-16 20:59:45:
At one point, we allowed read overruns of up to 2 bytes on invalid UTF, under the assumption that such overruns were harmless. But that assumption was proved wrong (see http://www.sqlite.org/src/info/3fe897352e) and such overruns have now been fixed.