]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Correctly handle comparing an INTEGER PRIMARY KEY against a floating point
authordrh <drh@noemail.net>
Sun, 6 Jul 2003 17:22:25 +0000 (17:22 +0000)
committerdrh <drh@noemail.net>
Sun, 6 Jul 2003 17:22:25 +0000 (17:22 +0000)
number.  Ticket #377. (CVS 1045)

FossilOrigin-Name: 982aa3356bcc217003cd9e6a829619219c334797

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

index f86502eff0b9f8c98c80b4cac75f7f3e9ee782d7..a9d6068b66c20f50af328aafec2d0621ad5fa691 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Make\ssure\sindices\sin\sATTACH-ed\sdatabases\sare\sput\sinto\sthe\sright\shash\stable.\nTicket\s#354.\s(CVS\s1044)
-D 2003-07-01T18:13:15
+C Correctly\shandle\scomparing\san\sINTEGER\sPRIMARY\sKEY\sagainst\sa\sfloating\spoint\nnumber.\s\sTicket\s#377.\s(CVS\s1045)
+D 2003-07-06T17:22:25
 F Makefile.in 9ad23ed4ca97f9670c4496432e3fbd4b3760ebde
 F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@@ -59,9 +59,9 @@ F src/trigger.c 6ff205aaac4869e402d9902e528e1d22a85de14c
 F src/update.c 24260b4fda00c9726d27699a0561d53c0dccc397
 F src/util.c 566c7780170dd11fb1ad5de3ba81f0dfea7cccf0
 F src/vacuum.c 0820984615786c9ccdaad8032a792309b354a8eb
-F src/vdbe.c f5d5779b1f1884e0922f70f459998f8f9a934097
+F src/vdbe.c 3779009cc7658d61b11d1980d6efc8af1ab0f7a1
 F src/vdbe.h 985c24f312d10f9ef8f9a8b8ea62fcdf68e82f21
-F src/where.c 1e645d430cb4b347159c28c6085e9801160f2099
+F src/where.c 6834140938558f6ca8ee5e6decd7b6a74d65af1f
 F test/all.test 569a92a8ee88f5300c057cc4a8f50fbbc69a3242
 F test/attach.test eccea2937923ac0be8ad1072585fd3b4f0b85598
 F test/attach2.test d69003d59f5b1260dfcf3fcc5f60f164680aa7ee
@@ -106,7 +106,7 @@ F test/pragma.test 4c707a6f7d3cbf72d46ed9d9eb0e1ea6e42dc3e4
 F test/printf.test 3ed02f1361402c0767492cd5cef4650e61df8308
 F test/quick.test c527bdb899b12a8cd8ceecce45f72922099f4095
 F test/quote.test 08f23385c685d3dc7914ec760d492cacea7f6e3d
-F test/rowid.test e4d6d619d8699a1fa5a48f3f78db39985bd47ebb
+F test/rowid.test 1936d0d866a8105ab53cf6cb40a549b6664d06ce
 F test/select1.test 0d708cec567104653ec9aa49fecf3444a2e7d150
 F test/select2.test aceea74fd895b9d007512f72499db589735bd8e4
 F test/select3.test 445a1a3dde4e2fd32541b311f55da5e2f8079d76
@@ -168,7 +168,7 @@ F www/speed.tcl 2f6b1155b99d39adb185f900456d1d592c4832b3
 F www/sqlite.tcl 3c83b08cf9f18aa2d69453ff441a36c40e431604
 F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331
 F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1
-P 9a87f2f326d7fc8bb9f832d0e3fd31141e14e08f
-R 690d67d55b36d46742737ebfcab1300e
+P eb4582831d536cd26a1738f9ad197e40486d0958
+R 43de0a05995ade2e959437ae132085ed
 U drh
-Z bb2529e86a37931176f7781f5edf39cb
+Z 1a72f69ccd161f8e14773ca5f56644c7
index e2376bf7ba9ed08e6d9dfa52cdf43e76ad3165f6..b04cb4d7bb7431d75a9e6171e5e7009159c40481 100644 (file)
@@ -1 +1 @@
-eb4582831d536cd26a1738f9ad197e40486d0958
\ No newline at end of file
+982aa3356bcc217003cd9e6a829619219c334797
\ No newline at end of file
index ee69bc2cae768852428cbc56934b39f59ef160b2..ee5b6b0ea88caa7d895b7d3b03a27cf69d51f127 100644 (file)
@@ -36,7 +36,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.231 2003/06/29 20:25:08 drh Exp $
+** $Id: vdbe.c,v 1.232 2003/07/06 17:22:25 drh Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -2268,6 +2268,30 @@ case OP_AddImm: {
   break;
 }
 
