From de087bd5ed87e6dfa487bfb8ab2c650c09da93be Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 23 Feb 2007 03:00:44 +0000 Subject: [PATCH] Clarify the documentation on how comparisons occur in an IN operator. Fix the comparison operators when both sides of an IN operator are expressions (ticket #2248). Changes to main.mk for adding FTS2 into the standard build also got mixed in with this check-in by mistake. (CVS 3656) FossilOrigin-Name: da81725ca1cd894b3f2d734767e10cc0dc329566 --- main.mk | 43 ++++++++++++++++++++++++++++++++----------- manifest | 20 ++++++++++---------- manifest.uuid | 2 +- src/expr.c | 4 ++-- test/types2.test | 31 +++++++++++++++++++++++++++++-- www/datatype3.tcl | 10 +++++++--- 6 files changed, 81 insertions(+), 29 deletions(-) diff --git a/main.mk b/main.mk index caa16ed2af..f8379ab5c1 100644 --- a/main.mk +++ b/main.mk @@ -101,6 +101,7 @@ SRC = \ $(TOP)/src/select.c \ $(TOP)/src/shell.c \ $(TOP)/src/sqlite.h.in \ + $(TOP)/src/sqlite3ext.h \ $(TOP)/src/sqliteInt.h \ $(TOP)/src/table.c \ $(TOP)/src/tclsqlite.c \ @@ -130,6 +131,24 @@ SRC += \ $(TOP)/ext/fts1/fts1_porter.c \ $(TOP)/ext/fts1/fts1_tokenizer.h \ $(TOP)/ext/fts1/fts1_tokenizer1.c +SRC += \ + $(TOP)/ext/fts2/fts2.c \ + $(TOP)/ext/fts2/fts2.h \ + $(TOP)/ext/fts2/fts2_hash.c \ + $(TOP)/ext/fts2/fts2_hash.h \ + $(TOP)/ext/fts2/fts2_porter.c \ + $(TOP)/ext/fts2/fts2_tokenizer.h \ + $(TOP)/ext/fts2/fts2_tokenizer1.c + +# Generated source code files +# +SRC += \ + keywordhash.h \ + opcodes.c \ + opcodes.h \ + parse.c \ + parse.h \ + sqlite3.h # Source code to the test files. @@ -182,16 +201,19 @@ HDR = \ # Header files used by extensions # -HDR += \ +EXTHDR += \ $(TOP)/ext/fts1/fts1.h \ $(TOP)/ext/fts1/fts1_hash.h \ $(TOP)/ext/fts1/fts1_tokenizer.h +EXTHDR += \ + $(TOP)/ext/fts2/fts2.h \ + $(TOP)/ext/fts2/fts2_hash.h \ + $(TOP)/ext/fts2/fts2_tokenizer.h # Header files used by the VDBE submodule # VDBEHDR = \ - $(HDR) \ $(TOP)/src/vdbeInt.h # This is the default Makefile target. The objects listed here @@ -222,12 +244,11 @@ objects: $(LIBOBJ_ORIG) # files are automatically generated. This target takes care of # all that automatic generation. # -target_source: $(SRC) $(VDBEHDR) opcodes.c keywordhash.h +target_source: $(SRC) rm -rf tsrc mkdir tsrc - cp $(SRC) $(VDBEHDR) tsrc + cp $(SRC) tsrc rm tsrc/sqlite.h.in tsrc/parse.y - cp parse.c opcodes.c keywordhash.h tsrc # Rules to build the LEMON compiler generator # @@ -371,22 +392,22 @@ util.o: $(TOP)/src/util.c $(HDR) vacuum.o: $(TOP)/src/vacuum.c $(HDR) $(TCCX) -c $(TOP)/src/vacuum.c -vdbe.o: $(TOP)/src/vdbe.c $(VDBEHDR) +vdbe.o: $(TOP)/src/vdbe.c $(VDBEHDR) $(HDR) $(TCCX) -c $(TOP)/src/vdbe.c -vdbeapi.o: $(TOP)/src/vdbeapi.c $(VDBEHDR) +vdbeapi.o: $(TOP)/src/vdbeapi.c $(VDBEHDR) $(HDR) $(TCCX) -c $(TOP)/src/vdbeapi.c -vdbeaux.o: $(TOP)/src/vdbeaux.c $(VDBEHDR) +vdbeaux.o: $(TOP)/src/vdbeaux.c $(VDBEHDR) $(HDR) $(TCCX) -c $(TOP)/src/vdbeaux.c -vdbefifo.o: $(TOP)/src/vdbefifo.c $(VDBEHDR) +vdbefifo.o: $(TOP)/src/vdbefifo.c $(VDBEHDR) $(HDR) $(TCCX) -c $(TOP)/src/vdbefifo.c -vdbemem.o: $(TOP)/src/vdbemem.c $(VDBEHDR) +vdbemem.o: $(TOP)/src/vdbemem.c $(VDBEHDR) $(HDR) $(TCCX) -c $(TOP)/src/vdbemem.c -vtab.o: $(TOP)/src/vtab.c $(VDBEHDR) +vtab.o: $(TOP)/src/vtab.c $(VDBEHDR) $(HDR) $(TCCX) -c $(TOP)/src/vtab.c where.o: $(TOP)/src/where.c $(HDR) diff --git a/manifest b/manifest index 7a68f44c84..1327744a82 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\stypos\sin\stest\snaming\s(was\susing\s'e'\sinstead\sof\s'f').\s(CVS\s3655) -D 2007-02-23T00:14:06 +C Clarify\sthe\sdocumentation\son\show\scomparisons\soccur\sin\san\sIN\soperator.\r\nFix\sthe\scomparison\soperators\swhen\sboth\ssides\sof\san\sIN\soperator\sare\r\nexpressions\s(ticket\s#2248).\r\nChanges\sto\smain.mk\sfor\sadding\sFTS2\sinto\sthe\sstandard\sbuild\salso\r\ngot\smixed\sin\swith\sthis\scheck-in\sby\smistake.\s(CVS\s3656) +D 2007-02-23T03:00:45 F Makefile.in 1fe3d0b46e40fd684e1e61f8e8056cefed16de9f F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -42,7 +42,7 @@ F ext/fts2/fts2_tokenizer.h 4c5ffe31d63622869eb6eec1503df7f6996fd1bd F ext/fts2/fts2_tokenizer1.c b26f0d2fae967fbe5722f82d08506d35f10ac4e7 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 F ltmain.sh 56abb507100ed2d4261f6dd1653dec3cf4066387 -F main.mk 22acd3d279ec40ba6959af643ba25975fcfbdcc7 +F main.mk cdb182b8940da62384f8cd0c527a3d32d5216aa1 F mkdll.sh cbc7d92d02f9317a3d24ab55bb727275417260ca F mkopcodec.awk bd46ad001c98dfbab07b1713cb8e692fa0e5415d F mkopcodeh.awk cde995d269aa06c94adbf6455bea0acedb913fa5 @@ -65,7 +65,7 @@ F src/complete.c 7d1a44be8f37de125fcafd3d3a018690b3799675 F src/date.c 393c73fc027597e008dcd81454544659e978b05c F src/delete.c 151d08386bf9c9e7f92f6b9106c71efec2def184 F src/experimental.c 1b2d1a6cd62ecc39610e97670332ca073c50792b -F src/expr.c a7c2369b2ba300aac4fadaf61e14c1dabaaf5d34 +F src/expr.c 24d52bd600aa5769ce60c6263275f8013ea5eb87 F src/func.c b7e1e220a6795ecae7649815145ea5f8644dfa5f F src/hash.c 449f3d6620193aa557f5d86cbc5cc6b87702b185 F src/hash.h 1b3f7e2609141fd571f62199fc38687d262e9564 @@ -336,7 +336,7 @@ F test/trigger6.test 0e411654f122552da6590f0b4e6f781048a4a9b9 F test/trigger7.test 0afa870be2ce1b132cdb85b17a4a4ef45aa8cece F test/trigger8.test 3a09275aa2214fdff56f731b1e775d8dfee4408a F test/types.test 98e7a631bddf0806204358b452b02d0e319318a6 -F test/types2.test 202b1afacdb80eddbb5fb5fab6207daaf5b4dfe1 +F test/types2.test 3555aacf8ed8dc883356e59efc314707e6247a84 F test/types3.test ea0ddf793ad5cd17c3b029dd8f48473059f873b6 F test/unique.test 0253c4227a5dc533e312202ce21ecfad18058d18 F test/update.test 7669ca789d62c258b678e8aa7a22a57eac10f2cf @@ -396,7 +396,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 cec3949b77a1593e89a43272a0a9cdcb1937045a +F www/datatype3.tcl 61baf9328eaba3d20eb7d8351a1eacfced8d4383 F www/datatypes.tcl 7c786d2e8ff434346764534ec015966d17efce60 F www/different.tcl 8b76ae88bf73e38097b7936e198df4f89baf587c F www/direct1b.gif 32b48b764244817b6b591898dc52a04299a7b8a7 @@ -432,7 +432,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513 -P d8845ac1fbf8c3f483d47c35f908817ea37128ec -R de64fb8cd0d6cb407730f343a5bbbd5e -U shess -Z f8e3df05d8b0f0ac4236ebfa09ee3629 +P 16cb00adeb3b68220ba2567b86b230bbbf2a0330 +R 8a25a5e663e2db06c8559f7592894f39 +U drh +Z fea7b5a99e3b60f2d1d6571464477514 diff --git a/manifest.uuid b/manifest.uuid index 481971e7f0..a713b7a30c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -16cb00adeb3b68220ba2567b86b230bbbf2a0330 \ No newline at end of file +da81725ca1cd894b3f2d734767e10cc0dc329566 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 530118ba2f..12a0023eaa 100644 --- a/src/expr.c +++ b/src/expr.c @@ -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.276 2007/02/14 09:19:36 danielk1977 Exp $ +** $Id: expr.c,v 1.277 2007/02/23 03:00:45 drh Exp $ */ #include "sqliteInt.h" #include @@ -131,7 +131,7 @@ static char comparisonAffinity(Expr *pExpr){ aff = sqlite3CompareAffinity(pExpr->pSelect->pEList->a[0].pExpr, aff); } else if( !aff ){ - aff = SQLITE_AFF_NUMERIC; + aff = SQLITE_AFF_NONE; } return aff; } diff --git a/test/types2.test b/test/types2.test index 5a6efb136b..4a70aa5fe2 100644 --- a/test/types2.test +++ b/test/types2.test @@ -12,7 +12,7 @@ # of this file is testing the interaction of manifest types, type affinity # and comparison expressions. # -# $Id: types2.test,v 1.6 2006/05/23 23:22:29 drh Exp $ +# $Id: types2.test,v 1.7 2007/02/23 03:00:45 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -204,7 +204,7 @@ ifcapable subquery { 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 + test_bool types2-5.5 {} {'10.0' IN (10, 20)} 0 # Compare literals against a column with TEXT affinity test_bool types2-5.6 {t1='10.0'} {t1 IN (10.0, 20)} 1 @@ -229,6 +229,33 @@ ifcapable subquery { test_bool types2-5.21 {o1='10.0'} {o1 IN (10, 20, '10.0')} 1 test_bool types2-5.22 {o1='10'} {o1 IN (10.0, 20, '10')} 1 test_bool types2-5.23 {o1=10} {n1 IN (20, '10', 10)} 1 + + # Ticket #2248: Comparisons of strings literals that look like + # numbers. + test_bool types2-5.24 {} {'1' IN ('1')} 1 + test_bool types2-5.25 {} {'2' IN (2)} 0 + test_bool types2-5.26 {} {3 IN ('3')} 0 + test_bool types2-5.27 {} {4 IN (4)} 1 + + # The affinity of columns on the right side of IN(...) is ignored. + # All values in the expression list are treated as ordinary expressions, + # even if they are columns with affinity. + test_bool types2-5.30 {t1='10'} {10 IN (5,t1,'abc')} 0 + test_bool types2-5.31 {t1='10'} {10 IN ('abc',t1,5)} 0 + test_bool types2-5.32 {t1='010'} {10 IN (5,t1,'abc')} 0 + test_bool types2-5.33 {t1='010'} {10 IN ('abc',t1,5)} 0 + test_bool types2-5.34 {t1='10'} {'10' IN (5,t1,'abc')} 1 + test_bool types2-5.35 {t1='10'} {'10' IN ('abc',t1,5)} 1 + test_bool types2-5.36 {t1='010'} {'10' IN (5,t1,'abc')} 0 + test_bool types2-5.37 {t1='010'} {'10' IN ('abc',t1,5)} 0 + + # Columns on both the left and right of IN(...). Only the column + # on the left matters. The all values on the right are treated like + # expressions. + test_bool types2-5.40 {t1='10',n1=10} {t1 IN (5,n1,11)} 1 + test_bool types2-5.41 {t1='010',n1=10} {t1 IN (5,n1,11)} 0 + test_bool types2-5.42 {t1='10',n1=10} {n1 IN (5,t1,11)} 1 + test_bool types2-5.43 {t1='010',n1=10} {n1 IN (5,t1,11)} 1 } # Tests named types2-6.* use the same infrastructure as the types2-2.* diff --git a/www/datatype3.tcl b/www/datatype3.tcl index 52e462dd91..ea5ef44ba7 100644 --- a/www/datatype3.tcl +++ b/www/datatype3.tcl @@ -1,4 +1,4 @@ -set rcsid {$Id: datatype3.tcl,v 1.14 2006/05/23 23:22:29 drh Exp $} +set rcsid {$Id: datatype3.tcl,v 1.15 2007/02/23 03:00:46 drh Exp $} source common.tcl header {Datatypes In SQLite Version 3} puts { @@ -225,8 +225,12 @@ similar manner to "a = b"). For example if 'b' is a column value and 'a' is an expression, then the affinity of 'b' is applied to 'a' before any comparisons take place.

-

SQLite treats the expression "a IN (x, y, z)" as equivalent to "a = z OR -a = y OR a = z". +

SQLite treats the expression "a IN (x, y, z)" as equivalent to "a = +x OR +a = +y OR a = +z". The values to the right of the IN operator (the "x", "y", +and "z" values in this example) are considered to be expressions, even if they +happen to be column values. If the value of the left of the IN operator is +a column, then the affinity of that column is used. If the value is an +expression then no conversions occur.

3.1 Comparison Example