]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix type coercion rules for the IN operator. Ticket #1821. (CVS 3188)
authordrh <drh@noemail.net>
Tue, 23 May 2006 23:22:29 +0000 (23:22 +0000)
committerdrh <drh@noemail.net>
Tue, 23 May 2006 23:22:29 +0000 (23:22 +0000)
FossilOrigin-Name: 6e5a49762166a942e1b2c3beae8a30c07187eb10

manifest
manifest.uuid
src/expr.c
src/prepare.c
test/in.test
test/types2.test
www/datatype3.tcl

index ff0597b9535239badd973f8f890e54a94238909b..53cbb551b6101cb74f07901d24a20bfaee2c5dca 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C If\san\ssqlite3_mprintf()\scall\suses\sa\sdisallowed\sinternal-use-only\sconversion\ncharacter,\sthen\sabort\sthe\scall\swith\sa\s-1\serror\scode.\s\sTicket\s#1818.\s(CVS\s3187)
-D 2006-05-22T22:04:00
+C Fix\stype\scoercion\srules\sfor\sthe\sIN\soperator.\s\sTicket\s#1821.\s(CVS\s3188)
+D 2006-05-23T23:22:29
 F Makefile.in 5d8dff443383918b700e495de42ec65bc1c8865b
 F Makefile.linux-gcc 74ba0eadf88748a9ce3fd03d2a3ede2e6715baec
 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -42,7 +42,7 @@ F src/complete.c 7d1a44be8f37de125fcafd3d3a018690b3799675
 F src/date.c cd2bd5d1ebc6fa12d6312f69789ae5b0a2766f2e
 F src/delete.c 2dea1a83e6ef534346e74fd03114d3a7b16f08fc
 F src/experimental.c 1b2d1a6cd62ecc39610e97670332ca073c50792b
-F src/expr.c c85d7bee7d8e3184e00166c2c2ab6edd57b60486
+F src/expr.c f1ad18d0b7bb3abbf09cb30871ae6e7618447bc5
 F src/func.c acbbf533b55221f26760798d99b37de3ac5678fe
 F src/hash.c 449f3d6620193aa557f5d86cbc5cc6b87702b185
 F src/hash.h 1b3f7e2609141fd571f62199fc38687d262e9564
@@ -63,7 +63,7 @@ F src/pager.c ddd05666bb89808a516baef2c186d6a75887ae90
 F src/pager.h 43f32f3847421f7502cfbb66f4eb2302b8033818
 F src/parse.y ee1887ce0e6eea15cc728913ad3462898f88e9b0
 F src/pragma.c 27d5e395c5d950931c7ac4fe610e7c2993e2fa55
-F src/prepare.c 6afd730cc8851c0920b5f9050294646b1c2ab28c
+F src/prepare.c bbf12d3147116b284b157232efaef3bbe5df08fc
 F src/printf.c 7029e5f7344a478394a02c52837ff296ee1ab240
 F src/random.c d40f8d356cecbd351ccfab6eaedd7ec1b54f5261
 F src/select.c 8daba07a04a6d41f5267ea8353324cbe5a210e14
@@ -167,7 +167,7 @@ F test/fkey1.test 153004438d51e6769fb1ce165f6313972d6263ce
 F test/format4.test 9f31d41d4f926cab97b2ebe6be00a6ab12dece87
 F test/func.test 27d02fd00b7c2a6b5c8c302d02f9f20876ce5cc8
 F test/hook.test 7e7645fd9a033f79cce8fdff151e32715e7ec50a
-F test/in.test 40feeebc7e38576255051aad428322be1545e0f1
+F test/in.test ff339115cf02b302f05fb6495e74a1c544d85121
 F test/index.test e65df12bed94b2903ee89987115e1578687e9266
 F test/index2.test ee83c6b5e3173a3d7137140d945d9a5d4fdfb9d6
 F test/index3.test f66718cd92ce1216819d47e6a156755e4b2c4ca1
@@ -270,7 +270,7 @@ F test/trigger6.test 0e411654f122552da6590f0b4e6f781048a4a9b9
 F test/trigger7.test 0afa870be2ce1b132cdb85b17a4a4ef45aa8cece
 F test/trigger8.test 3a09275aa2214fdff56f731b1e775d8dfee4408a
 F test/types.test a74083427a73ff8af2723bae209d09cce5722c3a