+/* Opcode: IsNumeric 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.
+*/
+case OP_IsNumeric: {
+  int tos = p->tos;
+  int r;
+  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 ){
+    POPSTACK;
+    pc = pOp->p2 - 1;
+  }
+  break;
+}
+
 /* Opcode: MustBeInt P1 P2 *
 ** 
 ** Force the top of the stack to be an integer.  If the top of the
@@ -2294,14 +2318,24 @@ case OP_MustBeInt: {
   }else if( aStack[tos].flags & STK_Str ){
     int v;
     if( !toInt(zStack[tos], &v) ){
-      goto mismatch;
+      double r;
+      if( !sqliteIsNumber(zStack[tos]) ){
+        goto mismatch;
+      }
+      Realify(p, tos);
+      assert( (aStack[tos].flags & STK_Real)!=0 );
+      v = aStack[tos].r;
+      r = (double)v;
+      if( r!=aStack[tos].r ){
+        goto mismatch;
+      }
     }
-    p->aStack[tos].i = v;
+    aStack[tos].i = v;
   }else{
     goto mismatch;
   }
   Release(p, tos);
-  p->aStack[tos].flags = STK_Int;
+  aStack[tos].flags = STK_Int;
   break;
 
 mismatch:
index 1400c62858cd0dc9e3bb18297ee520eab18989a2..a0504ec6d28933bb9f0b83f457f6518ea2d0d6bd 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.79 2003/05/17 17:35:13 drh Exp $
+** $Id: where.c,v 1.80 2003/07/06 17:22:25 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -853,7 +853,7 @@ WhereInfo *sqliteWhereBegin(
         }else{
           sqliteExprCode(pParse, aExpr[k].p->pLeft);
         }
-        sqliteVdbeAddOp(v, OP_MustBeInt, 1, brk);
+        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);
         }
@@ -872,7 +872,7 @@ WhereInfo *sqliteWhereBegin(
         }else{
           sqliteExprCode(pParse, aExpr[k].p->pLeft);
         }
-        sqliteVdbeAddOp(v, OP_MustBeInt, 1, sqliteVdbeCurrentAddr(v)+1);
+        /* sqliteVdbeAddOp(v, OP_MustBeInt, 0, sqliteVdbeCurrentAddr(v)+1); */
         pLevel->iMem = pParse->nMem++;
         sqliteVdbeAddOp(v, OP_MemStore, pLevel->iMem, 0);
         if( aExpr[k].p->op==TK_LT || aExpr[k].p->op==TK_GT ){
index bec3167758bf8a6b140cf3bd86993ab362b6fce8..67dc552525f35ddeefe540ab5449a5782278dedd 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.11 2003/06/01 01:10:33 drh Exp $
+# $Id: rowid.test,v 1.12 2003/07/06 17:22:25 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -417,5 +417,59 @@ do_test rowid-8.8 {
   }
 } {1 1 2 133 3 134}
 
+# ticket #377: Comparison between integer primiary key and floating point
+# values.
+#
+do_test rowid-9.1 {
+  execsql {
+    SELECT * FROM t3 WHERE a<123.5
+  }
+} {123}
+do_test rowid-9.2 {
+  execsql {
+    SELECT * FROM t3 WHERE a<124.5
+  }
+} {123 124}
+do_test rowid-9.3 {
+  execsql {
+    SELECT * FROM t3 WHERE a>123.5
+  }
+} {124}
+do_test rowid-9.4 {
+  execsql {
+    SELECT * FROM t3 WHERE a>122.5
+  }
+} {123 124}
+do_test rowid-9.5 {
+  execsql {
+    SELECT * FROM t3 WHERE a==123.5
+  }
+} {}
+do_test rowid-9.6 {
+  execsql {
+    SELECT * FROM t3 WHERE a==123.000
+  }
+} {123}
+do_test rowid-9.7 {
+  execsql {
+    SELECT * FROM t3 WHERE a>100.5 AND a<200.5
+  }
+} {123 124}
+do_test rowid-9.8 {
+  execsql {
+    SELECT * FROM t3 WHERE a>'xyz';
+  }
+} {}
+do_test rowid-9.9 {
+  execsql {
+    SELECT * FROM t3 WHERE a<'xyz';
+  }
+} {123 124}
+do_test rowid-9.10 {
+  execsql {
+    SELECT * FROM t3 WHERE a>=122.9 AND a<=123.1
+  }
+} {123}
+
 
 finish_test