From c5cdca613ab96d48a5e1f071d27c0f63fe122d15 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 11 Jan 2005 16:54:14 +0000 Subject: [PATCH] Improved test coverage for vdbeaux.c. (CVS 2195) FossilOrigin-Name: 3f46cd7767cf7c48dd1de7ae1c4104d6d1a609be --- manifest | 21 ++++++------- manifest.uuid | 2 +- src/test1.c | 24 ++++++++++++++- src/vdbeaux.c | 10 +++---- test/bind.test | 21 ++++++++++++- test/func.test | 3 +- test/index2.test | 72 +++++++++++++++++++++++++++++++++++++++++++++ test/interrupt.test | 14 +++++++-- 8 files changed, 146 insertions(+), 21 deletions(-) create mode 100644 test/index2.test diff --git a/manifest b/manifest index 788fc10adb..1f8b257dc2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improved\stest\scoverage\sfor\sutil.c.\s(CVS\s2194) -D 2005-01-11T15:28:33 +C Improved\stest\scoverage\sfor\svdbeaux.c.\s(CVS\s2195) +D 2005-01-11T16:54:15 F Makefile.in ecf441ac5ca1ccfc8748a8a9537706e69893dfa4 F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457 F README a01693e454a00cc117967e3f9fdab2d4d52e9bc1 @@ -65,7 +65,7 @@ F src/sqlite.h.in 0d5e48e506845b74a845c9470e01d3f472b59611 F src/sqliteInt.h a362fd46ba14f67e8e088d30ecbbe228545c43fe F src/table.c 25b3ff2b39b7d87e8d4a5da0713d68dfc06cbee9 F src/tclsqlite.c 354d3e4525c7b29c8f50b1a0125d55c63c916fbc -F src/test1.c ad1b46266b357c283981b2a289cf29bdb35cb26a +F src/test1.c d684fb31dccd68434e148bef51d9c0a24b09bdf0 F src/test2.c b11fa244fff02190707dd0879987c37c75e61fc8 F src/test3.c a72f20066cccd5a7b9f20b7b78fa9b05b47b3020 F src/test4.c 7c6b9fc33dd1f3f93c7f1ee6e5e6d016afa6c1df @@ -80,7 +80,7 @@ F src/vdbe.c 8ef389f567e233768a845e7dffacb21308e4f3e8 F src/vdbe.h 067ca8d6750ba4f69a50284765e5883dee860181 F src/vdbeInt.h 0f74561e629af86172de7cdf0ecaea014c51696c F src/vdbeapi.c 0cf3bdc1072616bedc8eec7fc22e3f5a169d33fd -F src/vdbeaux.c a7c4c90786e2633b38f2d89f3dc49aed747454e4 +F src/vdbeaux.c 60c24559b458d4da368694c0d322326b22edffd1 F src/vdbemem.c 5876c8abf4374fef671f4fd8dc333ef3fc95a2f0 F src/where.c 2fc4efc7375eb7f1ae18030311bcd6a18e3a0f46 F tclinstaller.tcl 36478c3bbfc5b93ceac42d94e3c736937b808432 @@ -97,7 +97,7 @@ F test/autovacuum_ioerr.test 55ea907df34edb9be78a910a1636c2eb3c17ecc4 F test/autovacuum_ioerr2.test bf427c86e4daa8638a2eb849bbe1446c234c73d3 F test/bigfile.test d3744a8821ce9abb8697f2826a3e3d22b719e89f F test/bigrow.test f0aeb7573dcb8caaafea76454be3ade29b7fc747 -F test/bind.test 3635ddfe0fb15ecfd158708feff6ef707e15c0a9 +F test/bind.test 7b00573c71e68bcce80cf08db434584fcb87d168 F test/blob.test fc41fe95bdc10da51f0dee73ce86e75ce1d6eb9d F test/btree.test 8aa7424aeec844df990273fe36447e5d7e407261 F test/btree2.test dbce930b549d5ac883a7d8905c976209ea241db3 @@ -129,13 +129,14 @@ F test/enc2.test 6d1a2650e9da43eab499d18ca694a0cb6ec69dee F test/enc3.test f6a5f0b7b7f3a88f030d3143729b87cd5c86d837 F test/expr.test bf826516ea0ba159eb9680fbcea955148bfe9bc3 F test/fkey1.test 81bb13caaa78f58d7d191d7f535529f7c91d821a -F test/func.test 810a1a2984ed83d55cc20746b049c7d099bd0408 +F test/func.test 5920cc058d02d4d602bf9d3d0eb34c9a71ae3879 F test/hook.test f8605cde4c77b2c6a4a73723bf6c507796a64dda F test/in.test b92a2df9162e1cbd33c6449a29a05e6955b1741a F test/index.test 1294997b4743007af57f8148c63ba14f07ad31ab +F test/index2.test ed2409af110aa06ec0c9fedfa050031887c38707 F test/insert.test 56f9c20c9adc8d707490c4ffa5d4daa94826ea03 F test/insert2.test 0bb50ff999e35a21549d8ee5dc44db8ac24d31a7 -F test/interrupt.test 0aa230f8aedec0ad7caaf5edaced337e4cfb3820 +F test/interrupt.test 738a389d2a69697785a0168cf74ef2c3da2f2cbf F test/intpkey.test b57cf5236fde1bd8cbc1388fa0c91908f6fd9194 F test/ioerr.test 01ac547c4a6fc53fcd9fe7ecc9698ab5d827093a F test/join.test ea8c77b9fbc377fe553cdb5ce5f1bd72021dca5d @@ -267,7 +268,7 @@ F www/tclsqlite.tcl e73f8f8e5f20e8277619433f7970060ab01088fc F www/vdbe.tcl 095f106d93875c94b47367384ebc870517431618 F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0 F www/whentouse.tcl c3b50d3ac31c54be2a1af9b488a89d22f1e6e746 -P a6b45722071bde543c4ea28a432339d8708a5cac -R b0945886e1d424e5155d631ce7e7c70d +P ad451a2ddc7993035768f2801d590311807f4397 +R 9858e5e9e52aaef041fc467d86a3aa07 U drh -Z b50ef0a8c73264bba1e64798ccde8b34 +Z 8655077bc04dd81af5a00bb7c6eeefb4 diff --git a/manifest.uuid b/manifest.uuid index fe78222dc6..4222073adc 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ad451a2ddc7993035768f2801d590311807f4397 \ No newline at end of file +3f46cd7767cf7c48dd1de7ae1c4104d6d1a609be \ No newline at end of file diff --git a/src/test1.c b/src/test1.c index adc635a4a3..b75fbb30c5 100644 --- a/src/test1.c +++ b/src/test1.c @@ -13,7 +13,7 @@ ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** -** $Id: test1.c,v 1.118 2005/01/11 15:28:33 drh Exp $ +** $Id: test1.c,v 1.119 2005/01/11 16:54:15 drh Exp $ */ #include "sqliteInt.h" #include "tcl.h" @@ -2506,6 +2506,27 @@ static int sqlite_set_magic( return TCL_OK; } +/* +** Usage: sqlite3_interrupt DB +** +** Trigger an interrupt on DB +*/ +static int test_interrupt( + void * clientData, + Tcl_Interp *interp, + int argc, + char **argv +){ + sqlite3 *db; + if( argc!=2 ){ + Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " DB", 0); + return TCL_ERROR; + } + if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; + sqlite3_interrupt(db); + return TCL_OK; +} + /* ** Usage: tcl_variable_type VARIABLENAME ** @@ -2737,6 +2758,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){ { "sqlite3_key", (Tcl_CmdProc*)test_key }, { "sqlite3_rekey", (Tcl_CmdProc*)test_rekey }, { "sqlite_set_magic", (Tcl_CmdProc*)sqlite_set_magic }, + { "sqlite3_interrupt", (Tcl_CmdProc*)test_interrupt }, }; static struct { char *zName; diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 2714b12b3a..fcf503ae11 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -492,6 +492,9 @@ int sqlite3VdbeList( int rc = SQLITE_OK; assert( p->explain ); + if( p->magic!=VDBE_MAGIC_RUN ) return SQLITE_MISUSE; + assert( db->magic==SQLITE_MAGIC_BUSY ); + assert( p->rc==SQLITE_OK || p->rc==SQLITE_BUSY ); /* Even though this opcode does not put dynamic strings onto the ** the stack, they may become dynamic if the user calls @@ -502,17 +505,14 @@ int sqlite3VdbeList( } p->resOnStack = 0; + i = p->pc++; if( i>=p->nOp ){ p->rc = SQLITE_OK; rc = SQLITE_DONE; }else if( db->flags & SQLITE_Interrupt ){ db->flags &= ~SQLITE_Interrupt; - if( db->magic!=SQLITE_MAGIC_BUSY ){ - p->rc = SQLITE_MISUSE; - }else{ - p->rc = SQLITE_INTERRUPT; - } + p->rc = SQLITE_INTERRUPT; rc = SQLITE_ERROR; sqlite3SetString(&p->zErrMsg, sqlite3ErrStr(p->rc), (char*)0); }else{ diff --git a/test/bind.test b/test/bind.test index bff7001ed5..85bebfbc3c 100644 --- a/test/bind.test +++ b/test/bind.test @@ -11,7 +11,7 @@ # This file implements regression tests for SQLite library. The # focus of this script testing the sqlite_bind API. # -# $Id: bind.test,v 1.23 2004/11/20 20:18:55 drh Exp $ +# $Id: bind.test,v 1.24 2005/01/11 16:54:15 drh Exp $ # set testdir [file dirname $argv0] @@ -419,12 +419,28 @@ do_test bind-10.6 { do_test bind-10.7 { sqlite3_bind_parameter_name $VM 3 } $v2 +do_test bind-10.7.1 { + sqlite3_bind_parameter_name 0 1 ;# Ignore if VM is NULL +} {} +do_test bind-10.7.2 { + sqlite3_bind_parameter_name $VM 0 ;# Ignore if index too small +} {} +do_test bind-10.7.3 { + sqlite3_bind_parameter_name $VM 4 ;# Ignore if index is too big +} {} do_test bind-10.8 { sqlite3_bind_int $VM 1 1 sqlite3_bind_int $VM 2 2 sqlite3_bind_int $VM 3 3 sqlite3_step $VM } SQLITE_DONE +do_test bind-10.8.1 { + # Binding attempts after program start should fail + set rc [catch { + sqlite3_bind_int $VM 1 1 + } msg] + lappend rc $msg +} {1 {}} do_test bind-10.9 { sqlite3_finalize $VM } SQLITE_OK @@ -443,6 +459,9 @@ do_test bind-10.11 { ] sqlite3_bind_parameter_count $VM } 5 +do_test bind-10.11.1 { + sqlite3_bind_parameter_index 0 :xyz ;# ignore NULL VM arguments +} 0 do_test bind-10.12 { sqlite3_bind_parameter_index $VM :xyz } 0 diff --git a/test/func.test b/test/func.test index a84a019dcb..1d85600701 100644 --- a/test/func.test +++ b/test/func.test @@ -11,7 +11,7 @@ # This file implements regression tests for SQLite library. The # focus of this file is testing built-in functions. # -# $Id: func.test,v 1.30 2005/01/11 13:02:34 danielk1977 Exp $ +# $Id: func.test,v 1.31 2005/01/11 16:54:15 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -248,6 +248,7 @@ do_test func-7.1 { # Tests for aggregate functions and how they handle NULLs. # do_test func-8.1 { + execsql {EXPLAIN SELECT sum(a) FROM t2;} execsql { SELECT sum(a), count(a), round(avg(a),2), min(a), max(a), count(*) FROM t2; } diff --git a/test/index2.test b/test/index2.test new file mode 100644 index 0000000000..e230f069e4 --- /dev/null +++ b/test/index2.test @@ -0,0 +1,72 @@ +# 2005 January 11 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing the CREATE INDEX statement. +# +# $Id: index2.test,v 1.1 2005/01/11 16:54:15 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Create a table with a large number of columns +# +do_test index2-1.1 { + set sql {CREATE TABLE t1(} + for {set i 1} {$i<1000} {incr i} { + append sql "c$i," + } + append sql "c1000);" + execsql $sql +} {} +do_test index2-1.2 { + set sql {INSERT INTO t1 VALUES(} + for {set i 1} {$i<1000} {incr i} { + append sql $i, + } + append sql {1000);} + execsql $sql +} {} +do_test index2-1.3 { + execsql {SELECT c123 FROM t1} +} 123 +do_test index2-1.4 { + execsql BEGIN + for {set j 1} {$j<=100} {incr j} { + set sql {INSERT INTO t1 VALUES(} + for {set i 1} {$i<1000} {incr i} { + append sql [expr {$j*10000+$i}], + } + append sql "[expr {$j*10000+1000}]);" + execsql $sql + } + execsql COMMIT + execsql {SELECT count(*) FROM t1} +} 101 +do_test index2-1.5 { + execsql {SELECT round(sum(c1000)) FROM t1} +} {50601000} + +# Create indices with many columns +# +do_test index2-2.1 { + set sql "CREATE INDEX t1i1 ON t1(" + for {set i 1} {$i<1000} {incr i} { + append sql c$i, + } + append sql c1000) + execsql $sql +} {} +do_test index2-2.2 { + execsql {EXPLAIN SELECT c9 FROM t1 ORDER BY c1, c2, c3, c4, c5} + execsql {SELECT c9 FROM t1 ORDER BY c1, c2, c3, c4, c5, c6 LIMIT 5} +} {9 10009 20009 30009 40009} + +finish_test diff --git a/test/interrupt.test b/test/interrupt.test index 1d7f0da7af..e58fc7bb17 100644 --- a/test/interrupt.test +++ b/test/interrupt.test @@ -11,11 +11,13 @@ # This file implements regression tests for SQLite library. The # focus of this script is the sqlite_interrupt() API. # -# $Id: interrupt.test,v 1.8 2004/11/14 04:04:18 drh Exp $ +# $Id: interrupt.test,v 1.9 2005/01/11 16:54:15 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl +db close +set DB [sqlite3 db test.db] # Compute a checksum on the entire database. # @@ -107,7 +109,15 @@ ifcapable {vacuum && !default_autovacuum} { expr {$::origsize>[file size test.db]} } 1 } -integrity_check interrupt-2.5 +ifcapable {explain} { + do_test interrupt-2.5 { + set sql {EXPLAIN SELECT max(a,b), a, b FROM t1} + execsql $sql + set rc [catch {db eval $sql {sqlite3_interrupt $DB}} msg] + lappend rc $msg + } {1 interrupted} +} +integrity_check interrupt-2.6 # Ticket #594. If an interrupt occurs in the middle of a transaction # and that transaction is later rolled back, the internal schema tables do