-F test/types2.test 81dd1897be8ef4b5b73d0006e6076abe40610de3
+F test/types2.test 202b1afacdb80eddbb5fb5fab6207daaf5b4dfe1
 F test/types3.test ea0ddf793ad5cd17c3b029dd8f48473059f873b6
 F test/unique.test 0253c4227a5dc533e312202ce21ecfad18058d18
 F test/update.test 7669ca789d62c258b678e8aa7a22a57eac10f2cf
@@ -319,7 +319,7 @@ F www/conflict.tcl cdd0f4b59b0ba6d61f67e6a38f3ae45853bacb30
 F www/copyright-release.html 294e011760c439c44951a6bfecd4c81a1ae359e8
 F www/copyright-release.pdf cfca3558fc97095e57c6117d08f1f5b80d95125a
 F www/copyright.tcl 58b9586cac0d5914387cfc170bfd80f999dde469
-F www/datatype3.tcl 3216d4586d28c4f1f2d4fbb4c42f12e1d6bdd67e
+F www/datatype3.tcl cec3949b77a1593e89a43272a0a9cdcb1937045a
 F www/datatypes.tcl 7c786d2e8ff434346764534ec015966d17efce60
 F www/different.tcl 7d528e1371655f6fcd32e8354c5b49f8ede332e7
 F www/direct1b.gif 32b48b764244817b6b591898dc52a04299a7b8a7
@@ -355,7 +355,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
 F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
-P 249b579f83b2922e3e03037186a9402af951e6d1
-R a4cc6ce39f4291b2e5ea3f338666a67e
+P 9d7297b9ef6ca2f35116e37f993bb029cf03d4f0
+R f27fe774c169114ee2aa60038b33ea52
 U drh
-Z b43f086e88f28ee93e96a6ef04d5296a
+Z 8380180038ff17613da9bacbf7554e8c
index b8f73f2d679ed398e8282ca8cc7c10ba6ee67170..af53cab72e20f75ae2b1ceac2a8828de3c9b8177 100644 (file)
@@ -1 +1 @@
-9d7297b9ef6ca2f35116e37f993bb029cf03d4f0
\ No newline at end of file
+6e5a49762166a942e1b2c3beae8a30c07187eb10
\ No newline at end of file
index f427c3fa61f3cc4a517313c9aa85a5f7995fe0f1..0577737a38b4ea7a4a71033d5addfb28d314e032 100644 (file)
@@ -12,7 +12,7 @@
 ** This file contains routines used for analyzing expressions and
 ** for generating VDBE code that evaluates expressions in SQLite.
 **
-** $Id: expr.c,v 1.257 2006/03/17 13:56:34 drh Exp $
+** $Id: expr.c,v 1.258 2006/05/23 23:22:29 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -1367,7 +1367,7 @@ void sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){
         struct ExprList_item *pItem;
 
         if( !affinity ){
-          affinity = SQLITE_AFF_NUMERIC;
+          affinity = SQLITE_AFF_NONE;
         }
         keyInfo.aColl[0] = pExpr->pLeft->pColl;
 
index 97532c8c4149e762aefc5151cc4a87da41662a45..582cff08617e094dbdfe8f8dbd766c909ab3a4c3 100644 (file)
@@ -13,7 +13,7 @@
 ** interface, and routines that contribute to loading the database schema
 ** from disk.
 **
-** $Id: prepare.c,v 1.33 2006/03/13 15:06:07 drh Exp $
+** $Id: prepare.c,v 1.34 2006/05/23 23:22:29 drh Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -211,7 +211,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
   **    meta[1]   File format of schema layer.
   **    meta[2]   Size of the page cache.
   **    meta[3]   Use freelist if 0.  Autovacuum if greater than zero.
-  **    meta[4]   Db text encoding. 1:UTF-8 3:UTF-16 LE 4:UTF-16 BE
+  **    meta[4]   Db text encoding. 1:UTF-8 2:UTF-16LE 3:UTF-16BE
   **    meta[5]   The user cookie. Used by the application.
   **    meta[6]   
   **    meta[7]
index 02b0ec593c97242ef3ad573904d5545fb8ecb02b..fd311896f2aa5813dfdc137917cb741dff0c49a0 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this file is testing the IN and BETWEEN operator.
 #
-# $Id: in.test,v 1.15 2006/01/30 14:36:59 drh Exp $
+# $Id: in.test,v 1.16 2006/05/23 23:22:29 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -322,5 +322,29 @@ do_test in-10.2 {
   }
 } {1 {constraint failed}}
 
