]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix comparisons of ROWID against floating point numbers so that they work
authordrh <drh@noemail.net>
Wed, 14 Jan 2004 21:59:22 +0000 (21:59 +0000)
committerdrh <drh@noemail.net>
Wed, 14 Jan 2004 21:59:22 +0000 (21:59 +0000)
correctly.  Ticket #377 and #567. (CVS 1178)

FossilOrigin-Name: c9ac3db8e08403398ec344757385334601a59374

manifest
manifest.uuid
src/encode.c
src/vdbe.c
src/where.c
test/misc3.test
test/rowid.test

index 7a7c3c6c31a3ead7b521d8099556fa35d2b9a3bb..8acd41063b7ea88169b18b3b76ed737f4483e158 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Version\s2.8.11\s(CVS\s1177)
-D 2004-01-14T13:50:59
+C Fix\scomparisons\sof\sROWID\sagainst\sfloating\spoint\snumbers\sso\sthat\sthey\swork\ncorrectly.\s\sTicket\s#377\sand\s#567.\s(CVS\s1178)
+D 2004-01-14T21:59:23
 F Makefile.in 0515ff9218ad8d5a8f6220f0494b8ef94c67013b
 F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@@ -30,7 +30,7 @@ F src/build.c a7493c433de5b552f9535d8fa7ed80aaf135491e
 F src/copy.c 9e47975ea96751c658bcf1a0c4f0bb7c6ee61e73
 F src/date.c bb89fdb9c89e367b9a728c58cb96e4823974a2c1
 F src/delete.c 0f81e6799c089487615d38e042a2de4d2d6192bc
-F src/encode.c 25ea901a9cefb3d93774afa4a06b57cb58acf544
+F src/encode.c 9e70ea1e4e746f23f18180949e94f1bb1c2220d3
 F src/expr.c 866a6d7aacc2825aa13056ccbea1a16f436a1ca5
 F src/func.c 62cf8fae8147c0301d1c6a4a94fe0a78f7aa5b33
 F src/hash.c 9b56ef3b291e25168f630d5643a4264ec011c70e
@@ -61,11 +61,11 @@ F src/trigger.c ce83e017b407d046e909d05373d7f8ee70f9f7f9
 F src/update.c 24260b4fda00c9726d27699a0561d53c0dccc397
 F src/util.c 64995b5949a5d377629ffd2598747bc771cade1e
 F src/vacuum.c 77485a64a6e4e358170f150fff681c1624a092b0
-F src/vdbe.c ff3551cbe96d31ec50e6a0fef654d69c8cd9ab91
+F src/vdbe.c 763ff006f6e5a7c4dd5ba64d4967df5d49d08064
 F src/vdbe.h 3957844e46fea71fd030e78f6a3bd2f7e320fb43
 F src/vdbeInt.h eab39bc209b267271bc4afbcf4991d6c229bae9a
 F src/vdbeaux.c 6f2d43643f83656b2555b7ee320397805db11d4c
-F src/where.c 5b149c9851954156679741ea25b058c09f91bbfa
+F src/where.c 1302d728bd338c237e6a8282e4e3eadbbdf11e45
 F test/all.test 569a92a8ee88f5300c057cc4a8f50fbbc69a3242
 F test/attach.test c26848402e7ac829e043e1fa5e0eb87032e5d81d
 F test/attach2.test d0105f4e8b1debf0ac25ed7df986b5854620e172
@@ -104,7 +104,7 @@ F test/memleak.test a18e6810cae96d2f6f5136920267adbefc8e1e90
 F test/minmax.test 6d9b6d6ee34f42e2a58dffece1f76d35f446b3af
 F test/misc1.test 0b98d493b0cf55cb5f53e1f3df8107c166eecb5a
 F test/misc2.test 10c2ce26407d37411b96273e552d5095393732be
-F test/misc3.test d16aadeed2b1dfd94fd2c5c73c6f650ca7db389c
+F test/misc3.test 01698429c87174fbad2bf35c6d737b4f83264490
 F test/misuse.test 1095f26d1aed406c65e1d2eba651c4bb7c38cbff
 F test/notnull.test 7a08117a71e74b0321aaa937dbeb41a09d6eb1d0
 F test/null.test c14d0f4739f21e929b8115b72bf0c765b6bb1721
@@ -114,7 +114,7 @@ F test/printf.test 3ed02f1361402c0767492cd5cef4650e61df8308
 F test/progress.test 701b6115c2613128ececdfe1398a1bd0e1a4cfb3 x
 F test/quick.test c527bdb899b12a8cd8ceecce45f72922099f4095
 F test/quote.test 08f23385c685d3dc7914ec760d492cacea7f6e3d
