From 70031fa396c6e64d10f9cddb4ea2deecd8ecaf63 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 8 Jul 2005 13:53:21 +0000 Subject: [PATCH] Add the SQLITE_CASE_SENSITIVE_LIKE compile-time option. (CVS 2539) FossilOrigin-Name: b72bff81f9937378417a0af0610d8558279b67a7 --- manifest | 14 ++--- manifest.uuid | 2 +- src/func.c | 12 +++- test/expr.test | 150 ++++++++++++++++++++++++++++++++++--------------- 4 files changed, 122 insertions(+), 56 deletions(-) diff --git a/manifest b/manifest index c98e4b66b6..7a6dc3b297 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Replace\sOP_List\swith\sOP_Fifo.\s\sThis\sis\sthe\sfirst\sstep\stoward\sallowing\nrecursive\sdelete\striggers\sand\slater\sforeign\skeys\swith\scascading\sdeletes.\s(CVS\s2538) -D 2005-07-08T13:08:00 +C Add\sthe\sSQLITE_CASE_SENSITIVE_LIKE\scompile-time\soption.\s(CVS\s2539) +D 2005-07-08T13:53:22 F Makefile.in 3c10cd7bc3ecbd60fe4d5a5c0f59bfa7fb217a66 F Makefile.linux-gcc 06be33b2a9ad4f005a5f42b22c4a19dab3cbb5c7 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -39,7 +39,7 @@ F src/date.c 7444b0900a28da77e57e3337a636873cff0ae940 F src/delete.c 250d436a68fe371b4ab403d1c0f6fdc9a6860c39 F src/experimental.c 50c1e3b34f752f4ac10c36f287db095c2b61766d F src/expr.c fdc8b82babbb266eeded4a314fd2f1d315133797 -F src/func.c cbdf7256400ac7d5f020d131261bb2bd41bb631f +F src/func.c e6637354fe3a66dfac063a49109f277cde9ce87d F src/hash.c 2b1b13f7400e179631c83a1be0c664608c8f021f F src/hash.h 1b0c445e1c89ff2aaad9b4605ba61375af001e84 F src/insert.c d61752504f8a67e28a3bd45288051a587ba899cd @@ -133,7 +133,7 @@ F test/diskfull.test e2f6cfd868713ead06dc82b84a4938e868128fc0 F test/enc.test 7a03417a1051fe8bc6c7641cf4c8c3f7e0066d52 F test/enc2.test d1ab077b84f4d3099246915422b1ab6b81481e0a F test/enc3.test f6a5f0b7b7f3a88f030d3143729b87cd5c86d837 -F test/expr.test 54d9d1cc05eb731fa62daa70f2d7163f8a03c54d +F test/expr.test 648f733f9d9aa9db82de59e69d1322b8b52f701a F test/fkey1.test 81bb13caaa78f58d7d191d7f535529f7c91d821a F test/func.test b062105b45cf8fb5b386ba137180c0f439eea0c9 F test/hook.test f8605cde4c77b2c6a4a73723bf6c507796a64dda @@ -285,7 +285,7 @@ F www/tclsqlite.tcl 425be741b8ae664f55cb1ef2371aab0a75109cf9 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b F www/whentouse.tcl 528299b8316726dbcc5548e9aa0648c8b1bd055b -P 05b6ac9a76fd5765c50e81588f8e71c59fe35ce4 -R ad75c3dbc9b87159735faff9e7381646 +P 94c120bb782fed53142317d1755e70c858930486 +R b0c32db552222c1fd1e02ca33b3a5bc8 U drh -Z 29241e9900ff613d77be112c57ad8310 +Z e8701805019a78e6817d706ed8df3c13 diff --git a/manifest.uuid b/manifest.uuid index d7402771fa..b7f5f9b4cd 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -94c120bb782fed53142317d1755e70c858930486 \ No newline at end of file +b72bff81f9937378417a0af0610d8558279b67a7 \ No newline at end of file diff --git a/src/func.c b/src/func.c index 7e8feadc0d..dd2a0cda62 100644 --- a/src/func.c +++ b/src/func.c @@ -16,7 +16,7 @@ ** sqliteRegisterBuildinFunctions() found at the bottom of the file. ** All other code has file scope. ** -** $Id: func.c,v 1.100 2005/06/25 18:42:14 drh Exp $ +** $Id: func.c,v 1.101 2005/07/08 13:53:22 drh Exp $ */ #include "sqliteInt.h" #include @@ -309,7 +309,15 @@ struct compareInfo { u8 noCase; }; static const struct compareInfo globInfo = { '*', '?', '[', 0 }; -static const struct compareInfo likeInfo = { '%', '_', 0, 1 }; +#ifndef SQLITE_CASE_SENSITIVE_LIKE + /* The correct SQL-92 behavior is for the LIKE operator to ignore + ** case. Thus 'a' LIKE 'A' would be true. */ + static const struct compareInfo likeInfo = { '%', '_', 0, 1 }; +#else + /* If SQLITE_CASE_SENSITIVE_LIKE is defined, then the LIKE operator + ** is case sensitive causing 'a' LIKE 'A' to be false */ + static const struct compareInfo likeInfo = { '%', '_', 0, 0 }; +#endif /* ** X is a pointer to the first byte of a UTF-8 character. Increment diff --git a/test/expr.test b/test/expr.test index c23b5687d3..f6eef41c22 100644 --- a/test/expr.test +++ b/test/expr.test @@ -11,7 +11,7 @@ # This file implements regression tests for SQLite library. The # focus of this file is testing expressions. # -# $Id: expr.test,v 1.43 2005/01/21 11:55:27 danielk1977 Exp $ +# $Id: expr.test,v 1.44 2005/07/08 13:53:22 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -206,7 +206,6 @@ test_expr epxr-3.42 {t1='abc', t2=NULL} {coalesce(t2==t1,99)} 99 test_expr epxr-3.43 {t1='abc', t2=NULL} {coalesce(t1!=t2,99)} 99 test_expr epxr-3.44 {t1='abc', t2=NULL} {coalesce(t2!=t1,99)} 99 - test_expr expr-4.1 {t1='abc', t2='Abc'} {t1t2} 1 test_expr expr-4.3 {t1='abc', t2='Bbc'} {t1r2} 0 +# CSL is true if LIKE is case sensitive and false if not. +# NCSL is the opposite. Use these variables as the result +# on operations where case makes a difference. +set CSL $sqlite_options(casesensitivelike) +set NCSL [expr {!$CSL}] + test_expr expr-5.1 {t1='abc', t2='xyz'} {t1 LIKE t2} 0 -test_expr expr-5.2 {t1='abc', t2='ABC'} {t1 LIKE t2} 1 -test_expr expr-5.3 {t1='abc', t2='A_C'} {t1 LIKE t2} 1 +test_expr expr-5.2a {t1='abc', t2='abc'} {t1 LIKE t2} 1 +test_expr expr-5.2b {t1='abc', t2='ABC'} {t1 LIKE t2} $NCSL +test_expr expr-5.3a {t1='abc', t2='a_c'} {t1 LIKE t2} 1 +test_expr expr-5.3b {t1='abc', t2='A_C'} {t1 LIKE t2} $NCSL test_expr expr-5.4 {t1='abc', t2='abc_'} {t1 LIKE t2} 0 -test_expr expr-5.5 {t1='abc', t2='A%C'} {t1 LIKE t2} 1 -test_expr expr-5.5a {t1='abdc', t2='a%c'} {t1 LIKE t2} 1 -test_expr expr-5.5b {t1='ac', t2='A%C'} {t1 LIKE t2} 1 -test_expr expr-5.6 {t1='abxyzzyc', t2='A%C'} {t1 LIKE t2} 1 -test_expr expr-5.7 {t1='abxyzzy', t2='A%C'} {t1 LIKE t2} 0 -test_expr expr-5.8 {t1='abxyzzycx', t2='A%C'} {t1 LIKE t2} 0 -test_expr expr-5.8b {t1='abxyzzycy', t2='A%CX'} {t1 LIKE t2} 0 -test_expr expr-5.9 {t1='abc', t2='A%_C'} {t1 LIKE t2} 1 -test_expr expr-5.9b {t1='ac', t2='A%_C'} {t1 LIKE t2} 0 -test_expr expr-5.10 {t1='abxyzzyc', t2='A%_C'} {t1 LIKE t2} 1 +test_expr expr-5.5a {t1='abc', t2='a%c'} {t1 LIKE t2} 1 +test_expr expr-5.5b {t1='abc', t2='A%C'} {t1 LIKE t2} $NCSL +test_expr expr-5.5c {t1='abdc', t2='a%c'} {t1 LIKE t2} 1 +test_expr expr-5.5d {t1='ac', t2='a%c'} {t1 LIKE t2} 1 +test_expr expr-5.5e {t1='ac', t2='A%C'} {t1 LIKE t2} $NCSL +test_expr expr-5.6a {t1='abxyzzyc', t2='a%c'} {t1 LIKE t2} 1 +test_expr expr-5.6b {t1='abxyzzyc', t2='A%C'} {t1 LIKE t2} $NCSL +test_expr expr-5.7a {t1='abxyzzy', t2='a%c'} {t1 LIKE t2} 0 +test_expr expr-5.7b {t1='abxyzzy', t2='A%C'} {t1 LIKE t2} 0 +test_expr expr-5.8a {t1='abxyzzycx', t2='a%c'} {t1 LIKE t2} 0 +test_expr expr-5.8b {t1='abxyzzycy', t2='a%cx'} {t1 LIKE t2} 0 +test_expr expr-5.8c {t1='abxyzzycx', t2='A%C'} {t1 LIKE t2} 0 +test_expr expr-5.8d {t1='abxyzzycy', t2='A%CX'} {t1 LIKE t2} 0 +test_expr expr-5.9a {t1='abc', t2='a%_c'} {t1 LIKE t2} 1 +test_expr expr-5.9b {t1='ac', t2='a%_c'} {t1 LIKE t2} 0 +test_expr expr-5.9c {t1='abc', t2='A%_C'} {t1 LIKE t2} $NCSL +test_expr expr-5.9d {t1='ac', t2='A%_C'} {t1 LIKE t2} 0 +test_expr expr-5.10a {t1='abxyzzyc', t2='a%_c'} {t1 LIKE t2} 1 +test_expr expr-5.10b {t1='abxyzzyc', t2='A%_C'} {t1 LIKE t2} $NCSL test_expr expr-5.11 {t1='abc', t2='xyz'} {t1 NOT LIKE t2} 1 -test_expr expr-5.12 {t1='abc', t2='ABC'} {t1 NOT LIKE t2} 0 +test_expr expr-5.12a {t1='abc', t2='abc'} {t1 NOT LIKE t2} 0 +test_expr expr-5.12b {t1='abc', t2='ABC'} {t1 NOT LIKE t2} $CSL # The following tests only work on versions of TCL that support Unicode # if {"\u1234"!="u1234"} { - test_expr expr-5.13 "t1='a\u0080c', t2='A_C'" {t1 LIKE t2} 1 - test_expr expr-5.14 "t1='a\u07FFc', t2='A_C'" {t1 LIKE t2} 1 - test_expr expr-5.15 "t1='a\u0800c', t2='A_C'" {t1 LIKE t2} 1 - test_expr expr-5.16 "t1='a\uFFFFc', t2='A_C'" {t1 LIKE t2} 1 + test_expr expr-5.13a "t1='a\u0080c', t2='a_c'" {t1 LIKE t2} 1 + test_expr expr-5.13b "t1='a\u0080c', t2='A_C'" {t1 LIKE t2} $NCSL + test_expr expr-5.14a "t1='a\u07FFc', t2='a_c'" {t1 LIKE t2} 1 + test_expr expr-5.14b "t1='a\u07FFc', t2='A_C'" {t1 LIKE t2} $NCSL + test_expr expr-5.15a "t1='a\u0800c', t2='a_c'" {t1 LIKE t2} 1 + test_expr expr-5.15b "t1='a\u0800c', t2='A_C'" {t1 LIKE t2} $NCSL + test_expr expr-5.16a "t1='a\uFFFFc', t2='a_c'" {t1 LIKE t2} 1 + test_expr expr-5.16b "t1='a\uFFFFc', t2='A_C'" {t1 LIKE t2} $NCSL test_expr expr-5.17 "t1='a\u0080', t2='A__'" {t1 LIKE t2} 0 test_expr expr-5.18 "t1='a\u07FF', t2='A__'" {t1 LIKE t2} 0 test_expr expr-5.19 "t1='a\u0800', t2='A__'" {t1 LIKE t2} 0 test_expr expr-5.20 "t1='a\uFFFF', t2='A__'" {t1 LIKE t2} 0 - test_expr expr-5.21 "t1='ax\uABCD', t2='A_\uABCD'" {t1 LIKE t2} 1 - test_expr expr-5.22 "t1='ax\u1234', t2='A%\u1234'" {t1 LIKE t2} 1 - test_expr expr-5.23 "t1='ax\uFEDC', t2='A_%'" {t1 LIKE t2} 1 - test_expr expr-5.24 "t1='ax\uFEDCy\uFEDC', t2='A%\uFEDC'" {t1 LIKE t2} 1 + test_expr expr-5.21a "t1='ax\uABCD', t2='a_\uABCD'" {t1 LIKE t2} 1 + test_expr expr-5.21b "t1='ax\uABCD', t2='A_\uABCD'" {t1 LIKE t2} $NCSL + test_expr expr-5.22a "t1='ax\u1234', t2='a%\u1234'" {t1 LIKE t2} 1 + test_expr expr-5.22b "t1='ax\u1234', t2='A%\u1234'" {t1 LIKE t2} $NCSL + test_expr expr-5.23a "t1='ax\uFEDC', t2='a_%'" {t1 LIKE t2} 1 + test_expr expr-5.23b "t1='ax\uFEDC', t2='A_%'" {t1 LIKE t2} $NCSL + test_expr expr-5.24a "t1='ax\uFEDCy\uFEDC', t2='a%\uFEDC'" {t1 LIKE t2} 1 + test_expr expr-5.24b "t1='ax\uFEDCy\uFEDC', t2='A%\uFEDC'" {t1 LIKE t2} $NCSL } test_expr expr-5.54 {t1='abc', t2=NULL} {t1 LIKE t2} {{}} @@ -268,42 +293,75 @@ test_expr expr-5.56 {t1='abc', t2=NULL} {t2 LIKE t1} {{}} test_expr expr-5.57 {t1='abc', t2=NULL} {t2 NOT LIKE t1} {{}} # LIKE expressions that use ESCAPE characters. -test_expr expr-5.58 {t1='abc', t2='A_C'} {t1 LIKE t2 ESCAPE '7'} 1 -test_expr expr-5.59 {t1='a_c', t2='A7_C'} {t1 LIKE t2 ESCAPE '7'} 1 -test_expr expr-5.60 {t1='abc', t2='A7_C'} {t1 LIKE t2 ESCAPE '7'} 0 -test_expr expr-5.61 {t1='a7Xc', t2='A7_C'} {t1 LIKE t2 ESCAPE '7'} 0 -test_expr expr-5.62 {t1='abcde', t2='A%E'} {t1 LIKE t2 ESCAPE '7'} 1 -test_expr expr-5.63 {t1='abcde', t2='A7%E'} {t1 LIKE t2 ESCAPE '7'} 0 -test_expr expr-5.64 {t1='a7cde', t2='A7%E'} {t1 LIKE t2 ESCAPE '7'} 0 -test_expr expr-5.65 {t1='a7cde', t2='A77%E'} {t1 LIKE t2 ESCAPE '7'} 1 -test_expr expr-5.66 {t1='abc7', t2='A%77'} {t1 LIKE t2 ESCAPE '7'} 1 -test_expr expr-5.67 {t1='abc_', t2='A%7_'} {t1 LIKE t2 ESCAPE '7'} 1 -test_expr expr-5.68 {t1='abc7', t2='A%7_'} {t1 LIKE t2 ESCAPE '7'} 0 +test_expr expr-5.58a {t1='abc', t2='a_c'} {t1 LIKE t2 ESCAPE '7'} 1 +test_expr expr-5.58b {t1='abc', t2='A_C'} {t1 LIKE t2 ESCAPE '7'} $NCSL +test_expr expr-5.59a {t1='a_c', t2='a7_c'} {t1 LIKE t2 ESCAPE '7'} 1 +test_expr expr-5.59b {t1='a_c', t2='A7_C'} {t1 LIKE t2 ESCAPE '7'} $NCSL +test_expr expr-5.60a {t1='abc', t2='a7_c'} {t1 LIKE t2 ESCAPE '7'} 0 +test_expr expr-5.60b {t1='abc', t2='A7_C'} {t1 LIKE t2 ESCAPE '7'} 0 +test_expr expr-5.61a {t1='a7Xc', t2='a7_c'} {t1 LIKE t2 ESCAPE '7'} 0 +test_expr expr-5.61b {t1='a7Xc', t2='A7_C'} {t1 LIKE t2 ESCAPE '7'} 0 +test_expr expr-5.62a {t1='abcde', t2='a%e'} {t1 LIKE t2 ESCAPE '7'} 1 +test_expr expr-5.62b {t1='abcde', t2='A%E'} {t1 LIKE t2 ESCAPE '7'} $NCSL +test_expr expr-5.63a {t1='abcde', t2='a7%e'} {t1 LIKE t2 ESCAPE '7'} 0 +test_expr expr-5.63b {t1='abcde', t2='A7%E'} {t1 LIKE t2 ESCAPE '7'} 0 +test_expr expr-5.64a {t1='a7cde', t2='a7%e'} {t1 LIKE t2 ESCAPE '7'} 0 +test_expr expr-5.64b {t1='a7cde', t2='A7%E'} {t1 LIKE t2 ESCAPE '7'} 0 +test_expr expr-5.65a {t1='a7cde', t2='a77%e'} {t1 LIKE t2 ESCAPE '7'} 1 +test_expr expr-5.65b {t1='a7cde', t2='A77%E'} {t1 LIKE t2 ESCAPE '7'} $NCSL +test_expr expr-5.66a {t1='abc7', t2='a%77'} {t1 LIKE t2 ESCAPE '7'} 1 +test_expr expr-5.66b {t1='abc7', t2='A%77'} {t1 LIKE t2 ESCAPE '7'} $NCSL +test_expr expr-5.67a {t1='abc_', t2='a%7_'} {t1 LIKE t2 ESCAPE '7'} 1 +test_expr expr-5.67b {t1='abc_', t2='A%7_'} {t1 LIKE t2 ESCAPE '7'} $NCSL +test_expr expr-5.68a {t1='abc7', t2='a%7_'} {t1 LIKE t2 ESCAPE '7'} 0 +test_expr expr-5.68b {t1='abc7', t2='A%7_'} {t1 LIKE t2 ESCAPE '7'} 0 # These are the same test as the block above, but using a multi-byte # character as the escape character. if {"\u1234"!="u1234"} { - test_expr expr-5.69 "t1='abc', t2='A_C'" \ + test_expr expr-5.69a "t1='abc', t2='a_c'" \ "t1 LIKE t2 ESCAPE '\u1234'" 1 - test_expr expr-5.70 "t1='a_c', t2='A\u1234_C'" \ + test_expr expr-5.69b "t1='abc', t2='A_C'" \ + "t1 LIKE t2 ESCAPE '\u1234'" $NCSL + test_expr expr-5.70a "t1='a_c', t2='a\u1234_c'" \ "t1 LIKE t2 ESCAPE '\u1234'" 1 - test_expr expr-5.71 "t1='abc', t2='A\u1234_C'" \ + test_expr expr-5.70b "t1='a_c', t2='A\u1234_C'" \ + "t1 LIKE t2 ESCAPE '\u1234'" $NCSL + test_expr expr-5.71a "t1='abc', t2='a\u1234_c'" \ "t1 LIKE t2 ESCAPE '\u1234'" 0 - test_expr expr-5.72 "t1='a\u1234Xc', t2='A\u1234_C'" \ + test_expr expr-5.71b "t1='abc', t2='A\u1234_C'" \ + "t1 LIKE t2 ESCAPE '\u1234'" 0 + test_expr expr-5.72a "t1='a\u1234Xc', t2='a\u1234_c'" \ "t1 LIKE t2 ESCAPE '\u1234'" 0 - test_expr expr-5.73 "t1='abcde', t2='A%E'" \ - "t1 LIKE t2 ESCAPE '\u1234'" 1 - test_expr expr-5.74 "t1='abcde', t2='A\u1234%E'" \ + test_expr expr-5.72b "t1='a\u1234Xc', t2='A\u1234_C'" \ "t1 LIKE t2 ESCAPE '\u1234'" 0 - test_expr expr-5.75 "t1='a\u1234cde', t2='A\u1234%E'" \ + test_expr expr-5.73a "t1='abcde', t2='a%e'" \ + "t1 LIKE t2 ESCAPE '\u1234'" 1 + test_expr expr-5.73b "t1='abcde', t2='A%E'" \ + "t1 LIKE t2 ESCAPE '\u1234'" $NCSL + test_expr expr-5.74a "t1='abcde', t2='a\u1234%e'" \ "t1 LIKE t2 ESCAPE '\u1234'" 0 - test_expr expr-5.76 "t1='a\u1234cde', t2='A\u1234\u1234%E'" \ + test_expr expr-5.74b "t1='abcde', t2='A\u1234%E'" \ + "t1 LIKE t2 ESCAPE '\u1234'" 0 + test_expr expr-5.75a "t1='a\u1234cde', t2='a\u1234%e'" \ + "t1 LIKE t2 ESCAPE '\u1234'" 0 + test_expr expr-5.75b "t1='a\u1234cde', t2='A\u1234%E'" \ + "t1 LIKE t2 ESCAPE '\u1234'" 0 + test_expr expr-5.76a "t1='a\u1234cde', t2='a\u1234\u1234%e'" \ "t1 LIKE t2 ESCAPE '\u1234'" 1 - test_expr expr-5.77 "t1='abc\u1234', t2='A%\u1234\u1234'" \ + test_expr expr-5.76b "t1='a\u1234cde', t2='A\u1234\u1234%E'" \ + "t1 LIKE t2 ESCAPE '\u1234'" $NCSL + test_expr expr-5.77a "t1='abc\u1234', t2='a%\u1234\u1234'" \ "t1 LIKE t2 ESCAPE '\u1234'" 1 - test_expr expr-5.78 "t1='abc_', t2='A%\u1234_'" \ + test_expr expr-5.77b "t1='abc\u1234', t2='A%\u1234\u1234'" \ + "t1 LIKE t2 ESCAPE '\u1234'" $NCSL + test_expr expr-5.78a "t1='abc_', t2='a%\u1234_'" \ "t1 LIKE t2 ESCAPE '\u1234'" 1 - test_expr expr-5.79 "t1='abc\u1234', t2='A%\u1234_'" \ + test_expr expr-5.78b "t1='abc_', t2='A%\u1234_'" \ + "t1 LIKE t2 ESCAPE '\u1234'" $NCSL + test_expr expr-5.79a "t1='abc\u1234', t2='a%\u1234_'" \ + "t1 LIKE t2 ESCAPE '\u1234'" 0 + test_expr expr-5.79b "t1='abc\u1234', t2='A%\u1234_'" \ "t1 LIKE t2 ESCAPE '\u1234'" 0 }