+# Ticket #1821
+#
+# Type affinity applied to the right-hand side of an IN operator.
+#
+do_test in-11.1 {
+  execsql {
+    CREATE TABLE t6(a,b NUMERIC);
+    INSERT INTO t6 VALUES(1,2);
+    INSERT INTO t6 VALUES(2,3);
+    SELECT * FROM t6 WHERE b IN (2);
+  }
+} {1 2}
+do_test in-11.2 {
+  # The '2' should be coerced into 2 because t6.b is NUMERIC
+  execsql {
+    SELECT * FROM t6 WHERE b IN ('2');
+  }
+} {1 2}
+do_test in-11.3 {
+  # No coercion should occur here because of the unary + before b.
+  execsql {
+    SELECT * FROM t6 WHERE +b IN ('2');
+  }
+} {}
 
 finish_test
index 36dd4896776ec1a0e8a95135a0808cde34cb169d..5a6efb136bdaa6a262eff3bccc1bd2e8a60f6d68 100644 (file)
@@ -12,7 +12,7 @@
 # of this file is testing the interaction of manifest types, type affinity
 # and comparison expressions.
 #
-# $Id: types2.test,v 1.5 2005/01/21 03:12:16 danielk1977 Exp $
+# $Id: types2.test,v 1.6 2006/05/23 23:22:29 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -199,10 +199,10 @@ test_bool types2-4.28 {o1='500'} {'500.0' > o1} 1
 ifcapable subquery {
   # types2-5.* - The 'IN (x, y....)' operator with no index.
   # 
-  # Compare literals against literals (always a numeric comparison).
+  # Compare literals against literals (no affinity applied)
   test_bool types2-5.1 {} {(NULL IN ('10.0', 20)) ISNULL} 1
-  test_bool types2-5.2 {} {10 IN ('10.0', 20)} 1
-  test_bool types2-5.3 {} {'10' IN ('10.0', 20)} 1
+  test_bool types2-5.2 {} {10 IN ('10.0', 20)} 0
+  test_bool types2-5.3 {} {'10' IN ('10.0', 20)} 0
   test_bool types2-5.4 {} {10 IN (10.0, 20)} 1
   test_bool types2-5.5 {} {'10.0' IN (10, 20)} 1
   
index 61ba0d39dcad13fac62490ee57bbb0445bc1cb02..52e462dd9198749528989738ea6bfb7169b5ed64 100644 (file)
@@ -1,4 +1,4 @@
-set rcsid {$Id: datatype3.tcl,v 1.13 2006/04/01 14:38:41 drh Exp $}
+set rcsid {$Id: datatype3.tcl,v 1.14 2006/05/23 23:22:29 drh Exp $}
 source common.tcl
 header {Datatypes In SQLite Version 3}
 puts {
@@ -87,6 +87,7 @@ following type affinities:</P>
        <LI>TEXT</LI>
        <LI>NUMERIC</LI>
        <LI>INTEGER</LI>
+        <LI>REAL</li>
        <LI>NONE</LI>
 </UL>
 
@@ -108,6 +109,12 @@ floating point component (or text value that converts to such) is
 inserted it is converted to an integer and stored using the INTEGER
 storage class.</P>
 
+<P>A column with REAL affinity behaves like a column with NUMERIC
+affinity except that it forces integer values into floating point
+representation.  (As an optimization, integer values are stored on
+disk as integers in order to take up less space and are only converted
+to floating point as the value is read out of the table.)</P>
+
 <P>A column with affinity NONE does not prefer one storage class over
 another.  It makes no attempt to coerce data before
 it is inserted.</P>
@@ -129,6 +136,10 @@ of the column, according to the following rules:</P>
          contains the string &quot;BLOB&quot; or if
         no datatype is specified then the column has affinity NONE.</P>
 
+        <LI><P>If the datatype for a column
+        contains any of the strings &quot;REAL&quot;, &quot;FLOA&quot;,
+        or &quot;DOUB&quot; then the column has REAL affinity</P>
+
        <LI><P>Otherwise, the affinity is NUMERIC.</P>
 </OL>
 
@@ -196,7 +207,7 @@ SQL scalar expression or literal other than a column value.</P>
        affinity is applied to any values with storage class TEXT extracted
        from the non-NUMERIC column.</P>
 
-       <LI><P>When the results of two expressions are compared, the no
+       <LI><P>When the results of two expressions are compared, no
         conversions occur.  The results are compared as is.  If a string
         is compared to a number, the number will always be less than the
         string.</P>