I think I may have found the problem:
The ToNumeric opcode calls sqlite3VdbeMemNumerify() which has (in 3.7.14.1) the
following code:
if( 0==sqlite3Atoi64(pMem->z, &pMem->u.i, pMem->n, pMem->enc) ){
MemSetTypeFlag(pMem, MEM_Int);
}else{
pMem->r = sqlite3VdbeRealValue(pMem);
MemSetTypeFlag(pMem, MEM_Real);
sqlite3VdbeIntegerAffinity(pMem);
}
So the result is an integer only oif the sqlite3Atoi64 function returns 0
This function hast he following head:
int sqlite3Atoi64(const char *zNum, i64 *pNum, int length, u8 enc){
int incr = (enc==SQLITE_UTF8?1:2);
u64 u = 0;
int neg = 0; /* assume positive */
int i;
int c = 0;
const char *zStart;
const char *zEnd = zNum + length;
...
Where the superflous space at the end of the string causes the following
condition to be TRUE
if( (c!=0 && &zNum[i]<zEnd) || (i==0 && zStart==zNum) || i>19*incr ){
/* zNum is empty or contains non-numeric text or is longer
** than 19 digits (thus guaranteeing that it is too large) */
return 1;
The conversion/counting loop inbetween needs to set zEnd to the last character
scanned to fix this.
-----Ursprüngliche Nachricht-----
Von: sqlite-users [mailto:[email protected]] Im
Auftrag von Ralf Junker
Gesendet: Dienstag, 23. Jänner 2018 16:22
An: SQLite mailing list <[email protected]>
Betreff: [EXTERNAL] Re: [sqlite] sqlite 3.21.0 bug? SELECT CAST
('9223372036854775807 ' AS NUMERIC);
On 23.01.2018 15:31, Richard Hipp wrote:
> I'm still unable to reproduce this problem.
sqlite3.exe from this ZIP:
https://www.sqlite.org/2018/sqlite-tools-win32-x86-3220000.zip
Running on Windows 7:
SQLite version 3.22.0 2018-01-22 18:45:57 Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> SELECT CAST ('9223372036854775807 ' AS NUMERIC);
9.22337203685478e+18
sqlite> SELECT CAST ('9223372036854775807' AS NUMERIC);
9223372036854775807
Notice the trailing white space which makes the difference.
Ralf
_______________________________________________
sqlite-users mailing list
[email protected]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
___________________________________________
Gunter Hick | Software Engineer | Scientific Games International GmbH |
Klitschgasse 2-4, A-1130 Vienna | FN 157284 a, HG Wien, DVR: 0430013 | (O) +43
1 80100 - 0
May be privileged. May be confidential. Please delete if not the addressee.
_______________________________________________
sqlite-users mailing list
[email protected]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users