aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshaneh <shaneh@noemail.net>2010-09-30 16:51:25 +0000
committershaneh <shaneh@noemail.net>2010-09-30 16:51:25 +0000
commit5f1d6b616e003f511fe113bcfe808698127fbf30 (patch)
tree0becc915ac5813ccd381aa61210aaf7e0a6705c2
parent9351862b6d269c96c18df8519bfd1a6ddb029e07 (diff)
downloadsqlite-5f1d6b616e003f511fe113bcfe808698127fbf30.tar.gz
sqlite-5f1d6b616e003f511fe113bcfe808698127fbf30.zip
Changes to remove sqlite3FitsIn64Bits().
FossilOrigin-Name: 43fef1cab6315f837782ea601d5a2aeb9843ab3c
-rw-r--r--manifest36
-rw-r--r--manifest.uuid2
-rw-r--r--src/expr.c15
-rw-r--r--src/sqliteInt.h1
-rw-r--r--src/test1.c2
-rw-r--r--src/util.c77
-rw-r--r--src/vdbe.c2
-rw-r--r--src/vdbemem.c2
-rw-r--r--test/expr.test2
9 files changed, 44 insertions, 95 deletions
diff --git a/manifest b/manifest
index ba581099d..24b3c8385 100644
--- a/manifest
+++ b/manifest
@@ -1,8 +1,5 @@
------BEGIN PGP SIGNED MESSAGE-----
-Hash: SHA1
-
-C Fix\sthe\shandling\sof\sdefault\svalues\sfor\sALTER\sTABLE\sADD\sCOLUMN\scolumns\sso\nthat\sis\sable\sto\sdeal\swith\snegative\snumbers,\sincluding\slarge\snegative\snumbers.\nTicket\s[8454a207b9fd2243c4]
-D 2010-09-30T14:48:06
+C Changes\sto\sremove\ssqlite3FitsIn64Bits().
+D 2010-09-30T16:51:26
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in c599a15d268b1db2aeadea19df2adc3bf2eb6bee
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -130,7 +127,7 @@ F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac
F src/ctime.c 4f3aadad62c6c9f0d4e5a96718516ac4e3c598df
F src/date.c 1548fdac51377e4e7833251de878b4058c148e1b
F src/delete.c 7ed8a8c8b5f748ece92df173d7e0f7810c899ebd
-F src/expr.c 05dbb04833ea04c28e835bf67295e367ca1c52d8
+F src/expr.c c5749e45576a58d9de27e6a8462fa84eac0b32fd
F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb
F src/fkey.c 17950a28f28b23e8ad3feaac5fc88c324d2f600a
F src/func.c 2b7cf54d2569c2eba42fe81165d1932b546681a3
@@ -180,12 +177,12 @@ F src/select.c cf3013b1953348c7c6ff9636342e87b9fda68466
F src/shell.c 8517fc1f9c59ae4007e6cc8b9af91ab231ea2056
F src/sqlite.h.in a5b50e1bc4d4d9a3cc95386747220a839d0c40f7
F src/sqlite3ext.h 69dfb8116af51b84a029cddb3b35062354270c89
-F src/sqliteInt.h 6fb1558f7810dc13406c7629b9ea20ec46b701e8
+F src/sqliteInt.h c63b0340dfdfde18ff255ddccf004edd2d073288
F src/sqliteLimit.h a17dcd3fb775d63b64a43a55c54cb282f9726f44
F src/status.c 496913d4e8441195f6f2a75b1c95993a45b9b30b
F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
F src/tclsqlite.c e91019fb6787166abca23a81b16c07fecc2ed751
-F src/test1.c 6fbbb504a7d1069415e443ae687d61cab72fa51e
+F src/test1.c e8803ee4bf6766f1b9cd8a3fed1559cc05caa306
F src/test2.c 80d323d11e909cf0eb1b6fbb4ac22276483bcf31
F src/test3.c 056093cfef69ff4227a6bdb9108564dc7f45e4bc
F src/test4.c 0528360b5025688002a5feb6be906ddce52eaaee
@@ -226,15 +223,15 @@ F src/tokenize.c 604607d6813e9551cf5189d899e0a25c12681080
F src/trigger.c b8bedb9c0084ceb51a40f54fcca2ce048c8de852
F src/update.c 227e6cd512108b84f69421fc6c7aa1b83d60d6e0
F src/utf.c 1baeeac91707a4df97ccc6141ec0f808278af685
-F src/util.c 7a5fb16c0b9a3e4c9fa6c375c8f514bc3bb155b6
+F src/util.c 0cca1dff4d04bbb378e0a7c2d342396363e9f0b4
F src/vacuum.c 924bd1bcee2dfb05376f79845bd3b4cec7b54b2f
-F src/vdbe.c 597ef9aceeb4d695eb65a61453dc1139175cf893
+F src/vdbe.c 447577ca9db7cccac30dd8ea07aeb6a4ddee9cde
F src/vdbe.h 4de0efb4b0fdaaa900cf419b35c458933ef1c6d2
F src/vdbeInt.h 7f4cf1b2b69bef3a432b1f23dfebef57275436b4
F src/vdbeapi.c 03cddfa4f85cadf608c0d28ff6b622b7da432446
F src/vdbeaux.c de0b06b11a25293e820a49159eca9f1c51a64716
F src/vdbeblob.c 258a6010ba7a82b72b327fb24c55790655689256
-F src/vdbemem.c 09b637201d66dae067f2beb838996a7e8adae44f
+F src/vdbemem.c ef015d9d05fbf3fcce664dadd5b589663878ab50
F src/vdbetrace.c 864cef96919323482ebd9986f2132435115e9cc2
F src/vtab.c 6c90e3e65b2f026fc54703a8f3c917155f419d87
F src/wal.c 7081f148cb52b0cf2280e6384196402dc58130a3
@@ -369,7 +366,7 @@ F test/eval.test bc269c365ba877554948441e91ad5373f9f91be3
F test/exclusive.test 0ba00fb15aeec1eba3d4b03a271b5081e21c35be
F test/exclusive2.test 76e63c05349cb70d09d60b99d2ae625525ff5155
F test/exec.test e949714dc127eaa5ecc7d723efec1ec27118fdd7
-F test/expr.test 9f521ae22f00e074959f72ce2e55d46b9ed23f68
+F test/expr.test 620a636cf7b7d4e5834a0b9d83a4da372e24a7b7
F test/fallocate.test 43dc34b8c24be6baffadc3b4401ee15710ce83c6
F test/filectrl.test 97003734290887566e01dded09dc9e99cb937e9e
F test/filefmt.test f77c92141960b7933bc6691631d2ad62257ef40a
@@ -873,14 +870,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P 14eed3a0e0a45c6f2904a3a134aa27c159916f7b
-R 4d517dec75ee1dd489234109dd0359e9
-U drh
-Z 470c7c5b24a8c0836423cc96a5b1f790
------BEGIN PGP SIGNATURE-----
-Version: GnuPG v1.4.6 (GNU/Linux)
-
-iD8DBQFMpKMqoxKgR168RlERAvkLAJ0XiYNxedhD7GFhtTggvRsz2xpfLQCgjac7
-zIAfAuf6n9xnxhw6RMuzDI0=
-=1JR8
------END PGP SIGNATURE-----
+P ce6cc16e3a151a0c67855abde1411422dfcc8828
+R f10482e4b62453ab01ff046fc673997a
+U shaneh
+Z e009fe1b0e7c264af8f0ee9d5e4c3177
diff --git a/manifest.uuid b/manifest.uuid
index 3ddafafe1..8a4935242 100644
--- a/manifest.uuid
+++ b/manifest.uuid
@@ -1 +1 @@
-ce6cc16e3a151a0c67855abde1411422dfcc8828 \ No newline at end of file
+43fef1cab6315f837782ea601d5a2aeb9843ab3c \ No newline at end of file
diff --git a/src/expr.c b/src/expr.c
index cf1823d9d..41be16260 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -555,7 +555,7 @@ void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr){
/* Wildcard of the form "?nnn". Convert "nnn" to an integer and
** use it as the variable number */
i64 i;
- int bOk = sqlite3Atoi64(&z[1], &i, sqlite3Strlen30(&z[1]), SQLITE_UTF8);
+ int bOk = 0==sqlite3Atoi64(&z[1], &i, sqlite3Strlen30(&z[1]), SQLITE_UTF8);
pExpr->iColumn = (ynVar)i;
testcase( i==0 );
testcase( i==1 );
@@ -1932,9 +1932,7 @@ static void codeReal(Vdbe *v, const char *z, int negateFlag, int iMem){
** Generate an instruction that will put the integer describe by
** text z[0..n-1] into register iMem.
**
-** The z[] string will probably not be zero-terminated. But the
-** z[n] character is guaranteed to be something that does not look
-** like the continuation of the number.
+** Expr.u.zToken is always UTF8 and zero-terminated.
*/
static void codeInteger(Parse *pParse, Expr *pExpr, int negFlag, int iMem){
Vdbe *v = pParse->pVdbe;
@@ -1943,13 +1941,14 @@ static void codeInteger(Parse *pParse, Expr *pExpr, int negFlag, int iMem){
if( negFlag ) i = -i;
sqlite3VdbeAddOp2(v, OP_Integer, i, iMem);
}else{
+ int c;
+ i64 value;
const char *z = pExpr->u.zToken;
assert( z!=0 );
- if( sqlite3FitsIn64Bits(z, negFlag) ){
- i64 value;
+ c = sqlite3Atoi64(z, &value, sqlite3Strlen30(z), SQLITE_UTF8);
+ if( c==0 || (c==2 && negFlag) ){
char *zV;
- sqlite3Atoi64(z, &value, sqlite3Strlen30(z), SQLITE_UTF8);
- if( negFlag ) value = -value;
+ if( negFlag ){ value = -value; }
zV = dup8bytes(v, (char*)&value);
sqlite3VdbeAddOp4(v, OP_Int64, 0, iMem, 0, zV, P4_INT64);
}else{
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index dd5d23943..8515efcc4 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -2828,7 +2828,6 @@ int sqlite3FixExprList(DbFixer*, ExprList*);
int sqlite3FixTriggerStep(DbFixer*, TriggerStep*);
int sqlite3AtoF(const char *z, double*, int, u8);
int sqlite3GetInt32(const char *, int*);
-int sqlite3FitsIn64Bits(const char *, int);
int sqlite3Utf16ByteLen(const void *pData, int nChar);
int sqlite3Utf8CharLen(const char *pData, int nByte);
int sqlite3Utf8Read(const u8*, const u8**);
diff --git a/src/test1.c b/src/test1.c
index b83263d00..af83d5cb4 100644
--- a/src/test1.c
+++ b/src/test1.c
@@ -1235,7 +1235,7 @@ static int sqlite3_mprintf_int64(
return TCL_ERROR;
}
for(i=2; i<5; i++){
- if( !sqlite3Atoi64(argv[i], &a[i-2], 1000000, SQLITE_UTF8) ){
+ if( sqlite3Atoi64(argv[i], &a[i-2], 1000000, SQLITE_UTF8) ){
Tcl_AppendResult(interp, "argument is not a valid 64-bit integer", 0);
return TCL_ERROR;
}
diff --git a/src/util.c b/src/util.c
index 36689ec1d..2fa178f50 100644
--- a/src/util.c
+++ b/src/util.c
@@ -382,10 +382,10 @@ do_atof_calc:
/* store the result */
*pResult = result;
- /* return number of bytes used */
+ /* return true if number and no extra chracters after */
return z>=zEnd && sqlite3Isdigit(z[-incr]);
#else
- return sqlite3Atoi64(z, pResult, length, enc);
+ return !sqlite3Atoi64(z, pResult, length, enc);
#endif /* SQLITE_OMIT_FLOATING_POINT */
}
@@ -393,6 +393,7 @@ do_atof_calc:
** Compare the 19-character string zNum against the text representation
** value 2^63: 9223372036854775808. Return negative, zero, or positive
** if zNum is less than, equal to, or greater than the string.
+** Note that zNum must contain exactly 19 characters.
**
** Unlike memcmp() this routine is guaranteed to return the difference
** in the values of the last digit if the only difference is in the
@@ -421,10 +422,14 @@ static int compare2pow63(const char *zNum, int incr){
/*
-** Return TRUE if zNum is a 64-bit signed integer and write
-** the value of the integer into *pNum. If zNum is not an integer
-** or is an integer that is too large to be expressed with 64 bits,
-** then return false.
+** Convert zNum to a 64-bit signed integer and write
+** the value of the integer into *pNum.
+** If zNum is exactly 9223372036854665808, return 2.
+** This is a special case as the context will determine
+** if it is too big (used as a negative).
+** If zNum is not an integer or is an integer that
+** is too large to be expressed with 64 bits,
+** then return 1. Otherwise return 0.
**
** length is the number of bytes in the string (bytes, not characters).
** The string is not necessarily zero-terminated. The encoding is
@@ -433,7 +438,7 @@ static int compare2pow63(const char *zNum, int incr){
int sqlite3Atoi64(const char *zNum, i64 *pNum, int length, u8 enc){
int incr = (enc==SQLITE_UTF8?1:2);
i64 v = 0;
- int neg = 0;
+ int neg = 0; /* assume positive */
int i;
int c = 0;
const char *zStart;
@@ -445,10 +450,7 @@ int sqlite3Atoi64(const char *zNum, i64 *pNum, int length, u8 enc){
neg = 1;
zNum+=incr;
}else if( *zNum=='+' ){
- neg = 0;
zNum+=incr;
- }else{
- neg = 0;
}
do_atoi_calc:
zStart = zNum;
@@ -462,59 +464,18 @@ do_atoi_calc:
testcase( i==20 );
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 guaranting that it is too large) */
- return 0;
+ ** than 19 digits (thus guaranteeing that it is too large) */
+ return 1;
}else if( i<19*incr ){
/* Less than 19 digits, so we know that it fits in 64 bits */
- return 1;
+ return 0;
}else{
/* 19-digit numbers must be no larger than 9223372036854775807 if positive
** or 9223372036854775808 if negative. Note that 9223372036854665808
- ** is 2^63. */
- return compare2pow63(zNum, incr)<neg;
- }
-}
-
-/*
-** The string zNum represents an unsigned integer. The zNum string
-** consists of one or more digit characters and is terminated by
-** a zero character. Any stray characters in zNum result in undefined
-** behavior.
-**
-** If the unsigned integer that zNum represents will fit in a
-** 64-bit signed integer, return TRUE. Otherwise return FALSE.
-**
-** If the negFlag parameter is true, that means that zNum really represents
-** a negative number. (The leading "-" is omitted from zNum.) This
-** parameter is needed to determine a boundary case. A string
-** of "9223373036854775808" returns false if negFlag is false or true
-** if negFlag is true.
-**
-** Leading zeros are ignored.
-*/
-int sqlite3FitsIn64Bits(const char *zNum, int negFlag){
- int i;
- int neg = 0;
-
- assert( zNum[0]>='0' && zNum[0]<='9' ); /* zNum is an unsigned number */
-
- if( negFlag ) neg = 1-neg;
- while( *zNum=='0' ){
- zNum++; /* Skip leading zeros. Ticket #2454 */
- }
- for(i=0; zNum[i]; i++){ assert( zNum[i]>='0' && zNum[i]<='9' ); }
- testcase( i==18 );
- testcase( i==19 );
- testcase( i==20 );
- if( i<19 ){
- /* Guaranteed to fit if less than 19 digits */
- return 1;
- }else if( i>19 ){
- /* Guaranteed to be too big if greater than 19 digits */
- return 0;
- }else{
- /* Compare against 2^63. */
- return compare2pow63(zNum, 1)<neg;
+ ** is 2^63. Return 1 if to large */
+ c=compare2pow63(zNum, incr);
+ if( c==0 && neg==0 ) return 2; /* too big, exactly 9223372036854665808 */
+ return c<neg ? 0 : 1;
}
}
diff --git a/src/vdbe.c b/src/vdbe.c
index 8c5f8c8d9..7718516fa 100644
--- a/src/vdbe.c
+++ b/src/vdbe.c
@@ -254,7 +254,7 @@ static void applyNumericAffinity(Mem *pRec){
u8 enc = pRec->enc;
if( (pRec->flags&MEM_Str)==0 ) return;
if( sqlite3AtoF(pRec->z, &rValue, pRec->n, enc)==0 ) return;
- if( sqlite3Atoi64(pRec->z, &iValue, pRec->n, enc) ){
+ if( 0==sqlite3Atoi64(pRec->z, &iValue, pRec->n, enc) ){
pRec->u.i = iValue;
pRec->flags |= MEM_Int;
}else{
diff --git a/src/vdbemem.c b/src/vdbemem.c
index ec7086ed3..598cb9d66 100644
--- a/src/vdbemem.c
+++ b/src/vdbemem.c
@@ -476,7 +476,7 @@ int sqlite3VdbeMemNumerify(Mem *pMem){
if( (pMem->flags & (MEM_Int|MEM_Real|MEM_Null))==0 ){
assert( (pMem->flags & (MEM_Blob|MEM_Str))!=0 );
assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
- if( sqlite3Atoi64(pMem->z, &pMem->u.i, pMem->n, pMem->enc) ){
+ if( 0==sqlite3Atoi64(pMem->z, &pMem->u.i, pMem->n, pMem->enc) ){
MemSetTypeFlag(pMem, MEM_Int);
}else{
pMem->r = sqlite3VdbeRealValue(pMem);
diff --git a/test/expr.test b/test/expr.test
index 87ee8ed3c..140ab8d8b 100644
--- a/test/expr.test
+++ b/test/expr.test
@@ -290,7 +290,7 @@ ifcapable floatingpoint {
test_expr expr-4.14 {r1='abc', r2='Bbc'} {r1>r2} 1
test_expr expr-4.15 {r1='0', r2='0.0'} {r1==r2} 1
test_expr expr-4.16 {r1='0.000', r2='0.0'} {r1==r2} 1
- test_expr expr-4.17 {r1=' 0.000', r2=' 0.0'} {r1==r2} 0
+ test_expr expr-4.17 {r1=' 0.000', r2=' 0.0'} {r1==r2} 1
test_expr expr-4.18 {r1='0.0', r2='abc'} {r1<r2} 1
test_expr expr-4.19 {r1='0.0', r2='abc'} {r1==r2} 0
test_expr expr-4.20 {r1='0.0', r2='abc'} {r1>r2} 0