| SHA1 Hash: | bf90f1fbf84a288e787a563a3952d30622b26ef9 |
|---|---|
| Date: | 2013-01-07 17:31:34 |
| User: | mistachkin |
| Comment: | Merge updates from trunk. |
- branch=configReadOnly inherited from [7c3401657a]
- sym-configReadOnly inherited from [7c3401657a]
Changes to Makefile.in
366 $(TOP)/src/test_malloc.c \ 366 $(TOP)/src/test_malloc.c \ 367 $(TOP)/src/test_multiplex.c \ 367 $(TOP)/src/test_multiplex.c \ 368 $(TOP)/src/test_mutex.c \ 368 $(TOP)/src/test_mutex.c \ 369 $(TOP)/src/test_onefile.c \ 369 $(TOP)/src/test_onefile.c \ 370 $(TOP)/src/test_osinst.c \ 370 $(TOP)/src/test_osinst.c \ 371 $(TOP)/src/test_pcache.c \ 371 $(TOP)/src/test_pcache.c \ 372 $(TOP)/src/test_quota.c \ 372 $(TOP)/src/test_quota.c \ > 373 $(TOP)/src/test_regexp.c \ 373 $(TOP)/src/test_rtree.c \ 374 $(TOP)/src/test_rtree.c \ 374 $(TOP)/src/test_schema.c \ 375 $(TOP)/src/test_schema.c \ 375 $(TOP)/src/test_server.c \ 376 $(TOP)/src/test_server.c \ 376 $(TOP)/src/test_superlock.c \ 377 $(TOP)/src/test_superlock.c \ 377 $(TOP)/src/test_syscall.c \ 378 $(TOP)/src/test_syscall.c \ 378 $(TOP)/src/test_stat.c \ 379 $(TOP)/src/test_stat.c \ 379 $(TOP)/src/test_tclvar.c \ 380 $(TOP)/src/test_tclvar.c \
Changes to Makefile.msc
687 $(TOP)\src\test_malloc.c \ 687 $(TOP)\src\test_malloc.c \ 688 $(TOP)\src\test_multiplex.c \ 688 $(TOP)\src\test_multiplex.c \ 689 $(TOP)\src\test_mutex.c \ 689 $(TOP)\src\test_mutex.c \ 690 $(TOP)\src\test_onefile.c \ 690 $(TOP)\src\test_onefile.c \ 691 $(TOP)\src\test_osinst.c \ 691 $(TOP)\src\test_osinst.c \ 692 $(TOP)\src\test_pcache.c \ 692 $(TOP)\src\test_pcache.c \ 693 $(TOP)\src\test_quota.c \ 693 $(TOP)\src\test_quota.c \ > 694 $(TOP)\src\test_regexp.c \ 694 $(TOP)\src\test_rtree.c \ 695 $(TOP)\src\test_rtree.c \ 695 $(TOP)\src\test_schema.c \ 696 $(TOP)\src\test_schema.c \ 696 $(TOP)\src\test_server.c \ 697 $(TOP)\src\test_server.c \ 697 $(TOP)\src\test_superlock.c \ 698 $(TOP)\src\test_superlock.c \ 698 $(TOP)\src\test_syscall.c \ 699 $(TOP)\src\test_syscall.c \ 699 $(TOP)\src\test_stat.c \ 700 $(TOP)\src\test_stat.c \ 700 $(TOP)\src\test_tclvar.c \ 701 $(TOP)\src\test_tclvar.c \
Changes to VERSION
Changes to configure
1 #! /bin/sh 1 #! /bin/sh 2 # Guess values for system-dependent variables and create Makefiles. 2 # Guess values for system-dependent variables and create Makefiles. 3 # Generated by GNU Autoconf 2.62 for sqlite 3.7.15. | 3 # Generated by GNU Autoconf 2.62 for sqlite 3.7.16. 4 # 4 # 5 # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 5 # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 6 # 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. 6 # 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. 7 # This configure script is free software; the Free Software Foundation 7 # This configure script is free software; the Free Software Foundation 8 # gives unlimited permission to copy, distribute and modify it. 8 # gives unlimited permission to copy, distribute and modify it. 9 ## --------------------- ## 9 ## --------------------- ## 10 ## M4sh Initialization. ## 10 ## M4sh Initialization. ## ................................................................................................................................................................................ 739 MFLAGS= 739 MFLAGS= 740 MAKEFLAGS= 740 MAKEFLAGS= 741 SHELL=${CONFIG_SHELL-/bin/sh} 741 SHELL=${CONFIG_SHELL-/bin/sh} 742 742 743 # Identity of this package. 743 # Identity of this package. 744 PACKAGE_NAME='sqlite' 744 PACKAGE_NAME='sqlite' 745 PACKAGE_TARNAME='sqlite' 745 PACKAGE_TARNAME='sqlite' 746 PACKAGE_VERSION='3.7.15' | 746 PACKAGE_VERSION='3.7.16' 747 PACKAGE_STRING='sqlite 3.7.15' | 747 PACKAGE_STRING='sqlite 3.7.16' 748 PACKAGE_BUGREPORT='' 748 PACKAGE_BUGREPORT='' 749 749 750 # Factoring default headers for most tests. 750 # Factoring default headers for most tests. 751 ac_includes_default="\ 751 ac_includes_default="\ 752 #include <stdio.h> 752 #include <stdio.h> 753 #ifdef HAVE_SYS_TYPES_H 753 #ifdef HAVE_SYS_TYPES_H 754 # include <sys/types.h> 754 # include <sys/types.h> ................................................................................................................................................................................ 1480 # 1480 # 1481 # Report the --help message. 1481 # Report the --help message. 1482 # 1482 # 1483 if test "$ac_init_help" = "long"; then 1483 if test "$ac_init_help" = "long"; then 1484 # Omit some internal or obsolete options to make the list less imposing. 1484 # Omit some internal or obsolete options to make the list less imposing. 1485 # This message is too long to be a string in the A/UX 3.1 sh. 1485 # This message is too long to be a string in the A/UX 3.1 sh. 1486 cat <<_ACEOF 1486 cat <<_ACEOF 1487 \`configure' configures sqlite 3.7.15 to adapt to many kinds of systems. | 1487 \`configure' configures sqlite 3.7.16 to adapt to many kinds of systems. 1488 1488 1489 Usage: $0 [OPTION]... [VAR=VALUE]... 1489 Usage: $0 [OPTION]... [VAR=VALUE]... 1490 1490 1491 To assign environment variables (e.g., CC, CFLAGS...), specify them as 1491 To assign environment variables (e.g., CC, CFLAGS...), specify them as 1492 VAR=VALUE. See below for descriptions of some of the useful variables. 1492 VAR=VALUE. See below for descriptions of some of the useful variables. 1493 1493 1494 Defaults for the options are specified in brackets. 1494 Defaults for the options are specified in brackets. ................................................................................................................................................................................ 1545 --build=BUILD configure for building on BUILD [guessed] 1545 --build=BUILD configure for building on BUILD [guessed] 1546 --host=HOST cross-compile to build programs to run on HOST [BUILD] 1546 --host=HOST cross-compile to build programs to run on HOST [BUILD] 1547 _ACEOF 1547 _ACEOF 1548 fi 1548 fi 1549 1549 1550 if test -n "$ac_init_help"; then 1550 if test -n "$ac_init_help"; then 1551 case $ac_init_help in 1551 case $ac_init_help in 1552 short | recursive ) echo "Configuration of sqlite 3.7.15:";; | 1552 short | recursive ) echo "Configuration of sqlite 3.7.16:";; 1553 esac 1553 esac 1554 cat <<\_ACEOF 1554 cat <<\_ACEOF 1555 1555 1556 Optional Features: 1556 Optional Features: 1557 --disable-option-checking ignore unrecognized --enable/--with options 1557 --disable-option-checking ignore unrecognized --enable/--with options 1558 --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) 1558 --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) 1559 --enable-FEATURE[=ARG] include FEATURE [ARG=yes] 1559 --enable-FEATURE[=ARG] include FEATURE [ARG=yes] ................................................................................................................................................................................ 1661 cd "$ac_pwd" || { ac_status=$?; break; } 1661 cd "$ac_pwd" || { ac_status=$?; break; } 1662 done 1662 done 1663 fi 1663 fi 1664 1664 1665 test -n "$ac_init_help" && exit $ac_status 1665 test -n "$ac_init_help" && exit $ac_status 1666 if $ac_init_version; then 1666 if $ac_init_version; then 1667 cat <<\_ACEOF 1667 cat <<\_ACEOF 1668 sqlite configure 3.7.15 | 1668 sqlite configure 3.7.16 1669 generated by GNU Autoconf 2.62 1669 generated by GNU Autoconf 2.62 1670 1670 1671 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 1671 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 1672 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. 1672 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. 1673 This configure script is free software; the Free Software Foundation 1673 This configure script is free software; the Free Software Foundation 1674 gives unlimited permission to copy, distribute and modify it. 1674 gives unlimited permission to copy, distribute and modify it. 1675 _ACEOF 1675 _ACEOF 1676 exit 1676 exit 1677 fi 1677 fi 1678 cat >config.log <<_ACEOF 1678 cat >config.log <<_ACEOF 1679 This file contains any messages produced by compilers while 1679 This file contains any messages produced by compilers while 1680 running configure, to aid debugging if configure makes a mistake. 1680 running configure, to aid debugging if configure makes a mistake. 1681 1681 1682 It was created by sqlite $as_me 3.7.15, which was | 1682 It was created by sqlite $as_me 3.7.16, which was 1683 generated by GNU Autoconf 2.62. Invocation command line was 1683 generated by GNU Autoconf 2.62. Invocation command line was 1684 1684 1685 $ $0 $@ 1685 $ $0 $@ 1686 1686 1687 _ACEOF 1687 _ACEOF 1688 exec 5>>config.log 1688 exec 5>>config.log 1689 { 1689 { ................................................................................................................................................................................ 3729 { $as_echo "$as_me:$LINENO: checking the name lister ($NM) interface" >&5 3729 { $as_echo "$as_me:$LINENO: checking the name lister ($NM) interface" >&5 3730 $as_echo_n "checking the name lister ($NM) interface... " >&6; } 3730 $as_echo_n "checking the name lister ($NM) interface... " >&6; } 3731 if test "${lt_cv_nm_interface+set}" = set; then 3731 if test "${lt_cv_nm_interface+set}" = set; then 3732 $as_echo_n "(cached) " >&6 3732 $as_echo_n "(cached) " >&6 3733 else 3733 else 3734 lt_cv_nm_interface="BSD nm" 3734 lt_cv_nm_interface="BSD nm" 3735 echo "int some_variable = 0;" > conftest.$ac_ext 3735 echo "int some_variable = 0;" > conftest.$ac_ext 3736 (eval echo "\"\$as_me:3737: $ac_compile\"" >&5) | 3736 (eval echo "\"\$as_me:3736: $ac_compile\"" >&5) 3737 (eval "$ac_compile" 2>conftest.err) 3737 (eval "$ac_compile" 2>conftest.err) 3738 cat conftest.err >&5 3738 cat conftest.err >&5 3739 (eval echo "\"\$as_me:3740: $NM \\\"conftest.$ac_objext\\\"\"" >&5) | 3739 (eval echo "\"\$as_me:3739: $NM \\\"conftest.$ac_objext\\\"\"" >&5) 3740 (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out) 3740 (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out) 3741 cat conftest.err >&5 3741 cat conftest.err >&5 3742 (eval echo "\"\$as_me:3743: output\"" >&5) | 3742 (eval echo "\"\$as_me:3742: output\"" >&5) 3743 cat conftest.out >&5 3743 cat conftest.out >&5 3744 if $GREP 'External.*some_variable' conftest.out > /dev/null; then 3744 if $GREP 'External.*some_variable' conftest.out > /dev/null; then 3745 lt_cv_nm_interface="MS dumpbin" 3745 lt_cv_nm_interface="MS dumpbin" 3746 fi 3746 fi 3747 rm -f conftest* 3747 rm -f conftest* 3748 fi 3748 fi 3749 { $as_echo "$as_me:$LINENO: result: $lt_cv_nm_interface" >&5 3749 { $as_echo "$as_me:$LINENO: result: $lt_cv_nm_interface" >&5 ................................................................................................................................................................................ 4957 ;; 4957 ;; 4958 esac 4958 esac 4959 fi 4959 fi 4960 rm -rf conftest* 4960 rm -rf conftest* 4961 ;; 4961 ;; 4962 *-*-irix6*) 4962 *-*-irix6*) 4963 # Find out which ABI we are using. 4963 # Find out which ABI we are using. 4964 echo '#line 4965 "configure"' > conftest.$ac_ext | 4964 echo '#line 4964 "configure"' > conftest.$ac_ext 4965 if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 4965 if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 4966 (eval $ac_compile) 2>&5 4966 (eval $ac_compile) 2>&5 4967 ac_status=$? 4967 ac_status=$? 4968 $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 4968 $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 4969 (exit $ac_status); }; then 4969 (exit $ac_status); }; then 4970 if test "$lt_cv_prog_gnu_ld" = yes; then 4970 if test "$lt_cv_prog_gnu_ld" = yes; then 4971 case `/usr/bin/file conftest.$ac_objext` in 4971 case `/usr/bin/file conftest.$ac_objext` in ................................................................................................................................................................................ 6826 # Note that $ac_compile itself does not contain backslashes and begins 6826 # Note that $ac_compile itself does not contain backslashes and begins 6827 # with a dollar sign (not a hyphen), so the echo should work correctly. 6827 # with a dollar sign (not a hyphen), so the echo should work correctly. 6828 # The option is referenced via a variable to avoid confusing sed. 6828 # The option is referenced via a variable to avoid confusing sed. 6829 lt_compile=`echo "$ac_compile" | $SED \ 6829 lt_compile=`echo "$ac_compile" | $SED \ 6830 -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ 6830 -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ 6831 -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ 6831 -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ 6832 -e 's:$: $lt_compiler_flag:'` 6832 -e 's:$: $lt_compiler_flag:'` 6833 (eval echo "\"\$as_me:6834: $lt_compile\"" >&5) | 6833 (eval echo "\"\$as_me:6833: $lt_compile\"" >&5) 6834 (eval "$lt_compile" 2>conftest.err) 6834 (eval "$lt_compile" 2>conftest.err) 6835 ac_status=$? 6835 ac_status=$? 6836 cat conftest.err >&5 6836 cat conftest.err >&5 6837 echo "$as_me:6838: \$? = $ac_status" >&5 | 6837 echo "$as_me:6837: \$? = $ac_status" >&5 6838 if (exit $ac_status) && test -s "$ac_outfile"; then 6838 if (exit $ac_status) && test -s "$ac_outfile"; then 6839 # The compiler can only warn and ignore the option if not recognized 6839 # The compiler can only warn and ignore the option if not recognized 6840 # So say no if there are warnings other than the usual output. 6840 # So say no if there are warnings other than the usual output. 6841 $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp 6841 $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp 6842 $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 6842 $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 6843 if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; the 6843 if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; the 6844 lt_cv_prog_compiler_rtti_exceptions=yes 6844 lt_cv_prog_compiler_rtti_exceptions=yes ................................................................................................................................................................................ 7165 # Note that $ac_compile itself does not contain backslashes and begins 7165 # Note that $ac_compile itself does not contain backslashes and begins 7166 # with a dollar sign (not a hyphen), so the echo should work correctly. 7166 # with a dollar sign (not a hyphen), so the echo should work correctly. 7167 # The option is referenced via a variable to avoid confusing sed. 7167 # The option is referenced via a variable to avoid confusing sed. 7168 lt_compile=`echo "$ac_compile" | $SED \ 7168 lt_compile=`echo "$ac_compile" | $SED \ 7169 -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ 7169 -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ 7170 -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ 7170 -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ 7171 -e 's:$: $lt_compiler_flag:'` 7171 -e 's:$: $lt_compiler_flag:'` 7172 (eval echo "\"\$as_me:7173: $lt_compile\"" >&5) | 7172 (eval echo "\"\$as_me:7172: $lt_compile\"" >&5) 7173 (eval "$lt_compile" 2>conftest.err) 7173 (eval "$lt_compile" 2>conftest.err) 7174 ac_status=$? 7174 ac_status=$? 7175 cat conftest.err >&5 7175 cat conftest.err >&5 7176 echo "$as_me:7177: \$? = $ac_status" >&5 | 7176 echo "$as_me:7176: \$? = $ac_status" >&5 7177 if (exit $ac_status) && test -s "$ac_outfile"; then 7177 if (exit $ac_status) && test -s "$ac_outfile"; then 7178 # The compiler can only warn and ignore the option if not recognized 7178 # The compiler can only warn and ignore the option if not recognized 7179 # So say no if there are warnings other than the usual output. 7179 # So say no if there are warnings other than the usual output. 7180 $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp 7180 $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp 7181 $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 7181 $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 7182 if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; the 7182 if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; the 7183 lt_cv_prog_compiler_pic_works=yes 7183 lt_cv_prog_compiler_pic_works=yes ................................................................................................................................................................................ 7270 # (2) before a word containing "conftest.", or (3) at the end. 7270 # (2) before a word containing "conftest.", or (3) at the end. 7271 # Note that $ac_compile itself does not contain backslashes and begins 7271 # Note that $ac_compile itself does not contain backslashes and begins 7272 # with a dollar sign (not a hyphen), so the echo should work correctly. 7272 # with a dollar sign (not a hyphen), so the echo should work correctly. 7273 lt_compile=`echo "$ac_compile" | $SED \ 7273 lt_compile=`echo "$ac_compile" | $SED \ 7274 -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ 7274 -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ 7275 -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ 7275 -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ 7276 -e 's:$: $lt_compiler_flag:'` 7276 -e 's:$: $lt_compiler_flag:'` 7277 (eval echo "\"\$as_me:7278: $lt_compile\"" >&5) | 7277 (eval echo "\"\$as_me:7277: $lt_compile\"" >&5) 7278 (eval "$lt_compile" 2>out/conftest.err) 7278 (eval "$lt_compile" 2>out/conftest.err) 7279 ac_status=$? 7279 ac_status=$? 7280 cat out/conftest.err >&5 7280 cat out/conftest.err >&5 7281 echo "$as_me:7282: \$? = $ac_status" >&5 | 7281 echo "$as_me:7281: \$? = $ac_status" >&5 7282 if (exit $ac_status) && test -s out/conftest2.$ac_objext 7282 if (exit $ac_status) && test -s out/conftest2.$ac_objext 7283 then 7283 then 7284 # The compiler can only warn and ignore the option if not recognized 7284 # The compiler can only warn and ignore the option if not recognized 7285 # So say no if there are warnings 7285 # So say no if there are warnings 7286 $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp 7286 $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp 7287 $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 7287 $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 7288 if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/d 7288 if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/d ................................................................................................................................................................................ 7325 # (2) before a word containing "conftest.", or (3) at the end. 7325 # (2) before a word containing "conftest.", or (3) at the end. 7326 # Note that $ac_compile itself does not contain backslashes and begins 7326 # Note that $ac_compile itself does not contain backslashes and begins 7327 # with a dollar sign (not a hyphen), so the echo should work correctly. 7327 # with a dollar sign (not a hyphen), so the echo should work correctly. 7328 lt_compile=`echo "$ac_compile" | $SED \ 7328 lt_compile=`echo "$ac_compile" | $SED \ 7329 -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ 7329 -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ 7330 -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ 7330 -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ 7331 -e 's:$: $lt_compiler_flag:'` 7331 -e 's:$: $lt_compiler_flag:'` 7332 (eval echo "\"\$as_me:7333: $lt_compile\"" >&5) | 7332 (eval echo "\"\$as_me:7332: $lt_compile\"" >&5) 7333 (eval "$lt_compile" 2>out/conftest.err) 7333 (eval "$lt_compile" 2>out/conftest.err) 7334 ac_status=$? 7334 ac_status=$? 7335 cat out/conftest.err >&5 7335 cat out/conftest.err >&5 7336 echo "$as_me:7337: \$? = $ac_status" >&5 | 7336 echo "$as_me:7336: \$? = $ac_status" >&5 7337 if (exit $ac_status) && test -s out/conftest2.$ac_objext 7337 if (exit $ac_status) && test -s out/conftest2.$ac_objext 7338 then 7338 then 7339 # The compiler can only warn and ignore the option if not recognized 7339 # The compiler can only warn and ignore the option if not recognized 7340 # So say no if there are warnings 7340 # So say no if there are warnings 7341 $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp 7341 $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp 7342 $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 7342 $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 7343 if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/d 7343 if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/d ................................................................................................................................................................................ 10138 else 10138 else 10139 if test "$cross_compiling" = yes; then : 10139 if test "$cross_compiling" = yes; then : 10140 lt_cv_dlopen_self=cross 10140 lt_cv_dlopen_self=cross 10141 else 10141 else 10142 lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 10142 lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 10143 lt_status=$lt_dlunknown 10143 lt_status=$lt_dlunknown 10144 cat > conftest.$ac_ext <<_LT_EOF 10144 cat > conftest.$ac_ext <<_LT_EOF 10145 #line 10146 "configure" | 10145 #line 10145 "configure" 10146 #include "confdefs.h" 10146 #include "confdefs.h" 10147 10147 10148 #if HAVE_DLFCN_H 10148 #if HAVE_DLFCN_H 10149 #include <dlfcn.h> 10149 #include <dlfcn.h> 10150 #endif 10150 #endif 10151 10151 10152 #include <stdio.h> 10152 #include <stdio.h> ................................................................................................................................................................................ 10234 else 10234 else 10235 if test "$cross_compiling" = yes; then : 10235 if test "$cross_compiling" = yes; then : 10236 lt_cv_dlopen_self_static=cross 10236 lt_cv_dlopen_self_static=cross 10237 else 10237 else 10238 lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 10238 lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 10239 lt_status=$lt_dlunknown 10239 lt_status=$lt_dlunknown 10240 cat > conftest.$ac_ext <<_LT_EOF 10240 cat > conftest.$ac_ext <<_LT_EOF 10241 #line 10242 "configure" | 10241 #line 10241 "configure" 10242 #include "confdefs.h" 10242 #include "confdefs.h" 10243 10243 10244 #if HAVE_DLFCN_H 10244 #if HAVE_DLFCN_H 10245 #include <dlfcn.h> 10245 #include <dlfcn.h> 10246 #endif 10246 #endif 10247 10247 10248 #include <stdio.h> 10248 #include <stdio.h> ................................................................................................................................................................................ 12904 12904 12905 12905 12906 12906 12907 12907 12908 12908 12909 12909 12910 12910 12911 < 12912 fi 12911 fi 12913 fi 12912 fi 12914 if test "${use_tcl}" = "no" ; then 12913 if test "${use_tcl}" = "no" ; then 12915 HAVE_TCL="" 12914 HAVE_TCL="" 12916 else 12915 else 12917 HAVE_TCL=1 12916 HAVE_TCL=1 12918 fi 12917 fi ................................................................................................................................................................................ 14029 14028 14030 exec 6>&1 14029 exec 6>&1 14031 14030 14032 # Save the log message, to keep $[0] and so on meaningful, and to 14031 # Save the log message, to keep $[0] and so on meaningful, and to 14033 # report actual input values of CONFIG_FILES etc. instead of their 14032 # report actual input values of CONFIG_FILES etc. instead of their 14034 # values after options handling. 14033 # values after options handling. 14035 ac_log=" 14034 ac_log=" 14036 This file was extended by sqlite $as_me 3.7.15, which was | 14035 This file was extended by sqlite $as_me 3.7.16, which was 14037 generated by GNU Autoconf 2.62. Invocation command line was 14036 generated by GNU Autoconf 2.62. Invocation command line was 14038 14037 14039 CONFIG_FILES = $CONFIG_FILES 14038 CONFIG_FILES = $CONFIG_FILES 14040 CONFIG_HEADERS = $CONFIG_HEADERS 14039 CONFIG_HEADERS = $CONFIG_HEADERS 14041 CONFIG_LINKS = $CONFIG_LINKS 14040 CONFIG_LINKS = $CONFIG_LINKS 14042 CONFIG_COMMANDS = $CONFIG_COMMANDS 14041 CONFIG_COMMANDS = $CONFIG_COMMANDS 14043 $ $0 $@ 14042 $ $0 $@ ................................................................................................................................................................................ 14082 $config_commands 14081 $config_commands 14083 14082 14084 Report bugs to <bug-autoconf@gnu.org>." 14083 Report bugs to <bug-autoconf@gnu.org>." 14085 14084 14086 _ACEOF 14085 _ACEOF 14087 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 14086 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 14088 ac_cs_version="\\ 14087 ac_cs_version="\\ 14089 sqlite config.status 3.7.15 | 14088 sqlite config.status 3.7.16 14090 configured by $0, generated by GNU Autoconf 2.62, 14089 configured by $0, generated by GNU Autoconf 2.62, 14091 with options \\"`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\ 14090 with options \\"`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\ 14092 14091 14093 Copyright (C) 2008 Free Software Foundation, Inc. 14092 Copyright (C) 2008 Free Software Foundation, Inc. 14094 This config.status script is free software; the Free Software Foundation 14093 This config.status script is free software; the Free Software Foundation 14095 gives unlimited permission to copy, distribute and modify it." 14094 gives unlimited permission to copy, distribute and modify it." 14096 14095
Changes to main.mk
249 $(TOP)/src/test_malloc.c \ 249 $(TOP)/src/test_malloc.c \ 250 $(TOP)/src/test_multiplex.c \ 250 $(TOP)/src/test_multiplex.c \ 251 $(TOP)/src/test_mutex.c \ 251 $(TOP)/src/test_mutex.c \ 252 $(TOP)/src/test_onefile.c \ 252 $(TOP)/src/test_onefile.c \ 253 $(TOP)/src/test_osinst.c \ 253 $(TOP)/src/test_osinst.c \ 254 $(TOP)/src/test_pcache.c \ 254 $(TOP)/src/test_pcache.c \ 255 $(TOP)/src/test_quota.c \ 255 $(TOP)/src/test_quota.c \ > 256 $(TOP)/src/test_regexp.c \ 256 $(TOP)/src/test_rtree.c \ 257 $(TOP)/src/test_rtree.c \ 257 $(TOP)/src/test_schema.c \ 258 $(TOP)/src/test_schema.c \ 258 $(TOP)/src/test_server.c \ 259 $(TOP)/src/test_server.c \ 259 $(TOP)/src/test_stat.c \ 260 $(TOP)/src/test_stat.c \ 260 $(TOP)/src/test_sqllog.c \ 261 $(TOP)/src/test_sqllog.c \ 261 $(TOP)/src/test_superlock.c \ 262 $(TOP)/src/test_superlock.c \ 262 $(TOP)/src/test_syscall.c \ 263 $(TOP)/src/test_syscall.c \
Changes to src/backup.c
208 } 208 } 209 209 210 /* 210 /* 211 ** Parameter zSrcData points to a buffer containing the data for 211 ** Parameter zSrcData points to a buffer containing the data for 212 ** page iSrcPg from the source database. Copy this data into the 212 ** page iSrcPg from the source database. Copy this data into the 213 ** destination database. 213 ** destination database. 214 */ 214 */ 215 static int backupOnePage(sqlite3_backup *p, Pgno iSrcPg, const u8 *zSrcData){ | 215 static int backupOnePage( > 216 sqlite3_backup *p, /* Backup handle */ > 217 Pgno iSrcPg, /* Source database page to backup */ > 218 const u8 *zSrcData, /* Source database page data */ > 219 int bUpdate /* True for an update, false otherwise */ > 220 ){ 216 Pager * const pDestPager = sqlite3BtreePager(p->pDest); 221 Pager * const pDestPager = sqlite3BtreePager(p->pDest); 217 const int nSrcPgsz = sqlite3BtreeGetPageSize(p->pSrc); 222 const int nSrcPgsz = sqlite3BtreeGetPageSize(p->pSrc); 218 int nDestPgsz = sqlite3BtreeGetPageSize(p->pDest); 223 int nDestPgsz = sqlite3BtreeGetPageSize(p->pDest); 219 const int nCopy = MIN(nSrcPgsz, nDestPgsz); 224 const int nCopy = MIN(nSrcPgsz, nDestPgsz); 220 const i64 iEnd = (i64)iSrcPg*(i64)nSrcPgsz; 225 const i64 iEnd = (i64)iSrcPg*(i64)nSrcPgsz; 221 #ifdef SQLITE_HAS_CODEC 226 #ifdef SQLITE_HAS_CODEC 222 /* Use BtreeGetReserveNoMutex() for the source b-tree, as although it is 227 /* Use BtreeGetReserveNoMutex() for the source b-tree, as although it is ................................................................................................................................................................................ 281 ** and the pager code use this trick (clearing the first byte 286 ** and the pager code use this trick (clearing the first byte 282 ** of the page 'extra' space to invalidate the Btree layers 287 ** of the page 'extra' space to invalidate the Btree layers 283 ** cached parse of the page). MemPage.isInit is marked 288 ** cached parse of the page). MemPage.isInit is marked 284 ** "MUST BE FIRST" for this purpose. 289 ** "MUST BE FIRST" for this purpose. 285 */ 290 */ 286 memcpy(zOut, zIn, nCopy); 291 memcpy(zOut, zIn, nCopy); 287 ((u8 *)sqlite3PagerGetExtra(pDestPg))[0] = 0; 292 ((u8 *)sqlite3PagerGetExtra(pDestPg))[0] = 0; > 293 if( iOff==0 && bUpdate==0 ){ > 294 sqlite3Put4byte(&zOut[28], sqlite3BtreeLastPage(p->pSrc)); > 295 } 288 } 296 } 289 sqlite3PagerUnref(pDestPg); 297 sqlite3PagerUnref(pDestPg); 290 } 298 } 291 299 292 return rc; 300 return rc; 293 } 301 } 294 302 ................................................................................................................................................................................ 387 assert( nSrcPage>=0 ); 395 assert( nSrcPage>=0 ); 388 for(ii=0; (nPage<0 || ii<nPage) && p->iNext<=(Pgno)nSrcPage && !rc; ii++){ 396 for(ii=0; (nPage<0 || ii<nPage) && p->iNext<=(Pgno)nSrcPage && !rc; ii++){ 389 const Pgno iSrcPg = p->iNext; /* Source page number */ 397 const Pgno iSrcPg = p->iNext; /* Source page number */ 390 if( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt) ){ 398 if( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt) ){ 391 DbPage *pSrcPg; /* Source page object */ 399 DbPage *pSrcPg; /* Source page object */ 392 rc = sqlite3PagerGet(pSrcPager, iSrcPg, &pSrcPg); 400 rc = sqlite3PagerGet(pSrcPager, iSrcPg, &pSrcPg); 393 if( rc==SQLITE_OK ){ 401 if( rc==SQLITE_OK ){ 394 rc = backupOnePage(p, iSrcPg, sqlite3PagerGetData(pSrcPg)); | 402 rc = backupOnePage(p, iSrcPg, sqlite3PagerGetData(pSrcPg), 0); 395 sqlite3PagerUnref(pSrcPg); 403 sqlite3PagerUnref(pSrcPg); 396 } 404 } 397 } 405 } 398 p->iNext++; 406 p->iNext++; 399 } 407 } 400 if( rc==SQLITE_OK ){ 408 if( rc==SQLITE_OK ){ 401 p->nPagecount = nSrcPage; 409 p->nPagecount = nSrcPage; ................................................................................................................................................................................ 635 /* The backup process p has already copied page iPage. But now it 643 /* The backup process p has already copied page iPage. But now it 636 ** has been modified by a transaction on the source pager. Copy 644 ** has been modified by a transaction on the source pager. Copy 637 ** the new data into the backup. 645 ** the new data into the backup. 638 */ 646 */ 639 int rc; 647 int rc; 640 assert( p->pDestDb ); 648 assert( p->pDestDb ); 641 sqlite3_mutex_enter(p->pDestDb->mutex); 649 sqlite3_mutex_enter(p->pDestDb->mutex); 642 rc = backupOnePage(p, iPage, aData); | 650 rc = backupOnePage(p, iPage, aData, 1); 643 sqlite3_mutex_leave(p->pDestDb->mutex); 651 sqlite3_mutex_leave(p->pDestDb->mutex); 644 assert( rc!=SQLITE_BUSY && rc!=SQLITE_LOCKED ); 652 assert( rc!=SQLITE_BUSY && rc!=SQLITE_LOCKED ); 645 if( rc!=SQLITE_OK ){ 653 if( rc!=SQLITE_OK ){ 646 p->rc = rc; 654 p->rc = rc; 647 } 655 } 648 } 656 } 649 } 657 }
Changes to src/btree.c
8022 if( !sCheck.aPgRef ){ 8022 if( !sCheck.aPgRef ){ 8023 *pnErr = 1; 8023 *pnErr = 1; 8024 sqlite3BtreeLeave(p); 8024 sqlite3BtreeLeave(p); 8025 return 0; 8025 return 0; 8026 } 8026 } 8027 i = PENDING_BYTE_PAGE(pBt); 8027 i = PENDING_BYTE_PAGE(pBt); 8028 if( i<=sCheck.nPage ) setPageReferenced(&sCheck, i); 8028 if( i<=sCheck.nPage ) setPageReferenced(&sCheck, i); 8029 sqlite3StrAccumInit(&sCheck.errMsg, zErr, sizeof(zErr), 20000); | 8029 sqlite3StrAccumInit(&sCheck.errMsg, zErr, sizeof(zErr), SQLITE_MAX_LENGTH); 8030 sCheck.errMsg.useMalloc = 2; 8030 sCheck.errMsg.useMalloc = 2; 8031 8031 8032 /* Check the integrity of the freelist 8032 /* Check the integrity of the freelist 8033 */ 8033 */ 8034 checkList(&sCheck, 1, get4byte(&pBt->pPage1->aData[32]), 8034 checkList(&sCheck, 1, get4byte(&pBt->pPage1->aData[32]), 8035 get4byte(&pBt->pPage1->aData[36]), "Main freelist: "); 8035 get4byte(&pBt->pPage1->aData[36]), "Main freelist: "); 8036 8036
Changes to src/build.c
2687 2687 2688 /* Figure out how many bytes of space are required to store explicitly 2688 /* Figure out how many bytes of space are required to store explicitly 2689 ** specified collation sequence names. 2689 ** specified collation sequence names. 2690 */ 2690 */ 2691 for(i=0; i<pList->nExpr; i++){ 2691 for(i=0; i<pList->nExpr; i++){ 2692 Expr *pExpr = pList->a[i].pExpr; 2692 Expr *pExpr = pList->a[i].pExpr; 2693 if( pExpr ){ 2693 if( pExpr ){ 2694 CollSeq *pColl = pExpr->pColl; | 2694 CollSeq *pColl = sqlite3ExprCollSeq(pParse, pExpr); 2695 /* Either pColl!=0 or there was an OOM failure. But if an OOM | 2695 if( pColl ){ 2696 ** failure we have quit before reaching this point. */ < 2697 if( ALWAYS(pColl) ){ < 2698 nExtra += (1 + sqlite3Strlen30(pColl->zName)); 2696 nExtra += (1 + sqlite3Strlen30(pColl->zName)); 2699 } 2697 } 2700 } 2698 } 2701 } 2699 } 2702 2700 2703 /* 2701 /* 2704 ** Allocate the index structure. 2702 ** Allocate the index structure. ................................................................................................................................................................................ 2753 ** same column more than once cannot be an error because that would 2751 ** same column more than once cannot be an error because that would 2754 ** break backwards compatibility - it needs to be a warning. 2752 ** break backwards compatibility - it needs to be a warning. 2755 */ 2753 */ 2756 for(i=0, pListItem=pList->a; i<pList->nExpr; i++, pListItem++){ 2754 for(i=0, pListItem=pList->a; i<pList->nExpr; i++, pListItem++){ 2757 const char *zColName = pListItem->zName; 2755 const char *zColName = pListItem->zName; 2758 Column *pTabCol; 2756 Column *pTabCol; 2759 int requestedSortOrder; 2757 int requestedSortOrder; > 2758 CollSeq *pColl; /* Collating sequence */ 2760 char *zColl; /* Collation sequence name */ 2759 char *zColl; /* Collation sequence name */ 2761 2760 2762 for(j=0, pTabCol=pTab->aCol; j<pTab->nCol; j++, pTabCol++){ 2761 for(j=0, pTabCol=pTab->aCol; j<pTab->nCol; j++, pTabCol++){ 2763 if( sqlite3StrICmp(zColName, pTabCol->zName)==0 ) break; 2762 if( sqlite3StrICmp(zColName, pTabCol->zName)==0 ) break; 2764 } 2763 } 2765 if( j>=pTab->nCol ){ 2764 if( j>=pTab->nCol ){ 2766 sqlite3ErrorMsg(pParse, "table %s has no column named %s", 2765 sqlite3ErrorMsg(pParse, "table %s has no column named %s", 2767 pTab->zName, zColName); 2766 pTab->zName, zColName); 2768 pParse->checkSchema = 1; 2767 pParse->checkSchema = 1; 2769 goto exit_create_index; 2768 goto exit_create_index; 2770 } 2769 } 2771 pIndex->aiColumn[i] = j; 2770 pIndex->aiColumn[i] = j; 2772 /* Justification of the ALWAYS(pListItem->pExpr->pColl): Because of < 2773 ** the way the "idxlist" non-terminal is constructed by the parser, < 2774 ** if pListItem->pExpr is not null then either pListItem->pExpr->pColl < 2775 ** must exist or else there must have been an OOM error. But if there < 2776 ** was an OOM error, we would never reach this point. */ < 2777 if( pListItem->pExpr && ALWAYS(pListItem->pExpr->pColl) ){ | 2771 if( pListItem->pExpr > 2772 && (pColl = sqlite3ExprCollSeq(pParse, pListItem->pExpr))!=0 > 2773 ){ 2778 int nColl; 2774 int nColl; 2779 zColl = pListItem->pExpr->pColl->zName; | 2775 zColl = pColl->zName; 2780 nColl = sqlite3Strlen30(zColl) + 1; 2776 nColl = sqlite3Strlen30(zColl) + 1; 2781 assert( nExtra>=nColl ); 2777 assert( nExtra>=nColl ); 2782 memcpy(zExtra, zColl, nColl); 2778 memcpy(zExtra, zColl, nColl); 2783 zColl = zExtra; 2779 zColl = zExtra; 2784 zExtra += nColl; 2780 zExtra += nColl; 2785 nExtra -= nColl; 2781 nExtra -= nColl; 2786 }else{ 2782 }else{
Changes to src/expr.c
27 ** 27 ** 28 ** CREATE TABLE t1(a); 28 ** CREATE TABLE t1(a); 29 ** SELECT * FROM t1 WHERE a; 29 ** SELECT * FROM t1 WHERE a; 30 ** SELECT a AS b FROM t1 WHERE b; 30 ** SELECT a AS b FROM t1 WHERE b; 31 ** SELECT * FROM t1 WHERE (select a from t1); 31 ** SELECT * FROM t1 WHERE (select a from t1); 32 */ 32 */ 33 char sqlite3ExprAffinity(Expr *pExpr){ 33 char sqlite3ExprAffinity(Expr *pExpr){ > 34 int op; > 35 pExpr = sqlite3ExprSkipCollate(pExpr); 34 int op = pExpr->op; | 36 op = pExpr->op; 35 if( op==TK_SELECT ){ 37 if( op==TK_SELECT ){ 36 assert( pExpr->flags&EP_xIsSelect ); 38 assert( pExpr->flags&EP_xIsSelect ); 37 return sqlite3ExprAffinity(pExpr->x.pSelect->pEList->a[0].pExpr); 39 return sqlite3ExprAffinity(pExpr->x.pSelect->pEList->a[0].pExpr); 38 } 40 } 39 #ifndef SQLITE_OMIT_CAST 41 #ifndef SQLITE_OMIT_CAST 40 if( op==TK_CAST ){ 42 if( op==TK_CAST ){ 41 assert( !ExprHasProperty(pExpr, EP_IntValue) ); 43 assert( !ExprHasProperty(pExpr, EP_IntValue) ); ................................................................................................................................................................................ 52 assert( pExpr->pTab && j<pExpr->pTab->nCol ); 54 assert( pExpr->pTab && j<pExpr->pTab->nCol ); 53 return pExpr->pTab->aCol[j].affinity; 55 return pExpr->pTab->aCol[j].affinity; 54 } 56 } 55 return pExpr->affinity; 57 return pExpr->affinity; 56 } 58 } 57 59 58 /* 60 /* 59 ** Set the explicit collating sequence for an expression to the | 61 ** Set the collating sequence for expression pExpr to be the collating 60 ** collating sequence supplied in the second argument. | 62 ** sequence named by pToken. Return a pointer to a new Expr node that > 63 ** implements the COLLATE operator. > 64 ** > 65 ** If a memory allocation error occurs, that fact is recorded in pParse->db > 66 ** and the pExpr parameter is returned unchanged. 61 */ 67 */ 62 Expr *sqlite3ExprSetColl(Expr *pExpr, CollSeq *pColl){ < 63 if( pExpr && pColl ){ < 64 pExpr->pColl = pColl; < > 68 Expr *sqlite3ExprAddCollateToken(Parse *pParse, Expr *pExpr, Token *pCollName){ > 69 if( pCollName->n>0 ){ > 70 Expr *pNew = sqlite3ExprAlloc(pParse->db, TK_COLLATE, pCollName, 1); > 71 if( pNew ){ > 72 pNew->pLeft = pExpr; 65 pExpr->flags |= EP_ExpCollate; | 73 pNew->flags |= EP_Collate; > 74 pExpr = pNew; > 75 } 66 } 76 } 67 return pExpr; 77 return pExpr; 68 } 78 } > 79 Expr *sqlite3ExprAddCollateString(Parse *pParse, Expr *pExpr, const char *zC){ > 80 Token s; > 81 assert( zC!=0 ); > 82 s.z = zC; > 83 s.n = sqlite3Strlen30(s.z); > 84 return sqlite3ExprAddCollateToken(pParse, pExpr, &s); 69 | 85 } > 86 70 /* 87 /* 71 ** Set the collating sequence for expression pExpr to be the collating < 72 ** sequence named by pToken. Return a pointer to the revised expression. < 73 ** The collating sequence is marked as "explicit" using the EP_ExpCollate < 74 ** flag. An explicit collating sequence will override implicit < 75 ** collating sequences. < > 88 ** Skip over any TK_COLLATE and/or TK_AS operators at the root of > 89 ** an expression. 76 */ 90 */ 77 Expr *sqlite3ExprSetCollByToken(Parse *pParse, Expr *pExpr, Token *pCollName){ < 78 char *zColl = 0; /* Dequoted name of collation sequence */ < 79 CollSeq *pColl; < 80 sqlite3 *db = pParse->db; < 81 zColl = sqlite3NameFromToken(db, pCollName); | 91 Expr *sqlite3ExprSkipCollate(Expr *pExpr){ 82 pColl = sqlite3LocateCollSeq(pParse, zColl); | 92 while( pExpr && (pExpr->op==TK_COLLATE || pExpr->op==TK_AS) ){ 83 sqlite3ExprSetColl(pExpr, pColl); | 93 pExpr = pExpr->pLeft; 84 sqlite3DbFree(db, zColl); < > 94 } 85 return pExpr; 95 return pExpr; 86 } 96 } 87 97 88 /* 98 /* 89 ** Return the default collation sequence for the expression pExpr. If | 99 ** Return the collation sequence for the expression pExpr. If 90 ** there is no default collation type, return 0. | 100 ** there is no defined collating sequence, return NULL. > 101 ** > 102 ** The collating sequence might be determined by a COLLATE operator > 103 ** or by the presence of a column with a defined collating sequence. > 104 ** COLLATE operators take first precedence. Left operands take > 105 ** precedence over right operands. 91 */ 106 */ 92 CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr){ 107 CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr){ > 108 sqlite3 *db = pParse->db; 93 CollSeq *pColl = 0; 109 CollSeq *pColl = 0; 94 Expr *p = pExpr; 110 Expr *p = pExpr; 95 while( p ){ 111 while( p ){ 96 int op; | 112 int op = p->op; > 113 if( op==TK_CAST || op==TK_UPLUS ){ 97 pColl = p->pColl; | 114 p = p->pLeft; > 115 continue; > 116 } > 117 assert( op!=TK_REGISTER || p->op2!=TK_COLLATE ); > 118 if( op==TK_COLLATE ){ > 119 if( db->init.busy ){ > 120 /* Do not report errors when parsing while the schema */ > 121 pColl = sqlite3FindCollSeq(db, ENC(db), p->u.zToken, 0); > 122 }else{ > 123 pColl = sqlite3GetCollSeq(pParse, ENC(db), 0, p->u.zToken); > 124 } 98 if( pColl ) break; | 125 break; 99 op = p->op; < > 126 } 100 if( p->pTab!=0 && ( | 127 if( p->pTab!=0 > 128 && (op==TK_AGG_COLUMN || op==TK_COLUMN 101 op==TK_AGG_COLUMN || op==TK_COLUMN || op==TK_REGISTER || op==TK_TRIGGER | 129 || op==TK_REGISTER || op==TK_TRIGGER) 102 )){ | 130 ){ 103 /* op==TK_REGISTER && p->pTab!=0 happens when pExpr was originally 131 /* op==TK_REGISTER && p->pTab!=0 happens when pExpr was originally 104 ** a TK_COLUMN but was previously evaluated and cached in a register */ 132 ** a TK_COLUMN but was previously evaluated and cached in a register */ 105 const char *zColl; < 106 int j = p->iColumn; 133 int j = p->iColumn; 107 if( j>=0 ){ 134 if( j>=0 ){ 108 sqlite3 *db = pParse->db; < 109 zColl = p->pTab->aCol[j].zColl; | 135 const char *zColl = p->pTab->aCol[j].zColl; 110 pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0); 136 pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0); 111 pExpr->pColl = pColl; < 112 } 137 } 113 break; 138 break; 114 } 139 } 115 if( op!=TK_CAST && op!=TK_UPLUS ){ | 140 if( p->flags & EP_Collate ){ > 141 if( ALWAYS(p->pLeft) && (p->pLeft->flags & EP_Collate)!=0 ){ > 142 p = p->pLeft; > 143 }else{ > 144 p = p->pRight; > 145 } > 146 }else{ 116 break; 147 break; 117 } 148 } 118 p = p->pLeft; < 119 } 149 } 120 if( sqlite3CheckCollSeq(pParse, pColl) ){ 150 if( sqlite3CheckCollSeq(pParse, pColl) ){ 121 pColl = 0; 151 pColl = 0; 122 } 152 } 123 return pColl; 153 return pColl; 124 } 154 } 125 155 ................................................................................................................................................................................ 215 CollSeq *sqlite3BinaryCompareCollSeq( 245 CollSeq *sqlite3BinaryCompareCollSeq( 216 Parse *pParse, 246 Parse *pParse, 217 Expr *pLeft, 247 Expr *pLeft, 218 Expr *pRight 248 Expr *pRight 219 ){ 249 ){ 220 CollSeq *pColl; 250 CollSeq *pColl; 221 assert( pLeft ); 251 assert( pLeft ); 222 if( pLeft->flags & EP_ExpCollate ){ | 252 if( pLeft->flags & EP_Collate ){ 223 assert( pLeft->pColl ); | 253 pColl = sqlite3ExprCollSeq(pParse, pLeft); 224 pColl = pLeft->pColl; < 225 }else if( pRight && pRight->flags & EP_ExpCollate ){ | 254 }else if( pRight && (pRight->flags & EP_Collate)!=0 ){ 226 assert( pRight->pColl ); < 227 pColl = pRight->pColl; < > 255 pColl = sqlite3ExprCollSeq(pParse, pRight); 228 }else{ 256 }else{ 229 pColl = sqlite3ExprCollSeq(pParse, pLeft); 257 pColl = sqlite3ExprCollSeq(pParse, pLeft); 230 if( !pColl ){ 258 if( !pColl ){ 231 pColl = sqlite3ExprCollSeq(pParse, pRight); 259 pColl = sqlite3ExprCollSeq(pParse, pRight); 232 } 260 } 233 } 261 } 234 return pColl; 262 return pColl; ................................................................................................................................................................................ 450 if( pRoot==0 ){ 478 if( pRoot==0 ){ 451 assert( db->mallocFailed ); 479 assert( db->mallocFailed ); 452 sqlite3ExprDelete(db, pLeft); 480 sqlite3ExprDelete(db, pLeft); 453 sqlite3ExprDelete(db, pRight); 481 sqlite3ExprDelete(db, pRight); 454 }else{ 482 }else{ 455 if( pRight ){ 483 if( pRight ){ 456 pRoot->pRight = pRight; 484 pRoot->pRight = pRight; 457 if( pRight->flags & EP_ExpCollate ){ < 458 pRoot->flags |= EP_ExpCollate; | 485 pRoot->flags |= EP_Collate & pRight->flags; 459 pRoot->pColl = pRight->pColl; < 460 } < 461 } 486 } 462 if( pLeft ){ 487 if( pLeft ){ 463 pRoot->pLeft = pLeft; 488 pRoot->pLeft = pLeft; 464 if( pLeft->flags & EP_ExpCollate ){ < 465 pRoot->flags |= EP_ExpCollate; | 489 pRoot->flags |= EP_Collate & pLeft->flags; 466 pRoot->pColl = pLeft->pColl; < 467 } < 468 } 490 } 469 exprSetHeight(pRoot); 491 exprSetHeight(pRoot); 470 } 492 } 471 } 493 } 472 494 473 /* 495 /* 474 ** Allocate a Expr node which joins as many as two subtrees. 496 ** Allocate a Expr node which joins as many as two subtrees. ................................................................................................................................................................................ 718 if( 0==(flags&EXPRDUP_REDUCE) ){ 740 if( 0==(flags&EXPRDUP_REDUCE) ){ 719 nSize = EXPR_FULLSIZE; 741 nSize = EXPR_FULLSIZE; 720 }else{ 742 }else{ 721 assert( !ExprHasAnyProperty(p, EP_TokenOnly|EP_Reduced) ); 743 assert( !ExprHasAnyProperty(p, EP_TokenOnly|EP_Reduced) ); 722 assert( !ExprHasProperty(p, EP_FromJoin) ); 744 assert( !ExprHasProperty(p, EP_FromJoin) ); 723 assert( (p->flags2 & EP2_MallocedToken)==0 ); 745 assert( (p->flags2 & EP2_MallocedToken)==0 ); 724 assert( (p->flags2 & EP2_Irreducible)==0 ); 746 assert( (p->flags2 & EP2_Irreducible)==0 ); 725 if( p->pLeft || p->pRight || p->pColl || p->x.pList ){ | 747 if( p->pLeft || p->pRight || p->x.pList ){ 726 nSize = EXPR_REDUCEDSIZE | EP_Reduced; 748 nSize = EXPR_REDUCEDSIZE | EP_Reduced; 727 }else{ 749 }else{ 728 nSize = EXPR_TOKENONLYSIZE | EP_TokenOnly; 750 nSize = EXPR_TOKENONLYSIZE | EP_TokenOnly; 729 } 751 } 730 } 752 } 731 return nSize; 753 return nSize; 732 } 754 } ................................................................................................................................................................................ 2742 testcase( regFree2==0 ); 2764 testcase( regFree2==0 ); 2743 codeCompare(pParse, pLeft, pRight, OP_Le, r1, r2, r4, SQLITE_STOREP2); 2765 codeCompare(pParse, pLeft, pRight, OP_Le, r1, r2, r4, SQLITE_STOREP2); 2744 sqlite3VdbeAddOp3(v, OP_And, r3, r4, target); 2766 sqlite3VdbeAddOp3(v, OP_And, r3, r4, target); 2745 sqlite3ReleaseTempReg(pParse, r3); 2767 sqlite3ReleaseTempReg(pParse, r3); 2746 sqlite3ReleaseTempReg(pParse, r4); 2768 sqlite3ReleaseTempReg(pParse, r4); 2747 break; 2769 break; 2748 } 2770 } > 2771 case TK_COLLATE: 2749 case TK_UPLUS: { 2772 case TK_UPLUS: { 2750 inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target); 2773 inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target); 2751 break; 2774 break; 2752 } 2775 } 2753 2776 2754 case TK_TRIGGER: { 2777 case TK_TRIGGER: { 2755 /* If the opcode is TK_TRIGGER, then the expression is a reference 2778 /* If the opcode is TK_TRIGGER, then the expression is a reference ................................................................................................................................................................................ 3110 3133 3111 case TK_UMINUS: zUniOp = "UMINUS"; break; 3134 case TK_UMINUS: zUniOp = "UMINUS"; break; 3112 case TK_UPLUS: zUniOp = "UPLUS"; break; 3135 case TK_UPLUS: zUniOp = "UPLUS"; break; 3113 case TK_BITNOT: zUniOp = "BITNOT"; break; 3136 case TK_BITNOT: zUniOp = "BITNOT"; break; 3114 case TK_NOT: zUniOp = "NOT"; break; 3137 case TK_NOT: zUniOp = "NOT"; break; 3115 case TK_ISNULL: zUniOp = "ISNULL"; break; 3138 case TK_ISNULL: zUniOp = "ISNULL"; break; 3116 case TK_NOTNULL: zUniOp = "NOTNULL"; break; 3139 case TK_NOTNULL: zUniOp = "NOTNULL"; break; > 3140 > 3141 case TK_COLLATE: { > 3142 sqlite3ExplainExpr(pOut, pExpr->pLeft); > 3143 sqlite3ExplainPrintf(pOut,".COLLATE(%s)",pExpr->u.zToken); > 3144 break; > 3145 } 3117 3146 3118 case TK_AGG_FUNCTION: 3147 case TK_AGG_FUNCTION: 3119 case TK_CONST_FUNC: 3148 case TK_CONST_FUNC: 3120 case TK_FUNCTION: { 3149 case TK_FUNCTION: { 3121 ExprList *pFarg; /* List of function arguments */ 3150 ExprList *pFarg; /* List of function arguments */ 3122 if( ExprHasAnyProperty(pExpr, EP_TokenOnly) ){ 3151 if( ExprHasAnyProperty(pExpr, EP_TokenOnly) ){ 3123 pFarg = 0; 3152 pFarg = 0; ................................................................................................................................................................................ 3248 }else{ 3277 }else{ 3249 sqlite3ExplainPush(pOut); 3278 sqlite3ExplainPush(pOut); 3250 for(i=0; i<pList->nExpr; i++){ 3279 for(i=0; i<pList->nExpr; i++){ 3251 sqlite3ExplainPrintf(pOut, "item[%d] = ", i); 3280 sqlite3ExplainPrintf(pOut, "item[%d] = ", i); 3252 sqlite3ExplainPush(pOut); 3281 sqlite3ExplainPush(pOut); 3253 sqlite3ExplainExpr(pOut, pList->a[i].pExpr); 3282 sqlite3ExplainExpr(pOut, pList->a[i].pExpr); 3254 sqlite3ExplainPop(pOut); 3283 sqlite3ExplainPop(pOut); > 3284 if( pList->a[i].zName ){ > 3285 sqlite3ExplainPrintf(pOut, " AS %s", pList->a[i].zName); > 3286 } > 3287 if( pList->a[i].bSpanIsTab ){ > 3288 sqlite3ExplainPrintf(pOut, " (%s)", pList->a[i].zSpan); > 3289 } 3255 if( i<pList->nExpr-1 ){ 3290 if( i<pList->nExpr-1 ){ 3256 sqlite3ExplainNL(pOut); 3291 sqlite3ExplainNL(pOut); 3257 } 3292 } 3258 } 3293 } 3259 sqlite3ExplainPop(pOut); 3294 sqlite3ExplainPop(pOut); 3260 } 3295 } 3261 } 3296 } ................................................................................................................................................................................ 3329 static int evalConstExpr(Walker *pWalker, Expr *pExpr){ 3364 static int evalConstExpr(Walker *pWalker, Expr *pExpr){ 3330 Parse *pParse = pWalker->pParse; 3365 Parse *pParse = pWalker->pParse; 3331 switch( pExpr->op ){ 3366 switch( pExpr->op ){ 3332 case TK_IN: 3367 case TK_IN: 3333 case TK_REGISTER: { 3368 case TK_REGISTER: { 3334 return WRC_Prune; 3369 return WRC_Prune; 3335 } 3370 } > 3371 case TK_COLLATE: { > 3372 return WRC_Continue; > 3373 } 3336 case TK_FUNCTION: 3374 case TK_FUNCTION: 3337 case TK_AGG_FUNCTION: 3375 case TK_AGG_FUNCTION: 3338 case TK_CONST_FUNC: { 3376 case TK_CONST_FUNC: { 3339 /* The arguments to a function have a fixed destination. 3377 /* The arguments to a function have a fixed destination. 3340 ** Mark them this way to avoid generated unneeded OP_SCopy 3378 ** Mark them this way to avoid generated unneeded OP_SCopy 3341 ** instructions. 3379 ** instructions. 3342 */ 3380 */ ................................................................................................................................................................................ 3350 } 3388 } 3351 } 3389 } 3352 break; 3390 break; 3353 } 3391 } 3354 } 3392 } 3355 if( isAppropriateForFactoring(pExpr) ){ 3393 if( isAppropriateForFactoring(pExpr) ){ 3356 int r1 = ++pParse->nMem; 3394 int r1 = ++pParse->nMem; 3357 int r2; < 3358 r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1); | 3395 int r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1); > 3396 /* If r2!=r1, it means that register r1 is never used. That is harmless 3359 if( NEVER(r1!=r2) ) sqlite3ReleaseTempReg(pParse, r1); | 3397 ** but suboptimal, so we want to know about the situation to fix it. > 3398 ** Hence the following assert: */ > 3399 assert( r2==r1 ); 3360 pExpr->op2 = pExpr->op; 3400 pExpr->op2 = pExpr->op; 3361 pExpr->op = TK_REGISTER; 3401 pExpr->op = TK_REGISTER; 3362 pExpr->iTable = r2; 3402 pExpr->iTable = r2; 3363 return WRC_Prune; 3403 return WRC_Prune; 3364 } 3404 } 3365 return WRC_Continue; 3405 return WRC_Continue; 3366 } 3406 } ................................................................................................................................................................................ 3769 } 3809 } 3770 assert( !ExprHasAnyProperty(pA, EP_TokenOnly|EP_Reduced) ); 3810 assert( !ExprHasAnyProperty(pA, EP_TokenOnly|EP_Reduced) ); 3771 assert( !ExprHasAnyProperty(pB, EP_TokenOnly|EP_Reduced) ); 3811 assert( !ExprHasAnyProperty(pB, EP_TokenOnly|EP_Reduced) ); 3772 if( ExprHasProperty(pA, EP_xIsSelect) || ExprHasProperty(pB, EP_xIsSelect) ){ 3812 if( ExprHasProperty(pA, EP_xIsSelect) || ExprHasProperty(pB, EP_xIsSelect) ){ 3773 return 2; 3813 return 2; 3774 } 3814 } 3775 if( (pA->flags & EP_Distinct)!=(pB->flags & EP_Distinct) ) return 2; 3815 if( (pA->flags & EP_Distinct)!=(pB->flags & EP_Distinct) ) return 2; 3776 if( pA->op!=pB->op ) return 2; | 3816 if( pA->op!=pB->op ){ > 3817 if( pA->op==TK_COLLATE && sqlite3ExprCompare(pA->pLeft, pB)<2 ){ > 3818 return 1; > 3819 } > 3820 if( pB->op==TK_COLLATE && sqlite3ExprCompare(pA, pB->pLeft)<2 ){ > 3821 return 1; > 3822 } > 3823 return 2; > 3824 } 3777 if( sqlite3ExprCompare(pA->pLeft, pB->pLeft) ) return 2; 3825 if( sqlite3ExprCompare(pA->pLeft, pB->pLeft) ) return 2; 3778 if( sqlite3ExprCompare(pA->pRight, pB->pRight) ) return 2; 3826 if( sqlite3ExprCompare(pA->pRight, pB->pRight) ) return 2; 3779 if( sqlite3ExprListCompare(pA->x.pList, pB->x.pList) ) return 2; 3827 if( sqlite3ExprListCompare(pA->x.pList, pB->x.pList) ) return 2; 3780 if( pA->iTable!=pB->iTable || pA->iColumn!=pB->iColumn ) return 2; 3828 if( pA->iTable!=pB->iTable || pA->iColumn!=pB->iColumn ) return 2; 3781 if( ExprHasProperty(pA, EP_IntValue) ){ 3829 if( ExprHasProperty(pA, EP_IntValue) ){ 3782 if( !ExprHasProperty(pB, EP_IntValue) || pA->u.iValue!=pB->u.iValue ){ 3830 if( !ExprHasProperty(pB, EP_IntValue) || pA->u.iValue!=pB->u.iValue ){ 3783 return 2; 3831 return 2; 3784 } 3832 } 3785 }else if( pA->op!=TK_COLUMN && ALWAYS(pA->op!=TK_AGG_COLUMN) && pA->u.zToken){ 3833 }else if( pA->op!=TK_COLUMN && ALWAYS(pA->op!=TK_AGG_COLUMN) && pA->u.zToken){ 3786 if( ExprHasProperty(pB, EP_IntValue) || NEVER(pB->u.zToken==0) ) return 2; 3834 if( ExprHasProperty(pB, EP_IntValue) || NEVER(pB->u.zToken==0) ) return 2; 3787 if( strcmp(pA->u.zToken,pB->u.zToken)!=0 ){ 3835 if( strcmp(pA->u.zToken,pB->u.zToken)!=0 ){ 3788 return 2; | 3836 return pA->op==TK_COLLATE ? 1 : 2; 3789 } 3837 } 3790 } 3838 } 3791 if( (pA->flags & EP_ExpCollate)!=(pB->flags & EP_ExpCollate) ) return 1; < 3792 if( (pA->flags & EP_ExpCollate)!=0 && pA->pColl!=pB->pColl ) return 2; < 3793 return 0; 3839 return 0; 3794 } 3840 } 3795 3841 3796 /* 3842 /* 3797 ** Compare two ExprList objects. Return 0 if they are identical and 3843 ** Compare two ExprList objects. Return 0 if they are identical and 3798 ** non-zero if they differ in any way. 3844 ** non-zero if they differ in any way. 3799 ** 3845 **
Changes to src/fkey.c
138 ** Register (x+3): 3.1 (type real) 138 ** Register (x+3): 3.1 (type real) 139 */ 139 */ 140 140 141 /* 141 /* 142 ** A foreign key constraint requires that the key columns in the parent 142 ** A foreign key constraint requires that the key columns in the parent 143 ** table are collectively subject to a UNIQUE or PRIMARY KEY constraint. 143 ** table are collectively subject to a UNIQUE or PRIMARY KEY constraint. 144 ** Given that pParent is the parent table for foreign key constraint pFKey, 144 ** Given that pParent is the parent table for foreign key constraint pFKey, 145 ** search the schema a unique index on the parent key columns. | 145 ** search the schema for a unique index on the parent key columns. 146 ** 146 ** 147 ** If successful, zero is returned. If the parent key is an INTEGER PRIMARY 147 ** If successful, zero is returned. If the parent key is an INTEGER PRIMARY 148 ** KEY column, then output variable *ppIdx is set to NULL. Otherwise, *ppIdx 148 ** KEY column, then output variable *ppIdx is set to NULL. Otherwise, *ppIdx 149 ** is set to point to the unique index. 149 ** is set to point to the unique index. 150 ** 150 ** 151 ** If the parent key consists of a single column (the foreign key constraint 151 ** If the parent key consists of a single column (the foreign key constraint 152 ** is not a composite foreign key), output variable *paiCol is set to NULL. 152 ** is not a composite foreign key), output variable *paiCol is set to NULL. ................................................................................................................................................................................ 174 ** consists of a a different number of columns to the child key in 174 ** consists of a a different number of columns to the child key in 175 ** the child table. 175 ** the child table. 176 ** 176 ** 177 ** then non-zero is returned, and a "foreign key mismatch" error loaded 177 ** then non-zero is returned, and a "foreign key mismatch" error loaded 178 ** into pParse. If an OOM error occurs, non-zero is returned and the 178 ** into pParse. If an OOM error occurs, non-zero is returned and the 179 ** pParse->db->mallocFailed flag is set. 179 ** pParse->db->mallocFailed flag is set. 180 */ 180 */ 181 static int locateFkeyIndex( | 181 int sqlite3FkLocateIndex( 182 Parse *pParse, /* Parse context to store any error in */ 182 Parse *pParse, /* Parse context to store any error in */ 183 Table *pParent, /* Parent table of FK constraint pFKey */ 183 Table *pParent, /* Parent table of FK constraint pFKey */ 184 FKey *pFKey, /* Foreign key to find index for */ 184 FKey *pFKey, /* Foreign key to find index for */ 185 Index **ppIdx, /* OUT: Unique index on parent table */ 185 Index **ppIdx, /* OUT: Unique index on parent table */ 186 int **paiCol /* OUT: Map of index columns in pFKey */ 186 int **paiCol /* OUT: Map of index columns in pFKey */ 187 ){ 187 ){ 188 Index *pIdx = 0; /* Value to return via *ppIdx */ 188 Index *pIdx = 0; /* Value to return via *ppIdx */ ................................................................................................................................................................................ 271 if( i==nCol ) break; /* pIdx is usable */ 271 if( i==nCol ) break; /* pIdx is usable */ 272 } 272 } 273 } 273 } 274 } 274 } 275 275 276 if( !pIdx ){ 276 if( !pIdx ){ 277 if( !pParse->disableTriggers ){ 277 if( !pParse->disableTriggers ){ 278 sqlite3ErrorMsg(pParse, "foreign key mismatch"); | 278 sqlite3ErrorMsg(pParse, > 279 "foreign key mismatch - \"%w\" referencing \"%w\"", > 280 pFKey->pFrom->zName, pFKey->zTo); 279 } 281 } 280 sqlite3DbFree(pParse->db, aiCol); 282 sqlite3DbFree(pParse->db, aiCol); 281 return 1; 283 return 1; 282 } 284 } 283 285 284 *ppIdx = pIdx; 286 *ppIdx = pIdx; 285 return 0; 287 return 0; ................................................................................................................................................................................ 507 509 508 pLeft = sqlite3Expr(db, TK_REGISTER, 0); 510 pLeft = sqlite3Expr(db, TK_REGISTER, 0); 509 if( pLeft ){ 511 if( pLeft ){ 510 /* Set the collation sequence and affinity of the LHS of each TK_EQ 512 /* Set the collation sequence and affinity of the LHS of each TK_EQ 511 ** expression to the parent key column defaults. */ 513 ** expression to the parent key column defaults. */ 512 if( pIdx ){ 514 if( pIdx ){ 513 Column *pCol; 515 Column *pCol; > 516 const char *zColl; 514 iCol = pIdx->aiColumn[i]; 517 iCol = pIdx->aiColumn[i]; 515 pCol = &pTab->aCol[iCol]; 518 pCol = &pTab->aCol[iCol]; 516 if( pTab->iPKey==iCol ) iCol = -1; 519 if( pTab->iPKey==iCol ) iCol = -1; 517 pLeft->iTable = regData+iCol+1; 520 pLeft->iTable = regData+iCol+1; 518 pLeft->affinity = pCol->affinity; 521 pLeft->affinity = pCol->affinity; 519 pLeft->pColl = sqlite3LocateCollSeq(pParse, pCol->zColl); | 522 zColl = pCol->zColl; > 523 if( zColl==0 ) zColl = db->pDfltColl->zName; > 524 pLeft = sqlite3ExprAddCollateString(pParse, pLeft, zColl); 520 }else{ 525 }else{ 521 pLeft->iTable = regData; 526 pLeft->iTable = regData; 522 pLeft->affinity = SQLITE_AFF_INTEGER; 527 pLeft->affinity = SQLITE_AFF_INTEGER; 523 } 528 } 524 } 529 } 525 iCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom; 530 iCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom; 526 assert( iCol>=0 ); 531 assert( iCol>=0 ); ................................................................................................................................................................................ 729 ** schema items cannot be located, set an error in pParse and return 734 ** schema items cannot be located, set an error in pParse and return 730 ** early. */ 735 ** early. */ 731 if( pParse->disableTriggers ){ 736 if( pParse->disableTriggers ){ 732 pTo = sqlite3FindTable(db, pFKey->zTo, zDb); 737 pTo = sqlite3FindTable(db, pFKey->zTo, zDb); 733 }else{ 738 }else{ 734 pTo = sqlite3LocateTable(pParse, 0, pFKey->zTo, zDb); 739 pTo = sqlite3LocateTable(pParse, 0, pFKey->zTo, zDb); 735 } 740 } 736 if( !pTo || locateFkeyIndex(pParse, pTo, pFKey, &pIdx, &aiFree) ){ | 741 if( !pTo || sqlite3FkLocateIndex(pParse, pTo, pFKey, &pIdx, &aiFree) ){ 737 assert( isIgnoreErrors==0 || (regOld!=0 && regNew==0) ); 742 assert( isIgnoreErrors==0 || (regOld!=0 && regNew==0) ); 738 if( !isIgnoreErrors || db->mallocFailed ) return; 743 if( !isIgnoreErrors || db->mallocFailed ) return; 739 if( pTo==0 ){ 744 if( pTo==0 ){ 740 /* If isIgnoreErrors is true, then a table is being dropped. In this 745 /* If isIgnoreErrors is true, then a table is being dropped. In this 741 ** case SQLite runs a "DELETE FROM xxx" on the table being dropped 746 ** case SQLite runs a "DELETE FROM xxx" on the table being dropped 742 ** before actually dropping it in order to check FK constraints. 747 ** before actually dropping it in order to check FK constraints. 743 ** If the parent table of an FK constraint on the current table is 748 ** If the parent table of an FK constraint on the current table is ................................................................................................................................................................................ 809 if( !pFKey->isDeferred && !pParse->pToplevel && !pParse->isMultiWrite ){ 814 if( !pFKey->isDeferred && !pParse->pToplevel && !pParse->isMultiWrite ){ 810 assert( regOld==0 && regNew!=0 ); 815 assert( regOld==0 && regNew!=0 ); 811 /* Inserting a single row into a parent table cannot cause an immediate 816 /* Inserting a single row into a parent table cannot cause an immediate 812 ** foreign key violation. So do nothing in this case. */ 817 ** foreign key violation. So do nothing in this case. */ 813 continue; 818 continue; 814 } 819 } 815 820 816 if( locateFkeyIndex(pParse, pTab, pFKey, &pIdx, &aiCol) ){ | 821 if( sqlite3FkLocateIndex(pParse, pTab, pFKey, &pIdx, &aiCol) ){ 817 if( !isIgnoreErrors || db->mallocFailed ) return; 822 if( !isIgnoreErrors || db->mallocFailed ) return; 818 continue; 823 continue; 819 } 824 } 820 assert( aiCol || pFKey->nCol==1 ); 825 assert( aiCol || pFKey->nCol==1 ); 821 826 822 /* Create a SrcList structure containing a single table (the table 827 /* Create a SrcList structure containing a single table (the table 823 ** the foreign key that refers to this table is attached to). This 828 ** the foreign key that refers to this table is attached to). This ................................................................................................................................................................................ 864 FKey *p; 869 FKey *p; 865 int i; 870 int i; 866 for(p=pTab->pFKey; p; p=p->pNextFrom){ 871 for(p=pTab->pFKey; p; p=p->pNextFrom){ 867 for(i=0; i<p->nCol; i++) mask |= COLUMN_MASK(p->aCol[i].iFrom); 872 for(i=0; i<p->nCol; i++) mask |= COLUMN_MASK(p->aCol[i].iFrom); 868 } 873 } 869 for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){ 874 for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){ 870 Index *pIdx = 0; 875 Index *pIdx = 0; 871 locateFkeyIndex(pParse, pTab, p, &pIdx, 0); | 876 sqlite3FkLocateIndex(pParse, pTab, p, &pIdx, 0); 872 if( pIdx ){ 877 if( pIdx ){ 873 for(i=0; i<pIdx->nColumn; i++) mask |= COLUMN_MASK(pIdx->aiColumn[i]); 878 for(i=0; i<pIdx->nColumn; i++) mask |= COLUMN_MASK(pIdx->aiColumn[i]); 874 } 879 } 875 } 880 } 876 } 881 } 877 return mask; 882 return mask; 878 } 883 } ................................................................................................................................................................................ 990 TriggerStep *pStep = 0; /* First (only) step of trigger program */ 995 TriggerStep *pStep = 0; /* First (only) step of trigger program */ 991 Expr *pWhere = 0; /* WHERE clause of trigger step */ 996 Expr *pWhere = 0; /* WHERE clause of trigger step */ 992 ExprList *pList = 0; /* Changes list if ON UPDATE CASCADE */ 997 ExprList *pList = 0; /* Changes list if ON UPDATE CASCADE */ 993 Select *pSelect = 0; /* If RESTRICT, "SELECT RAISE(...)" */ 998 Select *pSelect = 0; /* If RESTRICT, "SELECT RAISE(...)" */ 994 int i; /* Iterator variable */ 999 int i; /* Iterator variable */ 995 Expr *pWhen = 0; /* WHEN clause for the trigger */ 1000 Expr *pWhen = 0; /* WHEN clause for the trigger */ 996 1001 997 if( locateFkeyIndex(pParse, pTab, pFKey, &pIdx, &aiCol) ) return 0; | 1002 if( sqlite3FkLocateIndex(pParse, pTab, pFKey, &pIdx, &aiCol) ) return 0; 998 assert( aiCol || pFKey->nCol==1 ); 1003 assert( aiCol || pFKey->nCol==1 ); 999 1004 1000 for(i=0; i<pFKey->nCol; i++){ 1005 for(i=0; i<pFKey->nCol; i++){ 1001 Token tOld = { "old", 3 }; /* Literal "old" token */ 1006 Token tOld = { "old", 3 }; /* Literal "old" token */ 1002 Token tNew = { "new", 3 }; /* Literal "new" token */ 1007 Token tNew = { "new", 3 }; /* Literal "new" token */ 1003 Token tFromCol; /* Name of column in child table */ 1008 Token tFromCol; /* Name of column in child table */ 1004 Token tToCol; /* Name of column in parent table */ 1009 Token tToCol; /* Name of column in parent table */
Changes to src/insert.c
1270 #ifndef SQLITE_OMIT_CHECK 1270 #ifndef SQLITE_OMIT_CHECK 1271 if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){ 1271 if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){ 1272 ExprList *pCheck = pTab->pCheck; 1272 ExprList *pCheck = pTab->pCheck; 1273 pParse->ckBase = regData; 1273 pParse->ckBase = regData; 1274 onError = overrideError!=OE_Default ? overrideError : OE_Abort; 1274 onError = overrideError!=OE_Default ? overrideError : OE_Abort; 1275 for(i=0; i<pCheck->nExpr; i++){ 1275 for(i=0; i<pCheck->nExpr; i++){ 1276 int allOk = sqlite3VdbeMakeLabel(v); 1276 int allOk = sqlite3VdbeMakeLabel(v); 1277 Expr *pDup = sqlite3ExprDup(db, pCheck->a[i].pExpr, 0); < 1278 if( !db->mallocFailed ){ < 1279 assert( pDup!=0 ); < 1280 sqlite3ExprIfTrue(pParse, pDup, allOk, SQLITE_JUMPIFNULL); | 1277 sqlite3ExprIfTrue(pParse, pCheck->a[i].pExpr, allOk, SQLITE_JUMPIFNULL); 1281 if( onError==OE_Ignore ){ | 1278 if( onError==OE_Ignore ){ 1282 sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest); | 1279 sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest); 1283 }else{ | 1280 }else{ 1284 char *zConsName = pCheck->a[i].zName; | 1281 char *zConsName = pCheck->a[i].zName; 1285 if( onError==OE_Replace ) onError = OE_Abort; /* IMP: R-15569-63625 */ | 1282 if( onError==OE_Replace ) onError = OE_Abort; /* IMP: R-15569-63625 */ 1286 if( zConsName ){ | 1283 if( zConsName ){ 1287 zConsName = sqlite3MPrintf(db, "constraint %s failed", zConsName); | 1284 zConsName = sqlite3MPrintf(db, "constraint %s failed", zConsName); 1288 }else{ | 1285 }else{ 1289 zConsName = 0; | 1286 zConsName = 0; 1290 } | 1287 } 1291 sqlite3HaltConstraint(pParse, onError, zConsName, P4_DYNAMIC); | 1288 sqlite3HaltConstraint(pParse, onError, zConsName, P4_DYNAMIC); 1292 } | 1289 } 1293 sqlite3VdbeResolveLabel(v, allOk); | 1290 sqlite3VdbeResolveLabel(v, allOk); 1294 } < 1295 sqlite3ExprDelete(db, pDup); < 1296 } 1291 } 1297 } 1292 } 1298 #endif /* !defined(SQLITE_OMIT_CHECK) */ 1293 #endif /* !defined(SQLITE_OMIT_CHECK) */ 1299 1294 1300 /* If we have an INTEGER PRIMARY KEY, make sure the primary key 1295 /* If we have an INTEGER PRIMARY KEY, make sure the primary key 1301 ** of the new record does not previously exist. Except, if this 1296 ** of the new record does not previously exist. Except, if this 1302 ** is an UPDATE and the primary key is not changing, that is OK. 1297 ** is an UPDATE and the primary key is not changing, that is OK.
Changes to src/journal.c
54 sqlite3_file *pReal = (sqlite3_file *)&p[1]; 54 sqlite3_file *pReal = (sqlite3_file *)&p[1]; 55 rc = sqlite3OsOpen(p->pVfs, p->zJournal, pReal, p->flags, 0); 55 rc = sqlite3OsOpen(p->pVfs, p->zJournal, pReal, p->flags, 0); 56 if( rc==SQLITE_OK ){ 56 if( rc==SQLITE_OK ){ 57 p->pReal = pReal; 57 p->pReal = pReal; 58 if( p->iSize>0 ){ 58 if( p->iSize>0 ){ 59 assert(p->iSize<=p->nBuf); 59 assert(p->iSize<=p->nBuf); 60 rc = sqlite3OsWrite(p->pReal, p->zBuf, p->iSize, 0); 60 rc = sqlite3OsWrite(p->pReal, p->zBuf, p->iSize, 0); > 61 } > 62 if( rc!=SQLITE_OK ){ > 63 /* If an error occurred while writing to the file, close it before > 64 ** returning. This way, SQLite uses the in-memory journal data to > 65 ** roll back changes made to the internal page-cache before this > 66 ** function was called. */ > 67 sqlite3OsClose(pReal); > 68 p->pReal = 0; 61 } 69 } 62 } 70 } 63 } 71 } 64 return rc; 72 return rc; 65 } 73 } 66 74 67 /* 75 /*
Changes to src/os_unix.c
408 { "pwrite64", (sqlite3_syscall_ptr)pwrite64, 0 }, 408 { "pwrite64", (sqlite3_syscall_ptr)pwrite64, 0 }, 409 #else 409 #else 410 { "pwrite64", (sqlite3_syscall_ptr)0, 0 }, 410 { "pwrite64", (sqlite3_syscall_ptr)0, 0 }, 411 #endif 411 #endif 412 #define osPwrite64 ((ssize_t(*)(int,const void*,size_t,off_t))\ 412 #define osPwrite64 ((ssize_t(*)(int,const void*,size_t,off_t))\ 413 aSyscall[13].pCurrent) 413 aSyscall[13].pCurrent) 414 414 415 #if SQLITE_ENABLE_LOCKING_STYLE < 416 { "fchmod", (sqlite3_syscall_ptr)fchmod, 0 }, 415 { "fchmod", (sqlite3_syscall_ptr)fchmod, 0 }, 417 #else < 418 { "fchmod", (sqlite3_syscall_ptr)0, 0 }, < 419 #endif < 420 #define osFchmod ((int(*)(int,mode_t))aSyscall[14].pCurrent) 416 #define osFchmod ((int(*)(int,mode_t))aSyscall[14].pCurrent) 421 417 422 #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE 418 #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE 423 { "fallocate", (sqlite3_syscall_ptr)posix_fallocate, 0 }, 419 { "fallocate", (sqlite3_syscall_ptr)posix_fallocate, 0 }, 424 #else 420 #else 425 { "fallocate", (sqlite3_syscall_ptr)0, 0 }, 421 { "fallocate", (sqlite3_syscall_ptr)0, 0 }, 426 #endif 422 #endif ................................................................................................................................................................................ 437 433 438 { "rmdir", (sqlite3_syscall_ptr)rmdir, 0 }, 434 { "rmdir", (sqlite3_syscall_ptr)rmdir, 0 }, 439 #define osRmdir ((int(*)(const char*))aSyscall[19].pCurrent) 435 #define osRmdir ((int(*)(const char*))aSyscall[19].pCurrent) 440 436 441 { "fchown", (sqlite3_syscall_ptr)posixFchown, 0 }, 437 { "fchown", (sqlite3_syscall_ptr)posixFchown, 0 }, 442 #define osFchown ((int(*)(int,uid_t,gid_t))aSyscall[20].pCurrent) 438 #define osFchown ((int(*)(int,uid_t,gid_t))aSyscall[20].pCurrent) 443 439 444 { "umask", (sqlite3_syscall_ptr)umask, 0 }, < 445 #define osUmask ((mode_t(*)(mode_t))aSyscall[21].pCurrent) < 446 < 447 }; /* End of the overrideable system calls */ 440 }; /* End of the overrideable system calls */ 448 441 449 /* 442 /* 450 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the 443 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the 451 ** "unix" VFSes. Return SQLITE_OK opon successfully updating the 444 ** "unix" VFSes. Return SQLITE_OK opon successfully updating the 452 ** system call pointer, or SQLITE_NOTFOUND if there is no configurable 445 ** system call pointer, or SQLITE_NOTFOUND if there is no configurable 453 ** system call named zName. 446 ** system call named zName. ................................................................................................................................................................................ 544 ** In that way, if a database file is -rw-rw-rw or -rw-rw-r-, and a 537 ** In that way, if a database file is -rw-rw-rw or -rw-rw-r-, and a 545 ** transaction crashes and leaves behind hot journals, then any 538 ** transaction crashes and leaves behind hot journals, then any 546 ** process that is able to write to the database will also be able to 539 ** process that is able to write to the database will also be able to 547 ** recover the hot journals. 540 ** recover the hot journals. 548 */ 541 */ 549 static int robust_open(const char *z, int f, mode_t m){ 542 static int robust_open(const char *z, int f, mode_t m){ 550 int fd; 543 int fd; 551 mode_t m2; < 552 mode_t origM = 0; < 553 if( m==0 ){ < 554 m2 = SQLITE_DEFAULT_FILE_PERMISSIONS; | 544 mode_t m2 = m ? m : SQLITE_DEFAULT_FILE_PERMISSIONS; 555 }else{ < 556 m2 = m; < 557 origM = osUmask(0); < 558 } < 559 do{ 545 do{ 560 #if defined(O_CLOEXEC) 546 #if defined(O_CLOEXEC) 561 fd = osOpen(z,f|O_CLOEXEC,m2); 547 fd = osOpen(z,f|O_CLOEXEC,m2); 562 #else 548 #else 563 fd = osOpen(z,f,m2); 549 fd = osOpen(z,f,m2); 564 #endif 550 #endif 565 }while( fd<0 && errno==EINTR ); 551 }while( fd<0 && errno==EINTR ); > 552 if( fd>=0 ){ 566 if( m ){ | 553 if( m!=0 ){ 567 osUmask(origM); < > 554 struct stat statbuf; > 555 if( osFstat(fd, &statbuf)==0 && (statbuf.st_mode&0777)!=m ){ > 556 osFchmod(fd, m); 568 } | 557 } > 558 } 569 #if defined(FD_CLOEXEC) && (!defined(O_CLOEXEC) || O_CLOEXEC==0) 559 #if defined(FD_CLOEXEC) && (!defined(O_CLOEXEC) || O_CLOEXEC==0) 570 if( fd>=0 ) osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC); | 560 osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC); 571 #endif 561 #endif > 562 } 572 return fd; 563 return fd; 573 } 564 } 574 565 575 /* 566 /* 576 ** Helper functions to obtain and relinquish the global mutex. The 567 ** Helper functions to obtain and relinquish the global mutex. The 577 ** global mutex is used to protect the unixInodeInfo and 568 ** global mutex is used to protect the unixInodeInfo and 578 ** vxworksFileId objects used by this file, all of which may be 569 ** vxworksFileId objects used by this file, all of which may be ................................................................................................................................................................................ 6990 UNIXVFS("unix-proxy", proxyIoFinder ), 6981 UNIXVFS("unix-proxy", proxyIoFinder ), 6991 #endif 6982 #endif 6992 }; 6983 }; 6993 unsigned int i; /* Loop counter */ 6984 unsigned int i; /* Loop counter */ 6994 6985 6995 /* Double-check that the aSyscall[] array has been constructed 6986 /* Double-check that the aSyscall[] array has been constructed 6996 ** correctly. See ticket [bb3a86e890c8e96ab] */ 6987 ** correctly. See ticket [bb3a86e890c8e96ab] */ 6997 assert( ArraySize(aSyscall)==22 ); | 6988 assert( ArraySize(aSyscall)==21 ); 6998 6989 6999 /* Register all VFSes defined in the aVfs[] array */ 6990 /* Register all VFSes defined in the aVfs[] array */ 7000 for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){ 6991 for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){ 7001 sqlite3_vfs_register(&aVfs[i], i==0); 6992 sqlite3_vfs_register(&aVfs[i], i==0); 7002 } 6993 } 7003 return SQLITE_OK; 6994 return SQLITE_OK; 7004 } 6995 }
Changes to src/parse.y
431 groupby_opt(P) having_opt(Q) orderby_opt(Z) limit_opt(L). { 431 groupby_opt(P) having_opt(Q) orderby_opt(Z) limit_opt(L). { 432 A = sqlite3SelectNew(pParse,W,X,Y,P,Q,Z,D,L.pLimit,L.pOffset); 432 A = sqlite3SelectNew(pParse,W,X,Y,P,Q,Z,D,L.pLimit,L.pOffset); 433 } 433 } 434 434 435 // The "distinct" nonterminal is true (1) if the DISTINCT keyword is 435 // The "distinct" nonterminal is true (1) if the DISTINCT keyword is 436 // present and false (0) if it is not. 436 // present and false (0) if it is not. 437 // 437 // 438 %type distinct {int} | 438 %type distinct {u16} 439 distinct(A) ::= DISTINCT. {A = 1;} | 439 distinct(A) ::= DISTINCT. {A = SF_Distinct;} 440 distinct(A) ::= ALL. {A = 0;} 440 distinct(A) ::= ALL. {A = 0;} 441 distinct(A) ::= . {A = 0;} 441 distinct(A) ::= . {A = 0;} 442 442 443 // selcollist is a list of expressions that are to become the return 443 // selcollist is a list of expressions that are to become the return 444 // values of the SELECT statement. The "*" in statements like 444 // values of the SELECT statement. The "*" in statements like 445 // "SELECT * FROM ..." is encoded as a special expression with an 445 // "SELECT * FROM ..." is encoded as a special expression with an 446 // opcode of TK_ALL. 446 // opcode of TK_ALL. ................................................................................................................................................................................ 495 // in a SELECT statement. "stl_prefix" is a prefix of this list. 495 // in a SELECT statement. "stl_prefix" is a prefix of this list. 496 // 496 // 497 stl_prefix(A) ::= seltablist(X) joinop(Y). { 497 stl_prefix(A) ::= seltablist(X) joinop(Y). { 498 A = X; 498 A = X; 499 if( ALWAYS(A && A->nSrc>0) ) A->a[A->nSrc-1].jointype = (u8)Y; 499 if( ALWAYS(A && A->nSrc>0) ) A->a[A->nSrc-1].jointype = (u8)Y; 500 } 500 } 501 stl_prefix(A) ::= . {A = 0;} 501 stl_prefix(A) ::= . {A = 0;} 502 seltablist(A) ::= stl_prefix(X) nm(Y) dbnm(D) as(Z) indexed_opt(I) on_opt(N) usi | 502 seltablist(A) ::= stl_prefix(X) nm(Y) dbnm(D) as(Z) indexed_opt(I) > 503 on_opt(N) using_opt(U). { 503 A = sqlite3SrcListAppendFromTerm(pParse,X,&Y,&D,&Z,0,N,U); 504 A = sqlite3SrcListAppendFromTerm(pParse,X,&Y,&D,&Z,0,N,U); 504 sqlite3SrcListIndexedBy(pParse, A, &I); 505 sqlite3SrcListIndexedBy(pParse, A, &I); 505 } 506 } 506 %ifndef SQLITE_OMIT_SUBQUERY 507 %ifndef SQLITE_OMIT_SUBQUERY 507 seltablist(A) ::= stl_prefix(X) LP select(S) RP 508 seltablist(A) ::= stl_prefix(X) LP select(S) RP 508 as(Z) on_opt(N) using_opt(U). { 509 as(Z) on_opt(N) using_opt(U). { 509 A = sqlite3SrcListAppendFromTerm(pParse,X,0,0,&Z,S,N,U); 510 A = sqlite3SrcListAppendFromTerm(pParse,X,0,0,&Z,S,N,U); 510 } 511 } 511 seltablist(A) ::= stl_prefix(X) LP seltablist(F) RP 512 seltablist(A) ::= stl_prefix(X) LP seltablist(F) RP 512 as(Z) on_opt(N) using_opt(U). { 513 as(Z) on_opt(N) using_opt(U). { 513 if( X==0 && Z.n==0 && N==0 && U==0 ){ 514 if( X==0 && Z.n==0 && N==0 && U==0 ){ 514 A = F; 515 A = F; > 516 }else if( F->nSrc==1 ){ > 517 A = sqlite3SrcListAppendFromTerm(pParse,X,0,0,&Z,0,N,U); > 518 if( A ){ > 519 struct SrcList_item *pNew = &A->a[A->nSrc-1]; > 520 struct SrcList_item *pOld = F->a; > 521 pNew->zName = pOld->zName; > 522 pNew->zDatabase = pOld->zDatabase; > 523 pOld->zName = pOld->zDatabase = 0; > 524 } > 525 sqlite3SrcListDelete(pParse->db, F); 515 }else{ 526 }else{ 516 Select *pSubquery; 527 Select *pSubquery; 517 sqlite3SrcListShiftJoinType(F); 528 sqlite3SrcListShiftJoinType(F); 518 pSubquery = sqlite3SelectNew(pParse,0,F,0,0,0,0,0,0,0); | 529 pSubquery = sqlite3SelectNew(pParse,0,F,0,0,0,0,SF_NestedFrom,0,0); 519 A = sqlite3SrcListAppendFromTerm(pParse,X,0,0,&Z,pSubquery,N,U); 530 A = sqlite3SrcListAppendFromTerm(pParse,X,0,0,&Z,pSubquery,N,U); 520 } 531 } 521 } 532 } 522 < 523 // A seltablist_paren nonterminal represents anything in a FROM that < 524 // is contained inside parentheses. This can be either a subquery or < 525 // a grouping of table and subqueries. < 526 // < 527 // %type seltablist_paren {Select*} < 528 // %destructor seltablist_paren {sqlite3SelectDelete(pParse->db, $$);} < 529 // seltablist_paren(A) ::= select(S). {A = S;} < 530 // seltablist_paren(A) ::= seltablist(F). { < 531 // sqlite3SrcListShiftJoinType(F); < 532 // A = sqlite3SelectNew(pParse,0,F,0,0,0,0,0,0,0); < 533 // } < 534 %endif SQLITE_OMIT_SUBQUERY 533 %endif SQLITE_OMIT_SUBQUERY 535 534 536 %type dbnm {Token} 535 %type dbnm {Token} 537 dbnm(A) ::= . {A.z=0; A.n=0;} 536 dbnm(A) ::= . {A.z=0; A.n=0;} 538 dbnm(A) ::= DOT nm(X). {A = X;} 537 dbnm(A) ::= DOT nm(X). {A = X;} 539 538 540 %type fullname {SrcList*} 539 %type fullname {SrcList*} ................................................................................................................................................................................ 649 648 650 where_opt(A) ::= . {A = 0;} 649 where_opt(A) ::= . {A = 0;} 651 where_opt(A) ::= WHERE expr(X). {A = X.pExpr;} 650 where_opt(A) ::= WHERE expr(X). {A = X.pExpr;} 652 651 653 ////////////////////////// The UPDATE command //////////////////////////////// 652 ////////////////////////// The UPDATE command //////////////////////////////// 654 // 653 // 655 %ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT 654 %ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT 656 cmd ::= UPDATE orconf(R) fullname(X) indexed_opt(I) SET setlist(Y) where_opt(W) | 655 cmd ::= UPDATE orconf(R) fullname(X) indexed_opt(I) SET setlist(Y) where_opt(W) > 656 orderby_opt(O) limit_opt(L). { 657 sqlite3SrcListIndexedBy(pParse, X, &I); 657 sqlite3SrcListIndexedBy(pParse, X, &I); 658 sqlite3ExprListCheckLength(pParse,Y,"set list"); 658 sqlite3ExprListCheckLength(pParse,Y,"set list"); 659 W = sqlite3LimitWhere(pParse, X, W, O, L.pLimit, L.pOffset, "UPDATE"); 659 W = sqlite3LimitWhere(pParse, X, W, O, L.pLimit, L.pOffset, "UPDATE"); 660 sqlite3Update(pParse,X,Y,W,R); 660 sqlite3Update(pParse,X,Y,W,R); 661 } 661 } 662 %endif 662 %endif 663 %ifndef SQLITE_ENABLE_UPDATE_DELETE_LIMIT 663 %ifndef SQLITE_ENABLE_UPDATE_DELETE_LIMIT 664 cmd ::= UPDATE orconf(R) fullname(X) indexed_opt(I) SET setlist(Y) where_opt(W). | 664 cmd ::= UPDATE orconf(R) fullname(X) indexed_opt(I) SET setlist(Y) > 665 where_opt(W). { 665 sqlite3SrcListIndexedBy(pParse, X, &I); 666 sqlite3SrcListIndexedBy(pParse, X, &I); 666 sqlite3ExprListCheckLength(pParse,Y,"set list"); 667 sqlite3ExprListCheckLength(pParse,Y,"set list"); 667 sqlite3Update(pParse,X,Y,W,R); 668 sqlite3Update(pParse,X,Y,W,R); 668 } 669 } 669 %endif 670 %endif 670 671 671 %type setlist {ExprList*} 672 %type setlist {ExprList*} ................................................................................................................................................................................ 811 } 812 } 812 expr(A) ::= VARIABLE(X). { 813 expr(A) ::= VARIABLE(X). { 813 spanExpr(&A, pParse, TK_VARIABLE, &X); 814 spanExpr(&A, pParse, TK_VARIABLE, &X); 814 sqlite3ExprAssignVarNumber(pParse, A.pExpr); 815 sqlite3ExprAssignVarNumber(pParse, A.pExpr); 815 spanSet(&A, &X, &X); 816 spanSet(&A, &X, &X); 816 } 817 } 817 expr(A) ::= expr(E) COLLATE ids(C). { 818 expr(A) ::= expr(E) COLLATE ids(C). { 818 A.pExpr = sqlite3ExprSetCollByToken(pParse, E.pExpr, &C); | 819 A.pExpr = sqlite3ExprAddCollateToken(pParse, E.pExpr, &C); 819 A.zStart = E.zStart; 820 A.zStart = E.zStart; 820 A.zEnd = &C.z[C.n]; 821 A.zEnd = &C.z[C.n]; 821 } 822 } 822 %ifndef SQLITE_OMIT_CAST 823 %ifndef SQLITE_OMIT_CAST 823 expr(A) ::= CAST(X) LP expr(E) AS typetoken(T) RP(Y). { 824 expr(A) ::= CAST(X) LP expr(E) AS typetoken(T) RP(Y). { 824 A.pExpr = sqlite3PExpr(pParse, TK_CAST, E.pExpr, 0, &T); 825 A.pExpr = sqlite3PExpr(pParse, TK_CAST, E.pExpr, 0, &T); 825 spanSet(&A,&X,&Y); 826 spanSet(&A,&X,&Y); ................................................................................................................................................................................ 1136 %destructor idxlist {sqlite3ExprListDelete(pParse->db, $$);} 1137 %destructor idxlist {sqlite3ExprListDelete(pParse->db, $$);} 1137 %type idxlist_opt {ExprList*} 1138 %type idxlist_opt {ExprList*} 1138 %destructor idxlist_opt {sqlite3ExprListDelete(pParse->db, $$);} 1139 %destructor idxlist_opt {sqlite3ExprListDelete(pParse->db, $$);} 1139 1140 1140 idxlist_opt(A) ::= . {A = 0;} 1141 idxlist_opt(A) ::= . {A = 0;} 1141 idxlist_opt(A) ::= LP idxlist(X) RP. {A = X;} 1142 idxlist_opt(A) ::= LP idxlist(X) RP. {A = X;} 1142 idxlist(A) ::= idxlist(X) COMMA nm(Y) collate(C) sortorder(Z). { 1143 idxlist(A) ::= idxlist(X) COMMA nm(Y) collate(C) sortorder(Z). { 1143 Expr *p = 0; | 1144 Expr *p = sqlite3ExprAddCollateToken(pParse, 0, &C); 1144 if( C.n>0 ){ < 1145 p = sqlite3Expr(pParse->db, TK_COLUMN, 0); < 1146 sqlite3ExprSetCollByToken(pParse, p, &C); < 1147 } < 1148 A = sqlite3ExprListAppend(pParse,X, p); 1145 A = sqlite3ExprListAppend(pParse,X, p); 1149 sqlite3ExprListSetName(pParse,A,&Y,1); 1146 sqlite3ExprListSetName(pParse,A,&Y,1); 1150 sqlite3ExprListCheckLength(pParse, A, "index"); 1147 sqlite3ExprListCheckLength(pParse, A, "index"); 1151 if( A ) A->a[A->nExpr-1].sortOrder = (u8)Z; 1148 if( A ) A->a[A->nExpr-1].sortOrder = (u8)Z; 1152 } 1149 } 1153 idxlist(A) ::= nm(Y) collate(C) sortorder(Z). { 1150 idxlist(A) ::= nm(Y) collate(C) sortorder(Z). { 1154 Expr *p = 0; | 1151 Expr *p = sqlite3ExprAddCollateToken(pParse, 0, &C); 1155 if( C.n>0 ){ < 1156 p = sqlite3PExpr(pParse, TK_COLUMN, 0, 0, 0); < 1157 sqlite3ExprSetCollByToken(pParse, p, &C); < 1158 } < 1159 A = sqlite3ExprListAppend(pParse,0, p); 1152 A = sqlite3ExprListAppend(pParse,0, p); 1160 sqlite3ExprListSetName(pParse, A, &Y, 1); 1153 sqlite3ExprListSetName(pParse, A, &Y, 1); 1161 sqlite3ExprListCheckLength(pParse, A, "index"); 1154 sqlite3ExprListCheckLength(pParse, A, "index"); 1162 if( A ) A->a[A->nExpr-1].sortOrder = (u8)Z; 1155 if( A ) A->a[A->nExpr-1].sortOrder = (u8)Z; 1163 } 1156 } 1164 1157 1165 %type collate {Token} 1158 %type collate {Token}
Changes to src/pragma.c
944 ** dflt_value: The default value for the column, if any. 944 ** dflt_value: The default value for the column, if any. 945 */ 945 */ 946 if( sqlite3StrICmp(zLeft, "table_info")==0 && zRight ){ 946 if( sqlite3StrICmp(zLeft, "table_info")==0 && zRight ){ 947 Table *pTab; 947 Table *pTab; 948 if( sqlite3ReadSchema(pParse) ) goto pragma_out; 948 if( sqlite3ReadSchema(pParse) ) goto pragma_out; 949 pTab = sqlite3FindTable(db, zRight, zDb); 949 pTab = sqlite3FindTable(db, zRight, zDb); 950 if( pTab ){ 950 if( pTab ){ 951 int i; | 951 int i, k; 952 int nHidden = 0; 952 int nHidden = 0; 953 Column *pCol; 953 Column *pCol; > 954 Index *pPk; > 955 for(pPk=pTab->pIndex; pPk && pPk->autoIndex!=2; pPk=pPk->pNext){} 954 sqlite3VdbeSetNumCols(v, 6); 956 sqlite3VdbeSetNumCols(v, 6); 955 pParse->nMem = 6; 957 pParse->nMem = 6; 956 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cid", SQLITE_STATIC); 958 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cid", SQLITE_STATIC); 957 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC); 959 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC); 958 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "type", SQLITE_STATIC); 960 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "type", SQLITE_STATIC); 959 sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "notnull", SQLITE_STATIC); 961 sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "notnull", SQLITE_STATIC); 960 sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "dflt_value", SQLITE_STATIC); 962 sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "dflt_value", SQLITE_STATIC); ................................................................................................................................................................................ 971 pCol->zType ? pCol->zType : "", 0); 973 pCol->zType ? pCol->zType : "", 0); 972 sqlite3VdbeAddOp2(v, OP_Integer, (pCol->notNull ? 1 : 0), 4); 974 sqlite3VdbeAddOp2(v, OP_Integer, (pCol->notNull ? 1 : 0), 4); 973 if( pCol->zDflt ){ 975 if( pCol->zDflt ){ 974 sqlite3VdbeAddOp4(v, OP_String8, 0, 5, 0, (char*)pCol->zDflt, 0); 976 sqlite3VdbeAddOp4(v, OP_String8, 0, 5, 0, (char*)pCol->zDflt, 0); 975 }else{ 977 }else{ 976 sqlite3VdbeAddOp2(v, OP_Null, 0, 5); 978 sqlite3VdbeAddOp2(v, OP_Null, 0, 5); 977 } 979 } > 980 if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){ > 981 k = 0; > 982 }else if( pPk==0 ){ > 983 k = 1; > 984 }else{ > 985 for(k=1; ALWAYS(k<=pTab->nCol) && pPk->aiColumn[k-1]!=i; k++){} > 986 } 978 sqlite3VdbeAddOp2(v, OP_Integer, | 987 sqlite3VdbeAddOp2(v, OP_Integer, k, 6); 979 (pCol->colFlags&COLFLAG_PRIMKEY)!=0, 6); < 980 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6); 988 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6); 981 } 989 } 982 } 990 } 983 }else 991 }else 984 992 985 if( sqlite3StrICmp(zLeft, "index_info")==0 && zRight ){ 993 if( sqlite3StrICmp(zLeft, "index_info")==0 && zRight ){ 986 Index *pIdx; 994 Index *pIdx; ................................................................................................................................................................................ 1107 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 8); 1115 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 8); 1108 } 1116 } 1109 ++i; 1117 ++i; 1110 pFK = pFK->pNextFrom; 1118 pFK = pFK->pNextFrom; 1111 } 1119 } 1112 } 1120 } 1113 } 1121 } > 1122 }else > 1123 #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */ > 1124 > 1125 #ifndef SQLITE_OMIT_FOREIGN_KEY > 1126 if( sqlite3StrICmp(zLeft, "foreign_key_check")==0 ){ > 1127 FKey *pFK; /* A foreign key constraint */ > 1128 Table *pTab; /* Child table contain "REFERENCES" keyword */ > 1129 Table *pParent; /* Parent table that child points to */ > 1130 Index *pIdx; /* Index in the parent table */ > 1131 int i; /* Loop counter: Foreign key number for pTab */ > 1132 int j; /* Loop counter: Field of the foreign key */ > 1133 HashElem *k; /* Loop counter: Next table in schema */ > 1134 int x; /* result variable */ > 1135 int regResult; /* 3 registers to hold a result row */ > 1136 int regKey; /* Register to hold key for checking the FK */ > 1137 int regRow; /* Registers to hold a row from pTab */ > 1138 int addrTop; /* Top of a loop checking foreign keys */ > 1139 int addrOk; /* Jump here if the key is OK */ > 1140 int *aiCols; /* child to parent column mapping */ > 1141 > 1142 if( sqlite3ReadSchema(pParse) ) goto pragma_out; > 1143 regResult = pParse->nMem+1; > 1144 pParse->nMem += 4; > 1145 regKey = ++pParse->nMem; > 1146 regRow = ++pParse->nMem; > 1147 v = sqlite3GetVdbe(pParse); > 1148 sqlite3VdbeSetNumCols(v, 4); > 1149 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "table", SQLITE_STATIC); > 1150 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "rowid", SQLITE_STATIC); > 1151 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "parent", SQLITE_STATIC); > 1152 sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "fkid", SQLITE_STATIC); > 1153 sqlite3CodeVerifySchema(pParse, iDb); > 1154 k = sqliteHashFirst(&db->aDb[iDb].pSchema->tblHash); > 1155 while( k ){ > 1156 if( zRight ){ > 1157 pTab = sqlite3LocateTable(pParse, 0, zRight, zDb); > 1158 k = 0; > 1159 }else{ > 1160 pTab = (Table*)sqliteHashData(k); > 1161 k = sqliteHashNext(k); > 1162 } > 1163 if( pTab==0 || pTab->pFKey==0 ) continue; > 1164 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName); > 1165 if( pTab->nCol+regRow>pParse->nMem ) pParse->nMem = pTab->nCol + regRow; > 1166 sqlite3OpenTable(pParse, 0, iDb, pTab, OP_OpenRead); > 1167 sqlite3VdbeAddOp4(v, OP_String8, 0, regResult, 0, pTab->zName, > 1168 P4_TRANSIENT); > 1169 for(i=1, pFK=pTab->pFKey; pFK; i++, pFK=pFK->pNextFrom){ > 1170 pParent = sqlite3LocateTable(pParse, 0, pFK->zTo, zDb); > 1171 if( pParent==0 ) break; > 1172 pIdx = 0; > 1173 sqlite3TableLock(pParse, iDb, pParent->tnum, 0, pParent->zName); > 1174 x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, 0); > 1175 if( x==0 ){ > 1176 if( pIdx==0 ){ > 1177 sqlite3OpenTable(pParse, i, iDb, pParent, OP_OpenRead); > 1178 }else{ > 1179 KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIdx); > 1180 sqlite3VdbeAddOp3(v, OP_OpenRead, i, pIdx->tnum, iDb); > 1181 sqlite3VdbeChangeP4(v, -1, (char*)pKey, P4_KEYINFO_HANDOFF); > 1182 } > 1183 }else{ > 1184 k = 0; > 1185 break; > 1186 } > 1187 } > 1188 if( pFK ) break; > 1189 if( pParse->nTab<i ) pParse->nTab = i; > 1190 addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, 0); > 1191 for(i=1, pFK=pTab->pFKey; pFK; i++, pFK=pFK->pNextFrom){ > 1192 pParent = sqlite3LocateTable(pParse, 0, pFK->zTo, zDb); > 1193 assert( pParent!=0 ); > 1194 pIdx = 0; > 1195 aiCols = 0; > 1196 x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, &aiCols); > 1197 assert( x==0 ); > 1198 addrOk = sqlite3VdbeMakeLabel(v); > 1199 if( pIdx==0 ){ > 1200 int iKey = pFK->aCol[0].iFrom; > 1201 assert( iKey>=0 && iKey<pTab->nCol ); > 1202 if( iKey!=pTab->iPKey ){ > 1203 sqlite3VdbeAddOp3(v, OP_Column, 0, iKey, regRow); > 1204 sqlite3ColumnDefault(v, pTab, iKey, regRow); > 1205 sqlite3VdbeAddOp2(v, OP_IsNull, regRow, addrOk); > 1206 sqlite3VdbeAddOp2(v, OP_MustBeInt, regRow, > 1207 sqlite3VdbeCurrentAddr(v)+3); > 1208 }else{ > 1209 sqlite3VdbeAddOp2(v, OP_Rowid, 0, regRow); > 1210 } > 1211 sqlite3VdbeAddOp3(v, OP_NotExists, i, 0, regRow); > 1212 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrOk); > 1213 sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2); > 1214 }else{ > 1215 for(j=0; j<pFK->nCol; j++){ > 1216 sqlite3ExprCodeGetColumnOfTable(v, pTab, 0, > 1217 aiCols ? aiCols[j] : pFK->aCol[0].iFrom, regRow+j); > 1218 sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk); > 1219 } > 1220 sqlite3VdbeAddOp3(v, OP_MakeRecord, regRow, pFK->nCol, regKey); > 1221 sqlite3VdbeChangeP4(v, -1, > 1222 sqlite3IndexAffinityStr(v,pIdx), P4_TRANSIENT); > 1223 sqlite3VdbeAddOp4Int(v, OP_Found, i, addrOk, regKey, 0); > 1224 } > 1225 sqlite3VdbeAddOp2(v, OP_Rowid, 0, regResult+1); > 1226 sqlite3VdbeAddOp4(v, OP_String8, 0, regResult+2, 0, > 1227 pFK->zTo, P4_TRANSIENT); > 1228 sqlite3VdbeAddOp2(v, OP_Integer, i-1, regResult+3); > 1229 sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 4); > 1230 sqlite3VdbeResolveLabel(v, addrOk); > 1231 sqlite3DbFree(db, aiCols); > 1232 } > 1233 sqlite3VdbeAddOp2(v, OP_Next, 0, addrTop+1); > 1234 sqlite3VdbeJumpHere(v, addrTop); > 1235 } 1114 }else 1236 }else 1115 #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */ 1237 #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */ 1116 1238 1117 #ifndef NDEBUG 1239 #ifndef NDEBUG 1118 if( sqlite3StrICmp(zLeft, "parser_trace")==0 ){ 1240 if( sqlite3StrICmp(zLeft, "parser_trace")==0 ){ 1119 if( zRight ){ 1241 if( zRight ){ 1120 if( sqlite3GetBoolean(zRight, 0) ){ 1242 if( sqlite3GetBoolean(zRight, 0) ){
Changes to src/resolve.c
63 ** Is equivalent to: 63 ** Is equivalent to: 64 ** 64 ** 65 ** SELECT random()%5 AS x, count(*) FROM tab GROUP BY random()%5 65 ** SELECT random()%5 AS x, count(*) FROM tab GROUP BY random()%5 66 ** 66 ** 67 ** The result of random()%5 in the GROUP BY clause is probably different 67 ** The result of random()%5 in the GROUP BY clause is probably different 68 ** from the result in the result-set. We might fix this someday. Or 68 ** from the result in the result-set. We might fix this someday. Or 69 ** then again, we might not... 69 ** then again, we might not... > 70 ** > 71 ** If the reference is followed by a COLLATE operator, then make sure > 72 ** the COLLATE operator is preserved. For example: > 73 ** > 74 ** SELECT a+b, c+d FROM t1 ORDER BY 1 COLLATE nocase; > 75 ** > 76 ** Should be transformed into: > 77 ** > 78 ** SELECT a+b, c+d FROM t1 ORDER BY (a+b) COLLATE nocase; 70 ** 79 ** 71 ** The nSubquery parameter specifies how many levels of subquery the 80 ** The nSubquery parameter specifies how many levels of subquery the 72 ** alias is removed from the original expression. The usually value is 81 ** alias is removed from the original expression. The usually value is 73 ** zero but it might be more if the alias is contained within a subquery 82 ** zero but it might be more if the alias is contained within a subquery 74 ** of the original expression. The Expr.op2 field of TK_AGG_FUNCTION 83 ** of the original expression. The Expr.op2 field of TK_AGG_FUNCTION 75 ** structures must be increased by the nSubquery amount. 84 ** structures must be increased by the nSubquery amount. 76 */ 85 */ ................................................................................................................................................................................ 87 sqlite3 *db; /* The database connection */ 96 sqlite3 *db; /* The database connection */ 88 97 89 assert( iCol>=0 && iCol<pEList->nExpr ); 98 assert( iCol>=0 && iCol<pEList->nExpr ); 90 pOrig = pEList->a[iCol].pExpr; 99 pOrig = pEList->a[iCol].pExpr; 91 assert( pOrig!=0 ); 100 assert( pOrig!=0 ); 92 assert( pOrig->flags & EP_Resolved ); 101 assert( pOrig->flags & EP_Resolved ); 93 db = pParse->db; 102 db = pParse->db; 94 if( pOrig->op!=TK_COLUMN && zType[0]!='G' ){ < 95 pDup = sqlite3ExprDup(db, pOrig, 0); | 103 pDup = sqlite3ExprDup(db, pOrig, 0); > 104 if( pDup==0 ) return; > 105 if( pOrig->op!=TK_COLUMN && zType[0]!='G' ){ 96 incrAggFunctionDepth(pDup, nSubquery); 106 incrAggFunctionDepth(pDup, nSubquery); 97 pDup = sqlite3PExpr(pParse, TK_AS, pDup, 0, 0); 107 pDup = sqlite3PExpr(pParse, TK_AS, pDup, 0, 0); 98 if( pDup==0 ) return; 108 if( pDup==0 ) return; 99 if( pEList->a[iCol].iAlias==0 ){ 109 if( pEList->a[iCol].iAlias==0 ){ 100 pEList->a[iCol].iAlias = (u16)(++pParse->nAlias); 110 pEList->a[iCol].iAlias = (u16)(++pParse->nAlias); 101 } 111 } 102 pDup->iTable = pEList->a[iCol].iAlias; 112 pDup->iTable = pEList->a[iCol].iAlias; 103 }else if( ExprHasProperty(pOrig, EP_IntValue) || pOrig->u.zToken==0 ){ < 104 pDup = sqlite3ExprDup(db, pOrig, 0); < 105 if( pDup==0 ) return; < 106 }else{ < 107 char *zToken = pOrig->u.zToken; < 108 assert( zToken!=0 ); < 109 pOrig->u.zToken = 0; < 110 pDup = sqlite3ExprDup(db, pOrig, 0); < 111 pOrig->u.zToken = zToken; < 112 if( pDup==0 ) return; < 113 assert( (pDup->flags & (EP_Reduced|EP_TokenOnly))==0 ); < 114 pDup->flags2 |= EP2_MallocedToken; < 115 pDup->u.zToken = sqlite3DbStrDup(db, zToken); < 116 } 113 } 117 if( pExpr->flags & EP_ExpCollate ){ < 118 pDup->pColl = pExpr->pColl; < 119 pDup->flags |= EP_ExpCollate; < > 114 if( pExpr->op==TK_COLLATE ){ > 115 pDup = sqlite3ExprAddCollateString(pParse, pDup, pExpr->u.zToken); 120 } 116 } 121 117 122 /* Before calling sqlite3ExprDelete(), set the EP_Static flag. This 118 /* Before calling sqlite3ExprDelete(), set the EP_Static flag. This 123 ** prevents ExprDelete() from deleting the Expr structure itself, 119 ** prevents ExprDelete() from deleting the Expr structure itself, 124 ** allowing it to be repopulated by the memcpy() on the following line. 120 ** allowing it to be repopulated by the memcpy() on the following line. > 121 ** The pExpr->u.zToken might point into memory that will be freed by the > 122 ** sqlite3DbFree(db, pDup) on the last line of this block, so be sure to > 123 ** make a copy of the token before doing the sqlite3DbFree(). 125 */ 124 */ 126 ExprSetProperty(pExpr, EP_Static); 125 ExprSetProperty(pExpr, EP_Static); 127 sqlite3ExprDelete(db, pExpr); 126 sqlite3ExprDelete(db, pExpr); 128 memcpy(pExpr, pDup, sizeof(*pExpr)); 127 memcpy(pExpr, pDup, sizeof(*pExpr)); > 128 if( !ExprHasProperty(pExpr, EP_IntValue) && pExpr->u.zToken!=0 ){ > 129 assert( (pExpr->flags & (EP_Reduced|EP_TokenOnly))==0 ); > 130 pExpr->u.zToken = sqlite3DbStrDup(db, pExpr->u.zToken); > 131 pExpr->flags2 |= EP2_MallocedToken; > 132 } 129 sqlite3DbFree(db, pDup); 133 sqlite3DbFree(db, pDup); 130 } 134 } 131 135 132 136 133 /* 137 /* 134 ** Return TRUE if the name zCol occurs anywhere in the USING clause. 138 ** Return TRUE if the name zCol occurs anywhere in the USING clause. 135 ** 139 ** ................................................................................................................................................................................ 142 for(k=0; k<pUsing->nId; k++){ 146 for(k=0; k<pUsing->nId; k++){ 143 if( sqlite3StrICmp(pUsing->a[k].zName, zCol)==0 ) return 1; 147 if( sqlite3StrICmp(pUsing->a[k].zName, zCol)==0 ) return 1; 144 } 148 } 145 } 149 } 146 return 0; 150 return 0; 147 } 151 } 148 152 > 153 /* > 154 ** Subqueries stores the original database, table and column names for their > 155 ** result sets in ExprList.a[].zSpan, in the form "DATABASE.TABLE.COLUMN". > 156 ** Check to see if the zSpan given to this routine matches the zDb, zTab, > 157 ** and zCol. If any of zDb, zTab, and zCol are NULL then those fields will > 158 ** match anything. > 159 */ > 160 int sqlite3MatchSpanName( > 161 const char *zSpan, > 162 const char *zCol, > 163 const char *zTab, > 164 const char *zDb > 165 ){ > 166 int n; > 167 for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){} > 168 if( zDb && sqlite3StrNICmp(zSpan, zDb, n)!=0 ){ > 169 return 0; > 170 } > 171 zSpan += n+1; > 172 for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){} > 173 if( zTab && sqlite3StrNICmp(zSpan, zTab, n)!=0 ){ > 174 return 0; > 175 } > 176 zSpan += n+1; > 177 if( zCol && sqlite3StrICmp(zSpan, zCol)!=0 ){ > 178 return 0; > 179 } > 180 return 1; > 181 } 149 182 150 /* 183 /* 151 ** Given the name of a column of the form X.Y.Z or Y.Z or just Z, look up 184 ** Given the name of a column of the form X.Y.Z or Y.Z or just Z, look up 152 ** that name in the set of source tables in pSrcList and make the pExpr 185 ** that name in the set of source tables in pSrcList and make the pExpr 153 ** expression node refer back to that source column. The following changes 186 ** expression node refer back to that source column. The following changes 154 ** are made to pExpr: 187 ** are made to pExpr: 155 ** 188 ** ................................................................................................................................................................................ 197 assert( zCol ); /* The Z in X.Y.Z cannot be NULL */ 230 assert( zCol ); /* The Z in X.Y.Z cannot be NULL */ 198 assert( !ExprHasAnyProperty(pExpr, EP_TokenOnly|EP_Reduced) ); 231 assert( !ExprHasAnyProperty(pExpr, EP_TokenOnly|EP_Reduced) ); 199 232 200 /* Initialize the node to no-match */ 233 /* Initialize the node to no-match */ 201 pExpr->iTable = -1; 234 pExpr->iTable = -1; 202 pExpr->pTab = 0; 235 pExpr->pTab = 0; 203 ExprSetIrreducible(pExpr); 236 ExprSetIrreducible(pExpr); > 237 > 238 /* Translate the schema name in zDb into a pointer to the corresponding > 239 ** schema. If not found, pSchema will remain NULL and nothing will match > 240 ** resulting in an appropriate error message toward the end of this routine > 241 */ > 242 if( zDb ){ > 243 for(i=0; i<db->nDb; i++){ > 244 assert( db->aDb[i].zName ); > 245 if( sqlite3StrICmp(db->aDb[i].zName,zDb)==0 ){ > 246 pSchema = db->aDb[i].pSchema; > 247 break; > 248 } > 249 } > 250 } 204 251 205 /* Start at the inner-most context and move outward until a match is found */ 252 /* Start at the inner-most context and move outward until a match is found */ 206 while( pNC && cnt==0 ){ 253 while( pNC && cnt==0 ){ 207 ExprList *pEList; 254 ExprList *pEList; 208 SrcList *pSrcList = pNC->pSrcList; 255 SrcList *pSrcList = pNC->pSrcList; 209 256 210 if( pSrcList ){ 257 if( pSrcList ){ 211 for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){ 258 for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){ 212 Table *pTab; 259 Table *pTab; 213 int iDb; < 214 Column *pCol; 260 Column *pCol; 215 261 216 pTab = pItem->pTab; 262 pTab = pItem->pTab; 217 assert( pTab!=0 && pTab->zName!=0 ); 263 assert( pTab!=0 && pTab->zName!=0 ); 218 iDb = sqlite3SchemaToIndex(db, pTab->pSchema); < 219 assert( pTab->nCol>0 ); 264 assert( pTab->nCol>0 ); > 265 if( pItem->pSelect && (pItem->pSelect->selFlags & SF_NestedFrom)!=0 ){ 220 if( zTab ){ | 266 ExprList *pEList = pItem->pSelect->pEList; 221 if( pItem->zAlias ){ | 267 int hit = 0; 222 char *zTabName = pItem->zAlias; | 268 for(j=0; j<pEList->nExpr; j++){ 223 if( sqlite3StrICmp(zTabName, zTab)!=0 ) continue; | 269 if( sqlite3MatchSpanName(pEList->a[j].zSpan, zCol, zTab, zDb) ){ 224 }else{ < > 270 cnt++; 225 char *zTabName = pTab->zName; | 271 cntTab = 2; 226 if( NEVER(zTabName==0) || sqlite3StrICmp(zTabName, zTab)!=0 ){ | 272 pMatch = pItem; > 273 pExpr->iColumn = j; > 274 hit = 1; > 275 } > 276 } 227 continue; | 277 if( hit || zTab==0 ) continue; 228 } | 278 } 229 if( zDb!=0 && sqlite3StrICmp(db->aDb[iDb].zName, zDb)!=0 ){ < > 279 if( zDb && pTab->pSchema!=pSchema ){ 230 continue; | 280 continue; 231 } | 281 } > 282 if( zTab ){ > 283 const char *zTabName = pItem->zAlias ? pItem->zAlias : pTab->zName; > 284 assert( zTabName!=0 ); > 285 if( sqlite3StrICmp(zTabName, zTab)!=0 ){ > 286 continue; 232 } 287 } 233 } 288 } 234 if( 0==(cntTab++) ){ 289 if( 0==(cntTab++) ){ 235 pExpr->iTable = pItem->iCursor; < 236 pExpr->pTab = pTab; < 237 pSchema = pTab->pSchema; < 238 pMatch = pItem; 290 pMatch = pItem; 239 } 291 } 240 for(j=0, pCol=pTab->aCol; j<pTab->nCol; j++, pCol++){ 292 for(j=0, pCol=pTab->aCol; j<pTab->nCol; j++, pCol++){ 241 if( sqlite3StrICmp(pCol->zName, zCol)==0 ){ 293 if( sqlite3StrICmp(pCol->zName, zCol)==0 ){ 242 /* If there has been exactly one prior match and this match 294 /* If there has been exactly one prior match and this match 243 ** is for the right-hand table of a NATURAL JOIN or is in a 295 ** is for the right-hand table of a NATURAL JOIN or is in a 244 ** USING clause, then skip this match. 296 ** USING clause, then skip this match. 245 */ 297 */ 246 if( cnt==1 ){ 298 if( cnt==1 ){ 247 if( pItem->jointype & JT_NATURAL ) continue; 299 if( pItem->jointype & JT_NATURAL ) continue; 248 if( nameInUsingClause(pItem->pUsing, zCol) ) continue; 300 if( nameInUsingClause(pItem->pUsing, zCol) ) continue; 249 } 301 } 250 cnt++; 302 cnt++; 251 pExpr->iTable = pItem->iCursor; < 252 pExpr->pTab = pTab; < 253 pMatch = pItem; 303 pMatch = pItem; 254 pSchema = pTab->pSchema; < 255 /* Substitute the rowid (column -1) for the INTEGER PRIMARY KEY */ 304 /* Substitute the rowid (column -1) for the INTEGER PRIMARY KEY */ 256 pExpr->iColumn = j==pTab->iPKey ? -1 : (i16)j; 305 pExpr->iColumn = j==pTab->iPKey ? -1 : (i16)j; 257 break; 306 break; 258 } 307 } 259 } 308 } 260 } 309 } > 310 if( pMatch ){ > 311 pExpr->iTable = pMatch->iCursor; > 312 pExpr->pTab = pMatch->pTab; > 313 pSchema = pExpr->pTab->pSchema; 261 } | 314 } > 315 } /* if( pSrcList ) */ 262 316 263 #ifndef SQLITE_OMIT_TRIGGER 317 #ifndef SQLITE_OMIT_TRIGGER 264 /* If we have not already resolved the name, then maybe 318 /* If we have not already resolved the name, then maybe 265 ** it is a new.* or old.* trigger argument reference 319 ** it is a new.* or old.* trigger argument reference 266 */ 320 */ 267 if( zDb==0 && zTab!=0 && cnt==0 && pParse->pTriggerTab!=0 ){ 321 if( zDb==0 && zTab!=0 && cnt==0 && pParse->pTriggerTab!=0 ){ 268 int op = pParse->eTriggerOp; 322 int op = pParse->eTriggerOp; ................................................................................................................................................................................ 553 int n = pList ? pList->nExpr : 0; /* Number of arguments */ 607 int n = pList ? pList->nExpr : 0; /* Number of arguments */ 554 int no_such_func = 0; /* True if no such function exists */ 608 int no_such_func = 0; /* True if no such function exists */ 555 int wrong_num_args = 0; /* True if wrong number of arguments */ 609 int wrong_num_args = 0; /* True if wrong number of arguments */ 556 int is_agg = 0; /* True if is an aggregate function */ 610 int is_agg = 0; /* True if is an aggregate function */ 557 int auth; /* Authorization to use the function */ 611 int auth; /* Authorization to use the function */ 558 int nId; /* Number of characters in function name */ 612 int nId; /* Number of characters in function name */ 559 const char *zId; /* The function name. */ 613 const char *zId; /* The function name. */ 560 FuncDef *pDef; /* Information about the function */ < 561 u8 enc = ENC(pParse->db); /* The database encoding */ 614 u8 enc = ENC(pParse->db); /* The database encoding */ 562 615 563 testcase( pExpr->op==TK_CONST_FUNC ); 616 testcase( pExpr->op==TK_CONST_FUNC ); 564 assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); 617 assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); 565 zId = pExpr->u.zToken; 618 zId = pExpr->u.zToken; 566 nId = sqlite3Strlen30(zId); 619 nId = sqlite3Strlen30(zId); > 620 if( pParse->db->init.busy==0 ){ 567 pDef = sqlite3FindFunction(pParse->db, zId, nId, n, enc, 0); | 621 FuncDef *pDef = sqlite3FindFunction(pParse->db, zId, nId, n, enc, 0); 568 if( pDef==0 ){ | 622 if( pDef==0 ){ 569 pDef = sqlite3FindFunction(pParse->db, zId, nId, -2, enc, 0); | 623 pDef = sqlite3FindFunction(pParse->db, zId, nId, -2, enc, 0); 570 if( pDef==0 ){ | 624 if( pDef==0 ){ 571 no_such_func = 1; | 625 no_such_func = 1; 572 }else{ | 626 }else{ 573 wrong_num_args = 1; | 627 wrong_num_args = 1; 574 } | 628 } 575 }else{ | 629 }else{ 576 is_agg = pDef->xFunc==0; | 630 is_agg = pDef->xFunc==0; 577 } | 631 } 578 #ifndef SQLITE_OMIT_AUTHORIZATION 632 #ifndef SQLITE_OMIT_AUTHORIZATION 579 if( pDef ){ | 633 if( pDef ){ 580 auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0, pDef->zName, 0); | 634 auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0, pDef->zName, 0); 581 if( auth!=SQLITE_OK ){ | 635 if( auth!=SQLITE_OK ){ 582 if( auth==SQLITE_DENY ){ | 636 if( auth==SQLITE_DENY ){ 583 sqlite3ErrorMsg(pParse, "not authorized to use function: %s", | 637 sqlite3ErrorMsg(pParse, "not authorized to use function: %s", 584 pDef->zName); | 638 pDef->zName); 585 pNC->nErr++; | 639 pNC->nErr++; 586 } | 640 } 587 pExpr->op = TK_NULL; | 641 pExpr->op = TK_NULL; 588 return WRC_Prune; | 642 return WRC_Prune; 589 } | 643 } 590 } | 644 } 591 #endif 645 #endif > 646 } 592 if( is_agg && (pNC->ncFlags & NC_AllowAgg)==0 ){ 647 if( is_agg && (pNC->ncFlags & NC_AllowAgg)==0 ){ 593 sqlite3ErrorMsg(pParse, "misuse of aggregate function %.*s()", nId,zId); 648 sqlite3ErrorMsg(pParse, "misuse of aggregate function %.*s()", nId,zId); 594 pNC->nErr++; 649 pNC->nErr++; 595 is_agg = 0; 650 is_agg = 0; 596 }else if( no_such_func ){ 651 }else if( no_such_func ){ 597 sqlite3ErrorMsg(pParse, "no such function: %.*s", nId, zId); 652 sqlite3ErrorMsg(pParse, "no such function: %.*s", nId, zId); 598 pNC->nErr++; 653 pNC->nErr++; ................................................................................................................................................................................ 808 moreToDo = 0; 863 moreToDo = 0; 809 pEList = pSelect->pEList; 864 pEList = pSelect->pEList; 810 assert( pEList!=0 ); 865 assert( pEList!=0 ); 811 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){ 866 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){ 812 int iCol = -1; 867 int iCol = -1; 813 Expr *pE, *pDup; 868 Expr *pE, *pDup; 814 if( pItem->done ) continue; 869 if( pItem->done ) continue; 815 pE = pItem->pExpr; | 870 pE = sqlite3ExprSkipCollate(pItem->pExpr); 816 if( sqlite3ExprIsInteger(pE, &iCol) ){ 871 if( sqlite3ExprIsInteger(pE, &iCol) ){ 817 if( iCol<=0 || iCol>pEList->nExpr ){ 872 if( iCol<=0 || iCol>pEList->nExpr ){ 818 resolveOutOfRangeError(pParse, "ORDER", i+1, pEList->nExpr); 873 resolveOutOfRangeError(pParse, "ORDER", i+1, pEList->nExpr); 819 return 1; 874 return 1; 820 } 875 } 821 }else{ 876 }else{ 822 iCol = resolveAsName(pParse, pEList, pE); 877 iCol = resolveAsName(pParse, pEList, pE); ................................................................................................................................................................................ 826 assert(pDup); 881 assert(pDup); 827 iCol = resolveOrderByTermToExprList(pParse, pSelect, pDup); 882 iCol = resolveOrderByTermToExprList(pParse, pSelect, pDup); 828 } 883 } 829 sqlite3ExprDelete(db, pDup); 884 sqlite3ExprDelete(db, pDup); 830 } 885 } 831 } 886 } 832 if( iCol>0 ){ 887 if( iCol>0 ){ 833 CollSeq *pColl = pE->pColl; | 888 /* Convert the ORDER BY term into an integer column number iCol, 834 int flags = pE->flags & EP_ExpCollate; | 889 ** taking care to preserve the COLLATE clause if it exists */ 835 sqlite3ExprDelete(db, pE); < 836 pItem->pExpr = pE = sqlite3Expr(db, TK_INTEGER, 0); | 890 Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0); 837 if( pE==0 ) return 1; | 891 if( pNew==0 ) return 1; 838 pE->pColl = pColl; < 839 pE->flags |= EP_IntValue | flags; | 892 pNew->flags |= EP_IntValue; 840 pE->u.iValue = iCol; | 893 pNew->u.iValue = iCol; > 894 if( pItem->pExpr==pE ){ > 895 pItem->pExpr = pNew; > 896 }else{ > 897 assert( pItem->pExpr->op==TK_COLLATE ); > 898 assert( pItem->pExpr->pLeft==pE ); > 899 pItem->pExpr->pLeft = pNew; > 900 } > 901 sqlite3ExprDelete(db, pE); 841 pItem->iOrderByCol = (u16)iCol; 902 pItem->iOrderByCol = (u16)iCol; 842 pItem->done = 1; 903 pItem->done = 1; 843 }else{ 904 }else{ 844 moreToDo = 1; 905 moreToDo = 1; 845 } 906 } 846 } 907 } 847 pSelect = pSelect->pNext; 908 pSelect = pSelect->pNext; ................................................................................................................................................................................ 938 /* If an AS-name match is found, mark this ORDER BY column as being 999 /* If an AS-name match is found, mark this ORDER BY column as being 939 ** a copy of the iCol-th result-set column. The subsequent call to 1000 ** a copy of the iCol-th result-set column. The subsequent call to 940 ** sqlite3ResolveOrderGroupBy() will convert the expression to a 1001 ** sqlite3ResolveOrderGroupBy() will convert the expression to a 941 ** copy of the iCol-th result-set expression. */ 1002 ** copy of the iCol-th result-set expression. */ 942 pItem->iOrderByCol = (u16)iCol; 1003 pItem->iOrderByCol = (u16)iCol; 943 continue; 1004 continue; 944 } 1005 } 945 if( sqlite3ExprIsInteger(pE, &iCol) ){ | 1006 if( sqlite3ExprIsInteger(sqlite3ExprSkipCollate(pE), &iCol) ){ 946 /* The ORDER BY term is an integer constant. Again, set the column 1007 /* The ORDER BY term is an integer constant. Again, set the column 947 ** number so that sqlite3ResolveOrderGroupBy() will convert the 1008 ** number so that sqlite3ResolveOrderGroupBy() will convert the 948 ** order-by term to a copy of the result-set expression */ 1009 ** order-by term to a copy of the result-set expression */ 949 if( iCol<1 ){ | 1010 if( iCol<1 || iCol>0xffff ){ 950 resolveOutOfRangeError(pParse, zType, i+1, nResult); 1011 resolveOutOfRangeError(pParse, zType, i+1, nResult); 951 return 1; 1012 return 1; 952 } 1013 } 953 pItem->iOrderByCol = (u16)iCol; 1014 pItem->iOrderByCol = (u16)iCol; 954 continue; 1015 continue; 955 } 1016 } 956 1017 ................................................................................................................................................................................ 1019 memset(&sNC, 0, sizeof(sNC)); 1080 memset(&sNC, 0, sizeof(sNC)); 1020 sNC.pParse = pParse; 1081 sNC.pParse = pParse; 1021 if( sqlite3ResolveExprNames(&sNC, p->pLimit) || 1082 if( sqlite3ResolveExprNames(&sNC, p->pLimit) || 1022 sqlite3ResolveExprNames(&sNC, p->pOffset) ){ 1083 sqlite3ResolveExprNames(&sNC, p->pOffset) ){ 1023 return WRC_Abort; 1084 return WRC_Abort; 1024 } 1085 } 1025 1086 1026 /* Set up the local name-context to pass to sqlite3ResolveExprNames() to < 1027 ** resolve the result-set expression list. < 1028 */ < 1029 sNC.ncFlags = NC_AllowAgg; < 1030 sNC.pSrcList = p->pSrc; < 1031 sNC.pNext = pOuterNC; < 1032 < 1033 /* Resolve names in the result set. */ < 1034 pEList = p->pEList; < 1035 assert( pEList!=0 ); < 1036 for(i=0; i<pEList->nExpr; i++){ < 1037 Expr *pX = pEList->a[i].pExpr; < 1038 if( sqlite3ResolveExprNames(&sNC, pX) ){ < 1039 return WRC_Abort; < 1040 } < 1041 } < 1042 < 1043 /* Recursively resolve names in all subqueries 1087 /* Recursively resolve names in all subqueries 1044 */ 1088 */ 1045 for(i=0; i<p->pSrc->nSrc; i++){ 1089 for(i=0; i<p->pSrc->nSrc; i++){ 1046 struct SrcList_item *pItem = &p->pSrc->a[i]; 1090 struct SrcList_item *pItem = &p->pSrc->a[i]; 1047 if( pItem->pSelect ){ 1091 if( pItem->pSelect ){ 1048 NameContext *pNC; /* Used to iterate name contexts */ 1092 NameContext *pNC; /* Used to iterate name contexts */ 1049 int nRef = 0; /* Refcount for pOuterNC and outer contexts */ 1093 int nRef = 0; /* Refcount for pOuterNC and outer contexts */ ................................................................................................................................................................................ 1062 if( pParse->nErr || db->mallocFailed ) return WRC_Abort; 1106 if( pParse->nErr || db->mallocFailed ) return WRC_Abort; 1063 1107 1064 for(pNC=pOuterNC; pNC; pNC=pNC->pNext) nRef -= pNC->nRef; 1108 for(pNC=pOuterNC; pNC; pNC=pNC->pNext) nRef -= pNC->nRef; 1065 assert( pItem->isCorrelated==0 && nRef<=0 ); 1109 assert( pItem->isCorrelated==0 && nRef<=0 ); 1066 pItem->isCorrelated = (nRef!=0); 1110 pItem->isCorrelated = (nRef!=0); 1067 } 1111 } 1068 } 1112 } > 1113 > 1114 /* Set up the local name-context to pass to sqlite3ResolveExprNames() to > 1115 ** resolve the result-set expression list. > 1116 */ > 1117 sNC.ncFlags = NC_AllowAgg; > 1118 sNC.pSrcList = p->pSrc; > 1119 sNC.pNext = pOuterNC; > 1120 > 1121 /* Resolve names in the result set. */ > 1122 pEList = p->pEList; > 1123 assert( pEList!=0 ); > 1124 for(i=0; i<pEList->nExpr; i++){ > 1125 Expr *pX = pEList->a[i].pExpr; > 1126 if( sqlite3ResolveExprNames(&sNC, pX) ){ > 1127 return WRC_Abort; > 1128 } > 1129 } 1069 1130 1070 /* If there are no aggregate functions in the result-set, and no GROUP BY 1131 /* If there are no aggregate functions in the result-set, and no GROUP BY 1071 ** expression, do not allow aggregates in any of the other expressions. 1132 ** expression, do not allow aggregates in any of the other expressions. 1072 */ 1133 */ 1073 assert( (p->selFlags & SF_Aggregate)==0 ); 1134 assert( (p->selFlags & SF_Aggregate)==0 ); 1074 pGroupBy = p->pGroupBy; 1135 pGroupBy = p->pGroupBy; 1075 if( pGroupBy || (sNC.ncFlags & NC_HasAgg)!=0 ){ 1136 if( pGroupBy || (sNC.ncFlags & NC_HasAgg)!=0 ){
Changes to src/select.c
51 Parse *pParse, /* Parsing context */ 51 Parse *pParse, /* Parsing context */ 52 ExprList *pEList, /* which columns to include in the result */ 52 ExprList *pEList, /* which columns to include in the result */ 53 SrcList *pSrc, /* the FROM clause -- which tables to scan */ 53 SrcList *pSrc, /* the FROM clause -- which tables to scan */ 54 Expr *pWhere, /* the WHERE clause */ 54 Expr *pWhere, /* the WHERE clause */ 55 ExprList *pGroupBy, /* the GROUP BY clause */ 55 ExprList *pGroupBy, /* the GROUP BY clause */ 56 Expr *pHaving, /* the HAVING clause */ 56 Expr *pHaving, /* the HAVING clause */ 57 ExprList *pOrderBy, /* the ORDER BY clause */ 57 ExprList *pOrderBy, /* the ORDER BY clause */ 58 int isDistinct, /* true if the DISTINCT keyword is present */ | 58 u16 selFlags, /* Flag parameters, such as SF_Distinct */ 59 Expr *pLimit, /* LIMIT value. NULL means not used */ 59 Expr *pLimit, /* LIMIT value. NULL means not used */ 60 Expr *pOffset /* OFFSET value. NULL means no offset */ 60 Expr *pOffset /* OFFSET value. NULL means no offset */ 61 ){ 61 ){ 62 Select *pNew; 62 Select *pNew; 63 Select standin; 63 Select standin; 64 sqlite3 *db = pParse->db; 64 sqlite3 *db = pParse->db; 65 pNew = sqlite3DbMallocZero(db, sizeof(*pNew) ); 65 pNew = sqlite3DbMallocZero(db, sizeof(*pNew) ); ................................................................................................................................................................................ 75 pNew->pEList = pEList; 75 pNew->pEList = pEList; 76 if( pSrc==0 ) pSrc = sqlite3DbMallocZero(db, sizeof(*pSrc)); 76 if( pSrc==0 ) pSrc = sqlite3DbMallocZero(db, sizeof(*pSrc)); 77 pNew->pSrc = pSrc; 77 pNew->pSrc = pSrc; 78 pNew->pWhere = pWhere; 78 pNew->pWhere = pWhere; 79 pNew->pGroupBy = pGroupBy; 79 pNew->pGroupBy = pGroupBy; 80 pNew->pHaving = pHaving; 80 pNew->pHaving = pHaving; 81 pNew->pOrderBy = pOrderBy; 81 pNew->pOrderBy = pOrderBy; 82 pNew->selFlags = isDistinct ? SF_Distinct : 0; | 82 pNew->selFlags = selFlags; 83 pNew->op = TK_SELECT; 83 pNew->op = TK_SELECT; 84 pNew->pLimit = pLimit; 84 pNew->pLimit = pLimit; 85 pNew->pOffset = pOffset; 85 pNew->pOffset = pOffset; 86 assert( pOffset==0 || pLimit!=0 ); 86 assert( pOffset==0 || pLimit!=0 ); 87 pNew->addrOpenEphm[0] = -1; 87 pNew->addrOpenEphm[0] = -1; 88 pNew->addrOpenEphm[1] = -1; 88 pNew->addrOpenEphm[1] = -1; 89 pNew->addrOpenEphm[2] = -1; 89 pNew->addrOpenEphm[2] = -1; ................................................................................................................................................................................ 1331 } 1331 } 1332 *pnCol = nCol; 1332 *pnCol = nCol; 1333 *paCol = aCol; 1333 *paCol = aCol; 1334 1334 1335 for(i=0, pCol=aCol; i<nCol; i++, pCol++){ 1335 for(i=0, pCol=aCol; i<nCol; i++, pCol++){ 1336 /* Get an appropriate name for the column 1336 /* Get an appropriate name for the column 1337 */ 1337 */ 1338 p = pEList->a[i].pExpr; | 1338 p = sqlite3ExprSkipCollate(pEList->a[i].pExpr); 1339 assert( p->pRight==0 || ExprHasProperty(p->pRight, EP_IntValue) < 1340 || p->pRight->u.zToken==0 || p->pRight->u.zToken[0]!=0 ); < 1341 if( (zName = pEList->a[i].zName)!=0 ){ 1339 if( (zName = pEList->a[i].zName)!=0 ){ 1342 /* If the column contains an "AS <name>" phrase, use <name> as the name */ 1340 /* If the column contains an "AS <name>" phrase, use <name> as the name */ 1343 zName = sqlite3DbStrDup(db, zName); 1341 zName = sqlite3DbStrDup(db, zName); 1344 }else{ 1342 }else{ 1345 Expr *pColExpr = p; /* The expression that is the result column name */ 1343 Expr *pColExpr = p; /* The expression that is the result column name */ 1346 Table *pTab; /* Table associated with this expression */ 1344 Table *pTab; /* Table associated with this expression */ 1347 while( pColExpr->op==TK_DOT ){ 1345 while( pColExpr->op==TK_DOT ){ ................................................................................................................................................................................ 1371 /* Make sure the column name is unique. If the name is not unique, 1369 /* Make sure the column name is unique. If the name is not unique, 1372 ** append a integer to the name so that it becomes unique. 1370 ** append a integer to the name so that it becomes unique. 1373 */ 1371 */ 1374 nName = sqlite3Strlen30(zName); 1372 nName = sqlite3Strlen30(zName); 1375 for(j=cnt=0; j<i; j++){ 1373 for(j=cnt=0; j<i; j++){ 1376 if( sqlite3StrICmp(aCol[j].zName, zName)==0 ){ 1374 if( sqlite3StrICmp(aCol[j].zName, zName)==0 ){ 1377 char *zNewName; 1375 char *zNewName; > 1376 int k; > 1377 for(k=nName-1; k>1 && sqlite3Isdigit(zName[k]); k--){} > 1378 if( zName[k]==':' ) nName = k; 1378 zName[nName] = 0; 1379 zName[nName] = 0; 1379 zNewName = sqlite3MPrintf(db, "%s:%d", zName, ++cnt); 1380 zNewName = sqlite3MPrintf(db, "%s:%d", zName, ++cnt); 1380 sqlite3DbFree(db, zName); 1381 sqlite3DbFree(db, zName); 1381 zName = zNewName; 1382 zName = zNewName; 1382 j = -1; 1383 j = -1; 1383 if( zName==0 ) break; 1384 if( zName==0 ) break; 1384 } 1385 } ................................................................................................................................................................................ 2329 if( pKeyMerge ){ 2330 if( pKeyMerge ){ 2330 pKeyMerge->aSortOrder = (u8*)&pKeyMerge->aColl[nOrderBy]; 2331 pKeyMerge->aSortOrder = (u8*)&pKeyMerge->aColl[nOrderBy]; 2331 pKeyMerge->nField = (u16)nOrderBy; 2332 pKeyMerge->nField = (u16)nOrderBy; 2332 pKeyMerge->enc = ENC(db); 2333 pKeyMerge->enc = ENC(db); 2333 for(i=0; i<nOrderBy; i++){ 2334 for(i=0; i<nOrderBy; i++){ 2334 CollSeq *pColl; 2335 CollSeq *pColl; 2335 Expr *pTerm = pOrderBy->a[i].pExpr; 2336 Expr *pTerm = pOrderBy->a[i].pExpr; 2336 if( pTerm->flags & EP_ExpCollate ){ | 2337 if( pTerm->flags & EP_Collate ){ 2337 pColl = pTerm->pColl; | 2338 pColl = sqlite3ExprCollSeq(pParse, pTerm); 2338 }else{ 2339 }else{ 2339 pColl = multiSelectCollSeq(pParse, p, aPermute[i]); 2340 pColl = multiSelectCollSeq(pParse, p, aPermute[i]); 2340 pTerm->flags |= EP_ExpCollate; | 2341 if( pColl==0 ) pColl = db->pDfltColl; 2341 pTerm->pColl = pColl; | 2342 pOrderBy->a[i].pExpr = > 2343 sqlite3ExprAddCollateString(pParse, pTerm, pColl->zName); 2342 } 2344 } 2343 pKeyMerge->aColl[i] = pColl; 2345 pKeyMerge->aColl[i] = pColl; 2344 pKeyMerge->aSortOrder[i] = pOrderBy->a[i].sortOrder; 2346 pKeyMerge->aSortOrder[i] = pOrderBy->a[i].sortOrder; 2345 } 2347 } 2346 } 2348 } 2347 }else{ 2349 }else{ 2348 pKeyMerge = 0; 2350 pKeyMerge = 0; ................................................................................................................................................................................ 2537 2539 2538 /* Implement the main merge loop 2540 /* Implement the main merge loop 2539 */ 2541 */ 2540 sqlite3VdbeResolveLabel(v, labelCmpr); 2542 sqlite3VdbeResolveLabel(v, labelCmpr); 2541 sqlite3VdbeAddOp4(v, OP_Permutation, 0, 0, 0, (char*)aPermute, P4_INTARRAY); 2543 sqlite3VdbeAddOp4(v, OP_Permutation, 0, 0, 0, (char*)aPermute, P4_INTARRAY); 2542 sqlite3VdbeAddOp4(v, OP_Compare, destA.iSdst, destB.iSdst, nOrderBy, 2544 sqlite3VdbeAddOp4(v, OP_Compare, destA.iSdst, destB.iSdst, nOrderBy, 2543 (char*)pKeyMerge, P4_KEYINFO_HANDOFF); 2545 (char*)pKeyMerge, P4_KEYINFO_HANDOFF); > 2546 sqlite3VdbeChangeP5(v, OPFLAG_PERMUTE); 2544 sqlite3VdbeAddOp3(v, OP_Jump, addrAltB, addrAeqB, addrAgtB); 2547 sqlite3VdbeAddOp3(v, OP_Jump, addrAltB, addrAeqB, addrAgtB); 2545 2548 2546 /* Release temporary registers 2549 /* Release temporary registers 2547 */ 2550 */ 2548 if( regPrev ){ 2551 if( regPrev ){ 2549 sqlite3ReleaseTempRange(pParse, regPrev, nOrderBy+1); 2552 sqlite3ReleaseTempRange(pParse, regPrev, nOrderBy+1); 2550 } 2553 } ................................................................................................................................................................................ 2604 if( pExpr->iColumn<0 ){ 2607 if( pExpr->iColumn<0 ){ 2605 pExpr->op = TK_NULL; 2608 pExpr->op = TK_NULL; 2606 }else{ 2609 }else{ 2607 Expr *pNew; 2610 Expr *pNew; 2608 assert( pEList!=0 && pExpr->iColumn<pEList->nExpr ); 2611 assert( pEList!=0 && pExpr->iColumn<pEList->nExpr ); 2609 assert( pExpr->pLeft==0 && pExpr->pRight==0 ); 2612 assert( pExpr->pLeft==0 && pExpr->pRight==0 ); 2610 pNew = sqlite3ExprDup(db, pEList->a[pExpr->iColumn].pExpr, 0); 2613 pNew = sqlite3ExprDup(db, pEList->a[pExpr->iColumn].pExpr, 0); 2611 if( pNew && pExpr->pColl ){ < 2612 pNew->pColl = pExpr->pColl; < 2613 } < 2614 sqlite3ExprDelete(db, pExpr); 2614 sqlite3ExprDelete(db, pExpr); 2615 pExpr = pNew; 2615 pExpr = pNew; 2616 } 2616 } 2617 }else{ 2617 }else{ 2618 pExpr->pLeft = substExpr(db, pExpr->pLeft, iTable, pEList); 2618 pExpr->pLeft = substExpr(db, pExpr->pLeft, iTable, pEList); 2619 pExpr->pRight = substExpr(db, pExpr->pRight, iTable, pEList); 2619 pExpr->pRight = substExpr(db, pExpr->pRight, iTable, pEList); 2620 if( ExprHasProperty(pExpr, EP_xIsSelect) ){ 2620 if( ExprHasProperty(pExpr, EP_xIsSelect) ){ ................................................................................................................................................................................ 3157 sqlite3SelectDelete(db, pSub1); 3157 sqlite3SelectDelete(db, pSub1); 3158 3158 3159 return 1; 3159 return 1; 3160 } 3160 } 3161 #endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */ 3161 #endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */ 3162 3162 3163 /* 3163 /* 3164 ** Analyze the SELECT statement passed as an argument to see if it | 3164 ** Based on the contents of the AggInfo structure indicated by the first 3165 ** is a min() or max() query. Return WHERE_ORDERBY_MIN or WHERE_ORDERBY_MAX if | 3165 ** argument, this function checks if the following are true: 3166 ** it is, or 0 otherwise. At present, a query is considered to be | 3166 ** 3167 ** a min()/max() query if: | 3167 ** * the query contains just a single aggregate function, 3168 ** | 3168 ** * the aggregate function is either min() or max(), and 3169 ** 1. There is a single object in the FROM clause. | 3169 ** * the argument to the aggregate function is a column value. 3170 ** | 3170 ** 3171 ** 2. There is a single expression in the result set, and it is | 3171 ** If all of the above are true, then WHERE_ORDERBY_MIN or WHERE_ORDERBY_MAX 3172 ** either min(x) or max(x), where x is a column reference. | 3172 ** is returned as appropriate. Also, *ppMinMax is set to point to the 3173 */ | 3173 ** list of arguments passed to the aggregate before returning. 3174 static u8 minMaxQuery(Select *p){ | 3174 ** 3175 Expr *pExpr; | 3175 ** Or, if the conditions above are not met, *ppMinMax is set to 0 and 3176 ExprList *pEList = p->pEList; | 3176 ** WHERE_ORDERBY_NORMAL is returned. 3177 | 3177 */ 3178 if( pEList->nExpr!=1 ) return WHERE_ORDERBY_NORMAL; | 3178 static u8 minMaxQuery(AggInfo *pAggInfo, ExprList **ppMinMax){ 3179 pExpr = pEList->a[0].pExpr; | 3179 int eRet = WHERE_ORDERBY_NORMAL; /* Return value */ 3180 if( pExpr->op!=TK_AGG_FUNCTION ) return 0; | 3180 3181 if( NEVER(ExprHasProperty(pExpr, EP_xIsSelect)) ) return 0; | 3181 *ppMinMax = 0; 3182 pEList = pExpr->x.pList; | 3182 if( pAggInfo->nFunc==1 ){ 3183 if( pEList==0 || pEList->nExpr!=1 ) return 0; | 3183 Expr *pExpr = pAggInfo->aFunc[0].pExpr; /* Aggregate function */ 3184 if( pEList->a[0].pExpr->op!=TK_AGG_COLUMN ) return WHERE_ORDERBY_NORMAL; | 3184 ExprList *pEList = pExpr->x.pList; /* Arguments to agg function */ 3185 assert( !ExprHasProperty(pExpr, EP_IntValue) ); | 3185 3186 if( sqlite3StrICmp(pExpr->u.zToken,"min")==0 ){ | 3186 assert( pExpr->op==TK_AGG_FUNCTION ); 3187 return WHERE_ORDERBY_MIN; | 3187 if( pEList && pEList->nExpr==1 && pEList->a[0].pExpr->op==TK_AGG_COLUMN ){ 3188 }else if( sqlite3StrICmp(pExpr->u.zToken,"max")==0 ){ | 3188 const char *zFunc = pExpr->u.zToken; 3189 return WHERE_ORDERBY_MAX; | 3189 if( sqlite3StrICmp(zFunc, "min")==0 ){ 3190 } | 3190 eRet = WHERE_ORDERBY_MIN; 3191 return WHERE_ORDERBY_NORMAL; | 3191 *ppMinMax = pEList; > 3192 }else if( sqlite3StrICmp(zFunc, "max")==0 ){ > 3193 eRet = WHERE_ORDERBY_MAX; > 3194 *ppMinMax = pEList; > 3195 } > 3196 } > 3197 } > 3198 > 3199 assert( *ppMinMax==0 || (*ppMinMax)->nExpr==1 ); > 3200 return eRet; 3192 } 3201 } 3193 3202 3194 /* 3203 /* 3195 ** The select statement passed as the first argument is an aggregate query. 3204 ** The select statement passed as the first argument is an aggregate query. 3196 ** The second argment is the associated aggregate-info object. This 3205 ** The second argment is the associated aggregate-info object. This 3197 ** function tests if the SELECT is of the form: 3206 ** function tests if the SELECT is of the form: 3198 ** 3207 ** ................................................................................................................................................................................ 3279 static int selectExpander(Walker *pWalker, Select *p){ 3288 static int selectExpander(Walker *pWalker, Select *p){ 3280 Parse *pParse = pWalker->pParse; 3289 Parse *pParse = pWalker->pParse; 3281 int i, j, k; 3290 int i, j, k; 3282 SrcList *pTabList; 3291 SrcList *pTabList; 3283 ExprList *pEList; 3292 ExprList *pEList; 3284 struct SrcList_item *pFrom; 3293 struct SrcList_item *pFrom; 3285 sqlite3 *db = pParse->db; 3294 sqlite3 *db = pParse->db; > 3295 Expr *pE, *pRight, *pExpr; 3286 3296 3287 if( db->mallocFailed ){ 3297 if( db->mallocFailed ){ 3288 return WRC_Abort; 3298 return WRC_Abort; 3289 } 3299 } 3290 if( NEVER(p->pSrc==0) || (p->selFlags & SF_Expanded)!=0 ){ 3300 if( NEVER(p->pSrc==0) || (p->selFlags & SF_Expanded)!=0 ){ 3291 return WRC_Prune; 3301 return WRC_Prune; 3292 } 3302 } ................................................................................................................................................................................ 3364 ** The following code just has to locate the TK_ALL expressions and expand 3374 ** The following code just has to locate the TK_ALL expressions and expand 3365 ** each one to the list of all columns in all tables. 3375 ** each one to the list of all columns in all tables. 3366 ** 3376 ** 3367 ** The first loop just checks to see if there are any "*" operators 3377 ** The first loop just checks to see if there are any "*" operators 3368 ** that need expanding. 3378 ** that need expanding. 3369 */ 3379 */ 3370 for(k=0; k<pEList->nExpr; k++){ 3380 for(k=0; k<pEList->nExpr; k++){ 3371 Expr *pE = pEList->a[k].pExpr; | 3381 pE = pEList->a[k].pExpr; 3372 if( pE->op==TK_ALL ) break; 3382 if( pE->op==TK_ALL ) break; 3373 assert( pE->op!=TK_DOT || pE->pRight!=0 ); 3383 assert( pE->op!=TK_DOT || pE->pRight!=0 ); 3374 assert( pE->op!=TK_DOT || (pE->pLeft!=0 && pE->pLeft->op==TK_ID) ); 3384 assert( pE->op!=TK_DOT || (pE->pLeft!=0 && pE->pLeft->op==TK_ID) ); 3375 if( pE->op==TK_DOT && pE->pRight->op==TK_ALL ) break; 3385 if( pE->op==TK_DOT && pE->pRight->op==TK_ALL ) break; 3376 } 3386 } 3377 if( k<pEList->nExpr ){ 3387 if( k<pEList->nExpr ){ 3378 /* 3388 /* ................................................................................................................................................................................ 3382 */ 3392 */ 3383 struct ExprList_item *a = pEList->a; 3393 struct ExprList_item *a = pEList->a; 3384 ExprList *pNew = 0; 3394 ExprList *pNew = 0; 3385 int flags = pParse->db->flags; 3395 int flags = pParse->db->flags; 3386 int longNames = (flags & SQLITE_FullColNames)!=0 3396 int longNames = (flags & SQLITE_FullColNames)!=0 3387 && (flags & SQLITE_ShortColNames)==0; 3397 && (flags & SQLITE_ShortColNames)==0; 3388 3398 > 3399 /* When processing FROM-clause subqueries, it is always the case > 3400 ** that full_column_names=OFF and short_column_names=ON. The > 3401 ** sqlite3ResultSetOfSelect() routine makes it so. */ > 3402 assert( (p->selFlags & SF_NestedFrom)==0 > 3403 || ((flags & SQLITE_FullColNames)==0 && > 3404 (flags & SQLITE_ShortColNames)!=0) ); > 3405 3389 for(k=0; k<pEList->nExpr; k++){ 3406 for(k=0; k<pEList->nExpr; k++){ 3390 Expr *pE = a[k].pExpr; | 3407 pE = a[k].pExpr; > 3408 pRight = pE->pRight; 3391 assert( pE->op!=TK_DOT || pE->pRight!=0 ); | 3409 assert( pE->op!=TK_DOT || pRight!=0 ); 3392 if( pE->op!=TK_ALL && (pE->op!=TK_DOT || pE->pRight->op!=TK_ALL) ){ | 3410 if( pE->op!=TK_ALL && (pE->op!=TK_DOT || pRight->op!=TK_ALL) ){ 3393 /* This particular expression does not need to be expanded. 3411 /* This particular expression does not need to be expanded. 3394 */ 3412 */ 3395 pNew = sqlite3ExprListAppend(pParse, pNew, a[k].pExpr); 3413 pNew = sqlite3ExprListAppend(pParse, pNew, a[k].pExpr); 3396 if( pNew ){ 3414 if( pNew ){ 3397 pNew->a[pNew->nExpr-1].zName = a[k].zName; 3415 pNew->a[pNew->nExpr-1].zName = a[k].zName; 3398 pNew->a[pNew->nExpr-1].zSpan = a[k].zSpan; 3416 pNew->a[pNew->nExpr-1].zSpan = a[k].zSpan; 3399 a[k].zName = 0; 3417 a[k].zName = 0; ................................................................................................................................................................................ 3400 a[k].zSpan = 0; 3418 a[k].zSpan = 0; 3401 } 3419 } 3402 a[k].pExpr = 0; 3420 a[k].pExpr = 0; 3403 }else{ 3421 }else{ 3404 /* This expression is a "*" or a "TABLE.*" and needs to be 3422 /* This expression is a "*" or a "TABLE.*" and needs to be 3405 ** expanded. */ 3423 ** expanded. */ 3406 int tableSeen = 0; /* Set to 1 when TABLE matches */ 3424 int tableSeen = 0; /* Set to 1 when TABLE matches */ 3407 char *zTName; /* text of name of TABLE */ | 3425 char *zTName = 0; /* text of name of TABLE */ 3408 if( pE->op==TK_DOT ){ 3426 if( pE->op==TK_DOT ){ 3409 assert( pE->pLeft!=0 ); 3427 assert( pE->pLeft!=0 ); 3410 assert( !ExprHasProperty(pE->pLeft, EP_IntValue) ); 3428 assert( !ExprHasProperty(pE->pLeft, EP_IntValue) ); 3411 zTName = pE->pLeft->u.zToken; 3429 zTName = pE->pLeft->u.zToken; 3412 }else{ < 3413 zTName = 0; < 3414 } 3430 } 3415 for(i=0, pFrom=pTabList->a; i<pTabList->nSrc; i++, pFrom++){ 3431 for(i=0, pFrom=pTabList->a; i<pTabList->nSrc; i++, pFrom++){ 3416 Table *pTab = pFrom->pTab; 3432 Table *pTab = pFrom->pTab; > 3433 Select *pSub = pFrom->pSelect; 3417 char *zTabName = pFrom->zAlias; 3434 char *zTabName = pFrom->zAlias; > 3435 const char *zSchemaName = 0; > 3436 int iDb; 3418 if( zTabName==0 ){ 3437 if( zTabName==0 ){ 3419 zTabName = pTab->zName; 3438 zTabName = pTab->zName; 3420 } 3439 } 3421 if( db->mallocFailed ) break; 3440 if( db->mallocFailed ) break; > 3441 if( pSub==0 || (pSub->selFlags & SF_NestedFrom)==0 ){ > 3442 pSub = 0; 3422 if( zTName && sqlite3StrICmp(zTName, zTabName)!=0 ){ | 3443 if( zTName && sqlite3StrICmp(zTName, zTabName)!=0 ){ 3423 continue; | 3444 continue; 3424 } | 3445 } 3425 tableSeen = 1; < > 3446 iDb = sqlite3SchemaToIndex(db, pTab->pSchema); > 3447 zSchemaName = iDb>=0 ? db->aDb[iDb].zName : "*"; > 3448 } 3426 for(j=0; j<pTab->nCol; j++){ 3449 for(j=0; j<pTab->nCol; j++){ 3427 Expr *pExpr, *pRight; < 3428 char *zName = pTab->aCol[j].zName; 3450 char *zName = pTab->aCol[j].zName; 3429 char *zColname; /* The computed column name */ 3451 char *zColname; /* The computed column name */ 3430 char *zToFree; /* Malloced string that needs to be freed */ 3452 char *zToFree; /* Malloced string that needs to be freed */ 3431 Token sColname; /* Computed column name as a token */ 3453 Token sColname; /* Computed column name as a token */ > 3454 > 3455 assert( zName ); > 3456 if( zTName && pSub > 3457 && sqlite3MatchSpanName(pSub->pEList->a[j].zSpan, 0, zTName, 0)==0 > 3458 ){ > 3459 continue; > 3460 } 3432 3461 3433 /* If a column is marked as 'hidden' (currently only possible 3462 /* If a column is marked as 'hidden' (currently only possible 3434 ** for virtual tables), do not include it in the expanded 3463 ** for virtual tables), do not include it in the expanded 3435 ** result-set list. 3464 ** result-set list. 3436 */ 3465 */ 3437 if( IsHiddenColumn(&pTab->aCol[j]) ){ 3466 if( IsHiddenColumn(&pTab->aCol[j]) ){ 3438 assert(IsVirtual(pTab)); 3467 assert(IsVirtual(pTab)); 3439 continue; 3468 continue; 3440 } 3469 } > 3470 tableSeen = 1; 3441 3471 3442 if( i>0 && zTName==0 ){ 3472 if( i>0 && zTName==0 ){ 3443 if( (pFrom->jointype & JT_NATURAL)!=0 3473 if( (pFrom->jointype & JT_NATURAL)!=0 3444 && tableAndColumnIndex(pTabList, i, zName, 0, 0) 3474 && tableAndColumnIndex(pTabList, i, zName, 0, 0) 3445 ){ 3475 ){ 3446 /* In a NATURAL join, omit the join columns from the 3476 /* In a NATURAL join, omit the join columns from the 3447 ** table to the right of the join */ 3477 ** table to the right of the join */ ................................................................................................................................................................................ 3456 pRight = sqlite3Expr(db, TK_ID, zName); 3486 pRight = sqlite3Expr(db, TK_ID, zName); 3457 zColname = zName; 3487 zColname = zName; 3458 zToFree = 0; 3488 zToFree = 0; 3459 if( longNames || pTabList->nSrc>1 ){ 3489 if( longNames || pTabList->nSrc>1 ){ 3460 Expr *pLeft; 3490 Expr *pLeft; 3461 pLeft = sqlite3Expr(db, TK_ID, zTabName); 3491 pLeft = sqlite3Expr(db, TK_ID, zTabName); 3462 pExpr = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight, 0); 3492 pExpr = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight, 0); > 3493 if( zSchemaName ){ > 3494 pLeft = sqlite3Expr(db, TK_ID, zSchemaName); > 3495 pExpr = sqlite3PExpr(pParse, TK_DOT, pLeft, pExpr, 0); > 3496 } 3463 if( longNames ){ 3497 if( longNames ){ 3464 zColname = sqlite3MPrintf(db, "%s.%s", zTabName, zName); 3498 zColname = sqlite3MPrintf(db, "%s.%s", zTabName, zName); 3465 zToFree = zColname; 3499 zToFree = zColname; 3466 } 3500 } 3467 }else{ 3501 }else{ 3468 pExpr = pRight; 3502 pExpr = pRight; 3469 } 3503 } 3470 pNew = sqlite3ExprListAppend(pParse, pNew, pExpr); 3504 pNew = sqlite3ExprListAppend(pParse, pNew, pExpr); 3471 sColname.z = zColname; 3505 sColname.z = zColname; 3472 sColname.n = sqlite3Strlen30(zColname); 3506 sColname.n = sqlite3Strlen30(zColname); 3473 sqlite3ExprListSetName(pParse, pNew, &sColname, 0); 3507 sqlite3ExprListSetName(pParse, pNew, &sColname, 0); > 3508 if( pNew && (p->selFlags & SF_NestedFrom)!=0 ){ > 3509 struct ExprList_item *pX = &pNew->a[pNew->nExpr-1]; > 3510 if( pSub ){ > 3511 pX->zSpan = sqlite3DbStrDup(db, pSub->pEList->a[j].zSpan); > 3512 testcase( pX->zSpan==0 ); > 3513 }else{ > 3514 pX->zSpan = sqlite3MPrintf(db, "%s.%s.%s", > 3515 zSchemaName, zTabName, zColname); > 3516 testcase( pX->zSpan==0 ); > 3517 } > 3518 pX->bSpanIsTab = 1; > 3519 } 3474 sqlite3DbFree(db, zToFree); 3520 sqlite3DbFree(db, zToFree); 3475 } 3521 } 3476 } 3522 } 3477 if( !tableSeen ){ 3523 if( !tableSeen ){ 3478 if( zTName ){ 3524 if( zTName ){ 3479 sqlite3ErrorMsg(pParse, "no such table: %s", zTName); 3525 sqlite3ErrorMsg(pParse, "no such table: %s", zTName); 3480 }else{ 3526 }else{ ................................................................................................................................................................................ 4524 ** 4570 ** 4525 ** + The optimizer code in where.c (the thing that decides which 4571 ** + The optimizer code in where.c (the thing that decides which 4526 ** index or indices to use) should place a different priority on 4572 ** index or indices to use) should place a different priority on 4527 ** satisfying the 'ORDER BY' clause than it does in other cases. 4573 ** satisfying the 'ORDER BY' clause than it does in other cases. 4528 ** Refer to code and comments in where.c for details. 4574 ** Refer to code and comments in where.c for details. 4529 */ 4575 */ 4530 ExprList *pMinMax = 0; 4576 ExprList *pMinMax = 0; > 4577 u8 flag = WHERE_ORDERBY_NORMAL; > 4578 > 4579 assert( p->pGroupBy==0 ); > 4580 assert( flag==0 ); > 4581 if( p->pHaving==0 ){ 4531 u8 flag = minMaxQuery(p); | 4582 flag = minMaxQuery(&sAggInfo, &pMinMax); > 4583 } > 4584 assert( flag==0 || (pMinMax!=0 && pMinMax->nExpr==1) ); > 4585 4532 if( flag ){ 4586 if( flag ){ 4533 assert( !ExprHasProperty(p->pEList->a[0].pExpr, EP_xIsSelect) ); < 4534 assert( p->pEList->a[0].pExpr->x.pList->nExpr==1 ); < 4535 pMinMax = sqlite3ExprListDup(db, p->pEList->a[0].pExpr->x.pList,0); | 4587 pMinMax = sqlite3ExprListDup(db, pMinMax, 0); 4536 pDel = pMinMax; 4588 pDel = pMinMax; 4537 if( pMinMax && !db->mallocFailed ){ 4589 if( pMinMax && !db->mallocFailed ){ 4538 pMinMax->a[0].sortOrder = flag!=WHERE_ORDERBY_MIN ?1:0; 4590 pMinMax->a[0].sortOrder = flag!=WHERE_ORDERBY_MIN ?1:0; 4539 pMinMax->a[0].pExpr->op = TK_COLUMN; 4591 pMinMax->a[0].pExpr->op = TK_COLUMN; 4540 } 4592 } 4541 } 4593 } 4542 4594
Changes to src/shell.c
1475 if( db==0 || SQLITE_OK!=sqlite3_errcode(db) ){ 1475 if( db==0 || SQLITE_OK!=sqlite3_errcode(db) ){ 1476 fprintf(stderr,"Error: unable to open database \"%s\": %s\n", 1476 fprintf(stderr,"Error: unable to open database \"%s\": %s\n", 1477 p->zDbFilename, sqlite3_errmsg(db)); 1477 p->zDbFilename, sqlite3_errmsg(db)); 1478 exit(1); 1478 exit(1); 1479 } 1479 } 1480 #ifndef SQLITE_OMIT_LOAD_EXTENSION 1480 #ifndef SQLITE_OMIT_LOAD_EXTENSION 1481 sqlite3_enable_load_extension(p->db, 1); 1481 sqlite3_enable_load_extension(p->db, 1); > 1482 #endif > 1483 #ifdef SQLITE_ENABLE_REGEXP > 1484 { > 1485 extern int sqlite3_add_regexp_func(sqlite3*); > 1486 sqlite3_add_regexp_func(db); > 1487 } 1482 #endif 1488 #endif 1483 } 1489 } 1484 } 1490 } 1485 1491 1486 /* 1492 /* 1487 ** Do C-language style dequoting. 1493 ** Do C-language style dequoting. 1488 ** 1494 **
Changes to src/sqlite.h.in
1589 ** connection is opened. If it is globally disabled, filenames are 1589 ** connection is opened. If it is globally disabled, filenames are 1590 ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the 1590 ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the 1591 ** database connection is opened. By default, URI handling is globally 1591 ** database connection is opened. By default, URI handling is globally 1592 ** disabled. The default value may be changed by compiling with the 1592 ** disabled. The default value may be changed by compiling with the 1593 ** [SQLITE_USE_URI] symbol defined. 1593 ** [SQLITE_USE_URI] symbol defined. 1594 ** 1594 ** 1595 ** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN 1595 ** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN 1596 ** <dd> This option taks a single integer argument which is interpreted as | 1596 ** <dd> This option takes a single integer argument which is interpreted as 1597 ** a boolean in order to enable or disable the use of covering indices for 1597 ** a boolean in order to enable or disable the use of covering indices for 1598 ** full table scans in the query optimizer. The default setting is determined 1598 ** full table scans in the query optimizer. The default setting is determined 1599 ** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on" 1599 ** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on" 1600 ** if that compile-time option is omitted. 1600 ** if that compile-time option is omitted. 1601 ** The ability to disable the use of covering indices for full table scans 1601 ** The ability to disable the use of covering indices for full table scans 1602 ** is because some incorrectly coded legacy applications might malfunction 1602 ** is because some incorrectly coded legacy applications might malfunction 1603 ** malfunction when the optimization is enabled. Providing the ability to 1603 ** malfunction when the optimization is enabled. Providing the ability to
Changes to src/sqliteInt.h
1480 ** must be unique and what to do if they are not. When Index.onError=OE_None, 1480 ** must be unique and what to do if they are not. When Index.onError=OE_None, 1481 ** it means this is not a unique index. Otherwise it is a unique index 1481 ** it means this is not a unique index. Otherwise it is a unique index 1482 ** and the value of Index.onError indicate the which conflict resolution 1482 ** and the value of Index.onError indicate the which conflict resolution 1483 ** algorithm to employ whenever an attempt is made to insert a non-unique 1483 ** algorithm to employ whenever an attempt is made to insert a non-unique 1484 ** element. 1484 ** element. 1485 */ 1485 */ 1486 struct Index { 1486 struct Index { 1487 char *zName; /* Name of this index */ | 1487 char *zName; /* Name of this index */ 1488 int *aiColumn; /* Which columns are used by this index. 1st is 0 */ | 1488 int *aiColumn; /* Which columns are used by this index. 1st is 0 */ 1489 tRowcnt *aiRowEst; /* Result of ANALYZE: Est. rows selected by each column */ | 1489 tRowcnt *aiRowEst; /* From ANALYZE: Est. rows selected by each column */ 1490 Table *pTable; /* The SQL table being indexed */ | 1490 Table *pTable; /* The SQL table being indexed */ 1491 char *zColAff; /* String defining the affinity of each column */ | 1491 char *zColAff; /* String defining the affinity of each column */ 1492 Index *pNext; /* The next index associated with the same table */ | 1492 Index *pNext; /* The next index associated with the same table */ 1493 Schema *pSchema; /* Schema containing this index */ | 1493 Schema *pSchema; /* Schema containing this index */ 1494 u8 *aSortOrder; /* Array of size Index.nColumn. True==DESC, False==ASC */ | 1494 u8 *aSortOrder; /* for each column: True==DESC, False==ASC */ 1495 char **azColl; /* Array of collation sequence names for index */ | 1495 char **azColl; /* Array of collation sequence names for index */ 1496 int nColumn; /* Number of columns in the table used by this index */ < 1497 int tnum; /* Page containing root of this index in database file */ | 1496 int tnum; /* DB Page containing root of this index */ > 1497 u16 nColumn; /* Number of columns in table used by this index */ 1498 u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */ | 1498 u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */ 1499 u8 autoIndex; /* True if is automatically created (ex: by UNIQUE) */ | 1499 unsigned autoIndex:2; /* 1==UNIQUE, 2==PRIMARY KEY, 0==CREATE INDEX */ 1500 u8 bUnordered; /* Use this index for == or IN queries only */ | 1500 unsigned bUnordered:1; /* Use this index for == or IN queries only */ 1501 #ifdef SQLITE_ENABLE_STAT3 1501 #ifdef SQLITE_ENABLE_STAT3 1502 int nSample; /* Number of elements in aSample[] */ 1502 int nSample; /* Number of elements in aSample[] */ 1503 tRowcnt avgEq; /* Average nEq value for key values not in aSample */ 1503 tRowcnt avgEq; /* Average nEq value for key values not in aSample */ 1504 IndexSample *aSample; /* Samples of the left-most key */ 1504 IndexSample *aSample; /* Samples of the left-most key */ 1505 #endif 1505 #endif 1506 }; 1506 }; 1507 1507 ................................................................................................................................................................................ 1674 1674 1675 Expr *pLeft; /* Left subnode */ 1675 Expr *pLeft; /* Left subnode */ 1676 Expr *pRight; /* Right subnode */ 1676 Expr *pRight; /* Right subnode */ 1677 union { 1677 union { 1678 ExprList *pList; /* Function arguments or in "<expr> IN (<expr-list)" */ 1678 ExprList *pList; /* Function arguments or in "<expr> IN (<expr-list)" */ 1679 Select *pSelect; /* Used for sub-selects and "<expr> IN (<select>)" */ 1679 Select *pSelect; /* Used for sub-selects and "<expr> IN (<select>)" */ 1680 } x; 1680 } x; 1681 CollSeq *pColl; /* The collation type of the column or 0 */ < 1682 1681 1683 /* If the EP_Reduced flag is set in the Expr.flags mask, then no 1682 /* If the EP_Reduced flag is set in the Expr.flags mask, then no 1684 ** space is allocated for the fields below this point. An attempt to 1683 ** space is allocated for the fields below this point. An attempt to 1685 ** access them will result in a segfault or malfunction. 1684 ** access them will result in a segfault or malfunction. 1686 *********************************************************************/ 1685 *********************************************************************/ 1687 1686 1688 #if SQLITE_MAX_EXPR_DEPTH>0 1687 #if SQLITE_MAX_EXPR_DEPTH>0 ................................................................................................................................................................................ 1710 #define EP_Agg 0x0002 /* Contains one or more aggregate functions */ 1709 #define EP_Agg 0x0002 /* Contains one or more aggregate functions */ 1711 #define EP_Resolved 0x0004 /* IDs have been resolved to COLUMNs */ 1710 #define EP_Resolved 0x0004 /* IDs have been resolved to COLUMNs */ 1712 #define EP_Error 0x0008 /* Expression contains one or more errors */ 1711 #define EP_Error 0x0008 /* Expression contains one or more errors */ 1713 #define EP_Distinct 0x0010 /* Aggregate function with DISTINCT keyword */ 1712 #define EP_Distinct 0x0010 /* Aggregate function with DISTINCT keyword */ 1714 #define EP_VarSelect 0x0020 /* pSelect is correlated, not constant */ 1713 #define EP_VarSelect 0x0020 /* pSelect is correlated, not constant */ 1715 #define EP_DblQuoted 0x0040 /* token.z was originally in "..." */ 1714 #define EP_DblQuoted 0x0040 /* token.z was originally in "..." */ 1716 #define EP_InfixFunc 0x0080 /* True for an infix function: LIKE, GLOB, etc */ 1715 #define EP_InfixFunc 0x0080 /* True for an infix function: LIKE, GLOB, etc */ 1717 #define EP_ExpCollate 0x0100 /* Collating sequence specified explicitly */ | 1716 #define EP_Collate 0x0100 /* Tree contains a TK_COLLATE opeartor */ 1718 #define EP_FixedDest 0x0200 /* Result needed in a specific register */ 1717 #define EP_FixedDest 0x0200 /* Result needed in a specific register */ 1719 #define EP_IntValue 0x0400 /* Integer value contained in u.iValue */ 1718 #define EP_IntValue 0x0400 /* Integer value contained in u.iValue */ 1720 #define EP_xIsSelect 0x0800 /* x.pSelect is valid (otherwise x.pList is) */ 1719 #define EP_xIsSelect 0x0800 /* x.pSelect is valid (otherwise x.pList is) */ 1721 #define EP_Hint 0x1000 /* Not used */ 1720 #define EP_Hint 0x1000 /* Not used */ 1722 #define EP_Reduced 0x2000 /* Expr struct is EXPR_REDUCEDSIZE bytes only */ 1721 #define EP_Reduced 0x2000 /* Expr struct is EXPR_REDUCEDSIZE bytes only */ 1723 #define EP_TokenOnly 0x4000 /* Expr struct is EXPR_TOKENONLYSIZE bytes only */ 1722 #define EP_TokenOnly 0x4000 /* Expr struct is EXPR_TOKENONLYSIZE bytes only */ 1724 #define EP_Static 0x8000 /* Held in memory not obtained from malloc() */ 1723 #define EP_Static 0x8000 /* Held in memory not obtained from malloc() */ ................................................................................................................................................................................ 1768 /* 1767 /* 1769 ** A list of expressions. Each expression may optionally have a 1768 ** A list of expressions. Each expression may optionally have a 1770 ** name. An expr/name combination can be used in several ways, such 1769 ** name. An expr/name combination can be used in several ways, such 1771 ** as the list of "expr AS ID" fields following a "SELECT" or in the 1770 ** as the list of "expr AS ID" fields following a "SELECT" or in the 1772 ** list of "ID = expr" items in an UPDATE. A list of expressions can 1771 ** list of "ID = expr" items in an UPDATE. A list of expressions can 1773 ** also be used as the argument to a function, in which case the a.zName 1772 ** also be used as the argument to a function, in which case the a.zName 1774 ** field is not used. 1773 ** field is not used. > 1774 ** > 1775 ** By default the Expr.zSpan field holds a human-readable description of > 1776 ** the expression that is used in the generation of error messages and > 1777 ** column labels. In this case, Expr.zSpan is typically the text of a > 1778 ** column expression as it exists in a SELECT statement. However, if > 1779 ** the bSpanIsTab flag is set, then zSpan is overloaded to mean the name > 1780 ** of the result column in the form: DATABASE.TABLE.COLUMN. This later > 1781 ** form is used for name resolution with nested FROM clauses. 1775 */ 1782 */ 1776 struct ExprList { 1783 struct ExprList { 1777 int nExpr; /* Number of expressions on the list */ 1784 int nExpr; /* Number of expressions on the list */ 1778 int iECursor; /* VDBE Cursor associated with this ExprList */ 1785 int iECursor; /* VDBE Cursor associated with this ExprList */ 1779 struct ExprList_item { /* For each expression in the list */ 1786 struct ExprList_item { /* For each expression in the list */ 1780 Expr *pExpr; /* The list of expressions */ | 1787 Expr *pExpr; /* The list of expressions */ 1781 char *zName; /* Token associated with this expression */ | 1788 char *zName; /* Token associated with this expression */ 1782 char *zSpan; /* Original text of the expression */ | 1789 char *zSpan; /* Original text of the expression */ 1783 u8 sortOrder; /* 1 for DESC or 0 for ASC */ | 1790 u8 sortOrder; /* 1 for DESC or 0 for ASC */ 1784 u8 done; /* A flag to indicate when processing is finished */ | 1791 unsigned done :1; /* A flag to indicate when processing is finished */ > 1792 unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */ 1785 u16 iOrderByCol; /* For ORDER BY, column number in result set */ | 1793 u16 iOrderByCol; /* For ORDER BY, column number in result set */ 1786 u16 iAlias; /* Index into Parse.aAlias[] for zName */ | 1794 u16 iAlias; /* Index into Parse.aAlias[] for zName */ 1787 } *a; /* Alloc a power of two greater or equal to nExpr */ 1795 } *a; /* Alloc a power of two greater or equal to nExpr */ 1788 }; 1796 }; 1789 1797 1790 /* 1798 /* 1791 ** An instance of this structure is used by the parser to record both 1799 ** An instance of this structure is used by the parser to record both 1792 ** the parse tree for an expression and the span of input text for an 1800 ** the parse tree for an expression and the span of input text for an 1793 ** expression. 1801 ** expression. ................................................................................................................................................................................ 2099 #define SF_Aggregate 0x0004 /* Contains aggregate functions */ 2107 #define SF_Aggregate 0x0004 /* Contains aggregate functions */ 2100 #define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */ 2108 #define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */ 2101 #define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */ 2109 #define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */ 2102 #define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */ 2110 #define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */ 2103 #define SF_UseSorter 0x0040 /* Sort using a sorter */ 2111 #define SF_UseSorter 0x0040 /* Sort using a sorter */ 2104 #define SF_Values 0x0080 /* Synthesized from VALUES clause */ 2112 #define SF_Values 0x0080 /* Synthesized from VALUES clause */ 2105 #define SF_Materialize 0x0100 /* Force materialization of views */ 2113 #define SF_Materialize 0x0100 /* Force materialization of views */ > 2114 #define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */ 2106 2115 2107 2116 2108 /* 2117 /* 2109 ** The results of a select can be distributed in several ways. The 2118 ** The results of a select can be distributed in several ways. The 2110 ** "SRT" prefix means "SELECT Result Type". 2119 ** "SRT" prefix means "SELECT Result Type". 2111 */ 2120 */ 2112 #define SRT_Union 1 /* Store result as keys in an index */ 2121 #define SRT_Union 1 /* Store result as keys in an index */ ................................................................................................................................................................................ 2327 #define OPFLAG_APPEND 0x08 /* This is likely to be an append */ 2336 #define OPFLAG_APPEND 0x08 /* This is likely to be an append */ 2328 #define OPFLAG_USESEEKRESULT 0x10 /* Try to avoid a seek in BtreeInsert() */ 2337 #define OPFLAG_USESEEKRESULT 0x10 /* Try to avoid a seek in BtreeInsert() */ 2329 #define OPFLAG_CLEARCACHE 0x20 /* Clear pseudo-table cache in OP_Column */ 2338 #define OPFLAG_CLEARCACHE 0x20 /* Clear pseudo-table cache in OP_Column */ 2330 #define OPFLAG_LENGTHARG 0x40 /* OP_Column only used for length() */ 2339 #define OPFLAG_LENGTHARG 0x40 /* OP_Column only used for length() */ 2331 #define OPFLAG_TYPEOFARG 0x80 /* OP_Column only used for typeof() */ 2340 #define OPFLAG_TYPEOFARG 0x80 /* OP_Column only used for typeof() */ 2332 #define OPFLAG_BULKCSR 0x01 /* OP_Open** used to open bulk cursor */ 2341 #define OPFLAG_BULKCSR 0x01 /* OP_Open** used to open bulk cursor */ 2333 #define OPFLAG_P2ISREG 0x02 /* P2 to OP_Open** is a register number */ 2342 #define OPFLAG_P2ISREG 0x02 /* P2 to OP_Open** is a register number */ > 2343 #define OPFLAG_PERMUTE 0x01 /* OP_Compare: use the permutation */ 2334 2344 2335 /* 2345 /* 2336 * Each trigger present in the database schema is stored as an instance of 2346 * Each trigger present in the database schema is stored as an instance of 2337 * struct Trigger. 2347 * struct Trigger. 2338 * 2348 * 2339 * Pointers to instances of struct Trigger are stored in two ways. 2349 * Pointers to instances of struct Trigger are stored in two ways. 2340 * 1. In the "trigHash" hash table (part of the sqlite3* that represents the 2350 * 1. In the "trigHash" hash table (part of the sqlite3* that represents the ................................................................................................................................................................................ 2811 void sqlite3IdListDelete(sqlite3*, IdList*); 2821 void sqlite3IdListDelete(sqlite3*, IdList*); 2812 void sqlite3SrcListDelete(sqlite3*, SrcList*); 2822 void sqlite3SrcListDelete(sqlite3*, SrcList*); 2813 Index *sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*, 2823 Index *sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*, 2814 Token*, int, int); 2824 Token*, int, int); 2815 void sqlite3DropIndex(Parse*, SrcList*, int); 2825 void sqlite3DropIndex(Parse*, SrcList*, int); 2816 int sqlite3Select(Parse*, Select*, SelectDest*); 2826 int sqlite3Select(Parse*, Select*, SelectDest*); 2817 Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList*, 2827 Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList*, 2818 Expr*,ExprList*,int,Expr*,Expr*); | 2828 Expr*,ExprList*,u16,Expr*,Expr*); 2819 void sqlite3SelectDelete(sqlite3*, Select*); 2829 void sqlite3SelectDelete(sqlite3*, Select*); 2820 Table *sqlite3SrcListLookup(Parse*, SrcList*); 2830 Table *sqlite3SrcListLookup(Parse*, SrcList*); 2821 int sqlite3IsReadOnly(Parse*, Table*, int); 2831 int sqlite3IsReadOnly(Parse*, Table*, int); 2822 void sqlite3OpenTable(Parse*, int iCur, int iDb, Table*, int); 2832 void sqlite3OpenTable(Parse*, int iCur, int iDb, Table*, int); 2823 #if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY) 2833 #if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY) 2824 Expr *sqlite3LimitWhere(Parse *, SrcList *, Expr *, ExprList *, Expr *, Expr *, 2834 Expr *sqlite3LimitWhere(Parse *, SrcList *, Expr *, ExprList *, Expr *, Expr *, 2825 #endif 2835 #endif ................................................................................................................................................................................ 3019 u8 sqlite3HexToInt(int h); 3029 u8 sqlite3HexToInt(int h); 3020 int sqlite3TwoPartName(Parse *, Token *, Token *, Token **); 3030 int sqlite3TwoPartName(Parse *, Token *, Token *, Token **); 3021 const char *sqlite3ErrStr(int); 3031 const char *sqlite3ErrStr(int); 3022 int sqlite3ReadSchema(Parse *pParse); 3032 int sqlite3ReadSchema(Parse *pParse); 3023 CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char*,int); 3033 CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char*,int); 3024 CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName); 3034 CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName); 3025 CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr); 3035 CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr); 3026 Expr *sqlite3ExprSetColl(Expr*, CollSeq*); | 3036 Expr *sqlite3ExprAddCollateToken(Parse *pParse, Expr*, Token*); > 3037 Expr *sqlite3ExprAddCollateString(Parse*,Expr*,const char*); 3027 Expr *sqlite3ExprSetCollByToken(Parse *pParse, Expr*, Token*); | 3038 Expr *sqlite3ExprSkipCollate(Expr*); 3028 int sqlite3CheckCollSeq(Parse *, CollSeq *); 3039 int sqlite3CheckCollSeq(Parse *, CollSeq *); 3029 int sqlite3CheckObjectName(Parse *, const char *); 3040 int sqlite3CheckObjectName(Parse *, const char *); 3030 void sqlite3VdbeSetChanges(sqlite3 *, int); 3041 void sqlite3VdbeSetChanges(sqlite3 *, int); 3031 int sqlite3AddInt64(i64*,i64); 3042 int sqlite3AddInt64(i64*,i64); 3032 int sqlite3SubInt64(i64*,i64); 3043 int sqlite3SubInt64(i64*,i64); 3033 int sqlite3MulInt64(i64*,i64); 3044 int sqlite3MulInt64(i64*,i64); 3034 int sqlite3AbsInt32(int); 3045 int sqlite3AbsInt32(int); ................................................................................................................................................................................ 3067 void sqlite3AlterFunctions(void); 3078 void sqlite3AlterFunctions(void); 3068 void sqlite3AlterRenameTable(Parse*, SrcList*, Token*); 3079 void sqlite3AlterRenameTable(Parse*, SrcList*, Token*); 3069 int sqlite3GetToken(const unsigned char *, int *); 3080 int sqlite3GetToken(const unsigned char *, int *); 3070 void sqlite3NestedParse(Parse*, const char*, ...); 3081 void sqlite3NestedParse(Parse*, const char*, ...); 3071 void sqlite3ExpirePreparedStatements(sqlite3*); 3082 void sqlite3ExpirePreparedStatements(sqlite3*); 3072 int sqlite3CodeSubselect(Parse *, Expr *, int, int); 3083 int sqlite3CodeSubselect(Parse *, Expr *, int, int); 3073 void sqlite3SelectPrep(Parse*, Select*, NameContext*); 3084 void sqlite3SelectPrep(Parse*, Select*, NameContext*); > 3085 int sqlite3MatchSpanName(const char*, const char*, const char*, const char*); 3074 int sqlite3ResolveExprNames(NameContext*, Expr*); 3086 int sqlite3ResolveExprNames(NameContext*, Expr*); 3075 void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*); 3087 void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*); 3076 int sqlite3ResolveOrderGroupBy(Parse*, Select*, ExprList*, const char*); 3088 int sqlite3ResolveOrderGroupBy(Parse*, Select*, ExprList*, const char*); 3077 void sqlite3ColumnDefault(Vdbe *, Table *, int, int); 3089 void sqlite3ColumnDefault(Vdbe *, Table *, int, int); 3078 void sqlite3AlterFinishAddColumn(Parse *, Token *); 3090 void sqlite3AlterFinishAddColumn(Parse *, Token *); 3079 void sqlite3AlterBeginAddColumn(Parse *, SrcList *); 3091 void sqlite3AlterBeginAddColumn(Parse *, SrcList *); 3080 CollSeq *sqlite3GetCollSeq(Parse*, u8, CollSeq *, const char*); 3092 CollSeq *sqlite3GetCollSeq(Parse*, u8, CollSeq *, const char*); ................................................................................................................................................................................ 3205 #define sqlite3FkCheck(a,b,c,d) 3217 #define sqlite3FkCheck(a,b,c,d) 3206 #define sqlite3FkDropTable(a,b,c) 3218 #define sqlite3FkDropTable(a,b,c) 3207 #define sqlite3FkOldmask(a,b) 0 3219 #define sqlite3FkOldmask(a,b) 0 3208 #define sqlite3FkRequired(a,b,c,d) 0 3220 #define sqlite3FkRequired(a,b,c,d) 0 3209 #endif 3221 #endif 3210 #ifndef SQLITE_OMIT_FOREIGN_KEY 3222 #ifndef SQLITE_OMIT_FOREIGN_KEY 3211 void sqlite3FkDelete(sqlite3 *, Table*); 3223 void sqlite3FkDelete(sqlite3 *, Table*); > 3224 int sqlite3FkLocateIndex(Parse*,Table*,FKey*,Index**,int**); 3212 #else 3225 #else 3213 #define sqlite3FkDelete(a,b) 3226 #define sqlite3FkDelete(a,b) > 3227 #define sqlite3FkLocateIndex(a,b,c,d,e) 3214 #endif 3228 #endif 3215 3229 3216 3230 3217 /* 3231 /* 3218 ** Available fault injectors. Should be numbered beginning with 0. 3232 ** Available fault injectors. Should be numbered beginning with 0. 3219 */ 3233 */ 3220 #define SQLITE_FAULTINJECTOR_MALLOC 0 3234 #define SQLITE_FAULTINJECTOR_MALLOC 0
Changes to src/tclsqlite.c
3680 extern int Sqlitetestrtree_Init(Tcl_Interp*); 3680 extern int Sqlitetestrtree_Init(Tcl_Interp*); 3681 extern int Sqlitequota_Init(Tcl_Interp*); 3681 extern int Sqlitequota_Init(Tcl_Interp*); 3682 extern int Sqlitemultiplex_Init(Tcl_Interp*); 3682 extern int Sqlitemultiplex_Init(Tcl_Interp*); 3683 extern int SqliteSuperlock_Init(Tcl_Interp*); 3683 extern int SqliteSuperlock_Init(Tcl_Interp*); 3684 extern int SqlitetestSyscall_Init(Tcl_Interp*); 3684 extern int SqlitetestSyscall_Init(Tcl_Interp*); 3685 extern int Sqlitetestfuzzer_Init(Tcl_Interp*); 3685 extern int Sqlitetestfuzzer_Init(Tcl_Interp*); 3686 extern int Sqlitetestwholenumber_Init(Tcl_Interp*); 3686 extern int Sqlitetestwholenumber_Init(Tcl_Interp*); > 3687 extern int Sqlitetestregexp_Init(Tcl_Interp*); 3687 3688 3688 #if defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4) 3689 #if defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4) 3689 extern int Sqlitetestfts3_Init(Tcl_Interp *interp); 3690 extern int Sqlitetestfts3_Init(Tcl_Interp *interp); 3690 #endif 3691 #endif 3691 3692 3692 #ifdef SQLITE_ENABLE_ZIPVFS 3693 #ifdef SQLITE_ENABLE_ZIPVFS 3693 extern int Zipvfs_Init(Tcl_Interp*); 3694 extern int Zipvfs_Init(Tcl_Interp*); ................................................................................................................................................................................ 3723 Sqlitetestrtree_Init(interp); 3724 Sqlitetestrtree_Init(interp); 3724 Sqlitequota_Init(interp); 3725 Sqlitequota_Init(interp); 3725 Sqlitemultiplex_Init(interp); 3726 Sqlitemultiplex_Init(interp); 3726 SqliteSuperlock_Init(interp); 3727 SqliteSuperlock_Init(interp); 3727 SqlitetestSyscall_Init(interp); 3728 SqlitetestSyscall_Init(interp); 3728 Sqlitetestfuzzer_Init(interp); 3729 Sqlitetestfuzzer_Init(interp); 3729 Sqlitetestwholenumber_Init(interp); 3730 Sqlitetestwholenumber_Init(interp); > 3731 Sqlitetestregexp_Init(interp); 3730 3732 3731 #if defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4) 3733 #if defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4) 3732 Sqlitetestfts3_Init(interp); 3734 Sqlitetestfts3_Init(interp); 3733 #endif 3735 #endif 3734 3736 3735 Tcl_CreateObjCommand( 3737 Tcl_CreateObjCommand( 3736 interp, "load_testfixture_extensions", init_all_cmd, 0, 0 3738 interp, "load_testfixture_extensions", init_all_cmd, 0, 0
Added src/test_regexp.c
> 1 /* > 2 ** 2012-11-13 > 3 ** > 4 ** The author disclaims copyright to this source code. In place of > 5 ** a legal notice, here is a blessing: > 6 ** > 7 ** May you do good and not evil. > 8 ** May you find forgiveness for yourself and forgive others. > 9 ** May you share freely, never taking more than you give. > 10 ** > 11 ****************************************************************************** > 12 ** > 13 ** The code in this file implements a compact but reasonably > 14 ** efficient regular-expression matcher for posix extended regular > 15 ** expressions against UTF8 text. The following syntax is supported: > 16 ** > 17 ** X* zero or more occurrences of X > 18 ** X+ one or more occurrences of X > 19 ** X? zero or one occurrences of X > 20 ** X{p,q} between p and q occurrences of X > 21 ** (X) match X > 22 ** X|Y X or Y > 23 ** ^X X occurring at the beginning of the string > 24 ** X$ X occurring at the end of the string > 25 ** . Match any single character > 26 ** \c Character c where c is one of \{}()[]|*+?. > 27 ** \c C-language escapes for c in afnrtv. ex: \t or \n > 28 ** \uXXXX Where XXXX is exactly 4 hex digits, unicode value XXXX > 29 ** \xXXX Where XXX is any number of hex digits, unicode value XXX > 30 ** [abc] Any single character from the set abc > 31 ** [^abc] Any single character not in the set abc > 32 ** [a-z] Any single character in the range a-z > 33 ** [^a-z] Any single character not in the range a-z > 34 ** \b Word boundary > 35 ** \w Word character. [A-Za-z0-9_] > 36 ** \W Non-word character > 37 ** \d Digit > 38 ** \D Non-digit > 39 ** \s Whitespace character > 40 ** \S Non-whitespace character > 41 ** > 42 ** A nondeterministic finite automaton (NFA) is used for matching, so the > 43 ** performance is bounded by O(N*M) where N is the size of the regular > 44 ** expression and M is the size of the input string. The matcher never > 45 ** exhibits exponential behavior. Note that the X{p,q} operator expands > 46 ** to p copies of X following by q-p copies of X? and that the size of the > 47 ** regular expression in the O(N*M) performance bound is computed after > 48 ** this expansion. > 49 */ > 50 #include <string.h> > 51 #include <stdlib.h> > 52 #include "sqlite3.h" > 53 > 54 /* The end-of-input character */ > 55 #define RE_EOF 0 /* End of input */ > 56 > 57 /* The NFA is implemented as sequence of opcodes taken from the following > 58 ** set. Each opcode has a single integer argument. > 59 */ > 60 #define RE_OP_MATCH 1 /* Match the one character in the argument */ > 61 #define RE_OP_ANY 2 /* Match any one character. (Implements ".") */ > 62 #define RE_OP_ANYSTAR 3 /* Special optimized version of .* */ > 63 #define RE_OP_FORK 4 /* Continue to both next and opcode at iArg */ > 64 #define RE_OP_GOTO 5 /* Jump to opcode at iArg */ > 65 #define RE_OP_ACCEPT 6 /* Halt and indicate a successful match */ > 66 #define RE_OP_CC_INC 7 /* Beginning of a [...] character class */ > 67 #define RE_OP_CC_EXC 8 /* Beginning of a [^...] character class */ > 68 #define RE_OP_CC_VALUE 9 /* Single value in a character class */ > 69 #define RE_OP_CC_RANGE 10 /* Range of values in a character class */ > 70 #define RE_OP_WORD 11 /* Perl word character [A-Za-z0-9_] */ > 71 #define RE_OP_NOTWORD 12 /* Not a perl word character */ > 72 #define RE_OP_DIGIT 13 /* digit: [0-9] */ > 73 #define RE_OP_NOTDIGIT 14 /* Not a digit */ > 74 #define RE_OP_SPACE 15 /* space: [ \t\n\r\v\f] */ > 75 #define RE_OP_NOTSPACE 16 /* Not a digit */ > 76 #define RE_OP_BOUNDARY 17 /* Boundary between word and non-word */ > 77 > 78 /* Each opcode is a "state" in the NFA */ > 79 typedef unsigned short ReStateNumber; > 80 > 81 /* Because this is an NFA and not a DFA, multiple states can be active at > 82 ** once. An instance of the following object records all active states in > 83 ** the NFA. The implementation is optimized for the common case where the > 84 ** number of actives states is small. > 85 */ > 86 typedef struct ReStateSet { > 87 unsigned nState; /* Number of current states */ > 88 ReStateNumber *aState; /* Current states */ > 89 } ReStateSet; > 90 > 91 /* An input string read one character at a time. > 92 */ > 93 typedef struct ReInput ReInput; > 94 struct ReInput { > 95 const unsigned char *z; /* All text */ > 96 int i; /* Next byte to read */ > 97 int mx; /* EOF when i>=mx */ > 98 }; > 99 > 100 /* A compiled NFA (or an NFA that is in the process of being compiled) is > 101 ** an instance of the following object. > 102 */ > 103 typedef struct ReCompiled ReCompiled; > 104 struct ReCompiled { > 105 ReInput sIn; /* Regular expression text */ > 106 const char *zErr; /* Error message to return */ > 107 char *aOp; /* Operators for the virtual machine */ > 108 int *aArg; /* Arguments to each operator */ > 109 unsigned (*xNextChar)(ReInput*); /* Next character function */ > 110 char zInit[12]; /* Initial text to match */ > 111 int nInit; /* Number of characters in zInit */ > 112 unsigned nState; /* Number of entries in aOp[] and aArg[] */ > 113 unsigned nAlloc; /* Slots allocated for aOp[] and aArg[] */ > 114 }; > 115 > 116 /* Add a state to the given state set if it is not already there */ > 117 static void re_add_state(ReStateSet *pSet, int newState){ > 118 unsigned i; > 119 for(i=0; i<pSet->nState; i++) if( pSet->aState[i]==newState ) return; > 120 pSet->aState[pSet->nState++] = newState; > 121 } > 122 > 123 /* Extract the next unicode character from *pzIn and return it. Advance > 124 ** *pzIn to the first byte past the end of the character returned. To > 125 ** be clear: this routine converts utf8 to unicode. This routine is > 126 ** optimized for the common case where the next character is a single byte. > 127 */ > 128 static unsigned re_next_char(ReInput *p){ > 129 unsigned c; > 130 if( p->i>=p->mx ) return 0; > 131 c = p->z[p->i++]; > 132 if( c>=0x80 ){ > 133 if( (c&0xe0)==0xc0 && p->i<p->mx && (p->z[p->i]&0xc0)==0x80 ){ > 134 c = (c&0x1f)<<6 | (p->z[p->i++]&0x3f); > 135 if( c<0x80 ) c = 0xfffd; > 136 }else if( (c&0xf0)==0xe0 && p->i+1<p->mx && (p->z[p->i]&0xc0)==0x80 > 137 && (p->z[p->i+1]&0xc0)==0x80 ){ > 138 c = (c&0x0f)<<12 | ((p->z[p->i]&0x3f)<<6) | (p->z[p->i+1]&0x3f); > 139 p->i += 2; > 140 if( c<=0x3ff || (c>=0xd800 && c<=0xdfff) ) c = 0xfffd; > 141 }else if( (c&0xf8)==0xf0 && p->i+3<p->mx && (p->z[p->i]&0xc0)==0x80 > 142 && (p->z[p->i+1]&0xc0)==0x80 && (p->z[p->i+2]&0xc0)==0x80 ){ > 143 c = (c&0x07)<<18 | ((p->z[p->i]&0x3f)<<12) | ((p->z[p->i+1]&0x3f)<<6) > 144 | (p->z[p->i+2]&0x3f); > 145 p->i += 3; > 146 if( c<=0xffff || c>0x10ffff ) c = 0xfffd; > 147 }else{ > 148 c = 0xfffd; > 149 } > 150 } > 151 return c; > 152 } > 153 static unsigned re_next_char_nocase(ReInput *p){ > 154 unsigned c = re_next_char(p); > 155 if( c>='A' && c<='Z' ) c += 'a' - 'A'; > 156 return c; > 157 } > 158 > 159 /* Return true if c is a perl "word" character: [A-Za-z0-9_] */ > 160 static int re_word_char(int c){ > 161 return (c>='0' && c<='9') || (c>='a' && c<='z') > 162 || (c>='A' && c<='Z') || c=='_'; > 163 } > 164 > 165 /* Return true if c is a "digit" character: [0-9] */ > 166 static int re_digit_char(int c){ > 167 return (c>='0' && c<='9'); > 168 } > 169 > 170 /* Return true if c is a perl "space" character: [ \t\r\n\v\f] */ > 171 static int re_space_char(int c){ > 172 return c==' ' || c=='\t' || c=='\n' || c=='\r' || c=='\v' || c=='\f'; > 173 } > 174 > 175 /* Run a compiled regular expression on the zero-terminated input > 176 ** string zIn[]. Return true on a match and false if there is no match. > 177 */ > 178 int re_match(ReCompiled *pRe, const unsigned char *zIn, int nIn){ > 179 ReStateSet aStateSet[2], *pThis, *pNext; > 180 ReStateNumber aSpace[100]; > 181 ReStateNumber *pToFree; > 182 unsigned int i = 0; > 183 unsigned int iSwap = 0; > 184 int c = RE_EOF+1; > 185 int cPrev = 0; > 186 int rc = 0; > 187 ReInput in; > 188 > 189 in.z = zIn; > 190 in.i = 0; > 191 in.mx = nIn>=0 ? nIn : strlen((char const*)zIn); > 192 > 193 /* Look for the initial prefix match, if there is one. */ > 194 if( pRe->nInit ){ > 195 unsigned char x = pRe->zInit[0]; > 196 while( in.i+pRe->nInit<=in.mx > 197 && (zIn[in.i]!=x || memcmp(zIn+in.i, pRe->zInit, pRe->nInit)!=0) > 198 ){ > 199 in.i++; > 200 } > 201 if( in.i+pRe->nInit>in.mx ) return 0; > 202 } > 203 > 204 if( pRe->nState<=(sizeof(aSpace)/(sizeof(aSpace[0])*2)) ){ > 205 pToFree = 0; > 206 aStateSet[0].aState = aSpace; > 207 }else{ > 208 pToFree = sqlite3_malloc( sizeof(ReStateNumber)*2*pRe->nState ); > 209 if( pToFree==0 ) return -1; > 210 aStateSet[0].aState = pToFree; > 211 } > 212 aStateSet[1].aState = &aStateSet[0].aState[pRe->nState]; > 213 pNext = &aStateSet[1]; > 214 pNext->nState = 0; > 215 re_add_state(pNext, 0); > 216 while( c!=RE_EOF && pNext->nState>0 ){ > 217 cPrev = c; > 218 c = pRe->xNextChar(&in); > 219 pThis = pNext; > 220 pNext = &aStateSet[iSwap]; > 221 iSwap = 1 - iSwap; > 222 pNext->nState = 0; > 223 for(i=0; i<pThis->nState; i++){ > 224 int x = pThis->aState[i]; > 225 switch( pRe->aOp[x] ){ > 226 case RE_OP_MATCH: { > 227 if( pRe->aArg[x]==c ) re_add_state(pNext, x+1); > 228 break; > 229 } > 230 case RE_OP_ANY: { > 231 re_add_state(pNext, x+1); > 232 break; > 233 } > 234 case RE_OP_WORD: { > 235 if( re_word_char(c) ) re_add_state(pNext, x+1); > 236 break; > 237 } > 238 case RE_OP_NOTWORD: { > 239 if( !re_word_char(c) ) re_add_state(pNext, x+1); > 240 break; > 241 } > 242 case RE_OP_DIGIT: { > 243 if( re_digit_char(c) ) re_add_state(pNext, x+1); > 244 break; > 245 } > 246 case RE_OP_NOTDIGIT: { > 247 if( !re_digit_char(c) ) re_add_state(pNext, x+1); > 248 break; > 249 } > 250 case RE_OP_SPACE: { > 251 if( re_space_char(c) ) re_add_state(pNext, x+1); > 252 break; > 253 } > 254 case RE_OP_NOTSPACE: { > 255 if( !re_space_char(c) ) re_add_state(pNext, x+1); > 256 break; > 257 } > 258 case RE_OP_BOUNDARY: { > 259 if( re_word_char(c)!=re_word_char(cPrev) ) re_add_state(pThis, x+1); > 260 break; > 261 } > 262 case RE_OP_ANYSTAR: { > 263 re_add_state(pNext, x); > 264 re_add_state(pThis, x+1); > 265 break; > 266 } > 267 case RE_OP_FORK: { > 268 re_add_state(pThis, x+pRe->aArg[x]); > 269 re_add_state(pThis, x+1); > 270 break; > 271 } > 272 case RE_OP_GOTO: { > 273 re_add_state(pThis, x+pRe->aArg[x]); > 274 break; > 275 } > 276 case RE_OP_ACCEPT: { > 277 rc = 1; > 278 goto re_match_end; > 279 } > 280 case RE_OP_CC_INC: > 281 case RE_OP_CC_EXC: { > 282 int j = 1; > 283 int n = pRe->aArg[x]; > 284 int hit = 0; > 285 for(j=1; j>0 && j<n; j++){ > 286 if( pRe->aOp[x+j]==RE_OP_CC_VALUE ){ > 287 if( pRe->aArg[x+j]==c ){ > 288 hit = 1; > 289 j = -1; > 290 } > 291 }else{ > 292 if( pRe->aArg[x+j]<=c && pRe->aArg[x+j+1]>=c ){ > 293 hit = 1; > 294 j = -1; > 295 }else{ > 296 j++; > 297 } > 298 } > 299 } > 300 if( pRe->aOp[x]==RE_OP_CC_EXC ) hit = !hit; > 301 if( hit ) re_add_state(pNext, x+n); > 302 break; > 303 } > 304 } > 305 } > 306 } > 307 for(i=0; i<pNext->nState; i++){ > 308 if( pRe->aOp[pNext->aState[i]]==RE_OP_ACCEPT ){ rc = 1; break; } > 309 } > 310 re_match_end: > 311 sqlite3_free(pToFree); > 312 return rc; > 313 } > 314 > 315 /* Resize the opcode and argument arrays for an RE under construction. > 316 */ > 317 static int re_resize(ReCompiled *p, int N){ > 318 char *aOp; > 319 int *aArg; > 320 aOp = sqlite3_realloc(p->aOp, N*sizeof(p->aOp[0])); > 321 if( aOp==0 ) return 1; > 322 p->aOp = aOp; > 323 aArg = sqlite3_realloc(p->aArg, N*sizeof(p->aArg[0])); > 324 if( aArg==0 ) return 1; > 325 p->aArg = aArg; > 326 p->nAlloc = N; > 327 return 0; > 328 } > 329 > 330 /* Insert a new opcode and argument into an RE under construction. The > 331 ** insertion point is just prior to existing opcode iBefore. > 332 */ > 333 static int re_insert(ReCompiled *p, int iBefore, int op, int arg){ > 334 int i; > 335 if( p->nAlloc<=p->nState && re_resize(p, p->nAlloc*2) ) return 0; > 336 for(i=p->nState; i>iBefore; i--){ > 337 p->aOp[i] = p->aOp[i-1]; > 338 p->aArg[i] = p->aArg[i-1]; > 339 } > 340 p->nState++; > 341 p->aOp[iBefore] = op; > 342 p->aArg[iBefore] = arg; > 343 return iBefore; > 344 } > 345 > 346 /* Append a new opcode and argument to the end of the RE under construction. > 347 */ > 348 static int re_append(ReCompiled *p, int op, int arg){ > 349 return re_insert(p, p->nState, op, arg); > 350 } > 351 > 352 /* Make a copy of N opcodes starting at iStart onto the end of the RE > 353 ** under construction. > 354 */ > 355 static void re_copy(ReCompiled *p, int iStart, int N){ > 356 if( p->nState+N>=p->nAlloc && re_resize(p, p->nAlloc*2+N) ) return; > 357 memcpy(&p->aOp[p->nState], &p->aOp[iStart], N*sizeof(p->aOp[0])); > 358 memcpy(&p->aArg[p->nState], &p->aArg[iStart], N*sizeof(p->aArg[0])); > 359 p->nState += N; > 360 } > 361 > 362 /* Return true if c is a hexadecimal digit character: [0-9a-fA-F] > 363 ** If c is a hex digit, also set *pV = (*pV)*16 + valueof(c). If > 364 ** c is not a hex digit *pV is unchanged. > 365 */ > 366 static int re_hex(int c, int *pV){ > 367 if( c>='0' && c<='9' ){ > 368 c -= '0'; > 369 }else if( c>='a' && c<='f' ){ > 370 c -= 'a' - 10; > 371 }else if( c>='A' && c<='F' ){ > 372 c -= 'A' - 10; > 373 }else{ > 374 return 0; > 375 } > 376 *pV = (*pV)*16 + (c & 0xff); > 377 return 1; > 378 } > 379 > 380 /* A backslash character has been seen, read the next character and > 381 ** return its intepretation. > 382 */ > 383 static unsigned re_esc_char(ReCompiled *p){ > 384 static const char zEsc[] = "afnrtv\\()*.+?[$^{|}]"; > 385 static const char zTrans[] = "\a\f\n\r\t\v"; > 386 int i, v = 0; > 387 char c; > 388 if( p->sIn.i>=p->sIn.mx ) return 0; > 389 c = p->sIn.z[p->sIn.i]; > 390 if( c=='u' && p->sIn.i+5<p->sIn.mx ){ > 391 const unsigned char *zIn = p->sIn.z + p->sIn.i; > 392 v = 0; > 393 if( re_hex(zIn[1],&v) > 394 && re_hex(zIn[2],&v) > 395 && re_hex(zIn[3],&v) > 396 && re_hex(zIn[4],&v) > 397 ){ > 398 p->sIn.i += 5; > 399 return v; > 400 } > 401 } > 402 if( c=='x' ){ > 403 v = 0; > 404 for(i=1; p->sIn.i<p->sIn.mx && re_hex(p->sIn.z[p->sIn.i+i], &v); i++){} > 405 if( i>1 ){ > 406 p->sIn.i += i; > 407 return v; > 408 } > 409 } > 410 for(i=0; zEsc[i] && zEsc[i]!=c; i++){} > 411 if( zEsc[i] ){ > 412 if( i<6 ) c = zTrans[i]; > 413 p->sIn.i++; > 414 }else{ > 415 p->zErr = "unknown \\ escape"; > 416 } > 417 return c; > 418 } > 419 > 420 /* Forward declaration */ > 421 static const char *re_subcompile_string(ReCompiled*); > 422 > 423 /* Peek at the next byte of input */ > 424 static unsigned char rePeek(ReCompiled *p){ > 425 return p->sIn.i<p->sIn.mx ? p->sIn.z[p->sIn.i] : 0; > 426 } > 427 > 428 /* Compile RE text into a sequence of opcodes. Continue up to the > 429 ** first unmatched ")" character, then return. If an error is found, > 430 ** return a pointer to the error message string. > 431 */ > 432 static const char *re_subcompile_re(ReCompiled *p){ > 433 const char *zErr; > 434 int iStart, iEnd, iGoto; > 435 iStart = p->nState; > 436 zErr = re_subcompile_string(p); > 437 if( zErr ) return zErr; > 438 while( rePeek(p)=='|' ){ > 439 iEnd = p->nState; > 440 re_insert(p, iStart, RE_OP_FORK, iEnd + 2 - iStart); > 441 iGoto = re_append(p, RE_OP_GOTO, 0); > 442 p->sIn.i++; > 443 zErr = re_subcompile_string(p); > 444 if( zErr ) return zErr; > 445 p->aArg[iGoto] = p->nState - iGoto; > 446 } > 447 return 0; > 448 } > 449 > 450 /* Compile an element of regular expression text (anything that can be > 451 ** an operand to the "|" operator). Return NULL on success or a pointer > 452 ** to the error message if there is a problem. > 453 */ > 454 static const char *re_subcompile_string(ReCompiled *p){ > 455 int iPrev = -1; > 456 int iStart; > 457 unsigned c; > 458 const char *zErr; > 459 while( (c = p->xNextChar(&p->sIn))!=0 ){ > 460 iStart = p->nState; > 461 switch( c ){ > 462 case '|': > 463 case '$': > 464 case ')': { > 465 p->sIn.i--; > 466 return 0; > 467 } > 468 case '(': { > 469 zErr = re_subcompile_re(p); > 470 if( zErr ) return zErr; > 471 if( rePeek(p)!=')' ) return "unmatched '('"; > 472 p->sIn.i++; > 473 break; > 474 } > 475 case '.': { > 476 if( rePeek(p)=='*' ){ > 477 re_append(p, RE_OP_ANYSTAR, 0); > 478 p->sIn.i++; > 479 }else{ > 480 re_append(p, RE_OP_ANY, 0); > 481 } > 482 break; > 483 } > 484 case '*': { > 485 if( iPrev<0 ) return "'*' without operand"; > 486 re_insert(p, iPrev, RE_OP_GOTO, p->nState - iPrev + 1); > 487 re_append(p, RE_OP_FORK, iPrev - p->nState + 1); > 488 break; > 489 } > 490 case '+': { > 491 if( iPrev<0 ) return "'+' without operand"; > 492 re_append(p, RE_OP_FORK, iPrev - p->nState); > 493 break; > 494 } > 495 case '?': { > 496 if( iPrev<0 ) return "'?' without operand"; > 497 re_insert(p, iPrev, RE_OP_FORK, p->nState - iPrev+1); > 498 break; > 499 } > 500 case '{': { > 501 int m = 0, n = 0; > 502 int sz, j; > 503 if( iPrev<0 ) return "'{m,n}' without operand"; > 504 while( (c=rePeek(p))>='0' && c<='9' ){ m = m*10 + c - '0'; p->sIn.i++; } > 505 n = m; > 506 if( c==',' ){ > 507 p->sIn.i++; > 508 n = 0; > 509 while( (c=rePeek(p))>='0' && c<='9' ){ n = n*10 + c-'0'; p->sIn.i++; } > 510 } > 511 if( c!='}' ) return "unmatched '{'"; > 512 if( n>0 && n<m ) return "n less than m in '{m,n}'"; > 513 p->sIn.i++; > 514 sz = p->nState - iPrev; > 515 if( m==0 ){ > 516 if( n==0 ) return "both m and n are zero in '{m,n}'"; > 517 re_insert(p, iPrev, RE_OP_FORK, sz+1); > 518 n--; > 519 }else{ > 520 for(j=1; j<m; j++) re_copy(p, iPrev, sz); > 521 } > 522 for(j=m; j<n; j++){ > 523 re_append(p, RE_OP_FORK, sz+1); > 524 re_copy(p, iPrev, sz); > 525 } > 526 if( n==0 && m>0 ){ > 527 re_append(p, RE_OP_FORK, -sz); > 528 } > 529 break; > 530 } > 531 case '[': { > 532 int iFirst = p->nState; > 533 if( rePeek(p)=='^' ){ > 534 re_append(p, RE_OP_CC_EXC, 0); > 535 p->sIn.i++; > 536 }else{ > 537 re_append(p, RE_OP_CC_INC, 0); > 538 } > 539 while( (c = p->xNextChar(&p->sIn))!=0 ){ > 540 if( c=='[' && rePeek(p)==':' ){ > 541 return "POSIX character classes not supported"; > 542 } > 543 if( c=='\\' ) c = re_esc_char(p); > 544 if( rePeek(p)=='-' ){ > 545 re_append(p, RE_OP_CC_RANGE, c); > 546 p->sIn.i++; > 547 c = p->xNextChar(&p->sIn); > 548 if( c=='\\' ) c = re_esc_char(p); > 549 re_append(p, RE_OP_CC_RANGE, c); > 550 }else{ > 551 re_append(p, RE_OP_CC_VALUE, c); > 552 } > 553 if( rePeek(p)==']' ){ p->sIn.i++; break; } > 554 } > 555 if( c==0 ) return "unclosed '['"; > 556 p->aArg[iFirst] = p->nState - iFirst; > 557 break; > 558 } > 559 case '\\': { > 560 int specialOp = 0; > 561 switch( rePeek(p) ){ > 562 case 'b': specialOp = RE_OP_BOUNDARY; break; > 563 case 'd': specialOp = RE_OP_DIGIT; break; > 564 case 'D': specialOp = RE_OP_NOTDIGIT; break; > 565 case 's': specialOp = RE_OP_SPACE; break; > 566 case 'S': specialOp = RE_OP_NOTSPACE; break; > 567 case 'w': specialOp = RE_OP_WORD; break; > 568 case 'W': specialOp = RE_OP_NOTWORD; break; > 569 } > 570 if( specialOp ){ > 571 p->sIn.i++; > 572 re_append(p, specialOp, 0); > 573 }else{ > 574 c = re_esc_char(p); > 575 re_append(p, RE_OP_MATCH, c); > 576 } > 577 break; > 578 } > 579 default: { > 580 re_append(p, RE_OP_MATCH, c); > 581 break; > 582 } > 583 } > 584 iPrev = iStart; > 585 } > 586 return 0; > 587 } > 588 > 589 /* Free and reclaim all the memory used by a previously compiled > 590 ** regular expression. Applications should invoke this routine once > 591 ** for every call to re_compile() to avoid memory leaks. > 592 */ > 593 void re_free(ReCompiled *pRe){ > 594 if( pRe ){ > 595 sqlite3_free(pRe->aOp); > 596 sqlite3_free(pRe->aArg); > 597 sqlite3_free(pRe); > 598 } > 599 } > 600 > 601 /* > 602 ** Compile a textual regular expression in zIn[] into a compiled regular > 603 ** expression suitable for us by re_match() and return a pointer to the > 604 ** compiled regular expression in *ppRe. Return NULL on success or an > 605 ** error message if something goes wrong. > 606 */ > 607 const char *re_compile(ReCompiled **ppRe, const char *zIn, int noCase){ > 608 ReCompiled *pRe; > 609 const char *zErr; > 610 int i, j; > 611 > 612 *ppRe = 0; > 613 pRe = sqlite3_malloc( sizeof(*pRe) ); > 614 if( pRe==0 ){ > 615 return "out of memory"; > 616 } > 617 memset(pRe, 0, sizeof(*pRe)); > 618 pRe->xNextChar = noCase ? re_next_char_nocase : re_next_char; > 619 if( re_resize(pRe, 30) ){ > 620 re_free(pRe); > 621 return "out of memory"; > 622 } > 623 if( zIn[0]=='^' ){ > 624 zIn++; > 625 }else{ > 626 re_append(pRe, RE_OP_ANYSTAR, 0); > 627 } > 628 pRe->sIn.z = (unsigned char*)zIn; > 629 pRe->sIn.i = 0; > 630 pRe->sIn.mx = strlen(zIn); > 631 zErr = re_subcompile_re(pRe); > 632 if( zErr ){ > 633 re_free(pRe); > 634 return zErr; > 635 } > 636 if( rePeek(pRe)=='$' && pRe->sIn.i+1>=pRe->sIn.mx ){ > 637 re_append(pRe, RE_OP_MATCH, RE_EOF); > 638 re_append(pRe, RE_OP_ACCEPT, 0); > 639 *ppRe = pRe; > 640 }else if( pRe->sIn.i>=pRe->sIn.mx ){ > 641 re_append(pRe, RE_OP_ACCEPT, 0); > 642 *ppRe = pRe; > 643 }else{ > 644 re_free(pRe); > 645 return "unrecognized character"; > 646 } > 647 > 648 /* The following is a performance optimization. If the regex begins with > 649 ** ".*" (if the input regex lacks an initial "^") and afterwards there are > 650 ** one or more matching characters, enter those matching characters into > 651 ** zInit[]. The re_match() routine can then search ahead in the input > 652 ** string looking for the initial match without having to run the whole > 653 ** regex engine over the string. Do not worry able trying to match > 654 ** unicode characters beyond plane 0 - those are very rare and this is > 655 ** just an optimization. */ > 656 if( pRe->aOp[0]==RE_OP_ANYSTAR ){ > 657 for(j=0, i=1; j<sizeof(pRe->zInit)-2 && pRe->aOp[i]==RE_OP_MATCH; i++){ > 658 unsigned x = pRe->aArg[i]; > 659 if( x<=127 ){ > 660 pRe->zInit[j++] = x; > 661 }else if( x<=0xfff ){ > 662 pRe->zInit[j++] = 0xc0 | (x>>6); > 663 pRe->zInit[j++] = 0x80 | (x&0x3f); > 664 }else if( x<=0xffff ){ > 665 pRe->zInit[j++] = 0xd0 | (x>>12); > 666 pRe->zInit[j++] = 0x80 | ((x>>6)&0x3f); > 667 pRe->zInit[j++] = 0x80 | (x&0x3f); > 668 }else{ > 669 break; > 670 } > 671 } > 672 if( j>0 && pRe->zInit[j-1]==0 ) j--; > 673 pRe->nInit = j; > 674 } > 675 return pRe->zErr; > 676 } > 677 > 678 /* > 679 ** Implementation of the regexp() SQL function. This function implements > 680 ** the build-in REGEXP operator. The first argument to the function is the > 681 ** pattern and the second argument is the string. So, the SQL statements: > 682 ** > 683 ** A REGEXP B > 684 ** > 685 ** is implemented as regexp(B,A). > 686 */ > 687 static void re_sql_func( > 688 sqlite3_context *context, > 689 int argc, > 690 sqlite3_value **argv > 691 ){ > 692 ReCompiled *pRe; /* Compiled regular expression */ > 693 const char *zPattern; /* The regular expression */ > 694 const unsigned char *zStr;/* String being searched */ > 695 const char *zErr; /* Compile error message */ > 696 > 697 pRe = sqlite3_get_auxdata(context, 0); > 698 if( pRe==0 ){ > 699 zPattern = (const char*)sqlite3_value_text(argv[0]); > 700 if( zPattern==0 ) return; > 701 zErr = re_compile(&pRe, zPattern, 0); > 702 if( zErr ){ > 703 re_free(pRe); > 704 sqlite3_result_error(context, zErr, -1); > 705 return; > 706 } > 707 if( pRe==0 ){ > 708 sqlite3_result_error_nomem(context); > 709 return; > 710 } > 711 sqlite3_set_auxdata(context, 0, pRe, (void(*)(void*))re_free); > 712 } > 713 zStr = (const unsigned char*)sqlite3_value_text(argv[1]); > 714 if( zStr!=0 ){ > 715 sqlite3_result_int(context, re_match(pRe, zStr, -1)); > 716 } > 717 } > 718 > 719 /* > 720 ** Invoke this routine in order to install the REGEXP function in an > 721 ** SQLite database connection. > 722 ** > 723 ** Use: > 724 ** > 725 ** sqlite3_auto_extension(sqlite3_add_regexp_func); > 726 ** > 727 ** to cause this extension to be automatically loaded into each new > 728 ** database connection. > 729 */ > 730 int sqlite3_add_regexp_func(sqlite3 *db){ > 731 return sqlite3_create_function(db, "regexp", 2, SQLITE_UTF8, 0, > 732 re_sql_func, 0, 0); > 733 } > 734 > 735 > 736 /***************************** Test Code ***********************************/ > 737 #ifdef SQLITE_TEST > 738 #include <tcl.h> > 739 extern int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb); > 740 > 741 /* Implementation of the TCL command: > 742 ** > 743 ** sqlite3_add_regexp_func $DB > 744 */ > 745 static int tclSqlite3AddRegexpFunc( > 746 void * clientData, > 747 Tcl_Interp *interp, > 748 int objc, > 749 Tcl_Obj *CONST objv[] > 750 ){ > 751 sqlite3 *db; > 752 if( objc!=2 ){ > 753 Tcl_WrongNumArgs(interp, 1, objv, "DB"); > 754 return TCL_ERROR; > 755 } > 756 if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; > 757 sqlite3_add_regexp_func(db); > 758 return TCL_OK; > 759 } > 760 > 761 /* Register the sqlite3_add_regexp_func TCL command with the TCL interpreter. > 762 */ > 763 int Sqlitetestregexp_Init(Tcl_Interp *interp){ > 764 Tcl_CreateObjCommand(interp, "sqlite3_add_regexp_func", > 765 tclSqlite3AddRegexpFunc, 0, 0); > 766 return TCL_OK; > 767 } > 768 #endif /* SQLITE_TEST */ > 769 /**************************** End Of Test Code *******************************/
Changes to src/vdbe.c
418 #endif 418 #endif 419 419 420 #ifdef SQLITE_DEBUG 420 #ifdef SQLITE_DEBUG 421 /* 421 /* 422 ** Print the value of a register for tracing purposes: 422 ** Print the value of a register for tracing purposes: 423 */ 423 */ 424 static void memTracePrint(FILE *out, Mem *p){ 424 static void memTracePrint(FILE *out, Mem *p){ > 425 if( p->flags & MEM_Invalid ){ > 426 fprintf(out, " undefined"); 425 if( p->flags & MEM_Null ){ | 427 }else if( p->flags & MEM_Null ){ 426 fprintf(out, " NULL"); 428 fprintf(out, " NULL"); 427 }else if( (p->flags & (MEM_Int|MEM_Str))==(MEM_Int|MEM_Str) ){ 429 }else if( (p->flags & (MEM_Int|MEM_Str))==(MEM_Int|MEM_Str) ){ 428 fprintf(out, " si:%lld", p->u.i); 430 fprintf(out, " si:%lld", p->u.i); 429 }else if( p->flags & MEM_Int ){ 431 }else if( p->flags & MEM_Int ){ 430 fprintf(out, " i:%lld", p->u.i); 432 fprintf(out, " i:%lld", p->u.i); 431 #ifndef SQLITE_OMIT_FLOATING_POINT 433 #ifndef SQLITE_OMIT_FLOATING_POINT 432 }else if( p->flags & MEM_Real ){ 434 }else if( p->flags & MEM_Real ){ ................................................................................................................................................................................ 1073 n = pOp->p3; 1075 n = pOp->p3; 1074 pIn1 = &aMem[pOp->p1]; 1076 pIn1 = &aMem[pOp->p1]; 1075 pOut = &aMem[pOp->p2]; 1077 pOut = &aMem[pOp->p2]; 1076 assert( pOut!=pIn1 ); 1078 assert( pOut!=pIn1 ); 1077 while( 1 ){ 1079 while( 1 ){ 1078 sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem); 1080 sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem); 1079 Deephemeralize(pOut); 1081 Deephemeralize(pOut); > 1082 #ifdef SQLITE_DEBUG > 1083 pOut->pScopyFrom = 0; > 1084 #endif 1080 REGISTER_TRACE(pOp->p2+pOp->p3-n, pOut); 1085 REGISTER_TRACE(pOp->p2+pOp->p3-n, pOut); 1081 if( (n--)==0 ) break; 1086 if( (n--)==0 ) break; 1082 pOut++; 1087 pOut++; 1083 pIn1++; 1088 pIn1++; 1084 } 1089 } 1085 break; 1090 break; 1086 } 1091 } ................................................................................................................................................................................ 1261 ** If either operand is NULL, the result is NULL. 1266 ** If either operand is NULL, the result is NULL. 1262 */ 1267 */ 1263 case OP_Add: /* same as TK_PLUS, in1, in2, out3 */ 1268 case OP_Add: /* same as TK_PLUS, in1, in2, out3 */ 1264 case OP_Subtract: /* same as TK_MINUS, in1, in2, out3 */ 1269 case OP_Subtract: /* same as TK_MINUS, in1, in2, out3 */ 1265 case OP_Multiply: /* same as TK_STAR, in1, in2, out3 */ 1270 case OP_Multiply: /* same as TK_STAR, in1, in2, out3 */ 1266 case OP_Divide: /* same as TK_SLASH, in1, in2, out3 */ 1271 case OP_Divide: /* same as TK_SLASH, in1, in2, out3 */ 1267 case OP_Remainder: { /* same as TK_REM, in1, in2, out3 */ 1272 case OP_Remainder: { /* same as TK_REM, in1, in2, out3 */ > 1273 char bIntint; /* Started out as two integer operands */ 1268 int flags; /* Combined MEM_* flags from both inputs */ 1274 int flags; /* Combined MEM_* flags from both inputs */ 1269 i64 iA; /* Integer value of left operand */ 1275 i64 iA; /* Integer value of left operand */ 1270 i64 iB; /* Integer value of right operand */ 1276 i64 iB; /* Integer value of right operand */ 1271 double rA; /* Real value of left operand */ 1277 double rA; /* Real value of left operand */ 1272 double rB; /* Real value of right operand */ 1278 double rB; /* Real value of right operand */ 1273 1279 1274 pIn1 = &aMem[pOp->p1]; 1280 pIn1 = &aMem[pOp->p1]; ................................................................................................................................................................................ 1277 applyNumericAffinity(pIn2); 1283 applyNumericAffinity(pIn2); 1278 pOut = &aMem[pOp->p3]; 1284 pOut = &aMem[pOp->p3]; 1279 flags = pIn1->flags | pIn2->flags; 1285 flags = pIn1->flags | pIn2->flags; 1280 if( (flags & MEM_Null)!=0 ) goto arithmetic_result_is_null; 1286 if( (flags & MEM_Null)!=0 ) goto arithmetic_result_is_null; 1281 if( (pIn1->flags & pIn2->flags & MEM_Int)==MEM_Int ){ 1287 if( (pIn1->flags & pIn2->flags & MEM_Int)==MEM_Int ){ 1282 iA = pIn1->u.i; 1288 iA = pIn1->u.i; 1283 iB = pIn2->u.i; 1289 iB = pIn2->u.i; > 1290 bIntint = 1; 1284 switch( pOp->opcode ){ 1291 switch( pOp->opcode ){ 1285 case OP_Add: if( sqlite3AddInt64(&iB,iA) ) goto fp_math; break; 1292 case OP_Add: if( sqlite3AddInt64(&iB,iA) ) goto fp_math; break; 1286 case OP_Subtract: if( sqlite3SubInt64(&iB,iA) ) goto fp_math; break; 1293 case OP_Subtract: if( sqlite3SubInt64(&iB,iA) ) goto fp_math; break; 1287 case OP_Multiply: if( sqlite3MulInt64(&iB,iA) ) goto fp_math; break; 1294 case OP_Multiply: if( sqlite3MulInt64(&iB,iA) ) goto fp_math; break; 1288 case OP_Divide: { 1295 case OP_Divide: { 1289 if( iA==0 ) goto arithmetic_result_is_null; 1296 if( iA==0 ) goto arithmetic_result_is_null; 1290 if( iA==-1 && iB==SMALLEST_INT64 ) goto fp_math; 1297 if( iA==-1 && iB==SMALLEST_INT64 ) goto fp_math; ................................................................................................................................................................................ 1297 iB %= iA; 1304 iB %= iA; 1298 break; 1305 break; 1299 } 1306 } 1300 } 1307 } 1301 pOut->u.i = iB; 1308 pOut->u.i = iB; 1302 MemSetTypeFlag(pOut, MEM_Int); 1309 MemSetTypeFlag(pOut, MEM_Int); 1303 }else{ 1310 }else{ > 1311 bIntint = 0; 1304 fp_math: 1312 fp_math: 1305 rA = sqlite3VdbeRealValue(pIn1); 1313 rA = sqlite3VdbeRealValue(pIn1); 1306 rB = sqlite3VdbeRealValue(pIn2); 1314 rB = sqlite3VdbeRealValue(pIn2); 1307 switch( pOp->opcode ){ 1315 switch( pOp->opcode ){ 1308 case OP_Add: rB += rA; break; 1316 case OP_Add: rB += rA; break; 1309 case OP_Subtract: rB -= rA; break; 1317 case OP_Subtract: rB -= rA; break; 1310 case OP_Multiply: rB *= rA; break; 1318 case OP_Multiply: rB *= rA; break; ................................................................................................................................................................................ 1328 MemSetTypeFlag(pOut, MEM_Int); 1336 MemSetTypeFlag(pOut, MEM_Int); 1329 #else 1337 #else 1330 if( sqlite3IsNaN(rB) ){ 1338 if( sqlite3IsNaN(rB) ){ 1331 goto arithmetic_result_is_null; 1339 goto arithmetic_result_is_null; 1332 } 1340 } 1333 pOut->r = rB; 1341 pOut->r = rB; 1334 MemSetTypeFlag(pOut, MEM_Real); 1342 MemSetTypeFlag(pOut, MEM_Real); 1335 if( (flags & MEM_Real)==0 ){ | 1343 if( (flags & MEM_Real)==0 && !bIntint ){ 1336 sqlite3VdbeIntegerAffinity(pOut); 1344 sqlite3VdbeIntegerAffinity(pOut); 1337 } 1345 } 1338 #endif 1346 #endif 1339 } 1347 } 1340 break; 1348 break; 1341 1349 1342 arithmetic_result_is_null: 1350 arithmetic_result_is_null: ................................................................................................................................................................................ 1883 } 1891 } 1884 1892 1885 /* Opcode: Permutation * * * P4 * 1893 /* Opcode: Permutation * * * P4 * 1886 ** 1894 ** 1887 ** Set the permutation used by the OP_Compare operator to be the array 1895 ** Set the permutation used by the OP_Compare operator to be the array 1888 ** of integers in P4. 1896 ** of integers in P4. 1889 ** 1897 ** 1890 ** The permutation is only valid until the next OP_Permutation, OP_Compare, | 1898 ** The permutation is only valid until the next OP_Compare that has 1891 ** OP_Halt, or OP_ResultRow. Typically the OP_Permutation should occur | 1899 ** the OPFLAG_PERMUTE bit set in P5. Typically the OP_Permutation should 1892 ** immediately prior to the OP_Compare. | 1900 ** occur immediately prior to the OP_Compare. 1893 */ 1901 */ 1894 case OP_Permutation: { 1902 case OP_Permutation: { 1895 assert( pOp->p4type==P4_INTARRAY ); 1903 assert( pOp->p4type==P4_INTARRAY ); 1896 assert( pOp->p4.ai ); 1904 assert( pOp->p4.ai ); 1897 aPermute = pOp->p4.ai; 1905 aPermute = pOp->p4.ai; 1898 break; 1906 break; 1899 } 1907 } 1900 1908 1901 /* Opcode: Compare P1 P2 P3 P4 * | 1909 /* Opcode: Compare P1 P2 P3 P4 P5 1902 ** 1910 ** 1903 ** Compare two vectors of registers in reg(P1)..reg(P1+P3-1) (call this 1911 ** Compare two vectors of registers in reg(P1)..reg(P1+P3-1) (call this 1904 ** vector "A") and in reg(P2)..reg(P2+P3-1) ("B"). Save the result of 1912 ** vector "A") and in reg(P2)..reg(P2+P3-1) ("B"). Save the result of 1905 ** the comparison for use by the next OP_Jump instruct. 1913 ** the comparison for use by the next OP_Jump instruct. > 1914 ** > 1915 ** If P5 has the OPFLAG_PERMUTE bit set, then the order of comparison is > 1916 ** determined by the most recent OP_Permutation operator. If the > 1917 ** OPFLAG_PERMUTE bit is clear, then register are compared in sequential > 1918 ** order. 1906 ** 1919 ** 1907 ** P4 is a KeyInfo structure that defines collating sequences and sort 1920 ** P4 is a KeyInfo structure that defines collating sequences and sort 1908 ** orders for the comparison. The permutation applies to registers 1921 ** orders for the comparison. The permutation applies to registers 1909 ** only. The KeyInfo elements are used sequentially. 1922 ** only. The KeyInfo elements are used sequentially. 1910 ** 1923 ** 1911 ** The comparison is a sort comparison, so NULLs compare equal, 1924 ** The comparison is a sort comparison, so NULLs compare equal, 1912 ** NULLs are less than numbers, numbers are less than strings, 1925 ** NULLs are less than numbers, numbers are less than strings, ................................................................................................................................................................................ 1918 int p1; 1931 int p1; 1919 int p2; 1932 int p2; 1920 const KeyInfo *pKeyInfo; 1933 const KeyInfo *pKeyInfo; 1921 int idx; 1934 int idx; 1922 CollSeq *pColl; /* Collating sequence to use on this term */ 1935 CollSeq *pColl; /* Collating sequence to use on this term */ 1923 int bRev; /* True for DESCENDING sort order */ 1936 int bRev; /* True for DESCENDING sort order */ 1924 1937 > 1938 if( (pOp->p5 & OPFLAG_PERMUTE)==0 ) aPermute = 0; 1925 n = pOp->p3; 1939 n = pOp->p3; 1926 pKeyInfo = pOp->p4.pKeyInfo; 1940 pKeyInfo = pOp->p4.pKeyInfo; 1927 assert( n>0 ); 1941 assert( n>0 ); 1928 assert( pKeyInfo!=0 ); 1942 assert( pKeyInfo!=0 ); 1929 p1 = pOp->p1; 1943 p1 = pOp->p1; 1930 p2 = pOp->p2; 1944 p2 = pOp->p2; 1931 #if SQLITE_DEBUG 1945 #if SQLITE_DEBUG ................................................................................................................................................................................ 2061 break; 2075 break; 2062 } 2076 } 2063 2077 2064 /* Opcode: Once P1 P2 * * * 2078 /* Opcode: Once P1 P2 * * * 2065 ** 2079 ** 2066 ** Check if OP_Once flag P1 is set. If so, jump to instruction P2. Otherwise, 2080 ** Check if OP_Once flag P1 is set. If so, jump to instruction P2. Otherwise, 2067 ** set the flag and fall through to the next instruction. 2081 ** set the flag and fall through to the next instruction. 2068 ** < 2069 ** See also: JumpOnce < 2070 */ 2082 */ 2071 case OP_Once: { /* jump */ 2083 case OP_Once: { /* jump */ 2072 assert( pOp->p1<p->nOnceFlag ); 2084 assert( pOp->p1<p->nOnceFlag ); 2073 if( p->aOnceFlag[pOp->p1] ){ 2085 if( p->aOnceFlag[pOp->p1] ){ 2074 pc = pOp->p2-1; 2086 pc = pOp->p2-1; 2075 }else{ 2087 }else{ 2076 p->aOnceFlag[pOp->p1] = 1; 2088 p->aOnceFlag[pOp->p1] = 1;
Changes to src/vdbeaux.c
862 int i, j; 862 int i, j; 863 KeyInfo *pKeyInfo = pOp->p4.pKeyInfo; 863 KeyInfo *pKeyInfo = pOp->p4.pKeyInfo; 864 assert( pKeyInfo->aSortOrder!=0 ); 864 assert( pKeyInfo->aSortOrder!=0 ); 865 sqlite3_snprintf(nTemp, zTemp, "keyinfo(%d", pKeyInfo->nField); 865 sqlite3_snprintf(nTemp, zTemp, "keyinfo(%d", pKeyInfo->nField); 866 i = sqlite3Strlen30(zTemp); 866 i = sqlite3Strlen30(zTemp); 867 for(j=0; j<pKeyInfo->nField; j++){ 867 for(j=0; j<pKeyInfo->nField; j++){ 868 CollSeq *pColl = pKeyInfo->aColl[j]; 868 CollSeq *pColl = pKeyInfo->aColl[j]; 869 if( pColl ){ | 869 const char *zColl = pColl ? pColl->zName : "nil"; 870 int n = sqlite3Strlen30(pColl->zName); | 870 int n = sqlite3Strlen30(zColl); 871 if( i+n>nTemp-6 ){ | 871 if( i+n>nTemp-6 ){ 872 memcpy(&zTemp[i],",...",4); | 872 memcpy(&zTemp[i],",...",4); 873 break; | 873 break; 874 } | 874 } 875 zTemp[i++] = ','; | 875 zTemp[i++] = ','; 876 if( pKeyInfo->aSortOrder[j] ){ | 876 if( pKeyInfo->aSortOrder[j] ){ 877 zTemp[i++] = '-'; | 877 zTemp[i++] = '-'; 878 } | 878 } 879 memcpy(&zTemp[i], pColl->zName,n+1); | 879 memcpy(&zTemp[i], zColl, n+1); 880 i += n; | 880 i += n; 881 }else if( i+4<nTemp-6 ){ < 882 memcpy(&zTemp[i],",nil",4); < 883 i += 4; < 884 } < 885 } 881 } 886 zTemp[i++] = ')'; 882 zTemp[i++] = ')'; 887 zTemp[i] = 0; 883 zTemp[i] = 0; 888 assert( i<nTemp ); 884 assert( i<nTemp ); 889 break; 885 break; 890 } 886 } 891 case P4_COLLSEQ: { 887 case P4_COLLSEQ: {
Changes to src/where.c
249 #define WHERE_ROWID_RANGE 0x00002000 /* rowid<EXPR and/or rowid>EXPR */ 249 #define WHERE_ROWID_RANGE 0x00002000 /* rowid<EXPR and/or rowid>EXPR */ 250 #define WHERE_COLUMN_EQ 0x00010000 /* x=EXPR or x IN (...) or x IS NULL */ 250 #define WHERE_COLUMN_EQ 0x00010000 /* x=EXPR or x IN (...) or x IS NULL */ 251 #define WHERE_COLUMN_RANGE 0x00020000 /* x<EXPR and/or x>EXPR */ 251 #define WHERE_COLUMN_RANGE 0x00020000 /* x<EXPR and/or x>EXPR */ 252 #define WHERE_COLUMN_IN 0x00040000 /* x IN (...) */ 252 #define WHERE_COLUMN_IN 0x00040000 /* x IN (...) */ 253 #define WHERE_COLUMN_NULL 0x00080000 /* x IS NULL */ 253 #define WHERE_COLUMN_NULL 0x00080000 /* x IS NULL */ 254 #define WHERE_INDEXED 0x000f0000 /* Anything that uses an index */ 254 #define WHERE_INDEXED 0x000f0000 /* Anything that uses an index */ 255 #define WHERE_NOT_FULLSCAN 0x100f3000 /* Does not do a full table scan */ 255 #define WHERE_NOT_FULLSCAN 0x100f3000 /* Does not do a full table scan */ 256 #define WHERE_IN_ABLE 0x000f1000 /* Able to support an IN operator */ | 256 #define WHERE_IN_ABLE 0x080f1000 /* Able to support an IN operator */ 257 #define WHERE_TOP_LIMIT 0x00100000 /* x<EXPR or x<=EXPR constraint */ 257 #define WHERE_TOP_LIMIT 0x00100000 /* x<EXPR or x<=EXPR constraint */ 258 #define WHERE_BTM_LIMIT 0x00200000 /* x>EXPR or x>=EXPR constraint */ 258 #define WHERE_BTM_LIMIT 0x00200000 /* x>EXPR or x>=EXPR constraint */ 259 #define WHERE_BOTH_LIMIT 0x00300000 /* Both x>EXPR and x<EXPR */ 259 #define WHERE_BOTH_LIMIT 0x00300000 /* Both x>EXPR and x<EXPR */ 260 #define WHERE_IDX_ONLY 0x00400000 /* Use index only - omit table */ 260 #define WHERE_IDX_ONLY 0x00400000 /* Use index only - omit table */ 261 #define WHERE_ORDERED 0x00800000 /* Output will appear in correct order */ 261 #define WHERE_ORDERED 0x00800000 /* Output will appear in correct order */ 262 #define WHERE_REVERSE 0x01000000 /* Scan in reverse order */ 262 #define WHERE_REVERSE 0x01000000 /* Scan in reverse order */ 263 #define WHERE_UNIQUE 0x02000000 /* Selects no more than one row */ 263 #define WHERE_UNIQUE 0x02000000 /* Selects no more than one row */ ................................................................................................................................................................................ 399 memcpy(pWC->a, pOld, sizeof(pWC->a[0])*pWC->nTerm); 399 memcpy(pWC->a, pOld, sizeof(pWC->a[0])*pWC->nTerm); 400 if( pOld!=pWC->aStatic ){ 400 if( pOld!=pWC->aStatic ){ 401 sqlite3DbFree(db, pOld); 401 sqlite3DbFree(db, pOld); 402 } 402 } 403 pWC->nSlot = sqlite3DbMallocSize(db, pWC->a)/sizeof(pWC->a[0]); 403 pWC->nSlot = sqlite3DbMallocSize(db, pWC->a)/sizeof(pWC->a[0]); 404 } 404 } 405 pTerm = &pWC->a[idx = pWC->nTerm++]; 405 pTerm = &pWC->a[idx = pWC->nTerm++]; 406 pTerm->pExpr = p; | 406 pTerm->pExpr = sqlite3ExprSkipCollate(p); 407 pTerm->wtFlags = wtFlags; 407 pTerm->wtFlags = wtFlags; 408 pTerm->pWC = pWC; 408 pTerm->pWC = pWC; 409 pTerm->iParent = -1; 409 pTerm->iParent = -1; 410 return idx; 410 return idx; 411 } 411 } 412 412 413 /* 413 /* ................................................................................................................................................................................ 559 */ 559 */ 560 #define SWAP(TYPE,A,B) {TYPE t=A; A=B; B=t;} 560 #define SWAP(TYPE,A,B) {TYPE t=A; A=B; B=t;} 561 561 562 /* 562 /* 563 ** Commute a comparison operator. Expressions of the form "X op Y" 563 ** Commute a comparison operator. Expressions of the form "X op Y" 564 ** are converted into "Y op X". 564 ** are converted into "Y op X". 565 ** 565 ** 566 ** If a collation sequence is associated with either the left or right | 566 ** If left/right precendence rules come into play when determining the > 567 ** collating 567 ** side of the comparison, it remains associated with the same side after 568 ** side of the comparison, it remains associated with the same side after 568 ** the commutation. So "Y collate NOCASE op X" becomes 569 ** the commutation. So "Y collate NOCASE op X" becomes 569 ** "X collate NOCASE op Y". This is because any collation sequence on | 570 ** "X op Y". This is because any collation sequence on 570 ** the left hand side of a comparison overrides any collation sequence 571 ** the left hand side of a comparison overrides any collation sequence 571 ** attached to the right. For the same reason the EP_ExpCollate flag | 572 ** attached to the right. For the same reason the EP_Collate flag 572 ** is not commuted. 573 ** is not commuted. 573 */ 574 */ 574 static void exprCommute(Parse *pParse, Expr *pExpr){ 575 static void exprCommute(Parse *pParse, Expr *pExpr){ 575 u16 expRight = (pExpr->pRight->flags & EP_ExpCollate); | 576 u16 expRight = (pExpr->pRight->flags & EP_Collate); 576 u16 expLeft = (pExpr->pLeft->flags & EP_ExpCollate); | 577 u16 expLeft = (pExpr->pLeft->flags & EP_Collate); 577 assert( allowedOp(pExpr->op) && pExpr->op!=TK_IN ); 578 assert( allowedOp(pExpr->op) && pExpr->op!=TK_IN ); 578 pExpr->pRight->pColl = sqlite3ExprCollSeq(pParse, pExpr->pRight); | 579 if( expRight==expLeft ){ > 580 /* Either X and Y both have COLLATE operator or neither do */ > 581 if( expRight ){ > 582 /* Both X and Y have COLLATE operators. Make sure X is always > 583 ** used by clearing the EP_Collate flag from Y. */ > 584 pExpr->pRight->flags &= ~EP_Collate; 579 pExpr->pLeft->pColl = sqlite3ExprCollSeq(pParse, pExpr->pLeft); | 585 }else if( sqlite3ExprCollSeq(pParse, pExpr->pLeft)!=0 ){ 580 SWAP(CollSeq*,pExpr->pRight->pColl,pExpr->pLeft->pColl); < 581 pExpr->pRight->flags = (pExpr->pRight->flags & ~EP_ExpCollate) | expLeft; < > 586 /* Neither X nor Y have COLLATE operators, but X has a non-default > 587 ** collating sequence. So add the EP_Collate marker on X to cause > 588 ** it to be searched first. */ 582 pExpr->pLeft->flags = (pExpr->pLeft->flags & ~EP_ExpCollate) | expRight; | 589 pExpr->pLeft->flags |= EP_Collate; > 590 } > 591 } 583 SWAP(Expr*,pExpr->pRight,pExpr->pLeft); 592 SWAP(Expr*,pExpr->pRight,pExpr->pLeft); 584 if( pExpr->op>=TK_GT ){ 593 if( pExpr->op>=TK_GT ){ 585 assert( TK_LT==TK_GT+2 ); 594 assert( TK_LT==TK_GT+2 ); 586 assert( TK_GE==TK_LE+2 ); 595 assert( TK_GE==TK_LE+2 ); 587 assert( TK_GT>TK_EQ ); 596 assert( TK_GT>TK_EQ ); 588 assert( TK_GT<TK_LE ); 597 assert( TK_GT<TK_LE ); 589 assert( pExpr->op>=TK_GT && pExpr->op<=TK_GE ); 598 assert( pExpr->op>=TK_GT && pExpr->op<=TK_GE ); ................................................................................................................................................................................ 652 661 653 /* Figure out the collation sequence required from an index for 662 /* Figure out the collation sequence required from an index for 654 ** it to be useful for optimising expression pX. Store this 663 ** it to be useful for optimising expression pX. Store this 655 ** value in variable pColl. 664 ** value in variable pColl. 656 */ 665 */ 657 assert(pX->pLeft); 666 assert(pX->pLeft); 658 pColl = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight); 667 pColl = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight); 659 assert(pColl || pParse->nErr); | 668 if( pColl==0 ) pColl = pParse->db->pDfltColl; 660 669 661 for(j=0; pIdx->aiColumn[j]!=iColumn; j++){ 670 for(j=0; pIdx->aiColumn[j]!=iColumn; j++){ 662 if( NEVER(j>=pIdx->nColumn) ) return 0; 671 if( NEVER(j>=pIdx->nColumn) ) return 0; 663 } 672 } 664 if( pColl && sqlite3StrICmp(pColl->zName, pIdx->azColl[j]) ) continue; | 673 if( sqlite3StrICmp(pColl->zName, pIdx->azColl[j]) ) continue; 665 } 674 } 666 return pTerm; 675 return pTerm; 667 } 676 } 668 } 677 } 669 } 678 } 670 return 0; 679 return 0; 671 } 680 } ................................................................................................................................................................................ 1176 1185 1177 if( db->mallocFailed ){ 1186 if( db->mallocFailed ){ 1178 return; 1187 return; 1179 } 1188 } 1180 pTerm = &pWC->a[idxTerm]; 1189 pTerm = &pWC->a[idxTerm]; 1181 pMaskSet = pWC->pMaskSet; 1190 pMaskSet = pWC->pMaskSet; 1182 pExpr = pTerm->pExpr; 1191 pExpr = pTerm->pExpr; > 1192 assert( pExpr->op!=TK_AS && pExpr->op!=TK_COLLATE ); 1183 prereqLeft = exprTableUsage(pMaskSet, pExpr->pLeft); 1193 prereqLeft = exprTableUsage(pMaskSet, pExpr->pLeft); 1184 op = pExpr->op; 1194 op = pExpr->op; 1185 if( op==TK_IN ){ 1195 if( op==TK_IN ){ 1186 assert( pExpr->pRight==0 ); 1196 assert( pExpr->pRight==0 ); 1187 if( ExprHasProperty(pExpr, EP_xIsSelect) ){ 1197 if( ExprHasProperty(pExpr, EP_xIsSelect) ){ 1188 pTerm->prereqRight = exprSelectTableUsage(pMaskSet, pExpr->x.pSelect); 1198 pTerm->prereqRight = exprSelectTableUsage(pMaskSet, pExpr->x.pSelect); 1189 }else{ 1199 }else{ ................................................................................................................................................................................ 1202 ** on left table of a LEFT JOIN. Ticket #3015 */ 1212 ** on left table of a LEFT JOIN. Ticket #3015 */ 1203 } 1213 } 1204 pTerm->prereqAll = prereqAll; 1214 pTerm->prereqAll = prereqAll; 1205 pTerm->leftCursor = -1; 1215 pTerm->leftCursor = -1; 1206 pTerm->iParent = -1; 1216 pTerm->iParent = -1; 1207 pTerm->eOperator = 0; 1217 pTerm->eOperator = 0; 1208 if( allowedOp(op) && (pTerm->prereqRight & prereqLeft)==0 ){ 1218 if( allowedOp(op) && (pTerm->prereqRight & prereqLeft)==0 ){ 1209 Expr *pLeft = pExpr->pLeft; | 1219 Expr *pLeft = sqlite3ExprSkipCollate(pExpr->pLeft); 1210 Expr *pRight = pExpr->pRight; | 1220 Expr *pRight = sqlite3ExprSkipCollate(pExpr->pRight); 1211 if( pLeft->op==TK_COLUMN ){ 1221 if( pLeft->op==TK_COLUMN ){ 1212 pTerm->leftCursor = pLeft->iTable; 1222 pTerm->leftCursor = pLeft->iTable; 1213 pTerm->u.leftColumn = pLeft->iColumn; 1223 pTerm->u.leftColumn = pLeft->iColumn; 1214 pTerm->eOperator = operatorMask(op); 1224 pTerm->eOperator = operatorMask(op); 1215 } 1225 } 1216 if( pRight && pRight->op==TK_COLUMN ){ 1226 if( pRight && pRight->op==TK_COLUMN ){ 1217 WhereTerm *pNew; 1227 WhereTerm *pNew; ................................................................................................................................................................................ 1231 pTerm->nChild = 1; 1241 pTerm->nChild = 1; 1232 pTerm->wtFlags |= TERM_COPIED; 1242 pTerm->wtFlags |= TERM_COPIED; 1233 }else{ 1243 }else{ 1234 pDup = pExpr; 1244 pDup = pExpr; 1235 pNew = pTerm; 1245 pNew = pTerm; 1236 } 1246 } 1237 exprCommute(pParse, pDup); 1247 exprCommute(pParse, pDup); 1238 pLeft = pDup->pLeft; | 1248 pLeft = sqlite3ExprSkipCollate(pDup->pLeft); 1239 pNew->leftCursor = pLeft->iTable; 1249 pNew->leftCursor = pLeft->iTable; 1240 pNew->u.leftColumn = pLeft->iColumn; 1250 pNew->u.leftColumn = pLeft->iColumn; 1241 testcase( (prereqLeft | extraRight) != prereqLeft ); 1251 testcase( (prereqLeft | extraRight) != prereqLeft ); 1242 pNew->prereqRight = prereqLeft | extraRight; 1252 pNew->prereqRight = prereqLeft | extraRight; 1243 pNew->prereqAll = prereqAll; 1253 pNew->prereqAll = prereqAll; 1244 pNew->eOperator = operatorMask(pDup->op); 1254 pNew->eOperator = operatorMask(pDup->op); 1245 } 1255 } ................................................................................................................................................................................ 1310 ){ 1320 ){ 1311 Expr *pLeft; /* LHS of LIKE/GLOB operator */ 1321 Expr *pLeft; /* LHS of LIKE/GLOB operator */ 1312 Expr *pStr2; /* Copy of pStr1 - RHS of LIKE/GLOB operator */ 1322 Expr *pStr2; /* Copy of pStr1 - RHS of LIKE/GLOB operator */ 1313 Expr *pNewExpr1; 1323 Expr *pNewExpr1; 1314 Expr *pNewExpr2; 1324 Expr *pNewExpr2; 1315 int idxNew1; 1325 int idxNew1; 1316 int idxNew2; 1326 int idxNew2; 1317 CollSeq *pColl; /* Collating sequence to use */ | 1327 Token sCollSeqName; /* Name of collating sequence */ 1318 1328 1319 pLeft = pExpr->x.pList->a[1].pExpr; 1329 pLeft = pExpr->x.pList->a[1].pExpr; 1320 pStr2 = sqlite3ExprDup(db, pStr1, 0); 1330 pStr2 = sqlite3ExprDup(db, pStr1, 0); 1321 if( !db->mallocFailed ){ 1331 if( !db->mallocFailed ){ 1322 u8 c, *pC; /* Last character before the first wildcard */ 1332 u8 c, *pC; /* Last character before the first wildcard */ 1323 pC = (u8*)&pStr2->u.zToken[sqlite3Strlen30(pStr2->u.zToken)-1]; 1333 pC = (u8*)&pStr2->u.zToken[sqlite3Strlen30(pStr2->u.zToken)-1]; 1324 c = *pC; 1334 c = *pC; ................................................................................................................................................................................ 1332 if( c=='A'-1 ) isComplete = 0; /* EV: R-64339-08207 */ 1342 if( c=='A'-1 ) isComplete = 0; /* EV: R-64339-08207 */ 1333 1343 1334 1344 1335 c = sqlite3UpperToLower[c]; 1345 c = sqlite3UpperToLower[c]; 1336 } 1346 } 1337 *pC = c + 1; 1347 *pC = c + 1; 1338 } 1348 } 1339 pColl = sqlite3FindCollSeq(db, SQLITE_UTF8, noCase ? "NOCASE" : "BINARY",0); | 1349 sCollSeqName.z = noCase ? "NOCASE" : "BINARY"; > 1350 sCollSeqName.n = 6; > 1351 pNewExpr1 = sqlite3ExprDup(db, pLeft, 0); 1340 pNewExpr1 = sqlite3PExpr(pParse, TK_GE, 1352 pNewExpr1 = sqlite3PExpr(pParse, TK_GE, 1341 sqlite3ExprSetColl(sqlite3ExprDup(db,pLeft,0), pColl), < > 1353 sqlite3ExprAddCollateToken(pParse,pNewExpr1,&sCollSeqName), 1342 pStr1, 0); | 1354 pStr1, 0); 1343 idxNew1 = whereClauseInsert(pWC, pNewExpr1, TERM_VIRTUAL|TERM_DYNAMIC); 1355 idxNew1 = whereClauseInsert(pWC, pNewExpr1, TERM_VIRTUAL|TERM_DYNAMIC); 1344 testcase( idxNew1==0 ); 1356 testcase( idxNew1==0 ); 1345 exprAnalyze(pSrc, pWC, idxNew1); 1357 exprAnalyze(pSrc, pWC, idxNew1); > 1358 pNewExpr2 = sqlite3ExprDup(db, pLeft, 0); 1346 pNewExpr2 = sqlite3PExpr(pParse, TK_LT, 1359 pNewExpr2 = sqlite3PExpr(pParse, TK_LT, 1347 sqlite3ExprSetColl(sqlite3ExprDup(db,pLeft,0), pColl), < > 1360 sqlite3ExprAddCollateToken(pParse,pNewExpr2,&sCollSeqName), 1348 pStr2, 0); | 1361 pStr2, 0); 1349 idxNew2 = whereClauseInsert(pWC, pNewExpr2, TERM_VIRTUAL|TERM_DYNAMIC); 1362 idxNew2 = whereClauseInsert(pWC, pNewExpr2, TERM_VIRTUAL|TERM_DYNAMIC); 1350 testcase( idxNew2==0 ); 1363 testcase( idxNew2==0 ); 1351 exprAnalyze(pSrc, pWC, idxNew2); 1364 exprAnalyze(pSrc, pWC, idxNew2); 1352 pTerm = &pWC->a[idxTerm]; 1365 pTerm = &pWC->a[idxTerm]; 1353 if( isComplete ){ 1366 if( isComplete ){ 1354 pWC->a[idxNew1].iParent = idxTerm; 1367 pWC->a[idxNew1].iParent = idxTerm; 1355 pWC->a[idxNew2].iParent = idxTerm; 1368 pWC->a[idxNew2].iParent = idxTerm; ................................................................................................................................................................................ 1459 Index *pIdx, /* Index to match column of */ 1472 Index *pIdx, /* Index to match column of */ 1460 int iCol /* Column of index to match */ 1473 int iCol /* Column of index to match */ 1461 ){ 1474 ){ 1462 int i; 1475 int i; 1463 const char *zColl = pIdx->azColl[iCol]; 1476 const char *zColl = pIdx->azColl[iCol]; 1464 1477 1465 for(i=0; i<pList->nExpr; i++){ 1478 for(i=0; i<pList->nExpr; i++){ 1466 Expr *p = pList->a[i].pExpr; | 1479 Expr *p = sqlite3ExprSkipCollate(pList->a[i].pExpr); 1467 if( p->op==TK_COLUMN 1480 if( p->op==TK_COLUMN 1468 && p->iColumn==pIdx->aiColumn[iCol] 1481 && p->iColumn==pIdx->aiColumn[iCol] 1469 && p->iTable==iBase 1482 && p->iTable==iBase 1470 ){ 1483 ){ 1471 CollSeq *pColl = sqlite3ExprCollSeq(pParse, p); | 1484 CollSeq *pColl = sqlite3ExprCollSeq(pParse, pList->a[i].pExpr); 1472 if( ALWAYS(pColl) && 0==sqlite3StrICmp(pColl->zName, zColl) ){ 1485 if( ALWAYS(pColl) && 0==sqlite3StrICmp(pColl->zName, zColl) ){ 1473 return i; 1486 return i; 1474 } 1487 } 1475 } 1488 } 1476 } 1489 } 1477 1490 1478 return -1; 1491 return -1; ................................................................................................................................................................................ 1511 ** can be ignored. If it does not, and the column does not belong to the 1524 ** can be ignored. If it does not, and the column does not belong to the 1512 ** same table as index pIdx, return early. Finally, if there is no 1525 ** same table as index pIdx, return early. Finally, if there is no 1513 ** matching "col=X" expression and the column is on the same table as pIdx, 1526 ** matching "col=X" expression and the column is on the same table as pIdx, 1514 ** set the corresponding bit in variable mask. 1527 ** set the corresponding bit in variable mask. 1515 */ 1528 */ 1516 for(i=0; i<pDistinct->nExpr; i++){ 1529 for(i=0; i<pDistinct->nExpr; i++){ 1517 WhereTerm *pTerm; 1530 WhereTerm *pTerm; 1518 Expr *p = pDistinct->a[i].pExpr; | 1531 Expr *p = sqlite3ExprSkipCollate(pDistinct->a[i].pExpr); 1519 if( p->op!=TK_COLUMN ) return 0; 1532 if( p->op!=TK_COLUMN ) return 0; 1520 pTerm = findTerm(pWC, p->iTable, p->iColumn, ~(Bitmask)0, WO_EQ, 0); 1533 pTerm = findTerm(pWC, p->iTable, p->iColumn, ~(Bitmask)0, WO_EQ, 0); 1521 if( pTerm ){ 1534 if( pTerm ){ 1522 Expr *pX = pTerm->pExpr; 1535 Expr *pX = pTerm->pExpr; 1523 CollSeq *p1 = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight); 1536 CollSeq *p1 = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight); 1524 CollSeq *p2 = sqlite3ExprCollSeq(pParse, p); 1537 CollSeq *p2 = sqlite3ExprCollSeq(pParse, p); 1525 if( p1==p2 ) continue; 1538 if( p1==p2 ) continue; ................................................................................................................................................................................ 1563 pTab = pTabList->a[0].pTab; 1576 pTab = pTabList->a[0].pTab; 1564 1577 1565 /* If any of the expressions is an IPK column on table iBase, then return 1578 /* If any of the expressions is an IPK column on table iBase, then return 1566 ** true. Note: The (p->iTable==iBase) part of this test may be false if the 1579 ** true. Note: The (p->iTable==iBase) part of this test may be false if the 1567 ** current SELECT is a correlated sub-query. 1580 ** current SELECT is a correlated sub-query. 1568 */ 1581 */ 1569 for(i=0; i<pDistinct->nExpr; i++){ 1582 for(i=0; i<pDistinct->nExpr; i++){ 1570 Expr *p = pDistinct->a[i].pExpr; | 1583 Expr *p = sqlite3ExprSkipCollate(pDistinct->a[i].pExpr); 1571 if( p->op==TK_COLUMN && p->iTable==iBase && p->iColumn<0 ) return 1; 1584 if( p->op==TK_COLUMN && p->iTable==iBase && p->iColumn<0 ) return 1; 1572 } 1585 } 1573 1586 1574 /* Loop through all indices on the table, checking each to see if it makes 1587 /* Loop through all indices on the table, checking each to see if it makes 1575 ** the DISTINCT qualifier redundant. It does so if: 1588 ** the DISTINCT qualifier redundant. It does so if: 1576 ** 1589 ** 1577 ** 1. The index is itself UNIQUE, and 1590 ** 1. The index is itself UNIQUE, and ................................................................................................................................................................................ 2040 /* Count the number of possible WHERE clause constraints referring 2053 /* Count the number of possible WHERE clause constraints referring 2041 ** to this virtual table */ 2054 ** to this virtual table */ 2042 for(i=nTerm=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){ 2055 for(i=nTerm=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){ 2043 if( pTerm->leftCursor != pSrc->iCursor ) continue; 2056 if( pTerm->leftCursor != pSrc->iCursor ) continue; 2044 assert( (pTerm->eOperator&(pTerm->eOperator-1))==0 ); 2057 assert( (pTerm->eOperator&(pTerm->eOperator-1))==0 ); 2045 testcase( pTerm->eOperator==WO_IN ); 2058 testcase( pTerm->eOperator==WO_IN ); 2046 testcase( pTerm->eOperator==WO_ISNULL ); 2059 testcase( pTerm->eOperator==WO_ISNULL ); 2047 if( pTerm->eOperator & (WO_IN|WO_ISNULL) ) continue; | 2060 if( pTerm->eOperator & (WO_ISNULL) ) continue; 2048 if( pTerm->wtFlags & TERM_VNULL ) continue; 2061 if( pTerm->wtFlags & TERM_VNULL ) continue; 2049 nTerm++; 2062 nTerm++; 2050 } 2063 } 2051 2064 2052 /* If the ORDER BY clause contains only columns in the current 2065 /* If the ORDER BY clause contains only columns in the current 2053 ** virtual table then allocate space for the aOrderBy part of 2066 ** virtual table then allocate space for the aOrderBy part of 2054 ** the sqlite3_index_info structure. 2067 ** the sqlite3_index_info structure. ................................................................................................................................................................................ 2088 *(int*)&pIdxInfo->nOrderBy = nOrderBy; 2101 *(int*)&pIdxInfo->nOrderBy = nOrderBy; 2089 *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint = pIdxCons; 2102 *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint = pIdxCons; 2090 *(struct sqlite3_index_orderby**)&pIdxInfo->aOrderBy = pIdxOrderBy; 2103 *(struct sqlite3_index_orderby**)&pIdxInfo->aOrderBy = pIdxOrderBy; 2091 *(struct sqlite3_index_constraint_usage**)&pIdxInfo->aConstraintUsage = 2104 *(struct sqlite3_index_constraint_usage**)&pIdxInfo->aConstraintUsage = 2092 pUsage; 2105 pUsage; 2093 2106 2094 for(i=j=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){ 2107 for(i=j=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){ > 2108 u8 op; 2095 if( pTerm->leftCursor != pSrc->iCursor ) continue; 2109 if( pTerm->leftCursor != pSrc->iCursor ) continue; 2096 assert( (pTerm->eOperator&(pTerm->eOperator-1))==0 ); 2110 assert( (pTerm->eOperator&(pTerm->eOperator-1))==0 ); 2097 testcase( pTerm->eOperator==WO_IN ); 2111 testcase( pTerm->eOperator==WO_IN ); 2098 testcase( pTerm->eOperator==WO_ISNULL ); 2112 testcase( pTerm->eOperator==WO_ISNULL ); 2099 if( pTerm->eOperator & (WO_IN|WO_ISNULL) ) continue; | 2113 if( pTerm->eOperator & (WO_ISNULL) ) continue; 2100 if( pTerm->wtFlags & TERM_VNULL ) continue; 2114 if( pTerm->wtFlags & TERM_VNULL ) continue; 2101 pIdxCons[j].iColumn = pTerm->u.leftColumn; 2115 pIdxCons[j].iColumn = pTerm->u.leftColumn; 2102 pIdxCons[j].iTermOffset = i; 2116 pIdxCons[j].iTermOffset = i; 2103 pIdxCons[j].op = (u8)pTerm->eOperator; | 2117 op = (u8)pTerm->eOperator; > 2118 if( op==WO_IN ) op = WO_EQ; > 2119 pIdxCons[j].op = op; 2104 /* The direct assignment in the previous line is possible only because 2120 /* The direct assignment in the previous line is possible only because 2105 ** the WO_ and SQLITE_INDEX_CONSTRAINT_ codes are identical. The 2121 ** the WO_ and SQLITE_INDEX_CONSTRAINT_ codes are identical. The 2106 ** following asserts verify this fact. */ 2122 ** following asserts verify this fact. */ 2107 assert( WO_EQ==SQLITE_INDEX_CONSTRAINT_EQ ); 2123 assert( WO_EQ==SQLITE_INDEX_CONSTRAINT_EQ ); 2108 assert( WO_LT==SQLITE_INDEX_CONSTRAINT_LT ); 2124 assert( WO_LT==SQLITE_INDEX_CONSTRAINT_LT ); 2109 assert( WO_LE==SQLITE_INDEX_CONSTRAINT_LE ); 2125 assert( WO_LE==SQLITE_INDEX_CONSTRAINT_LE ); 2110 assert( WO_GT==SQLITE_INDEX_CONSTRAINT_GT ); 2126 assert( WO_GT==SQLITE_INDEX_CONSTRAINT_GT ); 2111 assert( WO_GE==SQLITE_INDEX_CONSTRAINT_GE ); 2127 assert( WO_GE==SQLITE_INDEX_CONSTRAINT_GE ); 2112 assert( WO_MATCH==SQLITE_INDEX_CONSTRAINT_MATCH ); 2128 assert( WO_MATCH==SQLITE_INDEX_CONSTRAINT_MATCH ); 2113 assert( pTerm->eOperator & (WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE|WO_MATCH) ); | 2129 assert( pTerm->eOperator & (WO_IN|WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE|WO_MATCH) ); 2114 j++; 2130 j++; 2115 } 2131 } 2116 for(i=0; i<nOrderBy; i++){ 2132 for(i=0; i<nOrderBy; i++){ 2117 Expr *pExpr = pOrderBy->a[i].pExpr; 2133 Expr *pExpr = pOrderBy->a[i].pExpr; 2118 pIdxOrderBy[i].iColumn = pExpr->iColumn; 2134 pIdxOrderBy[i].iColumn = pExpr->iColumn; 2119 pIdxOrderBy[i].desc = pOrderBy->a[i].sortOrder; 2135 pIdxOrderBy[i].desc = pOrderBy->a[i].sortOrder; 2120 } 2136 } ................................................................................................................................................................................ 2192 Table *pTab = pSrc->pTab; 2208 Table *pTab = pSrc->pTab; 2193 sqlite3_index_info *pIdxInfo; 2209 sqlite3_index_info *pIdxInfo; 2194 struct sqlite3_index_constraint *pIdxCons; 2210 struct sqlite3_index_constraint *pIdxCons; 2195 struct sqlite3_index_constraint_usage *pUsage; 2211 struct sqlite3_index_constraint_usage *pUsage; 2196 WhereTerm *pTerm; 2212 WhereTerm *pTerm; 2197 int i, j; 2213 int i, j; 2198 int nOrderBy; 2214 int nOrderBy; > 2215 int bAllowIN; /* Allow IN optimizations */ 2199 double rCost; 2216 double rCost; 2200 2217 2201 /* Make sure wsFlags is initialized to some sane value. Otherwise, if the 2218 /* Make sure wsFlags is initialized to some sane value. Otherwise, if the 2202 ** malloc in allocateIndexInfo() fails and this function returns leaving 2219 ** malloc in allocateIndexInfo() fails and this function returns leaving 2203 ** wsFlags in an uninitialized state, the caller may behave unpredictably. 2220 ** wsFlags in an uninitialized state, the caller may behave unpredictably. 2204 */ 2221 */ 2205 memset(&p->cost, 0, sizeof(p->cost)); 2222 memset(&p->cost, 0, sizeof(p->cost)); ................................................................................................................................................................................ 2226 /* The module name must be defined. Also, by this point there must 2243 /* The module name must be defined. Also, by this point there must 2227 ** be a pointer to an sqlite3_vtab structure. Otherwise 2244 ** be a pointer to an sqlite3_vtab structure. Otherwise 2228 ** sqlite3ViewGetColumnNames() would have picked up the error. 2245 ** sqlite3ViewGetColumnNames() would have picked up the error. 2229 */ 2246 */ 2230 assert( pTab->azModuleArg && pTab->azModuleArg[0] ); 2247 assert( pTab->azModuleArg && pTab->azModuleArg[0] ); 2231 assert( sqlite3GetVTable(pParse->db, pTab) ); 2248 assert( sqlite3GetVTable(pParse->db, pTab) ); 2232 2249 > 2250 /* Try once or twice. On the first attempt, allow IN optimizations. > 2251 ** If an IN optimization is accepted by the virtual table xBestIndex > 2252 ** method, but the pInfo->aConstrainUsage.omit flag is not set, then > 2253 ** the query will not work because it might allow duplicate rows in > 2254 ** output. In that case, run the xBestIndex method a second time > 2255 ** without the IN constraints. Usually this loop only runs once. > 2256 ** The loop will exit using a "break" statement. > 2257 */ > 2258 for(bAllowIN=1; 1; bAllowIN--){ > 2259 assert( bAllowIN==0 || bAllowIN==1 ); > 2260 2233 /* Set the aConstraint[].usable fields and initialize all | 2261 /* Set the aConstraint[].usable fields and initialize all 2234 ** output variables to zero. | 2262 ** output variables to zero. 2235 ** | 2263 ** 2236 ** aConstraint[].usable is true for constraints where the right-hand | 2264 ** aConstraint[].usable is true for constraints where the right-hand 2237 ** side contains only references to tables to the left of the current | 2265 ** side contains only references to tables to the left of the current 2238 ** table. In other words, if the constraint is of the form: | 2266 ** table. In other words, if the constraint is of the form: 2239 ** | 2267 ** 2240 ** column = expr | 2268 ** column = expr 2241 ** | 2269 ** 2242 ** and we are evaluating a join, then the constraint on column is | 2270 ** and we are evaluating a join, then the constraint on column is 2243 ** only valid if all tables referenced in expr occur to the left | 2271 ** only valid if all tables referenced in expr occur to the left 2244 ** of the table containing column. | 2272 ** of the table containing column. 2245 ** | 2273 ** 2246 ** The aConstraints[] array contains entries for all constraints | 2274 ** The aConstraints[] array contains entries for all constraints 2247 ** on the current table. That way we only have to compute it once | 2275 ** on the current table. That way we only have to compute it once 2248 ** even though we might try to pick the best index multiple times. | 2276 ** even though we might try to pick the best index multiple times. 2249 ** For each attempt at picking an index, the order of tables in the | 2277 ** For each attempt at picking an index, the order of tables in the 2250 ** join might be different so we have to recompute the usable flag | 2278 ** join might be different so we have to recompute the usable flag 2251 ** each time. | 2279 ** each time. 2252 */ | 2280 */ 2253 pIdxCons = *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint; | 2281 pIdxCons = *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint; 2254 pUsage = pIdxInfo->aConstraintUsage; | 2282 pUsage = pIdxInfo->aConstraintUsage; 2255 for(i=0; i<pIdxInfo->nConstraint; i++, pIdxCons++){ | 2283 for(i=0; i<pIdxInfo->nConstraint; i++, pIdxCons++){ 2256 j = pIdxCons->iTermOffset; | 2284 j = pIdxCons->iTermOffset; 2257 pTerm = &pWC->a[j]; | 2285 pTerm = &pWC->a[j]; 2258 pIdxCons->usable = (pTerm->prereqRight&p->notReady) ? 0 : 1; | 2286 if( (pTerm->prereqRight&p->notReady)==0 > 2287 && (bAllowIN || pTerm->eOperator!=WO_IN) > 2288 ){ > 2289 pIdxCons->usable = 1; > 2290 }else{ > 2291 pIdxCons->usable = 0; 2259 } | 2292 } > 2293 } 2260 memset(pUsage, 0, sizeof(pUsage[0])*pIdxInfo->nConstraint); | 2294 memset(pUsage, 0, sizeof(pUsage[0])*pIdxInfo->nConstraint); 2261 if( pIdxInfo->needToFreeIdxStr ){ | 2295 if( pIdxInfo->needToFreeIdxStr ){ 2262 sqlite3_free(pIdxInfo->idxStr); | 2296 sqlite3_free(pIdxInfo->idxStr); 2263 } | 2297 } 2264 pIdxInfo->idxStr = 0; | 2298 pIdxInfo->idxStr = 0; 2265 pIdxInfo->idxNum = 0; | 2299 pIdxInfo->idxNum = 0; 2266 pIdxInfo->needToFreeIdxStr = 0; | 2300 pIdxInfo->needToFreeIdxStr = 0; 2267 pIdxInfo->orderByConsumed = 0; | 2301 pIdxInfo->orderByConsumed = 0; 2268 /* ((double)2) In case of SQLITE_OMIT_FLOATING_POINT... */ | 2302 /* ((double)2) In case of SQLITE_OMIT_FLOATING_POINT... */ 2269 pIdxInfo->estimatedCost = SQLITE_BIG_DBL / ((double)2); | 2303 pIdxInfo->estimatedCost = SQLITE_BIG_DBL / ((double)2); 2270 nOrderBy = pIdxInfo->nOrderBy; | 2304 nOrderBy = pIdxInfo->nOrderBy; 2271 if( !p->pOrderBy ){ | 2305 if( !p->pOrderBy ){ 2272 pIdxInfo->nOrderBy = 0; | 2306 pIdxInfo->nOrderBy = 0; 2273 } | 2307 } 2274 | 2308 2275 if( vtabBestIndex(pParse, pTab, pIdxInfo) ){ | 2309 if( vtabBestIndex(pParse, pTab, pIdxInfo) ){ 2276 return; | 2310 return; 2277 } | 2311 } 2278 | 2312 2279 pIdxCons = *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint; | 2313 pIdxCons = *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint; 2280 for(i=0; i<pIdxInfo->nConstraint; i++){ | 2314 for(i=0; i<pIdxInfo->nConstraint; i++, pIdxCons++){ 2281 if( pUsage[i].argvIndex>0 ){ | 2315 if( pUsage[i].argvIndex>0 ){ > 2316 j = pIdxCons->iTermOffset; > 2317 pTerm = &pWC->a[j]; 2282 p->cost.used |= pWC->a[pIdxCons[i].iTermOffset].prereqRight; | 2318 p->cost.used |= pTerm->prereqRight; > 2319 if( pTerm->eOperator==WO_IN && pUsage[i].omit==0 ){ > 2320 /* Do not attempt to use an IN constraint if the virtual table > 2321 ** says that the equivalent EQ constraint cannot be safely omitted. > 2322 ** If we do attempt to use such a constraint, some rows might be > 2323 ** repeated in the output. */ > 2324 break; 2283 } | 2325 } 2284 } | 2326 } 2285 | 2327 } > 2328 if( i>=pIdxInfo->nConstraint ) break; > 2329 } > 2330 2286 /* If there is an ORDER BY clause, and the selected virtual table index 2331 /* If there is an ORDER BY clause, and the selected virtual table index 2287 ** does not satisfy it, increase the cost of the scan accordingly. This 2332 ** does not satisfy it, increase the cost of the scan accordingly. This 2288 ** matches the processing for non-virtual tables in bestBtreeIndex(). 2333 ** matches the processing for non-virtual tables in bestBtreeIndex(). 2289 */ 2334 */ 2290 rCost = pIdxInfo->estimatedCost; 2335 rCost = pIdxInfo->estimatedCost; 2291 if( p->pOrderBy && pIdxInfo->orderByConsumed==0 ){ 2336 if( p->pOrderBy && pIdxInfo->orderByConsumed==0 ){ 2292 rCost += estLog(rCost)*rCost; 2337 rCost += estLog(rCost)*rCost; ................................................................................................................................................................................ 2849 int isMatch; /* ORDER BY term matches the index term */ 2894 int isMatch; /* ORDER BY term matches the index term */ 2850 const char *zColl; /* Name of collating sequence for i-th index term */ 2895 const char *zColl; /* Name of collating sequence for i-th index term */ 2851 WhereTerm *pConstraint; /* A constraint in the WHERE clause */ 2896 WhereTerm *pConstraint; /* A constraint in the WHERE clause */ 2852 2897 2853 /* If the next term of the ORDER BY clause refers to anything other than 2898 /* If the next term of the ORDER BY clause refers to anything other than 2854 ** a column in the "base" table, then this index will not be of any 2899 ** a column in the "base" table, then this index will not be of any 2855 ** further use in handling the ORDER BY. */ 2900 ** further use in handling the ORDER BY. */ 2856 pOBExpr = pOBItem->pExpr; | 2901 pOBExpr = sqlite3ExprSkipCollate(pOBItem->pExpr); 2857 if( pOBExpr->op!=TK_COLUMN || pOBExpr->iTable!=base ){ 2902 if( pOBExpr->op!=TK_COLUMN || pOBExpr->iTable!=base ){ 2858 break; 2903 break; 2859 } 2904 } 2860 2905 2861 /* Find column number and collating sequence for the next entry 2906 /* Find column number and collating sequence for the next entry 2862 ** in the index */ 2907 ** in the index */ 2863 if( pIdx->zName && i<pIdx->nColumn ){ 2908 if( pIdx->zName && i<pIdx->nColumn ){ ................................................................................................................................................................................ 2875 } 2920 } 2876 2921 2877 /* Check to see if the column number and collating sequence of the 2922 /* Check to see if the column number and collating sequence of the 2878 ** index match the column number and collating sequence of the ORDER BY 2923 ** index match the column number and collating sequence of the ORDER BY 2879 ** clause entry. Set isMatch to 1 if they both match. */ 2924 ** clause entry. Set isMatch to 1 if they both match. */ 2880 if( pOBExpr->iColumn==iColumn ){ 2925 if( pOBExpr->iColumn==iColumn ){ 2881 if( zColl ){ 2926 if( zColl ){ 2882 pColl = sqlite3ExprCollSeq(pParse, pOBExpr); | 2927 pColl = sqlite3ExprCollSeq(pParse, pOBItem->pExpr); 2883 if( !pColl ) pColl = db->pDfltColl; 2928 if( !pColl ) pColl = db->pDfltColl; 2884 isMatch = sqlite3StrICmp(pColl->zName, zColl)==0; 2929 isMatch = sqlite3StrICmp(pColl->zName, zColl)==0; 2885 }else{ 2930 }else{ 2886 isMatch = 1; 2931 isMatch = 1; 2887 } 2932 } 2888 }else{ 2933 }else{ 2889 isMatch = 0; 2934 isMatch = 0; ................................................................................................................................................................................ 3016 Index *pIdx; /* Copy of pProbe, or zero for IPK index */ 3061 Index *pIdx; /* Copy of pProbe, or zero for IPK index */ 3017 int eqTermMask; /* Current mask of valid equality operators */ 3062 int eqTermMask; /* Current mask of valid equality operators */ 3018 int idxEqTermMask; /* Index mask of valid equality operators */ 3063 int idxEqTermMask; /* Index mask of valid equality operators */ 3019 Index sPk; /* A fake index object for the primary key */ 3064 Index sPk; /* A fake index object for the primary key */ 3020 tRowcnt aiRowEstPk[2]; /* The aiRowEst[] value for the sPk index */ 3065 tRowcnt aiRowEstPk[2]; /* The aiRowEst[] value for the sPk index */ 3021 int aiColumnPk = -1; /* The aColumn[] value for the sPk index */ 3066 int aiColumnPk = -1; /* The aColumn[] value for the sPk index */ 3022 int wsFlagMask; /* Allowed flags in p->cost.plan.wsFlag */ 3067 int wsFlagMask; /* Allowed flags in p->cost.plan.wsFlag */ > 3068 int nPriorSat; /* ORDER BY terms satisfied by outer loops */ > 3069 int nOrderBy; /* Number of ORDER BY terms */ > 3070 char bSortInit; /* Initializer for bSort in inner loop */ > 3071 char bDistInit; /* Initializer for bDist in inner loop */ > 3072 3023 3073 3024 /* Initialize the cost to a worst-case value */ 3074 /* Initialize the cost to a worst-case value */ 3025 memset(&p->cost, 0, sizeof(p->cost)); 3075 memset(&p->cost, 0, sizeof(p->cost)); 3026 p->cost.rCost = SQLITE_BIG_DBL; 3076 p->cost.rCost = SQLITE_BIG_DBL; 3027 3077 3028 /* If the pSrc table is the right table of a LEFT JOIN then we may not 3078 /* If the pSrc table is the right table of a LEFT JOIN then we may not 3029 ** use an index to satisfy IS NULL constraints on that table. This is 3079 ** use an index to satisfy IS NULL constraints on that table. This is ................................................................................................................................................................................ 3064 pProbe = &sPk; 3114 pProbe = &sPk; 3065 wsFlagMask = ~( 3115 wsFlagMask = ~( 3066 WHERE_COLUMN_IN|WHERE_COLUMN_EQ|WHERE_COLUMN_NULL|WHERE_COLUMN_RANGE 3116 WHERE_COLUMN_IN|WHERE_COLUMN_EQ|WHERE_COLUMN_NULL|WHERE_COLUMN_RANGE 3067 ); 3117 ); 3068 eqTermMask = WO_EQ|WO_IN; 3118 eqTermMask = WO_EQ|WO_IN; 3069 pIdx = 0; 3119 pIdx = 0; 3070 } 3120 } > 3121 > 3122 nOrderBy = p->pOrderBy ? p->pOrderBy->nExpr : 0; > 3123 if( p->i ){ > 3124 nPriorSat = p->aLevel[p->i-1].plan.nOBSat; > 3125 bSortInit = nPriorSat<nOrderBy; > 3126 bDistInit = 0; > 3127 }else{ > 3128 nPriorSat = 0; > 3129 bSortInit = nOrderBy>0; > 3130 bDistInit = p->pDistinct!=0; > 3131 } 3071 3132 3072 /* Loop over all indices looking for the best one to use 3133 /* Loop over all indices looking for the best one to use 3073 */ 3134 */ 3074 for(; pProbe; pIdx=pProbe=pProbe->pNext){ 3135 for(; pProbe; pIdx=pProbe=pProbe->pNext){ 3075 const tRowcnt * const aiRowEst = pProbe->aiRowEst; 3136 const tRowcnt * const aiRowEst = pProbe->aiRowEst; 3076 WhereCost pc; /* Cost of using pProbe */ 3137 WhereCost pc; /* Cost of using pProbe */ 3077 double log10N = (double)1; /* base-10 logarithm of nRow (inexact) */ 3138 double log10N = (double)1; /* base-10 logarithm of nRow (inexact) */ ................................................................................................................................................................................ 3142 ** SELECT a, b FROM tbl WHERE a = 1; 3203 ** SELECT a, b FROM tbl WHERE a = 1; 3143 ** SELECT a, b, c FROM tbl WHERE a = 1; 3204 ** SELECT a, b, c FROM tbl WHERE a = 1; 3144 */ 3205 */ 3145 int bInEst = 0; /* True if "x IN (SELECT...)" seen */ 3206 int bInEst = 0; /* True if "x IN (SELECT...)" seen */ 3146 int nInMul = 1; /* Number of distinct equalities to lookup */ 3207 int nInMul = 1; /* Number of distinct equalities to lookup */ 3147 double rangeDiv = (double)1; /* Estimated reduction in search space */ 3208 double rangeDiv = (double)1; /* Estimated reduction in search space */ 3148 int nBound = 0; /* Number of range constraints seen */ 3209 int nBound = 0; /* Number of range constraints seen */ 3149 int bSort; /* True if external sort required */ | 3210 char bSort = bSortInit; /* True if external sort required */ 3150 int bDist; /* True if index cannot help with DISTINCT */ | 3211 char bDist = bDistInit; /* True if index cannot help with DISTINCT */ 3151 int bLookup = 0; /* True if not a covering index */ | 3212 char bLookup = 0; /* True if not a covering index */ 3152 int nPriorSat; /* ORDER BY terms satisfied by outer loops */ < 3153 int nOrderBy; /* Number of ORDER BY terms */ < 3154 WhereTerm *pTerm; /* A single term of the WHERE clause */ 3213 WhereTerm *pTerm; /* A single term of the WHERE clause */ 3155 #ifdef SQLITE_ENABLE_STAT3 3214 #ifdef SQLITE_ENABLE_STAT3 3156 WhereTerm *pFirstTerm = 0; /* First term matching the index */ 3215 WhereTerm *pFirstTerm = 0; /* First term matching the index */ 3157 #endif 3216 #endif 3158 3217 3159 WHERETRACE(( 3218 WHERETRACE(( 3160 " %s(%s):\n", 3219 " %s(%s):\n", 3161 pSrc->pTab->zName, (pIdx ? pIdx->zName : "ipk") 3220 pSrc->pTab->zName, (pIdx ? pIdx->zName : "ipk") 3162 )); 3221 )); 3163 memset(&pc, 0, sizeof(pc)); 3222 memset(&pc, 0, sizeof(pc)); 3164 nOrderBy = p->pOrderBy ? p->pOrderBy->nExpr : 0; < 3165 if( p->i ){ < 3166 nPriorSat = pc.plan.nOBSat = p->aLevel[p->i-1].plan.nOBSat; < 3167 bSort = nPriorSat<nOrderBy; < 3168 bDist = 0; < 3169 }else{ < 3170 nPriorSat = pc.plan.nOBSat = 0; | 3223 pc.plan.nOBSat = nPriorSat; 3171 bSort = nOrderBy>0; < 3172 bDist = p->pDistinct!=0; < 3173 } < 3174 3224 3175 /* Determine the values of pc.plan.nEq and nInMul */ 3225 /* Determine the values of pc.plan.nEq and nInMul */ 3176 for(pc.plan.nEq=0; pc.plan.nEq<pProbe->nColumn; pc.plan.nEq++){ 3226 for(pc.plan.nEq=0; pc.plan.nEq<pProbe->nColumn; pc.plan.nEq++){ 3177 int j = pProbe->aiColumn[pc.plan.nEq]; 3227 int j = pProbe->aiColumn[pc.plan.nEq]; 3178 pTerm = findTerm(pWC, iCur, j, p->notReady, eqTermMask, pIdx); 3228 pTerm = findTerm(pWC, iCur, j, p->notReady, eqTermMask, pIdx); 3179 if( pTerm==0 ) break; 3229 if( pTerm==0 ) break; 3180 pc.plan.wsFlags |= (WHERE_COLUMN_EQ|WHERE_ROWID_EQ); 3230 pc.plan.wsFlags |= (WHERE_COLUMN_EQ|WHERE_ROWID_EQ); ................................................................................................................................................................................ 4042 4092 4043 #ifndef SQLITE_OMIT_VIRTUALTABLE 4093 #ifndef SQLITE_OMIT_VIRTUALTABLE 4044 if( (pLevel->plan.wsFlags & WHERE_VIRTUALTABLE)!=0 ){ 4094 if( (pLevel->plan.wsFlags & WHERE_VIRTUALTABLE)!=0 ){ 4045 /* Case 0: The table is a virtual-table. Use the VFilter and VNext 4095 /* Case 0: The table is a virtual-table. Use the VFilter and VNext 4046 ** to access the data. 4096 ** to access the data. 4047 */ 4097 */ 4048 int iReg; /* P3 Value for OP_VFilter */ 4098 int iReg; /* P3 Value for OP_VFilter */ > 4099 int addrNotFound; 4049 sqlite3_index_info *pVtabIdx = pLevel->plan.u.pVtabIdx; 4100 sqlite3_index_info *pVtabIdx = pLevel->plan.u.pVtabIdx; 4050 int nConstraint = pVtabIdx->nConstraint; 4101 int nConstraint = pVtabIdx->nConstraint; 4051 struct sqlite3_index_constraint_usage *aUsage = 4102 struct sqlite3_index_constraint_usage *aUsage = 4052 pVtabIdx->aConstraintUsage; 4103 pVtabIdx->aConstraintUsage; 4053 const struct sqlite3_index_constraint *aConstraint = 4104 const struct sqlite3_index_constraint *aConstraint = 4054 pVtabIdx->aConstraint; 4105 pVtabIdx->aConstraint; 4055 4106 4056 sqlite3ExprCachePush(pParse); 4107 sqlite3ExprCachePush(pParse); 4057 iReg = sqlite3GetTempRange(pParse, nConstraint+2); 4108 iReg = sqlite3GetTempRange(pParse, nConstraint+2); > 4109 addrNotFound = pLevel->addrBrk; 4058 for(j=1; j<=nConstraint; j++){ 4110 for(j=1; j<=nConstraint; j++){ 4059 for(k=0; k<nConstraint; k++){ 4111 for(k=0; k<nConstraint; k++){ 4060 if( aUsage[k].argvIndex==j ){ 4112 if( aUsage[k].argvIndex==j ){ 4061 int iTerm = aConstraint[k].iTermOffset; | 4113 WhereTerm *pTerm = &pWC->a[aConstraint[k].iTermOffset]; > 4114 int iTarget = iReg+j+1; > 4115 if( pTerm->eOperator & WO_IN ){ > 4116 codeEqualityTerm(pParse, pTerm, pLevel, iTarget); > 4117 addrNotFound = pLevel->addrNxt; > 4118 }else{ 4062 sqlite3ExprCode(pParse, pWC->a[iTerm].pExpr->pRight, iReg+j+1); | 4119 sqlite3ExprCode(pParse, pTerm->pExpr->pRight, iTarget); > 4120 } 4063 break; 4121 break; 4064 } 4122 } 4065 } 4123 } 4066 if( k==nConstraint ) break; 4124 if( k==nConstraint ) break; 4067 } 4125 } 4068 sqlite3VdbeAddOp2(v, OP_Integer, pVtabIdx->idxNum, iReg); 4126 sqlite3VdbeAddOp2(v, OP_Integer, pVtabIdx->idxNum, iReg); 4069 sqlite3VdbeAddOp2(v, OP_Integer, j-1, iReg+1); 4127 sqlite3VdbeAddOp2(v, OP_Integer, j-1, iReg+1); 4070 sqlite3VdbeAddOp4(v, OP_VFilter, iCur, addrBrk, iReg, pVtabIdx->idxStr, | 4128 sqlite3VdbeAddOp4(v, OP_VFilter, iCur, addrNotFound, iReg, pVtabIdx->idxStr, 4071 pVtabIdx->needToFreeIdxStr ? P4_MPRINTF : P4_STATIC); 4129 pVtabIdx->needToFreeIdxStr ? P4_MPRINTF : P4_STATIC); 4072 pVtabIdx->needToFreeIdxStr = 0; 4130 pVtabIdx->needToFreeIdxStr = 0; 4073 for(j=0; j<nConstraint; j++){ 4131 for(j=0; j<nConstraint; j++){ 4074 if( aUsage[j].omit ){ 4132 if( aUsage[j].omit ){ 4075 int iTerm = aConstraint[j].iTermOffset; 4133 int iTerm = aConstraint[j].iTermOffset; 4076 disableTerm(pLevel, &pWC->a[iTerm]); 4134 disableTerm(pLevel, &pWC->a[iTerm]); 4077 } 4135 }
Changes to test/auth2.test
127 do_test auth2-2.3 { 127 do_test auth2-2.3 { 128 set ::authargs {} 128 set ::authargs {} 129 db eval { 129 db eval { 130 SELECT a, b FROM v2; 130 SELECT a, b FROM v2; 131 } 131 } 132 set ::authargs 132 set ::authargs 133 } {SQLITE_SELECT {} {} {} {} 133 } {SQLITE_SELECT {} {} {} {} 134 SQLITE_READ v2 a main {} < 135 SQLITE_READ v2 b main {} < 136 SQLITE_READ t2 x main v2 134 SQLITE_READ t2 x main v2 137 SQLITE_READ t2 y main v2 135 SQLITE_READ t2 y main v2 138 SQLITE_READ t2 y main v2 136 SQLITE_READ t2 y main v2 139 SQLITE_READ t2 z main v2 137 SQLITE_READ t2 z main v2 > 138 SQLITE_READ v2 a main {} > 139 SQLITE_READ v2 b main {} 140 SQLITE_SELECT {} {} {} v2 140 SQLITE_SELECT {} {} {} v2 141 } 141 } 142 do_test auth2-2.4 { 142 do_test auth2-2.4 { 143 db2 eval { 143 db2 eval { 144 CREATE TABLE t3(p,q,r); 144 CREATE TABLE t3(p,q,r); 145 } 145 } 146 set ::authargs {} 146 set ::authargs {} 147 db eval { 147 db eval { 148 SELECT b, a FROM v2; 148 SELECT b, a FROM v2; 149 } 149 } 150 set ::authargs 150 set ::authargs 151 } {SQLITE_SELECT {} {} {} {} 151 } {SQLITE_SELECT {} {} {} {} 152 SQLITE_READ v2 b main {} < 153 SQLITE_READ v2 a main {} < 154 SQLITE_READ t2 x main v2 152 SQLITE_READ t2 x main v2 155 SQLITE_READ t2 y main v2 153 SQLITE_READ t2 y main v2 156 SQLITE_READ t2 y main v2 154 SQLITE_READ t2 y main v2 157 SQLITE_READ t2 z main v2 155 SQLITE_READ t2 z main v2 158 SQLITE_SELECT {} {} {} v2 < 159 SQLITE_SELECT {} {} {} {} < 160 SQLITE_READ v2 b main {} 156 SQLITE_READ v2 b main {} 161 SQLITE_READ v2 a main {} 157 SQLITE_READ v2 a main {} > 158 SQLITE_SELECT {} {} {} v2 > 159 SQLITE_SELECT {} {} {} {} 162 SQLITE_READ t2 x main v2 160 SQLITE_READ t2 x main v2 163 SQLITE_READ t2 y main v2 161 SQLITE_READ t2 y main v2 164 SQLITE_READ t2 y main v2 162 SQLITE_READ t2 y main v2 165 SQLITE_READ t2 z main v2 163 SQLITE_READ t2 z main v2 > 164 SQLITE_READ v2 b main {} > 165 SQLITE_READ v2 a main {} 166 SQLITE_SELECT {} {} {} v2 166 SQLITE_SELECT {} {} {} v2 167 } 167 } 168 db2 close 168 db2 close 169 169 170 finish_test 170 finish_test
Changes to test/check.test
11 # This file implements regression tests for SQLite library. The 11 # This file implements regression tests for SQLite library. The 12 # focus of this file is testing CHECK constraints 12 # focus of this file is testing CHECK constraints 13 # 13 # 14 # $Id: check.test,v 1.13 2009/06/05 17:09:12 drh Exp $ 14 # $Id: check.test,v 1.13 2009/06/05 17:09:12 drh Exp $ 15 15 16 set testdir [file dirname $argv0] 16 set testdir [file dirname $argv0] 17 source $testdir/tester.tcl 17 source $testdir/tester.tcl > 18 set ::testprefix check 18 19 19 # Only run these tests if the build includes support for CHECK constraints 20 # Only run these tests if the build includes support for CHECK constraints 20 ifcapable !check { 21 ifcapable !check { 21 finish_test 22 finish_test 22 return 23 return 23 } 24 } 24 25 ................................................................................................................................................................................ 408 } {0 {}} 409 } {0 {}} 409 do_test check-6.15 { 410 do_test check-6.15 { 410 execsql {SELECT * FROM t1} 411 execsql {SELECT * FROM t1} 411 } {3 12.0 2 20.0} 412 } {3 12.0 2 20.0} 412 413 413 414 414 } 415 } 415 416 > 417 #-------------------------------------------------------------------------- > 418 # If a connection opens a database that contains a CHECK constraint that > 419 # uses an unknown UDF, the schema should not be considered malformed. > 420 # Attempting to modify the table should fail (since the CHECK constraint > 421 # cannot be tested). > 422 # > 423 reset_db > 424 proc myfunc {x} {expr $x < 10} > 425 db func myfunc myfunc > 426 > 427 do_execsql_test 7.1 { CREATE TABLE t6(a CHECK (myfunc(a))) } > 428 do_execsql_test 7.2 { INSERT INTO t6 VALUES(9) } > 429 do_catchsql_test 7.3 { INSERT INTO t6 VALUES(11) } {1 {constraint failed}} > 430 > 431 do_test 7.4 { > 432 sqlite3 db2 test.db > 433 execsql { SELECT * FROM t6 } db2 > 434 } {9} > 435 > 436 do_test 7.5 { > 437 catchsql { INSERT INTO t6 VALUES(8) } db2 > 438 } {1 {unknown function: myfunc()}} > 439 > 440 do_test 7.6 { > 441 catchsql { CREATE TABLE t7(a CHECK (myfunc(a))) } db2 > 442 } {1 {no such function: myfunc}} > 443 > 444 do_test 7.7 { > 445 db2 func myfunc myfunc > 446 execsql { INSERT INTO t6 VALUES(8) } db2 > 447 } {} > 448 > 449 do_test 7.8 { > 450 db2 func myfunc myfunc > 451 catchsql { INSERT INTO t6 VALUES(12) } db2 > 452 } {1 {constraint failed}} > 453 > 454 416 finish_test 455 finish_test
Changes to test/collate1.test
71 } {} 71 } {} 72 do_test collate1-1.1 { 72 do_test collate1-1.1 { 73 execsql { 73 execsql { 74 SELECT c2 FROM collate1t1 ORDER BY 1; 74 SELECT c2 FROM collate1t1 ORDER BY 1; 75 } 75 } 76 } {{} 0x119 0x2D} 76 } {{} 0x119 0x2D} 77 do_test collate1-1.2 { 77 do_test collate1-1.2 { > 78 breakpoint 78 execsql { 79 execsql { 79 SELECT c2 FROM collate1t1 ORDER BY 1 COLLATE hex; 80 SELECT c2 FROM collate1t1 ORDER BY 1 COLLATE hex; 80 } 81 } 81 } {{} 0x2D 0x119} 82 } {{} 0x2D 0x119} 82 do_test collate1-1.3 { 83 do_test collate1-1.3 { 83 execsql { 84 execsql { 84 SELECT c2 FROM collate1t1 ORDER BY 1 COLLATE hex DESC; 85 SELECT c2 FROM collate1t1 ORDER BY 1 COLLATE hex DESC;
Changes to test/distinct.test
164 2 "b, a FROM t1" {} {B A b a} 164 2 "b, a FROM t1" {} {B A b a} 165 3 "a, b, c FROM t1" {hash} {a b c A B C} 165 3 "a, b, c FROM t1" {hash} {a b c A B C} 166 4 "a, b, c FROM t1 ORDER BY a, b, c" {btree} {A B C a b c} 166 4 "a, b, c FROM t1 ORDER BY a, b, c" {btree} {A B C a b c} 167 5 "b FROM t1 WHERE a = 'a'" {} {b} 167 5 "b FROM t1 WHERE a = 'a'" {} {b} 168 6 "b FROM t1" {hash} {b B} 168 6 "b FROM t1" {hash} {b B} 169 7 "a FROM t1" {} {A a} 169 7 "a FROM t1" {} {A a} 170 8 "b COLLATE nocase FROM t1" {} {b} 170 8 "b COLLATE nocase FROM t1" {} {b} 171 9 "b COLLATE nocase FROM t1 ORDER BY b COLLATE nocase" {} {B} | 171 9 "b COLLATE nocase FROM t1 ORDER BY b COLLATE nocase" {} {b} 172 } { 172 } { 173 do_execsql_test 2.$tn.1 "SELECT DISTINCT $sql" $res 173 do_execsql_test 2.$tn.1 "SELECT DISTINCT $sql" $res 174 do_temptables_test 2.$tn.2 "SELECT DISTINCT $sql" $temptables 174 do_temptables_test 2.$tn.2 "SELECT DISTINCT $sql" $temptables 175 } 175 } 176 176 177 do_execsql_test 2.A { 177 do_execsql_test 2.A { 178 SELECT (SELECT DISTINCT o.a FROM t1 AS i) FROM t1 AS o ORDER BY rowid; 178 SELECT (SELECT DISTINCT o.a FROM t1 AS i) FROM t1 AS o ORDER BY rowid;
Changes to test/e_fkey.test
623 } 623 } 624 } {} 624 } {} 625 proc test_efkey_57 {tn isError sql} { 625 proc test_efkey_57 {tn isError sql} { 626 catchsql { DROP TABLE t1 } 626 catchsql { DROP TABLE t1 } 627 execsql $sql 627 execsql $sql 628 do_test e_fkey-18.$tn { 628 do_test e_fkey-18.$tn { 629 catchsql { INSERT INTO t2 VALUES(NULL) } 629 catchsql { INSERT INTO t2 VALUES(NULL) } 630 } [lindex {{0 {}} {1 {foreign key mismatch}}} $isError] | 630 } [lindex {{0 {}} {/1 {foreign key mismatch - ".*" referencing ".*"}/}} \ > 631 $isError] 631 } 632 } 632 test_efkey_57 2 0 { CREATE TABLE t1(x PRIMARY KEY) } 633 test_efkey_57 2 0 { CREATE TABLE t1(x PRIMARY KEY) } 633 test_efkey_57 3 0 { CREATE TABLE t1(x UNIQUE) } 634 test_efkey_57 3 0 { CREATE TABLE t1(x UNIQUE) } 634 test_efkey_57 4 0 { CREATE TABLE t1(x); CREATE UNIQUE INDEX t1i ON t1(x) } 635 test_efkey_57 4 0 { CREATE TABLE t1(x); CREATE UNIQUE INDEX t1i ON t1(x) } 635 test_efkey_57 5 1 { 636 test_efkey_57 5 1 { 636 CREATE TABLE t1(x); 637 CREATE TABLE t1(x); 637 CREATE UNIQUE INDEX t1i ON t1(x COLLATE nocase); 638 CREATE UNIQUE INDEX t1i ON t1(x COLLATE nocase); ................................................................................................................................................................................ 694 INSERT INTO child1 VALUES('xxx', 1); 695 INSERT INTO child1 VALUES('xxx', 1); 695 INSERT INTO child2 VALUES('xxx', 2); 696 INSERT INTO child2 VALUES('xxx', 2); 696 INSERT INTO child3 VALUES(3, 4); 697 INSERT INTO child3 VALUES(3, 4); 697 } 698 } 698 } {} 699 } {} 699 do_test e_fkey-19.2 { 700 do_test e_fkey-19.2 { 700 catchsql { INSERT INTO child4 VALUES('xxx', 5) } 701 catchsql { INSERT INTO child4 VALUES('xxx', 5) } 701 } {1 {foreign key mismatch}} | 702 } {1 {foreign key mismatch - "child4" referencing "parent"}} 702 do_test e_fkey-19.3 { 703 do_test e_fkey-19.3 { 703 catchsql { INSERT INTO child5 VALUES('xxx', 6) } 704 catchsql { INSERT INTO child5 VALUES('xxx', 6) } 704 } {1 {foreign key mismatch}} | 705 } {1 {foreign key mismatch - "child5" referencing "parent"}} 705 do_test e_fkey-19.4 { 706 do_test e_fkey-19.4 { 706 catchsql { INSERT INTO child6 VALUES(2, 3) } 707 catchsql { INSERT INTO child6 VALUES(2, 3) } 707 } {1 {foreign key mismatch}} | 708 } {1 {foreign key mismatch - "child6" referencing "parent"}} 708 do_test e_fkey-19.5 { 709 do_test e_fkey-19.5 { 709 catchsql { INSERT INTO child7 VALUES(3) } 710 catchsql { INSERT INTO child7 VALUES(3) } 710 } {1 {foreign key mismatch}} | 711 } {1 {foreign key mismatch - "child7" referencing "parent"}} 711 712 712 #------------------------------------------------------------------------- 713 #------------------------------------------------------------------------- 713 # Test errors in the database schema that are detected while preparing 714 # Test errors in the database schema that are detected while preparing 714 # DML statements. The error text for these messages always matches 715 # DML statements. The error text for these messages always matches 715 # either "foreign key mismatch" or "no such table*" (using [string match]). 716 # either "foreign key mismatch" or "no such table*" (using [string match]). 716 # 717 # 717 # EVIDENCE-OF: R-45488-08504 If the database schema contains foreign key 718 # EVIDENCE-OF: R-45488-08504 If the database schema contains foreign key ................................................................................................................................................................................ 761 CREATE TABLE p7(a, b, PRIMARY KEY(a, b)); 762 CREATE TABLE p7(a, b, PRIMARY KEY(a, b)); 762 CREATE TABLE c7(c, d REFERENCES p7); 763 CREATE TABLE c7(c, d REFERENCES p7); 763 } 764 } 764 } {} 765 } {} 765 766 766 foreach {tn tbl ptbl err} { 767 foreach {tn tbl ptbl err} { 767 2 c1 {} "no such table: main.nosuchtable" 768 2 c1 {} "no such table: main.nosuchtable" 768 3 c2 p2 "foreign key mismatch" | 769 3 c2 p2 "foreign key mismatch - \"c2\" referencing \"p2\"" 769 4 c3 p3 "foreign key mismatch" | 770 4 c3 p3 "foreign key mismatch - \"c3\" referencing \"p3\"" 770 5 c4 p4 "foreign key mismatch" | 771 5 c4 p4 "foreign key mismatch - \"c4\" referencing \"p4\"" 771 6 c5 p5 "foreign key mismatch" | 772 6 c5 p5 "foreign key mismatch - \"c5\" referencing \"p5\"" 772 7 c6 p6 "foreign key mismatch" | 773 7 c6 p6 "foreign key mismatch - \"c6\" referencing \"p6\"" 773 8 c7 p7 "foreign key mismatch" | 774 8 c7 p7 "foreign key mismatch - \"c7\" referencing \"p7\"" 774 } { 775 } { 775 do_test e_fkey-20.$tn.1 { 776 do_test e_fkey-20.$tn.1 { 776 catchsql "INSERT INTO $tbl VALUES('a', 'b')" 777 catchsql "INSERT INTO $tbl VALUES('a', 'b')" 777 } [list 1 $err] 778 } [list 1 $err] 778 do_test e_fkey-20.$tn.2 { 779 do_test e_fkey-20.$tn.2 { 779 catchsql "UPDATE $tbl SET c = ?, d = ?" 780 catchsql "UPDATE $tbl SET c = ?, d = ?" 780 } [list 1 $err] 781 } [list 1 $err] ................................................................................................................................................................................ 816 execsql { 817 execsql { 817 INSERT INTO parent2 VALUES('I', 'II'); 818 INSERT INTO parent2 VALUES('I', 'II'); 818 INSERT INTO child8 VALUES('I', 'II'); 819 INSERT INTO child8 VALUES('I', 'II'); 819 } 820 } 820 } {} 821 } {} 821 do_test e_fkey-21.3 { 822 do_test e_fkey-21.3 { 822 catchsql { INSERT INTO child9 VALUES('I') } 823 catchsql { INSERT INTO child9 VALUES('I') } 823 } {1 {foreign key mismatch}} | 824 } {1 {foreign key mismatch - "child9" referencing "parent2"}} 824 do_test e_fkey-21.4 { 825 do_test e_fkey-21.4 { 825 catchsql { INSERT INTO child9 VALUES('II') } 826 catchsql { INSERT INTO child9 VALUES('II') } 826 } {1 {foreign key mismatch}} | 827 } {1 {foreign key mismatch - "child9" referencing "parent2"}} 827 do_test e_fkey-21.5 { 828 do_test e_fkey-21.5 { 828 catchsql { INSERT INTO child9 VALUES(NULL) } 829 catchsql { INSERT INTO child9 VALUES(NULL) } 829 } {1 {foreign key mismatch}} | 830 } {1 {foreign key mismatch - "child9" referencing "parent2"}} 830 do_test e_fkey-21.6 { 831 do_test e_fkey-21.6 { 831 catchsql { INSERT INTO child10 VALUES('I', 'II', 'III') } 832 catchsql { INSERT INTO child10 VALUES('I', 'II', 'III') } 832 } {1 {foreign key mismatch}} | 833 } {1 {foreign key mismatch - "child10" referencing "parent2"}} 833 do_test e_fkey-21.7 { 834 do_test e_fkey-21.7 { 834 catchsql { INSERT INTO child10 VALUES(1, 2, 3) } 835 catchsql { INSERT INTO child10 VALUES(1, 2, 3) } 835 } {1 {foreign key mismatch}} | 836 } {1 {foreign key mismatch - "child10" referencing "parent2"}} 836 do_test e_fkey-21.8 { 837 do_test e_fkey-21.8 { 837 catchsql { INSERT INTO child10 VALUES(NULL, NULL, NULL) } 838 catchsql { INSERT INTO child10 VALUES(NULL, NULL, NULL) } 838 } {1 {foreign key mismatch}} | 839 } {1 {foreign key mismatch - "child10" referencing "parent2"}} 839 840 840 #------------------------------------------------------------------------- 841 #------------------------------------------------------------------------- 841 # Test errors that are reported when creating the child table. 842 # Test errors that are reported when creating the child table. 842 # Specifically: 843 # Specifically: 843 # 844 # 844 # * different number of child and parent key columns, and 845 # * different number of child and parent key columns, and 845 # * child columns that do not exist. 846 # * child columns that do not exist. ................................................................................................................................................................................ 1147 do_test e_fkey-28.8 { 1148 do_test e_fkey-28.8 { 1148 drop_all_tables 1149 drop_all_tables 1149 execsql { 1150 execsql { 1150 CREATE TABLE p(x PRIMARY KEY); 1151 CREATE TABLE p(x PRIMARY KEY); 1151 CREATE TABLE c(a, b, FOREIGN KEY(a,b) REFERENCES p); 1152 CREATE TABLE c(a, b, FOREIGN KEY(a,b) REFERENCES p); 1152 } 1153 } 1153 catchsql {DELETE FROM p} 1154 catchsql {DELETE FROM p} 1154 } {1 {foreign key mismatch}} | 1155 } {1 {foreign key mismatch - "c" referencing "p"}} 1155 do_test e_fkey-28.9 { 1156 do_test e_fkey-28.9 { 1156 drop_all_tables 1157 drop_all_tables 1157 execsql { 1158 execsql { 1158 CREATE TABLE p(x, y, PRIMARY KEY(x,y)); 1159 CREATE TABLE p(x, y, PRIMARY KEY(x,y)); 1159 CREATE TABLE c(a REFERENCES p); 1160 CREATE TABLE c(a REFERENCES p); 1160 } 1161 } 1161 catchsql {DELETE FROM p} 1162 catchsql {DELETE FROM p} 1162 } {1 {foreign key mismatch}} | 1163 } {1 {foreign key mismatch - "c" referencing "p"}} 1163 1164 1164 1165 1165 #------------------------------------------------------------------------- 1166 #------------------------------------------------------------------------- 1166 # EVIDENCE-OF: R-24676-09859 1167 # EVIDENCE-OF: R-24676-09859 1167 # 1168 # 1168 # Test the example schema in the "Composite Foreign Key Constraints" 1169 # Test the example schema in the "Composite Foreign Key Constraints" 1169 # section. 1170 # section. ................................................................................................................................................................................ 2725 SELECT * FROM c3; 2726 SELECT * FROM c3; 2726 ROLLBACK; 2727 ROLLBACK; 2727 } 2728 } 2728 } {{} 2} 2729 } {{} 2} 2729 do_test e_fkey-60.4 { 2730 do_test e_fkey-60.4 { 2730 execsql { CREATE TABLE nosuchtable(x PRIMARY KEY) } 2731 execsql { CREATE TABLE nosuchtable(x PRIMARY KEY) } 2731 catchsql { DELETE FROM p } 2732 catchsql { DELETE FROM p } 2732 } {1 {foreign key mismatch}} | 2733 } {1 {foreign key mismatch - "c2" referencing "p"}} 2733 do_test e_fkey-60.5 { 2734 do_test e_fkey-60.5 { 2734 execsql { DROP TABLE c1 } 2735 execsql { DROP TABLE c1 } 2735 catchsql { DELETE FROM p } 2736 catchsql { DELETE FROM p } 2736 } {1 {foreign key mismatch}} | 2737 } {1 {foreign key mismatch - "c2" referencing "p"}} 2737 do_test e_fkey-60.6 { 2738 do_test e_fkey-60.6 { 2738 execsql { DROP TABLE c2 } 2739 execsql { DROP TABLE c2 } 2739 execsql { DELETE FROM p } 2740 execsql { DELETE FROM p } 2740 } {} 2741 } {} 2741 2742 2742 #------------------------------------------------------------------------- 2743 #------------------------------------------------------------------------- 2743 # Test that the special behaviours of ALTER and DROP TABLE are only 2744 # Test that the special behaviours of ALTER and DROP TABLE are only
Changes to test/e_insert.test
137 82 "INSERT OR IGNORE INTO a1 (b, a) VALUES(1, 2),(3,4)" {} 137 82 "INSERT OR IGNORE INTO a1 (b, a) VALUES(1, 2),(3,4)" {} 138 83 "REPLACE INTO a1 (b, a) VALUES(1, 2),(3,4)" {} 138 83 "REPLACE INTO a1 (b, a) VALUES(1, 2),(3,4)" {} 139 84 "REPLACE INTO main.a1 (b, a) VALUES(1, 2),(3,4)" {} 139 84 "REPLACE INTO main.a1 (b, a) VALUES(1, 2),(3,4)" {} 140 } 140 } 141 141 142 delete_all_data 142 delete_all_data 143 143 144 # EVIDENCE-OF: R-20288-20462 The first form (with the "VALUES" keyword) | 144 # EVIDENCE-OF: R-21490-41092 The first form (with the "VALUES" keyword) 145 # creates a single new row in an existing table. | 145 # creates one or more new rows in an existing table. 146 # 146 # 147 do_insert_tests e_insert-1.1 { 147 do_insert_tests e_insert-1.1 { 148 0 "SELECT count(*) FROM a2" {0} 148 0 "SELECT count(*) FROM a2" {0} 149 149 150 1a "INSERT INTO a2 VALUES(1, 2, 3)" {} 150 1a "INSERT INTO a2 VALUES(1, 2, 3)" {} 151 1b "SELECT count(*) FROM a2" {1} 151 1b "SELECT count(*) FROM a2" {1} 152 152 153 2a "INSERT INTO a2(a, b) VALUES(1, 2)" {} 153 2a "INSERT INTO a2(a, b) VALUES(1, 2)" {} 154 2b "SELECT count(*) FROM a2" {2} 154 2b "SELECT count(*) FROM a2" {2} 155 } | 155 > 156 3a "INSERT INTO a2(a) VALUES(3),(4)" {} > 157 3b "SELECT count(*) FROM a2" {4} 156 | 158 } > 159 157 # EVIDENCE-OF: R-36040-20870 If no column-list is specified then the | 160 # EVIDENCE-OF: R-53616-44976 If no column-list is specified then the 158 # number of values must be the same as the number of columns in the | 161 # number of values inserted into each row must be the same as the number 159 # table. | 162 # of columns in the table. 160 # 163 # 161 # A test in the block above verifies that if the VALUES list has the 164 # A test in the block above verifies that if the VALUES list has the 162 # correct number of columns (for table a2, 3 columns) works. So these 165 # correct number of columns (for table a2, 3 columns) works. So these 163 # tests just show that other values cause an error. 166 # tests just show that other values cause an error. 164 # 167 # 165 do_insert_tests e_insert-1.2 -error { 168 do_insert_tests e_insert-1.2 -error { 166 table %s has %d columns but %d values were supplied 169 table %s has %d columns but %d values were supplied ................................................................................................................................................................................ 167 } { 170 } { 168 1 "INSERT INTO a2 VALUES(1)" {a2 3 1} 171 1 "INSERT INTO a2 VALUES(1)" {a2 3 1} 169 2 "INSERT INTO a2 VALUES(1,2)" {a2 3 2} 172 2 "INSERT INTO a2 VALUES(1,2)" {a2 3 2} 170 3 "INSERT INTO a2 VALUES(1,2,3,4)" {a2 3 4} 173 3 "INSERT INTO a2 VALUES(1,2,3,4)" {a2 3 4} 171 4 "INSERT INTO a2 VALUES(1,2,3,4,5)" {a2 3 5} 174 4 "INSERT INTO a2 VALUES(1,2,3,4,5)" {a2 3 5} 172 } 175 } 173 176 174 # EVIDENCE-OF: R-04006-57648 In this case the result of evaluating the | 177 # EVIDENCE-OF: R-34231-22576 In this case the result of evaluating the 175 # left-most expression in the VALUES list is inserted into the left-most | 178 # left-most expression in each term of the VALUES list is inserted into 176 # column of the new row, and so on. | 179 # the left-most column of the each new row, and forth for each > 180 # subsequent expression. 177 # 181 # 178 delete_all_data 182 delete_all_data 179 do_insert_tests e_insert-1.3 { 183 do_insert_tests e_insert-1.3 { 180 1a "INSERT INTO a2 VALUES(1, 2, 3)" {} 184 1a "INSERT INTO a2 VALUES(1, 2, 3)" {} 181 1b "SELECT * FROM a2 WHERE oid=last_insert_rowid()" {1 2 3} 185 1b "SELECT * FROM a2 WHERE oid=last_insert_rowid()" {1 2 3} 182 186 183 2a "INSERT INTO a2 VALUES('abc', NULL, 3*3+1)" {} 187 2a "INSERT INTO a2 VALUES('abc', NULL, 3*3+1)" {} 184 2b "SELECT * FROM a2 WHERE oid=last_insert_rowid()" {abc {} 10} 188 2b "SELECT * FROM a2 WHERE oid=last_insert_rowid()" {abc {} 10} 185 189 186 3a "INSERT INTO a2 VALUES((SELECT count(*) FROM a2), 'x', 'y')" {} 190 3a "INSERT INTO a2 VALUES((SELECT count(*) FROM a2), 'x', 'y')" {} 187 3b "SELECT * FROM a2 WHERE oid=last_insert_rowid()" {2 x y} 191 3b "SELECT * FROM a2 WHERE oid=last_insert_rowid()" {2 x y} 188 } 192 } 189 193 190 # EVIDENCE-OF: R-62524-00361 If a column-list is specified, then the | 194 # EVIDENCE-OF: R-44710-64652 If a column-list is specified, then the > 195 # number of values in each term of the VALUS list must match the number 191 # number of values must match the number of specified columns. | 196 # of specified columns. 192 # 197 # 193 do_insert_tests e_insert-1.4 -error { 198 do_insert_tests e_insert-1.4 -error { 194 %d values for %d columns 199 %d values for %d columns 195 } { 200 } { 196 1 "INSERT INTO a2(a, b, c) VALUES(1)" {1 3} 201 1 "INSERT INTO a2(a, b, c) VALUES(1)" {1 3} 197 2 "INSERT INTO a2(a, b, c) VALUES(1,2)" {2 3} 202 2 "INSERT INTO a2(a, b, c) VALUES(1,2)" {2 3} 198 3 "INSERT INTO a2(a, b, c) VALUES(1,2,3,4)" {4 3} 203 3 "INSERT INTO a2(a, b, c) VALUES(1,2,3,4)" {4 3}
Changes to test/e_uri.test
257 7 {file:test.db?mode=memory} {not an error} 257 7 {file:test.db?mode=memory} {not an error} 258 8 {file:test.db?mode=MEMORY} {no such access mode: MEMORY} 258 8 {file:test.db?mode=MEMORY} {no such access mode: MEMORY} 259 " { 259 " { 260 do_test 7.$tn { open_uri_error $uri } $error 260 do_test 7.$tn { open_uri_error $uri } $error 261 } 261 } 262 262 263 263 264 # EVIDENCE-OF: R-09651-31805 If "ro" is specified, then the database is | 264 # EVIDENCE-OF: R-43036-46756 If "ro" is specified, then the database is 265 # opened for read-only access, just as if the SQLITE_OPEN_READONLY flag 265 # opened for read-only access, just as if the SQLITE_OPEN_READONLY flag 266 # had been set in the third argument to sqlite3_prepare_v2(). | 266 # had been set in the third argument to sqlite3_open_v2(). 267 # 267 # 268 # EVIDENCE-OF: R-40137-26050 If the mode option is set to "rw", then the 268 # EVIDENCE-OF: R-40137-26050 If the mode option is set to "rw", then the 269 # database is opened for read-write (but not create) access, as if 269 # database is opened for read-write (but not create) access, as if 270 # SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had been set. 270 # SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had been set. 271 # 271 # 272 # EVIDENCE-OF: R-26845-32976 Value "rwc" is equivalent to setting both 272 # EVIDENCE-OF: R-26845-32976 Value "rwc" is equivalent to setting both 273 # SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. 273 # SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE.
Changes to test/filefmt.test
209 sql36231 { DROP TABLE t1 } 209 sql36231 { DROP TABLE t1 } 210 } {} 210 } {} 211 do_execsql_test filefmt-3.3 { 211 do_execsql_test filefmt-3.3 { 212 SELECT * FROM sqlite_master; 212 SELECT * FROM sqlite_master; 213 PRAGMA integrity_check; 213 PRAGMA integrity_check; 214 } {ok} 214 } {ok} 215 215 > 216 reset_db > 217 do_execsql_test filefmt-4.1 { > 218 PRAGMA auto_vacuum = 1; > 219 CREATE TABLE t1(x, y); > 220 CREATE TABLE t2(x, y); > 221 > 222 INSERT INTO t1 VALUES(randomblob(100), randomblob(100)); > 223 INSERT INTO t1 VALUES(randomblob(100), randomblob(100)); > 224 INSERT INTO t1 VALUES(randomblob(100), randomblob(100)); > 225 INSERT INTO t1 VALUES(randomblob(100), randomblob(100)); > 226 INSERT INTO t1 VALUES(randomblob(100), randomblob(100)); > 227 INSERT INTO t1 VALUES(randomblob(100), randomblob(100)); > 228 > 229 INSERT INTO t2 SELECT randomblob(100), randomblob(100) FROM t1; > 230 INSERT INTO t2 SELECT randomblob(100), randomblob(100) FROM t1; > 231 INSERT INTO t2 SELECT randomblob(100), randomblob(100) FROM t1; > 232 INSERT INTO t2 SELECT randomblob(100), randomblob(100) FROM t1; > 233 } > 234 > 235 do_test filefmt-4.2 { > 236 sql36231 { INSERT INTO t2 SELECT * FROM t1 } > 237 } {} > 238 > 239 do_test filefmt-4.3 { > 240 forcedelete bak.db > 241 db backup bak.db > 242 } {} > 243 > 244 do_test filefmt-4.4 { > 245 sqlite3 db2 bak.db > 246 db2 eval { PRAGMA integrity_check } > 247 } {ok} > 248 db2 close > 249 216 finish_test 250 finish_test > 251
Changes to test/fkey2.test
135 4.13 "UPDATE t7 SET b = 1" {0 {}} 135 4.13 "UPDATE t7 SET b = 1" {0 {}} 136 4.14 "INSERT INTO t8 VALUES('a', 'b')" {1 {foreign key constraint failed}} 136 4.14 "INSERT INTO t8 VALUES('a', 'b')" {1 {foreign key constraint failed}} 137 4.15 "UPDATE t7 SET b = 5" {1 {foreign key constraint failed}} 137 4.15 "UPDATE t7 SET b = 5" {1 {foreign key constraint failed}} 138 4.16 "UPDATE t7 SET rowid = 5" {1 {foreign key constraint failed}} 138 4.16 "UPDATE t7 SET rowid = 5" {1 {foreign key constraint failed}} 139 4.17 "UPDATE t7 SET a = 10" {0 {}} 139 4.17 "UPDATE t7 SET a = 10" {0 {}} 140 140 141 5.1 "INSERT INTO t9 VALUES(1, 3)" {1 {no such table: main.nosuchtable}} 141 5.1 "INSERT INTO t9 VALUES(1, 3)" {1 {no such table: main.nosuchtable}} 142 5.2 "INSERT INTO t10 VALUES(1, 3)" {1 {foreign key mismatch}} | 142 5.2 "INSERT INTO t10 VALUES(1, 3)" > 143 {1 {foreign key mismatch - "t10" referencing "t9"}} 143 } 144 } 144 145 145 do_test fkey2-1.1.0 { 146 do_test fkey2-1.1.0 { 146 execsql [string map {/D/ {}} $FkeySimpleSchema] 147 execsql [string map {/D/ {}} $FkeySimpleSchema] 147 } {} 148 } {} 148 foreach {tn zSql res} $FkeySimpleTests { 149 foreach {tn zSql res} $FkeySimpleTests { 149 do_test fkey2-1.1.$tn { catchsql $zSql } $res | 150 do_test fkey2-1.1.$tn.1 { catchsql $zSql } $res > 151 do_test fkey2-1.1.$tn.2 { execsql {PRAGMA foreign_key_check(t1)} } {} > 152 do_test fkey2-1.1.$tn.3 { execsql {PRAGMA foreign_key_check(t2)} } {} > 153 do_test fkey2-1.1.$tn.4 { execsql {PRAGMA foreign_key_check(t3)} } {} > 154 do_test fkey2-1.1.$tn.5 { execsql {PRAGMA foreign_key_check(t4)} } {} > 155 do_test fkey2-1.1.$tn.6 { execsql {PRAGMA foreign_key_check(t7)} } {} > 156 do_test fkey2-1.1.$tn.7 { execsql {PRAGMA foreign_key_check(t8)} } {} 150 } 157 } 151 drop_all_tables 158 drop_all_tables 152 159 153 do_test fkey2-1.2.0 { 160 do_test fkey2-1.2.0 { 154 execsql [string map {/D/ {DEFERRABLE INITIALLY DEFERRED}} $FkeySimpleSchema] 161 execsql [string map {/D/ {DEFERRABLE INITIALLY DEFERRED}} $FkeySimpleSchema] 155 } {} 162 } {} 156 foreach {tn zSql res} $FkeySimpleTests { 163 foreach {tn zSql res} $FkeySimpleTests { 157 do_test fkey2-1.2.$tn { catchsql $zSql } $res 164 do_test fkey2-1.2.$tn { catchsql $zSql } $res > 165 do_test fkey2-1.2.$tn.2 { execsql {PRAGMA foreign_key_check(t1)} } {} > 166 do_test fkey2-1.2.$tn.3 { execsql {PRAGMA foreign_key_check(t2)} } {} > 167 do_test fkey2-1.2.$tn.4 { execsql {PRAGMA foreign_key_check(t3)} } {} > 168 do_test fkey2-1.2.$tn.5 { execsql {PRAGMA foreign_key_check(t4)} } {} > 169 do_test fkey2-1.2.$tn.6 { execsql {PRAGMA foreign_key_check(t7)} } {} > 170 do_test fkey2-1.2.$tn.7 { execsql {PRAGMA foreign_key_check(t8)} } {} 158 } 171 } 159 drop_all_tables 172 drop_all_tables 160 173 161 do_test fkey2-1.3.0 { 174 do_test fkey2-1.3.0 { 162 execsql [string map {/D/ {}} $FkeySimpleSchema] 175 execsql [string map {/D/ {}} $FkeySimpleSchema] 163 execsql { PRAGMA count_changes = 1 } 176 execsql { PRAGMA count_changes = 1 } 164 } {} 177 } {} 165 foreach {tn zSql res} $FkeySimpleTests { 178 foreach {tn zSql res} $FkeySimpleTests { 166 if {$res == "0 {}"} { set res {0 1} } 179 if {$res == "0 {}"} { set res {0 1} } 167 do_test fkey2-1.3.$tn { catchsql $zSql } $res 180 do_test fkey2-1.3.$tn { catchsql $zSql } $res > 181 do_test fkey2-1.3.$tn.2 { execsql {PRAGMA foreign_key_check(t1)} } {} > 182 do_test fkey2-1.3.$tn.3 { execsql {PRAGMA foreign_key_check(t2)} } {} > 183 do_test fkey2-1.3.$tn.4 { execsql {PRAGMA foreign_key_check(t3)} } {} > 184 do_test fkey2-1.3.$tn.5 { execsql {PRAGMA foreign_key_check(t4)} } {} > 185 do_test fkey2-1.3.$tn.6 { execsql {PRAGMA foreign_key_check(t7)} } {} > 186 do_test fkey2-1.3.$tn.7 { execsql {PRAGMA foreign_key_check(t8)} } {} 168 } 187 } 169 execsql { PRAGMA count_changes = 0 } 188 execsql { PRAGMA count_changes = 0 } 170 drop_all_tables 189 drop_all_tables 171 190 172 do_test fkey2-1.4.0 { 191 do_test fkey2-1.4.0 { 173 execsql [string map {/D/ {}} $FkeySimpleSchema] 192 execsql [string map {/D/ {}} $FkeySimpleSchema] 174 execsql { PRAGMA count_changes = 1 } 193 execsql { PRAGMA count_changes = 1 } ................................................................................................................................................................................ 677 CREATE UNIQUE INDEX i ON p(a COLLATE nocase); 696 CREATE UNIQUE INDEX i ON p(a COLLATE nocase); 678 CREATE TABLE c(x REFERENCES p(a)); 697 CREATE TABLE c(x REFERENCES p(a)); 679 }] { 698 }] { 680 drop_all_tables 699 drop_all_tables 681 do_test fkey2-10.1.[incr tn] { 700 do_test fkey2-10.1.[incr tn] { 682 execsql $zSql 701 execsql $zSql 683 catchsql { INSERT INTO c DEFAULT VALUES } 702 catchsql { INSERT INTO c DEFAULT VALUES } 684 } {1 {foreign key mismatch}} | 703 } {/1 {foreign key mismatch - "c" referencing "."}/} 685 } 704 } 686 705 687 # "rowid" cannot be used as part of a child or parent key definition 706 # "rowid" cannot be used as part of a child or parent key definition 688 # unless it happens to be the name of an explicitly declared column. 707 # unless it happens to be the name of an explicitly declared column. 689 # 708 # 690 do_test fkey2-10.2.1 { 709 do_test fkey2-10.2.1 { 691 drop_all_tables 710 drop_all_tables ................................................................................................................................................................................ 705 drop_all_tables 724 drop_all_tables 706 catchsql { 725 catchsql { 707 CREATE TABLE t1(a, b); 726 CREATE TABLE t1(a, b); 708 CREATE TABLE t2(c, d, FOREIGN KEY(c) REFERENCES t1(rowid)); 727 CREATE TABLE t2(c, d, FOREIGN KEY(c) REFERENCES t1(rowid)); 709 INSERT INTO t1(rowid, a, b) VALUES(1, 1, 1); 728 INSERT INTO t1(rowid, a, b) VALUES(1, 1, 1); 710 INSERT INTO t2 VALUES(1, 1); 729 INSERT INTO t2 VALUES(1, 1); 711 } 730 } 712 } {1 {foreign key mismatch}} | 731 } {1 {foreign key mismatch - "t2" referencing "t1"}} 713 do_test fkey2-10.2.2 { 732 do_test fkey2-10.2.2 { 714 drop_all_tables 733 drop_all_tables 715 catchsql { 734 catchsql { 716 CREATE TABLE t1(rowid PRIMARY KEY, b); 735 CREATE TABLE t1(rowid PRIMARY KEY, b); 717 CREATE TABLE t2(c, d, FOREIGN KEY(c) REFERENCES t1(rowid)); 736 CREATE TABLE t2(c, d, FOREIGN KEY(c) REFERENCES t1(rowid)); 718 INSERT INTO t1(rowid, b) VALUES(1, 1); 737 INSERT INTO t1(rowid, b) VALUES(1, 1); 719 INSERT INTO t2 VALUES(1, 1); 738 INSERT INTO t2 VALUES(1, 1); ................................................................................................................................................................................ 1219 } {} 1238 } {} 1220 do_test fkey-2.14.3.8 { 1239 do_test fkey-2.14.3.8 { 1221 execsql { 1240 execsql { 1222 CREATE TABLE pp(x, y, PRIMARY KEY(x, y)); 1241 CREATE TABLE pp(x, y, PRIMARY KEY(x, y)); 1223 CREATE TABLE cc(a, b, FOREIGN KEY(a, b) REFERENCES pp(x, z)); 1242 CREATE TABLE cc(a, b, FOREIGN KEY(a, b) REFERENCES pp(x, z)); 1224 } 1243 } 1225 catchsql { INSERT INTO cc VALUES(1, 2) } 1244 catchsql { INSERT INTO cc VALUES(1, 2) } 1226 } {1 {foreign key mismatch}} | 1245 } {1 {foreign key mismatch - "cc" referencing "pp"}} 1227 do_test fkey-2.14.3.9 { 1246 do_test fkey-2.14.3.9 { 1228 execsql { DROP TABLE cc } 1247 execsql { DROP TABLE cc } 1229 } {} 1248 } {} 1230 do_test fkey-2.14.3.10 { 1249 do_test fkey-2.14.3.10 { 1231 execsql { 1250 execsql { 1232 CREATE TABLE cc(a, b, 1251 CREATE TABLE cc(a, b, 1233 FOREIGN KEY(a, b) REFERENCES pp DEFERRABLE INITIALLY DEFERRED 1252 FOREIGN KEY(a, b) REFERENCES pp DEFERRABLE INITIALLY DEFERRED
Added test/fkey5.test
> 1 # 2012 December 17 > 2 # > 3 # The author disclaims copyright to this source code. In place of > 4 # a legal notice, here is a blessing: > 5 # > 6 # May you do good and not evil. > 7 # May you find forgiveness for yourself and forgive others. > 8 # May you share freely, never taking more than you give. > 9 # > 10 #*********************************************************************** > 11 # This file implements regression tests for SQLite library. > 12 # > 13 # This file tests the PRAGMA foreign_key_check command. > 14 # > 15 > 16 set testdir [file dirname $argv0] > 17 source $testdir/tester.tcl > 18 > 19 ifcapable {!foreignkey} { > 20 finish_test > 21 return > 22 } > 23 > 24 do_test fkey5-1.1 { > 25 db eval { > 26 CREATE TABLE p1(a INTEGER PRIMARY KEY); INSERT INTO p1 VALUES(88),(89); > 27 CREATE TABLE p2(a INT PRIMARY KEY); INSERT INTO p2 VALUES(77),(78); > 28 CREATE TABLE p3(a TEXT PRIMARY KEY); > 29 INSERT INTO p3 VALUES(66),(67),('alpha'),('BRAVO'); > 30 CREATE TABLE p4(a TEXT PRIMARY KEY COLLATE nocase); > 31 INSERT INTO p4 VALUES('alpha'),('BRAVO'),('55'),('Delta'),('ECHO'); > 32 CREATE TABLE p5(a INTEGER PRIMARY KEY, b, c, UNIQUE(b,c)); > 33 INSERT INTO p5 VALUES(1,'Alpha','abc'),(2,'beta','def'); > 34 CREATE TABLE p6(a INTEGER PRIMARY KEY, b TEXT COLLATE nocase, > 35 c TEXT COLLATE rtrim, UNIQUE(b,c)); > 36 INSERT INTO p6 VALUES(1,'Alpha','abc '),(2,'bETA','def '); > 37 > 38 CREATE TABLE c1(x INTEGER PRIMARY KEY references p1); > 39 CREATE TABLE c2(x INTEGER PRIMARY KEY references p2); > 40 CREATE TABLE c3(x INTEGER PRIMARY KEY references p3); > 41 CREATE TABLE c4(x INTEGER PRIMARY KEY references p4); > 42 CREATE TABLE c5(x INT references p1); > 43 CREATE TABLE c6(x INT references p2); > 44 CREATE TABLE c7(x INT references p3); > 45 CREATE TABLE c8(x INT references p4); > 46 CREATE TABLE c9(x TEXT UNIQUE references p1); > 47 CREATE TABLE c10(x TEXT UNIQUE references p2); > 48 CREATE TABLE c11(x TEXT UNIQUE references p3); > 49 CREATE TABLE c12(x TEXT UNIQUE references p4); > 50 CREATE TABLE c13(x TEXT COLLATE nocase references p3); > 51 CREATE TABLE c14(x TEXT COLLATE nocase references p4); > 52 CREATE TABLE c15(x, y, FOREIGN KEY(x,y) REFERENCES p5(b,c)); > 53 CREATE TABLE c16(x, y, FOREIGN KEY(x,y) REFERENCES p5(c,b)); > 54 CREATE TABLE c17(x, y, FOREIGN KEY(x,y) REFERENCES p6(b,c)); > 55 CREATE TABLE c18(x, y, FOREIGN KEY(x,y) REFERENCES p6(c,b)); > 56 CREATE TABLE c19(x TEXT COLLATE nocase, y TEXT COLLATE rtrim, > 57 FOREIGN KEY(x,y) REFERENCES p5(b,c)); > 58 CREATE TABLE c20(x TEXT COLLATE nocase, y TEXT COLLATE rtrim, > 59 FOREIGN KEY(x,y) REFERENCES p5(c,b)); > 60 CREATE TABLE c21(x TEXT COLLATE nocase, y TEXT COLLATE rtrim, > 61 FOREIGN KEY(x,y) REFERENCES p6(b,c)); > 62 CREATE TABLE c22(x TEXT COLLATE nocase, y TEXT COLLATE rtrim, > 63 FOREIGN KEY(x,y) REFERENCES p6(c,b)); > 64 > 65 PRAGMA foreign_key_check; > 66 } > 67 } {} > 68 do_test fkey5-1.2 { > 69 db eval { > 70 INSERT INTO c1 VALUES(90),(87),(88); > 71 PRAGMA foreign_key_check; > 72 } > 73 } {c1 87 p1 0 c1 90 p1 0} > 74 do_test fkey5-1.3 { > 75 db eval { > 76 PRAGMA foreign_key_check(c1); > 77 } > 78 } {c1 87 p1 0 c1 90 p1 0} > 79 do_test fkey5-1.4 { > 80 db eval { > 81 PRAGMA foreign_key_check(c2); > 82 } > 83 } {} > 84 > 85 do_test fkey5-2.0 { > 86 db eval { > 87 INSERT INTO c5 SELECT x FROM c1; > 88 DELETE FROM c1; > 89 PRAGMA foreign_key_check; > 90 } > 91 } {c5 1 p1 0 c5 3 p1 0} > 92 do_test fkey5-2.1 { > 93 db eval { > 94 PRAGMA foreign_key_check(c5); > 95 } > 96 } {c5 1 p1 0 c5 3 p1 0} > 97 do_test fkey5-2.2 { > 98 db eval { > 99 PRAGMA foreign_key_check(c1); > 100 } > 101 } {} > 102 > 103 do_test fkey5-3.0 { > 104 db eval { > 105 INSERT INTO c9 SELECT x FROM c5; > 106 DELETE FROM c5; > 107 PRAGMA foreign_key_check; > 108 } > 109 } {c9 1 p1 0 c9 3 p1 0} > 110 do_test fkey5-3.1 { > 111 db eval { > 112 PRAGMA foreign_key_check(c9); > 113 } > 114 } {c9 1 p1 0 c9 3 p1 0} > 115 do_test fkey5-3.2 { > 116 db eval { > 117 PRAGMA foreign_key_check(c5); > 118 } > 119 } {} > 120 > 121 do_test fkey5-4.0 { > 122 db eval { > 123 DELETE FROM c9; > 124 INSERT INTO c2 VALUES(79),(77),(76); > 125 PRAGMA foreign_key_check; > 126 } > 127 } {c2 76 p2 0 c2 79 p2 0} > 128 do_test fkey5-4.1 { > 129 db eval { > 130 PRAGMA foreign_key_check(c2); > 131 } > 132 } {c2 76 p2 0 c2 79 p2 0} > 133 do_test fkey5-4.2 { > 134 db eval { > 135 INSERT INTO c6 SELECT x FROM c2; > 136 DELETE FROM c2; > 137 PRAGMA foreign_key_check; > 138 } > 139 } {c6 1 p2 0 c6 3 p2 0} > 140 do_test fkey5-4.3 { > 141 db eval { > 142 PRAGMA foreign_key_check(c6); > 143 } > 144 } {c6 1 p2 0 c6 3 p2 0} > 145 do_test fkey5-4.4 { > 146 db eval { > 147 INSERT INTO c10 SELECT x FROM c6; > 148 DELETE FROM c6; > 149 PRAGMA foreign_key_check; > 150 } > 151 } {c10 1 p2 0 c10 3 p2 0} > 152 do_test fkey5-4.5 { > 153 db eval { > 154 PRAGMA foreign_key_check(c10); > 155 } > 156 } {c10 1 p2 0 c10 3 p2 0} > 157 > 158 do_test fkey5-5.0 { > 159 db eval { > 160 DELETE FROM c10; > 161 INSERT INTO c3 VALUES(68),(67),(65); > 162 PRAGMA foreign_key_check; > 163 } > 164 } {c3 65 p3 0 c3 68 p3 0} > 165 do_test fkey5-5.1 { > 166 db eval { > 167 PRAGMA foreign_key_check(c3); > 168 } > 169 } {c3 65 p3 0 c3 68 p3 0} > 170 do_test fkey5-5.2 { > 171 db eval { > 172 INSERT INTO c7 SELECT x FROM c3; > 173 INSERT INTO c7 VALUES('Alpha'),('alpha'),('foxtrot'); > 174 DELETE FROM c3; > 175 PRAGMA foreign_key_check; > 176 } > 177 } {c7 1 p3 0 c7 3 p3 0 c7 4 p3 0 c7 6 p3 0} > 178 do_test fkey5-5.3 { > 179 db eval { > 180 PRAGMA foreign_key_check(c7); > 181 } > 182 } {c7 1 p3 0 c7 3 p3 0 c7 4 p3 0 c7 6 p3 0} > 183 do_test fkey5-5.4 { > 184 db eval { > 185 INSERT INTO c11 SELECT x FROM c7; > 186 DELETE FROM c7; > 187 PRAGMA foreign_key_check; > 188 } > 189 } {c11 1 p3 0 c11 3 p3 0 c11 4 p3 0 c11 6 p3 0} > 190 do_test fkey5-5.5 { > 191 db eval { > 192 PRAGMA foreign_key_check(c11); > 193 } > 194 } {c11 1 p3 0 c11 3 p3 0 c11 4 p3 0 c11 6 p3 0} > 195 > 196 do_test fkey5-6.0 { > 197 db eval { > 198 DELETE FROM c11; > 199 INSERT INTO c4 VALUES(54),(55),(56); > 200 PRAGMA foreign_key_check; > 201 } > 202 } {c4 54 p4 0 c4 56 p4 0} > 203 do_test fkey5-6.1 { > 204 db eval { > 205 PRAGMA foreign_key_check(c4); > 206 } > 207 } {c4 54 p4 0 c4 56 p4 0} > 208 do_test fkey5-6.2 { > 209 db eval { > 210 INSERT INTO c8 SELECT x FROM c4; > 211 INSERT INTO c8 VALUES('Alpha'),('ALPHA'),('foxtrot'); > 212 DELETE FROM c4; > 213 PRAGMA foreign_key_check; > 214 } > 215 } {c8 1 p4 0 c8 3 p4 0 c8 6 p4 0} > 216 do_test fkey5-6.3 { > 217 db eval { > 218 PRAGMA foreign_key_check(c8); > 219 } > 220 } {c8 1 p4 0 c8 3 p4 0 c8 6 p4 0} > 221 do_test fkey5-6.4 { > 222 db eval { > 223 INSERT INTO c12 SELECT x FROM c8; > 224 DELETE FROM c8; > 225 PRAGMA foreign_key_check; > 226 } > 227 } {c12 1 p4 0 c12 3 p4 0 c12 6 p4 0} > 228 do_test fkey5-6.5 { > 229 db eval { > 230 PRAGMA foreign_key_check(c12); > 231 } > 232 } {c12 1 p4 0 c12 3 p4 0 c12 6 p4 0} > 233 > 234 do_test fkey5-7.1 { > 235 db eval { > 236 INSERT OR IGNORE INTO c13 SELECT * FROM c12; > 237 INSERT OR IGNORE INTO C14 SELECT * FROM c12; > 238 DELETE FROM c12; > 239 PRAGMA foreign_key_check; > 240 } > 241 } {c14 1 p4 0 c14 3 p4 0 c14 6 p4 0 c13 1 p3 0 c13 2 p3 0 c13 3 p3 0 c13 4 p3 0 > 242 do_test fkey5-7.2 { > 243 db eval { > 244 PRAGMA foreign_key_check(c14); > 245 } > 246 } {c14 1 p4 0 c14 3 p4 0 c14 6 p4 0} > 247 do_test fkey5-7.3 { > 248 db eval { > 249 PRAGMA foreign_key_check(c13); > 250 } > 251 } {c13 1 p3 0 c13 2 p3 0 c13 3 p3 0 c13 4 p3 0 c13 5 p3 0 c13 6 p3 0} > 252 > 253 do_test fkey5-8.0 { > 254 db eval { > 255 DELETE FROM c13; > 256 DELETE FROM c14; > 257 INSERT INTO c19 VALUES('alpha','abc'); > 258 PRAGMA foreign_key_check(c19); > 259 } > 260 } {c19 1 p5 0} > 261 do_test fkey5-8.1 { > 262 db eval { > 263 DELETE FROM c19; > 264 INSERT INTO c19 VALUES('Alpha','abc'); > 265 PRAGMA foreign_key_check(c19); > 266 } > 267 } {} > 268 do_test fkey5-8.2 { > 269 db eval { > 270 INSERT INTO c20 VALUES('Alpha','abc'); > 271 PRAGMA foreign_key_check(c20); > 272 } > 273 } {c20 1 p5 0} > 274 do_test fkey5-8.3 { > 275 db eval { > 276 DELETE FROM c20; > 277 INSERT INTO c20 VALUES('abc','Alpha'); > 278 PRAGMA foreign_key_check(c20); > 279 } > 280 } {} > 281 do_test fkey5-8.4 { > 282 db eval { > 283 INSERT INTO c21 VALUES('alpha','abc '); > 284 PRAGMA foreign_key_check(c21); > 285 } > 286 } {} > 287 do_test fkey5-8.5 { > 288 db eval { > 289 DELETE FROM c21; > 290 INSERT INTO c19 VALUES('Alpha','abc'); > 291 PRAGMA foreign_key_check(c21); > 292 } > 293 } {} > 294 do_test fkey5-8.6 { > 295 db eval { > 296 INSERT INTO c22 VALUES('Alpha','abc'); > 297 PRAGMA foreign_key_check(c22); > 298 } > 299 } {c22 1 p6 0} > 300 do_test fkey5-8.7 { > 301 db eval { > 302 DELETE FROM c22; > 303 INSERT INTO c22 VALUES('abc ','ALPHA'); > 304 PRAGMA foreign_key_check(c22); > 305 } > 306 } {} > 307 > 308 > 309 > 310 finish_test
Changes to test/fkey_malloc.test
25 CREATE TABLE t1(a PRIMARY KEY, b UNIQUE); 25 CREATE TABLE t1(a PRIMARY KEY, b UNIQUE); 26 CREATE TABLE t2(x REFERENCES t1 ON UPDATE CASCADE ON DELETE CASCADE); 26 CREATE TABLE t2(x REFERENCES t1 ON UPDATE CASCADE ON DELETE CASCADE); 27 } -sqlbody { 27 } -sqlbody { 28 INSERT INTO t1 VALUES('aaa', 1); 28 INSERT INTO t1 VALUES('aaa', 1); 29 INSERT INTO t2 VALUES('aaa'); 29 INSERT INTO t2 VALUES('aaa'); 30 UPDATE t1 SET a = 'bbb'; 30 UPDATE t1 SET a = 'bbb'; 31 DELETE FROM t1; 31 DELETE FROM t1; > 32 PRAGMA foreign_key_check; 32 } 33 } 33 34 34 do_malloc_test fkey_malloc-2 -sqlprep { 35 do_malloc_test fkey_malloc-2 -sqlprep { 35 PRAGMA foreign_keys = 1; 36 PRAGMA foreign_keys = 1; 36 CREATE TABLE t1(a, b, UNIQUE(a, b)); 37 CREATE TABLE t1(a, b, UNIQUE(a, b)); 37 } -sqlbody { 38 } -sqlbody { 38 CREATE TABLE t2(x, y, 39 CREATE TABLE t2(x, y, ................................................................................................................................................................................ 124 CREATE TABLE z(e, f, FOREIGN KEY(e, f) REFERENCES x); 125 CREATE TABLE z(e, f, FOREIGN KEY(e, f) REFERENCES x); 125 } -sqlbody { 126 } -sqlbody { 126 DROP TABLE y; 127 DROP TABLE y; 127 DROP TABLE x; 128 DROP TABLE x; 128 } 129 } 129 130 130 finish_test 131 finish_test 131 < 132 <
Changes to test/interrupt.test
162 for {set i 1} {$i<$max_count-5} {incr i 1} { 162 for {set i 1} {$i<$max_count-5} {incr i 1} { 163 do_test interrupt-4.$i.1 { 163 do_test interrupt-4.$i.1 { 164 set ::sqlite_interrupt_count $::i 164 set ::sqlite_interrupt_count $::i 165 catchsql $sql 165 catchsql $sql 166 } {1 interrupted} 166 } {1 interrupted} 167 } 167 } 168 168 > 169 if {0} { # This doesn't work anymore since the collation factor is > 170 # no longer called during schema parsing. 169 # Interrupt during parsing 171 # Interrupt during parsing 170 # 172 # 171 do_test interrupt-5.1 { 173 do_test interrupt-5.1 { 172 proc fake_interrupt {args} { 174 proc fake_interrupt {args} { 173 db collate fake_collation no-op 175 db collate fake_collation no-op 174 sqlite3_interrupt db 176 sqlite3_interrupt db 175 return SQLITE_OK 177 return SQLITE_OK 176 } 178 } 177 db collation_needed fake_interrupt 179 db collation_needed fake_interrupt 178 catchsql { 180 catchsql { 179 CREATE INDEX fake ON fake1(a COLLATE fake_collation, b, c DESC); 181 CREATE INDEX fake ON fake1(a COLLATE fake_collation, b, c DESC); 180 } 182 } 181 } {1 interrupt} 183 } {1 interrupt} 182 | 184 } 183 finish_test 185 finish_test
Added test/ioerr6.test
> 1 # 2012 December 18 > 2 # > 3 # The author disclaims copyright to this source code. In place of > 4 # a legal notice, here is a blessing: > 5 # > 6 # May you do good and not evil. > 7 # May you find forgiveness for yourself and forgive others. > 8 # May you share freely, never taking more than you give. > 9 # > 10 #*********************************************************************** > 11 # > 12 > 13 set testdir [file dirname $argv0] > 14 source $testdir/tester.tcl > 15 source $testdir/malloc_common.tcl > 16 set ::testprefix ioerr6 > 17 > 18 ifcapable !atomicwrite { > 19 puts "skipping tests - not compiled with SQLITE_ENABLE_ATOMIC_WRITE..." > 20 finish_test > 21 return > 22 } > 23 faultsim_save_and_close > 24 > 25 do_test 1.1 { > 26 testvfs shmfault -default true > 27 shmfault devchar atomic > 28 sqlite3 db test.db > 29 execsql { > 30 CREATE TABLE t1(a, b); > 31 CREATE INDEX i1 ON t1(a, b); > 32 INSERT INTO t1 VALUES(1, 2); > 33 INSERT INTO t1 VALUES(2, 4); > 34 INSERT INTO t1 VALUES(3, 6); > 35 INSERT INTO t1 VALUES(4, 8); > 36 } > 37 > 38 # Cause the first call to xWrite() to fail with SQLITE_FULL. > 39 shmfault full 2 1 > 40 catchsql { INSERT INTO t1 VALUES(5, 10) } > 41 } {1 {database or disk is full}} > 42 > 43 do_test 1.2 { > 44 execsql { PRAGMA integrity_check } > 45 } {ok} > 46 > 47 db close > 48 shmfault delete > 49 > 50 do_faultsim_test 2 -faults full* -prep { > 51 shmfault devchar atomic > 52 faultsim_restore > 53 sqlite3 db test.db > 54 } -body { > 55 db eval { > 56 CREATE TABLE t1(x PRIMARY KEY); > 57 INSERT INTO t1 VALUES('abc'); > 58 } > 59 } -test { > 60 set res [db one { PRAGMA integrity_check }] > 61 if {$res != "ok"} { > 62 error "integrity check: $res" > 63 } > 64 } > 65 > 66 do_faultsim_test 2 -faults full* -prep { > 67 shmfault devchar atomic > 68 faultsim_restore > 69 sqlite3 db test.db > 70 } -body { > 71 db eval { > 72 CREATE TABLE t1(x); > 73 CREATE TABLE t2(x); > 74 } > 75 } -test { > 76 db eval { CREATE TABLE t3(x) } > 77 if {[db one { PRAGMA integrity_check }] != "ok"} { > 78 error "integrity check failed" > 79 } > 80 } > 81 > 82 finish_test > 83
Changes to test/minmax.test
13 # aggregate min() and max() functions and which are handled as 13 # aggregate min() and max() functions and which are handled as 14 # as a special case. 14 # as a special case. 15 # 15 # 16 # $Id: minmax.test,v 1.21 2008/07/08 18:05:26 drh Exp $ 16 # $Id: minmax.test,v 1.21 2008/07/08 18:05:26 drh Exp $ 17 17 18 set testdir [file dirname $argv0] 18 set testdir [file dirname $argv0] 19 source $testdir/tester.tcl 19 source $testdir/tester.tcl > 20 set ::testprefix minmax 20 21 21 do_test minmax-1.0 { 22 do_test minmax-1.0 { 22 execsql { 23 execsql { 23 BEGIN; 24 BEGIN; 24 CREATE TABLE t1(x, y); 25 CREATE TABLE t1(x, y); 25 INSERT INTO t1 VALUES(1,1); 26 INSERT INTO t1 VALUES(1,1); 26 INSERT INTO t1 VALUES(2,2); 27 INSERT INTO t1 VALUES(2,2); ................................................................................................................................................................................ 532 } {25} 533 } {25} 533 do_test minmax-12.17 { 534 do_test minmax-12.17 { 534 execsql { 535 execsql { 535 SELECT max(rowid) FROM t7 WHERE a=3 AND b=5 AND c=15; 536 SELECT max(rowid) FROM t7 WHERE a=3 AND b=5 AND c=15; 536 } 537 } 537 } {5} 538 } {5} 538 539 > 540 #------------------------------------------------------------------------- > 541 reset_db 539 542 > 543 proc do_test_13 {op name sql1 sql2 res} { > 544 set ::sqlite_search_count 0 > 545 uplevel [list do_execsql_test $name.1 $sql1 $res] > 546 set a $::sqlite_search_count > 547 > 548 set ::sqlite_search_count 0 > 549 uplevel [list do_execsql_test $name.2 $sql2 $res] > 550 set b $::sqlite_search_count > 551 > 552 uplevel [list do_test $name.3 [list expr "$a $op $b"] 1] > 553 } > 554 > 555 # Run a test named $name. Check that SQL statements $sql1 and $sql2 both > 556 # return the same result, but that $sql2 increments the $sqlite_search_count > 557 # variable more often (indicating that it is visiting more rows to determine > 558 # the result). > 559 # > 560 proc do_test_13_opt {name sql1 sql2 res} { > 561 uplevel [list do_test_13 < $name $sql1 $sql2 $res] > 562 } > 563 > 564 # Like [do_test_13_noopt], except this time check that the $sqlite_search_count > 565 # variable is incremented the same number of times by both SQL statements. > 566 # > 567 proc do_test_13_noopt {name sql1 sql2 res} { > 568 uplevel [list do_test_13 == $name $sql1 $sql2 $res] > 569 } > 570 > 571 do_execsql_test 13.1 { > 572 CREATE TABLE t1(a, b, c); > 573 INSERT INTO t1 VALUES('a', 1, 1); > 574 INSERT INTO t1 VALUES('b', 6, 6); > 575 INSERT INTO t1 VALUES('c', 5, 5); > 576 INSERT INTO t1 VALUES('a', 4, 4); > 577 INSERT INTO t1 VALUES('a', 5, 5); > 578 INSERT INTO t1 VALUES('c', 6, 6); > 579 INSERT INTO t1 VALUES('b', 4, 4); > 580 INSERT INTO t1 VALUES('c', 7, 7); > 581 INSERT INTO t1 VALUES('b', 2, 2); > 582 INSERT INTO t1 VALUES('b', 3, 3); > 583 INSERT INTO t1 VALUES('a', 3, 3); > 584 INSERT INTO t1 VALUES('b', 5, 5); > 585 INSERT INTO t1 VALUES('c', 4, 4); > 586 INSERT INTO t1 VALUES('c', 3, 3); > 587 INSERT INTO t1 VALUES('a', 2, 2); > 588 SELECT * FROM t1 ORDER BY a, b, c; > 589 } {a 1 1 a 2 2 a 3 3 a 4 4 a 5 5 > 590 b 2 2 b 3 3 b 4 4 b 5 5 b 6 6 > 591 c 3 3 c 4 4 c 5 5 c 6 6 c 7 7 > 592 } > 593 do_execsql_test 13.2 { CREATE INDEX i1 ON t1(a, b, c) } > 594 > 595 do_test_13_opt 13.3 { > 596 SELECT min(b) FROM t1 WHERE a='b' > 597 } { > 598 SELECT min(c) FROM t1 WHERE a='b' > 599 } {2} > 600 > 601 do_test_13_opt 13.4 { > 602 SELECT a, min(b) FROM t1 WHERE a='b' > 603 } { > 604 SELECT a, min(c) FROM t1 WHERE a='b' > 605 } {b 2} > 606 > 607 do_test_13_opt 13.4 { > 608 SELECT a||c, max(b)+4 FROM t1 WHERE a='c' > 609 } { > 610 SELECT a||c, max(c)+4 FROM t1 WHERE a='c' > 611 } {c7 11} > 612 > 613 do_test_13_noopt 13.5 { > 614 SELECT a||c, max(b+1) FROM t1 WHERE a='c' > 615 } { > 616 SELECT a||c, max(c+1) FROM t1 WHERE a='c' > 617 } {c7 8} > 618 > 619 do_test_13_noopt 13.6 { > 620 SELECT count(b) FROM t1 WHERE a='c' > 621 } { > 622 SELECT count(c) FROM t1 WHERE a='c' > 623 } {5} > 624 > 625 do_test_13_noopt 13.7 { > 626 SELECT min(b), count(b) FROM t1 WHERE a='a'; > 627 } { > 628 SELECT min(c), count(c) FROM t1 WHERE a='a'; > 629 } {1 5} 540 630 541 631 542 finish_test 632 finish_test
Changes to test/pager1.test
879 INSERT INTO t1 VALUES('IV', 'sixteen'); 879 INSERT INTO t1 VALUES('IV', 'sixteen'); 880 INSERT INTO t1 VALUES('V' , 'twentyfive'); 880 INSERT INTO t1 VALUES('V' , 'twentyfive'); 881 COMMIT; 881 COMMIT; 882 } {delete} 882 } {delete} 883 tv filter {} 883 tv filter {} 884 db close 884 db close 885 tv delete 885 tv delete > 886 catch { > 887 test_syscall install fchmod > 888 test_syscall fault 1 1 > 889 } 886 do_test pager1.4.7.2 { 890 do_test pager1.4.7.2 { 887 faultsim_restore_and_reopen 891 faultsim_restore_and_reopen 888 catch {file attributes test.db-journal -permissions r--------} 892 catch {file attributes test.db-journal -permissions r--------} 889 catch {file attributes test.db-journal -readonly 1} 893 catch {file attributes test.db-journal -readonly 1} 890 catchsql { SELECT * FROM t1 } 894 catchsql { SELECT * FROM t1 } 891 } {1 {unable to open database file}} 895 } {1 {unable to open database file}} > 896 catch { > 897 test_syscall reset > 898 test_syscall fault 0 0 > 899 } 892 do_test pager1.4.7.3 { 900 do_test pager1.4.7.3 { 893 db close 901 db close 894 catch {file attributes test.db-journal -permissions rw-rw-rw-} 902 catch {file attributes test.db-journal -permissions rw-rw-rw-} 895 catch {file attributes test.db-journal -readonly 0} 903 catch {file attributes test.db-journal -readonly 0} 896 delete_file test.db-journal 904 delete_file test.db-journal 897 file exists test.db-journal 905 file exists test.db-journal 898 } {0} 906 } {0}
Changes to test/pragma.test
530 do_test pragma-6.2.2 { 530 do_test pragma-6.2.2 { 531 execsql { 531 execsql { 532 CREATE TABLE t5( 532 CREATE TABLE t5( 533 a TEXT DEFAULT CURRENT_TIMESTAMP, 533 a TEXT DEFAULT CURRENT_TIMESTAMP, 534 b DEFAULT (5+3), 534 b DEFAULT (5+3), 535 c TEXT, 535 c TEXT, 536 d INTEGER DEFAULT NULL, 536 d INTEGER DEFAULT NULL, 537 e TEXT DEFAULT '' | 537 e TEXT DEFAULT '', > 538 UNIQUE(b,c,d), > 539 PRIMARY KEY(e,b,c) 538 ); 540 ); 539 PRAGMA table_info(t5); 541 PRAGMA table_info(t5); 540 } 542 } 541 } {0 a TEXT 0 CURRENT_TIMESTAMP 0 1 b {} 0 5+3 0 2 c TEXT 0 <<NULL>> 0 3 d INTEG | 543 } {0 a TEXT 0 CURRENT_TIMESTAMP 0 1 b {} 0 5+3 2 2 c TEXT 0 <<NULL>> 3 3 d INTEG 542 db nullvalue {} 544 db nullvalue {} > 545 do_test pragma-6.2.3 { > 546 execsql { > 547 CREATE TABLE t2_3(a,b INTEGER PRIMARY KEY,c); > 548 pragma table_info(t2_3) > 549 } > 550 } {0 a {} 0 {} 0 1 b INTEGER 0 {} 1 2 c {} 0 {} 0} 543 ifcapable {foreignkey} { 551 ifcapable {foreignkey} { 544 do_test pragma-6.3.1 { 552 do_test pragma-6.3.1 { 545 execsql { 553 execsql { 546 CREATE TABLE t3(a int references t2(b), b UNIQUE); 554 CREATE TABLE t3(a int references t2(b), b UNIQUE); 547 pragma foreign_key_list(t3); 555 pragma foreign_key_list(t3); 548 } 556 } 549 } {0 0 t2 a b {NO ACTION} {NO ACTION} NONE} 557 } {0 0 t2 a b {NO ACTION} {NO ACTION} NONE} ................................................................................................................................................................................ 1615 execsql { PRAGMA main.integrity_check; } 1623 execsql { PRAGMA main.integrity_check; } 1616 } [list $mainerr] 1624 } [list $mainerr] 1617 do_test 22.4.3 { 1625 do_test 22.4.3 { 1618 execsql { PRAGMA aux.integrity_check; } 1626 execsql { PRAGMA aux.integrity_check; } 1619 } {ok} 1627 } {ok} 1620 1628 1621 finish_test 1629 finish_test 1622 < 1623 <
Added test/regexp1.test
> 1 # 2012 December 31 > 2 # > 3 # The author disclaims copyright to this source code. In place of > 4 # a legal notice, here is a blessing: > 5 # > 6 # May you do good and not evil. > 7 # May you find forgiveness for yourself and forgive others. > 8 # May you share freely, never taking more than you give. > 9 # > 10 #*********************************************************************** > 11 # > 12 # This file implements test for the REGEXP operator in test_regexp.c. > 13 # > 14 > 15 set testdir [file dirname $argv0] > 16 source $testdir/tester.tcl > 17 > 18 do_test regexp1-1.1 { > 19 sqlite3_add_regexp_func db > 20 db eval { > 21 CREATE TABLE t1(x INTEGER PRIMARY KEY, y TEXT); > 22 INSERT INTO t1 VALUES(1, 'For since by man came death,'); > 23 INSERT INTO t1 VALUES(2, 'by man came also the resurrection of the dead.'); > 24 INSERT INTO t1 VALUES(3, 'For as in Adam all die,'); > 25 INSERT INTO t1 VALUES(4, 'even so in Christ shall all be made alive.'); > 26 > 27 SELECT x FROM t1 WHERE y REGEXP '^For ' ORDER BY x; > 28 } > 29 } {1 3} > 30 > 31 do_execsql_test regexp1-1.2 { > 32 SELECT x FROM t1 WHERE y REGEXP 'by|in' ORDER BY x; > 33 } {1 2 3 4} > 34 do_execsql_test regexp1-1.3 { > 35 SELECT x FROM t1 WHERE y REGEXP 'by|Christ' ORDER BY x; > 36 } {1 2 4} > 37 do_execsql_test regexp1-1.4 { > 38 SELECT x FROM t1 WHERE y REGEXP 'shal+ al+' ORDER BY x; > 39 } {4} > 40 do_execsql_test regexp1-1.5 { > 41 SELECT x FROM t1 WHERE y REGEXP 'shall x*y*z*all' ORDER BY x; > 42 } {4} > 43 do_execsql_test regexp1-1.6 { > 44 SELECT x FROM t1 WHERE y REGEXP 'shallx?y? ?z?all' ORDER BY x; > 45 } {4} > 46 do_execsql_test regexp1-1.7 { > 47 SELECT x FROM t1 WHERE y REGEXP 'r{2}' ORDER BY x; > 48 } {2} > 49 do_execsql_test regexp1-1.8 { > 50 SELECT x FROM t1 WHERE y REGEXP 'r{3}' ORDER BY x; > 51 } {} > 52 do_execsql_test regexp1-1.9 { > 53 SELECT x FROM t1 WHERE y REGEXP 'r{1}' ORDER BY x; > 54 } {1 2 3 4} > 55 do_execsql_test regexp1-1.10 { > 56 SELECT x FROM t1 WHERE y REGEXP 'ur{2,10}e' ORDER BY x; > 57 } {2} > 58 do_execsql_test regexp1-1.11 { > 59 SELECT x FROM t1 WHERE y REGEXP '[Aa]dam' ORDER BY x; > 60 } {3} > 61 do_execsql_test regexp1-1.12 { > 62 SELECT x FROM t1 WHERE y REGEXP '[^Aa]dam' ORDER BY x; > 63 } {} > 64 do_execsql_test regexp1-1.13 { > 65 SELECT x FROM t1 WHERE y REGEXP '[^b-zB-Z]dam' ORDER BY x; > 66 } {3} > 67 do_execsql_test regexp1-1.14 { > 68 SELECT x FROM t1 WHERE y REGEXP 'alive' ORDER BY x; > 69 } {4} > 70 do_execsql_test regexp1-1.15 { > 71 SELECT x FROM t1 WHERE y REGEXP '^alive' ORDER BY x; > 72 } {} > 73 do_execsql_test regexp1-1.16 { > 74 SELECT x FROM t1 WHERE y REGEXP 'alive$' ORDER BY x; > 75 } {} > 76 do_execsql_test regexp1-1.17 { > 77 SELECT x FROM t1 WHERE y REGEXP 'alive.$' ORDER BY x; > 78 } {4} > 79 do_execsql_test regexp1-1.18 { > 80 SELECT x FROM t1 WHERE y REGEXP 'alive\.$' ORDER BY x; > 81 } {4} > 82 do_execsql_test regexp1-1.19 { > 83 SELECT x FROM t1 WHERE y REGEXP 'ma[nd]' ORDER BY x; > 84 } {1 2 4} > 85 do_execsql_test regexp1-1.20 { > 86 SELECT x FROM t1 WHERE y REGEXP '\bma[nd]' ORDER BY x; > 87 } {1 2 4} > 88 do_execsql_test regexp1-1.21 { > 89 SELECT x FROM t1 WHERE y REGEXP 'ma[nd]\b' ORDER BY x; > 90 } {1 2} > 91 do_execsql_test regexp1-1.22 { > 92 SELECT x FROM t1 WHERE y REGEXP 'ma\w' ORDER BY x; > 93 } {1 2 4} > 94 do_execsql_test regexp1-1.23 { > 95 SELECT x FROM t1 WHERE y REGEXP 'ma\W' ORDER BY x; > 96 } {} > 97 do_execsql_test regexp1-1.24 { > 98 SELECT x FROM t1 WHERE y REGEXP '\sma\w' ORDER BY x; > 99 } {1 2 4} > 100 do_execsql_test regexp1-1.25 { > 101 SELECT x FROM t1 WHERE y REGEXP '\Sma\w' ORDER BY x; > 102 } {} > 103 do_execsql_test regexp1-1.26 { > 104 SELECT x FROM t1 WHERE y REGEXP 'alive\S$' ORDER BY x; > 105 } {4} > 106 do_execsql_test regexp1-1.27 { > 107 SELECT x FROM t1 WHERE y REGEXP > 108 '\b(unto|us|son|given|his|name|called|' || > 109 'wonderful|councelor|mighty|god|everlasting|father|' || > 110 'prince|peace|alive)\b'; > 111 } {4} > 112 > 113 do_execsql_test regexp1-2.1 { > 114 SELECT 'aaaabbbbcccc' REGEXP 'ab*c', > 115 'aaaacccc' REGEXP 'ab*c'; > 116 } {1 1} > 117 do_execsql_test regexp1-2.2 { > 118 SELECT 'aaaabbbbcccc' REGEXP 'ab+c', > 119 'aaaacccc' REGEXP 'ab+c'; > 120 } {1 0} > 121 do_execsql_test regexp1-2.3 { > 122 SELECT 'aaaabbbbcccc' REGEXP 'ab?c', > 123 'aaaacccc' REGEXP 'ab?c'; > 124 } {0 1} > 125 do_execsql_test regexp1-2.4 { > 126 SELECT 'aaaabbbbbbcccc' REGEXP 'ab{3,5}c', > 127 'aaaabbbbbcccc' REGEXP 'ab{3,5}c', > 128 'aaaabbbbcccc' REGEXP 'ab{3,5}c', > 129 'aaaabbbcccc' REGEXP 'ab{3,5}c', > 130 'aaaabbcccc' REGEXP 'ab{3,5}c', > 131 'aaaabcccc' REGEXP 'ab{3,5}c' > 132 } {0 1 1 1 0 0} > 133 do_execsql_test regexp1-2.5 { > 134 SELECT 'aaaabbbbcccc' REGEXP 'a(a|b|c)+c', > 135 'aaaabbbbcccc' REGEXP '^a(a|b|c){11}c$', > 136 'aaaabbbbcccc' REGEXP '^a(a|b|c){10}c$', > 137 'aaaabbbbcccc' REGEXP '^a(a|b|c){9}c$' > 138 } {1 0 1 0} > 139 do_execsql_test regexp1-2.6 { > 140 SELECT 'aaaabbbbcccc' REGEXP '^a(a|bb|c)+c$', > 141 'aaaabbbbcccc' REGEXP '^a(a|bbb|c)+c$', > 142 'aaaabbbbcccc' REGEXP '^a(a|bbbb|c)+c$' > 143 } {1 0 1} > 144 do_execsql_test regexp1-2.7 { > 145 SELECT 'aaaabbbbcccc' REGEXP '^a([ac]+|bb){3}c$', > 146 'aaaabbbbcccc' REGEXP '^a([ac]+|bb){4}c$', > 147 'aaaabbbbcccc' REGEXP '^a([ac]+|bb){5}c$' > 148 } {0 1 1} > 149 > 150 do_execsql_test regexp1-2.8 { > 151 SELECT 'abc*def+ghi.jkl[mno]pqr' REGEXP 'c.d', > 152 'abc*def+ghi.jkl[mno]pqr' REGEXP 'c\*d', > 153 'abc*def+ghi.jkl[mno]pqr' REGEXP 'f\+g', > 154 'abc*def+ghi.jkl[mno]pqr' REGEXP 'i\.j', > 155 'abc*def+ghi.jkl[mno]pqr' REGEXP 'l\[mno\]p' > 156 } {1 1 1 1 1} > 157 > 158 do_test regexp1-2.9 { > 159 set v1 "abc\ndef" > 160 db eval {SELECT $v1 REGEXP '^abc\ndef$'} > 161 } {1} > 162 do_test regexp1-2.10 { > 163 set v1 "abc\adef" > 164 db eval {SELECT $v1 REGEXP '^abc\adef$'} > 165 } {1} > 166 do_test regexp1-2.11 { > 167 set v1 "abc\tdef" > 168 db eval {SELECT $v1 REGEXP '^abc\tdef$'} > 169 } {1} > 170 do_test regexp1-2.12 { > 171 set v1 "abc\rdef" > 172 db eval {SELECT $v1 REGEXP '^abc\rdef$'} > 173 } {1} > 174 do_test regexp1-2.13 { > 175 set v1 "abc\fdef" > 176 db eval {SELECT $v1 REGEXP '^abc\fdef$'} > 177 } {1} > 178 do_test regexp1-2.14 { > 179 set v1 "abc\vdef" > 180 db eval {SELECT $v1 REGEXP '^abc\vdef$'} > 181 } {1} > 182 do_execsql_test regexp1-2.15 { > 183 SELECT 'abc\def' REGEXP '^abc\\def', > 184 'abc(def' REGEXP '^abc\(def', > 185 'abc)def' REGEXP '^abc\)def', > 186 'abc*def' REGEXP '^abc\*def', > 187 'abc.def' REGEXP '^abc\.def', > 188 'abc+def' REGEXP '^abc\+def', > 189 'abc?def' REGEXP '^abc\?def', > 190 'abc[def' REGEXP '^abc\[def', > 191 'abc$def' REGEXP '^abc\$', > 192 '^def' REGEXP '\^def', > 193 'abc{4}x' REGEXP '^abc\{4\}x$', > 194 'abc|def' REGEXP '^abc\|def$' > 195 } {1 1 1 1 1 1 1 1 1 1 1 1} > 196 > 197 do_execsql_test regexp1-2.20 { > 198 SELECT 'abc$¢€xyz' REGEXP '^abc\u0024\u00a2\u20acxyz$', > 199 'abc$¢€xyz' REGEXP '^abc\u0024\u00A2\u20ACxyz$', > 200 'abc$¢€xyz' REGEXP '^abc\x24\xa2\x20acxyz$' > 201 } {1 1 1} > 202 do_execsql_test regexp1-2.21 { > 203 SELECT 'abc$¢€xyz' REGEXP '^abc[\u0024][\u00a2][\u20ac]xyz$', > 204 'abc$¢€xyz' REGEXP '^abc[\u0024\u00A2\u20AC]{3}xyz$', > 205 'abc$¢€xyz' REGEXP '^abc[\x24][\xa2\x20ac]+xyz$' >