-F test/rowid.test 1936d0d866a8105ab53cf6cb40a549b6664d06ce
+F test/rowid.test 77f7e8c7ca626a15ff91a536595b695cfce7c845
 F test/select1.test 0d708cec567104653ec9aa49fecf3444a2e7d150
 F test/select2.test aceea74fd895b9d007512f72499db589735bd8e4
 F test/select3.test 445a1a3dde4e2fd32541b311f55da5e2f8079d76
@@ -179,7 +179,7 @@ F www/speed.tcl 2f6b1155b99d39adb185f900456d1d592c4832b3
 F www/sqlite.tcl 3c83b08cf9f18aa2d69453ff441a36c40e431604
 F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da
 F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1
-P 2812dd5fc99c959f41b24b0f6b280b67b06fe9d9
-R 7743767b16f5b5e66e4c5fdeadd3f02e
+P a9f25347de6d2bf843a8aebf7935e9c8a1f2319c
+R 8641e6b22bbcab376fe70750a642a5f8
 U drh
-Z d2ade93349c33e5a70eeb1653f73e3b7
+Z 7e6cc2ec80fafcf5309e5e8766ecebcd
index 2f0597ff48875fe205d7ed2f9b1b5b7bf3202b8e..cb72c2d3fc85449f82ea051b665495d396ac72d5 100644 (file)
@@ -1 +1 @@
-a9f25347de6d2bf843a8aebf7935e9c8a1f2319c
\ No newline at end of file
+c9ac3db8e08403398ec344757385334601a59374
\ No newline at end of file
index d5e5514c706cac1f9f7f1add04e88f82497f29cf..925995d190855060c077465a10c6875b6d13ca73 100644 (file)
@@ -15,7 +15,7 @@
 ** data in an SQLite database.  The code in this file is not used by any other
 ** part of the SQLite library.
 **
-** $Id: encode.c,v 1.9 2003/06/28 16:25:34 drh Exp $
+** $Id: encode.c,v 1.10 2004/01/14 21:59:23 drh Exp $
 */
 #include <string.h>
 
@@ -190,16 +190,18 @@ int sqlite_decode_binary(const unsigned char *in, unsigned char *out){
 }
 
 #ifdef ENCODER_TEST
+#include <stdio.h>
 /*
 ** The subroutines above are not tested by the usual test suite.  To test
 ** these routines, compile just this one file with a -DENCODER_TEST=1 option
 ** and run the result.
 */
 int main(int argc, char **argv){
-  int i, j, n, m, nOut;
+  int i, j, n, m, nOut, nByte;
   unsigned char in[30000];
   unsigned char out[33000];
 
+  nByte = 0;
   for(i=0; i<sizeof(in); i++){
     printf("Test %d: ", i+1);
     n = rand() % (i+1);
@@ -213,6 +215,7 @@ int main(int argc, char **argv){
     }else{
       for(j=0; j<n; j++) in[j] = rand() & 0xff;
     }
+    nByte += n;
     nOut = sqlite_encode_binary(in, n, out);
     if( nOut!=strlen(out) ){
       printf(" ERROR return value is %d instead of %d\n", nOut, strlen(out));
@@ -241,5 +244,6 @@ int main(int argc, char **argv){
     }
     printf(" OK\n");
   }
+  fprintf(stderr, "Finished.  Total encoding: %d bytes\n", nByte);
 }
 #endif /* ENCODER_TEST */
index 8e01614ddac01159a77c578355a5d48ef771a2a9..505ff5fe31ad6410da5576a0e7a708f004729be7 100644 (file)
@@ -43,7 +43,7 @@
 ** in this file for details.  If in doubt, do not deviate from existing
 ** commenting and indentation practices when changing or adding code.
 **
-** $Id: vdbe.c,v 1.249 2004/01/07 20:37:52 drh Exp $
+** $Id: vdbe.c,v 1.250 2004/01/14 21:59:23 drh Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -1217,27 +1217,38 @@ case OP_AddImm: {
   break;
 }
 
-/* Opcode: IsNumeric P1 P2 *
+/* Opcode: ForceInt P1 P2 *
 **
-** Check the top of the stack to see if it is a numeric value.  A numeric
-** value is an integer, a real number, or a string that looks like an 
-** integer or a real number.  When P1==0, pop the stack and jump to P2
-** if the value is numeric.  Otherwise fall through and leave the stack
-** unchanged.  The sense of the test is inverted when P1==1.
+** Convert the top of the stack into an integer.  If the current top of
+** the stack is not numeric (meaning that is is a NULL or a string that
+** does not look like an integer or floating point number) then pop the
+** stack and jump to P2.  If the top of the stack is numeric then
+** convert it into the least integer that is greater than or equal to its
+** current value if P1==0, or to the least integer that is strictly
+** greater than its current value if P1==1.
 */
-case OP_IsNumeric: {
+case OP_ForceInt: {
   int tos = p->tos;
-  int r;
+  int v;
   VERIFY( if( tos<0 ) goto not_enough_stack; )
-  r = (aStack[tos].flags & (STK_Int|STK_Real))!=0 
-           || (zStack[tos] && sqliteIsNumber(zStack[tos]));
-  if( pOp->p1 ){
-    r = !r;
-  }
-  if( r ){
+  if( (aStack[tos].flags & (STK_Int|STK_Real))==0
+         && (zStack[tos]==0 || sqliteIsNumber(zStack[tos])==0) ){
     POPSTACK;
     pc = pOp->p2 - 1;
+    break;
+  }
+  if( aStack[tos].flags & STK_Int ){
+    v = aStack[tos].i + (pOp->p1!=0);
+  }else{
+    Realify(p, tos);
+    v = (int)aStack[tos].r;
+    if( aStack[tos].r>(double)v ) v++;
+    if( pOp->p1 && aStack[tos].r==(double)v ) v++;
   }
+  if( aStack[tos].flags & STK_Dyn ) sqliteFree(zStack[tos]);
+  zStack[tos] = 0;
+  aStack[tos].i = v;
+  aStack[tos].flags = STK_Int;
   break;
 }
 
index b93e2ceb21ca1c7bcff4bc812a6738809c1e74c4..1cfaf63d2bad2cdfb8c93afd795e8e77e257d110 100644 (file)
@@ -12,7 +12,7 @@
 ** This module contains C code that generates VDBE code used to process
 ** the WHERE clause of SQL statements.
 **
-** $Id: where.c,v 1.86 2004/01/07 20:37:52 drh Exp $
+** $Id: where.c,v 1.87 2004/01/14 21:59:24 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -855,10 +855,8 @@ WhereInfo *sqliteWhereBegin(
         }else{
           sqliteExprCode(pParse, aExpr[k].p->pLeft);
         }
-        sqliteVdbeAddOp(v, OP_IsNumeric, 1, brk);
-        if( aExpr[k].p->op==TK_LT || aExpr[k].p->op==TK_GT ){
-          sqliteVdbeAddOp(v, OP_AddImm, 1, 0);
-        }
+        sqliteVdbeAddOp(v, OP_ForceInt,
+          aExpr[k].p->op==TK_LT || aExpr[k].p->op==TK_GT, brk);
         sqliteVdbeAddOp(v, OP_MoveTo, iCur, brk);
         aExpr[k].p = 0;
       }else{
index fcecdeb67f823f56a06682a47abf0aec525862b4..980ec5a7479cb5269eb7a84662cec83082f3df82 100644 (file)
@@ -13,7 +13,7 @@
 # This file implements tests for miscellanous features that were
 # left out of other test files.
 #
-# $Id: misc3.test,v 1.5 2004/01/14 13:38:54 drh Exp $
+# $Id: misc3.test,v 1.6 2004/01/14 21:59:24 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -207,4 +207,5 @@ do_test misc3-4.3 {
   }
 } {64}
 
+
 finish_test
index 67dc552525f35ddeefe540ab5449a5782278dedd..52172323ac0fde3cdcc4b14898d778be0547a4cc 100644 (file)
@@ -12,7 +12,7 @@
 # focus of this file is testing the magic ROWID column that is
 # found on all tables.
 #
-# $Id: rowid.test,v 1.12 2003/07/06 17:22:25 drh Exp $
+# $Id: rowid.test,v 1.13 2004/01/14 21:59:24 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -471,5 +471,163 @@ do_test rowid-9.10 {
   }
 } {123}
 
+# Ticket #567.  Comparisons of ROWID or integery primary key against
+# floating point numbers still do not always work.
+#
+do_test rowid-10.1 {
+  execsql {
+    CREATE TABLE t5(a);
+    INSERT INTO t5 VALUES(1);
+    INSERT INTO t5 VALUES(2);
+    INSERT INTO t5 SELECT a+2 FROM t5;
+    INSERT INTO t5 SELECT a+4 FROM t5;
+    SELECT rowid, * FROM t5;
+  }
+} {1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8}
+do_test rowid-10.2 {
+  execsql {SELECT rowid, a FROM t5 WHERE rowid>=5.5}
+} {6 6 7 7 8 8}
+do_test rowid-10.3 {
+  execsql {SELECT rowid, a FROM t5 WHERE rowid>=5.0}
+} {5 5 6 6 7 7 8 8}
+do_test rowid-10.4 {
+  execsql {SELECT rowid, a FROM t5 WHERE rowid>5.5}
+} {6 6 7 7 8 8}
+do_test rowid-10.3.2 {
+  execsql {SELECT rowid, a FROM t5 WHERE rowid>5.0}
+} {6 6 7 7 8 8}
+do_test rowid-10.5 {
+  execsql {SELECT rowid, a FROM t5 WHERE 5.5<=rowid}
+} {6 6 7 7 8 8}
+do_test rowid-10.6 {
+  execsql {SELECT rowid, a FROM t5 WHERE 5.5<rowid}
+} {6 6 7 7 8 8}
+do_test rowid-10.7 {
+  execsql {SELECT rowid, a FROM t5 WHERE rowid<=5.5}
+} {1 1 2 2 3 3 4 4 5 5}
+do_test rowid-10.8 {
+  execsql {SELECT rowid, a FROM t5 WHERE rowid<5.5}
+} {1 1 2 2 3 3 4 4 5 5}
+do_test rowid-10.9 {
+  execsql {SELECT rowid, a FROM t5 WHERE 5.5>=rowid}
+} {1 1 2 2 3 3 4 4 5 5}
+do_test rowid-10.10 {
+  execsql {SELECT rowid, a FROM t5 WHERE 5.5>rowid}
+} {1 1 2 2 3 3 4 4 5 5}
+do_test rowid-10.11 {
+  execsql {SELECT rowid, a FROM t5 WHERE rowid>=5.5 ORDER BY rowid DESC}
+} {8 8 7 7 6 6}
+do_test rowid-10.11.2 {
+  execsql {SELECT rowid, a FROM t5 WHERE rowid>=5.0 ORDER BY rowid DESC}
+} {8 8 7 7 6 6 5 5}
+do_test rowid-10.12 {
+  execsql {SELECT rowid, a FROM t5 WHERE rowid>5.5 ORDER BY rowid DESC}
+} {8 8 7 7 6 6}
+do_test rowid-10.12.2 {
+  execsql {SELECT rowid, a FROM t5 WHERE rowid>5.0 ORDER BY rowid DESC}
+} {8 8 7 7 6 6}
+do_test rowid-10.13 {
+  execsql {SELECT rowid, a FROM t5 WHERE 5.5<=rowid ORDER BY rowid DESC}
+} {8 8 7 7 6 6}
+do_test rowid-10.14 {
+  execsql {SELECT rowid, a FROM t5 WHERE 5.5<rowid ORDER BY rowid DESC}
+} {8 8 7 7 6 6}
+do_test rowid-10.15 {
+  execsql {SELECT rowid, a FROM t5 WHERE rowid<=5.5 ORDER BY rowid DESC}
+} {5 5 4 4 3 3 2 2 1 1}
+do_test rowid-10.16 {
+  execsql {SELECT rowid, a FROM t5 WHERE rowid<5.5 ORDER BY rowid DESC}
+} {5 5 4 4 3 3 2 2 1 1}
+do_test rowid-10.17 {
+  execsql {SELECT rowid, a FROM t5 WHERE 5.5>=rowid ORDER BY rowid DESC}
+} {5 5 4 4 3 3 2 2 1 1}
+do_test rowid-10.18 {
+  execsql {SELECT rowid, a FROM t5 WHERE 5.5>rowid ORDER BY rowid DESC}
+} {5 5 4 4 3 3 2 2 1 1}
+
+do_test rowid-10.30 {
+  execsql {
+    CREATE TABLE t6(a);
+    INSERT INTO t6(rowid,a) SELECT -a,a FROM t5;
+    SELECT rowid, * FROM t6;
+  }
+} {-8 8 -7 7 -6 6 -5 5 -4 4 -3 3 -2 2 -1 1}
+do_test rowid-10.31.1 {
+  execsql {SELECT rowid, a FROM t6 WHERE rowid>=-5.5}
+} {-5 5 -4 4 -3 3 -2 2 -1 1}
+do_test rowid-10.31.2 {
+  execsql {SELECT rowid, a FROM t6 WHERE rowid>=-5.0}
+} {-5 5 -4 4 -3 3 -2 2 -1 1}
+do_test rowid-10.32.1 {
+  execsql {SELECT rowid, a FROM t6 WHERE rowid>=-5.5 ORDER BY rowid DESC}
+} {-1 1 -2 2 -3 3 -4 4 -5 5}
+do_test rowid-10.32.1 {
+  execsql {SELECT rowid, a FROM t6 WHERE rowid>=-5.0 ORDER BY rowid DESC}
+} {-1 1 -2 2 -3 3 -4 4 -5 5}
+do_test rowid-10.33 {
+  execsql {SELECT rowid, a FROM t6 WHERE -5.5<=rowid}
+} {-5 5 -4 4 -3 3 -2 2 -1 1}
+do_test rowid-10.34 {
+  execsql {SELECT rowid, a FROM t6 WHERE -5.5<=rowid ORDER BY rowid DESC}
+} {-1 1 -2 2 -3 3 -4 4 -5 5}
+do_test rowid-10.35.1 {
+  execsql {SELECT rowid, a FROM t6 WHERE rowid>-5.5}
+} {-5 5 -4 4 -3 3 -2 2 -1 1}
+do_test rowid-10.35.2 {
+  execsql {SELECT rowid, a FROM t6 WHERE rowid>-5.0}
+} {-4 4 -3 3 -2 2 -1 1}
+do_test rowid-10.36.1 {
+  execsql {SELECT rowid, a FROM t6 WHERE rowid>-5.5 ORDER BY rowid DESC}
+} {-1 1 -2 2 -3 3 -4 4 -5 5}
+do_test rowid-10.36.2 {
+  execsql {SELECT rowid, a FROM t6 WHERE rowid>-5.0 ORDER BY rowid DESC}
+} {-1 1 -2 2 -3 3 -4 4}
+do_test rowid-10.37 {
+  execsql {SELECT rowid, a FROM t6 WHERE -5.5<rowid}
+} {-5 5 -4 4 -3 3 -2 2 -1 1}
+do_test rowid-10.38 {
+  execsql {SELECT rowid, a FROM t6 WHERE -5.5<rowid ORDER BY rowid DESC}
+} {-1 1 -2 2 -3 3 -4 4 -5 5}
+do_test rowid-10.39 {
+  execsql {SELECT rowid, a FROM t6 WHERE rowid<=-5.5}
+} {-8 8 -7 7 -6 6}
+do_test rowid-10.40 {
+  execsql {SELECT rowid, a FROM t6 WHERE rowid<=-5.5 ORDER BY rowid DESC}
+} {-6 6 -7 7 -8 8}
+do_test rowid-10.41 {
+  execsql {SELECT rowid, a FROM t6 WHERE -5.5>=rowid}
+} {-8 8 -7 7 -6 6}
+do_test rowid-10.42 {
+  execsql {SELECT rowid, a FROM t6 WHERE -5.5>=rowid ORDER BY rowid DESC}
+} {-6 6 -7 7 -8 8}
+do_test rowid-10.43 {
+  execsql {SELECT rowid, a FROM t6 WHERE rowid<-5.5}
+} {-8 8 -7 7 -6 6}
+do_test rowid-10.44 {
+  execsql {SELECT rowid, a FROM t6 WHERE rowid<-5.5 ORDER BY rowid DESC}
+} {-6 6 -7 7 -8 8}
+do_test rowid-10.44 {
+  execsql {SELECT rowid, a FROM t6 WHERE -5.5>rowid}
+} {-8 8 -7 7 -6 6}
+do_test rowid-10.46 {
+  execsql {SELECT rowid, a FROM t6 WHERE -5.5>rowid ORDER BY rowid DESC}
+} {-6 6 -7 7 -8 8}
+
+# Comparison of rowid against string values.
+#
+do_test rowid-11.1 {
+  execsql {SELECT rowid, a FROM t5 WHERE rowid>'abc'}
+} {}
+do_test rowid-11.2 {
+  execsql {SELECT rowid, a FROM t5 WHERE rowid>='abc'}
+} {}
+do_test rowid-11.3 {
+  execsql {SELECT rowid, a FROM t5 WHERE rowid<'abc'}
+} {1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8}
+do_test rowid-11.4 {
+  execsql {SELECT rowid, a FROM t5 WHERE rowid<='abc'}
+} {1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8}
+
+
 
 finish_test