drh | e755072 | 2017-06-29 20:31:01 +0000 | [diff] [blame] | 1 | # 2017-06-29 |
| 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 | # Testing of the STMT virtual table. |
| 13 | # |
| 14 | # This also validates the SQLITE_STMTSTATUS_REPREPARE and |
| 15 | # SQLITE_STMTSTATUS_RUN values for sqlite3_stmt_status(). |
| 16 | # |
| 17 | |
| 18 | set testdir [file dirname $argv0] |
| 19 | source $testdir/tester.tcl |
| 20 | |
| 21 | ifcapable !stmtvtab { |
| 22 | finish_test |
| 23 | return |
| 24 | } |
| 25 | |
dan | 04ed43d | 2017-07-14 20:53:21 +0000 | [diff] [blame] | 26 | db cache flush |
drh | e755072 | 2017-06-29 20:31:01 +0000 | [diff] [blame] | 27 | db cache size 20 |
| 28 | unset -nocomplain x y z |
| 29 | set x giraffe |
| 30 | set y mango |
| 31 | set z alabama |
| 32 | do_execsql_test stmtvtab1-100 { |
| 33 | CREATE TABLE t1(a,b,c); |
| 34 | INSERT INTO t1 VALUES($a,$b,$c); |
| 35 | CREATE INDEX t1a ON t1(a); |
drh | e83b847 | 2017-07-14 15:14:21 +0000 | [diff] [blame] | 36 | SELECT run, sql FROM sqlite_stmt ORDER BY 1; |
| 37 | } {1 {SELECT run, sql FROM sqlite_stmt ORDER BY 1;} 1 {CREATE INDEX t1a ON t1(a);} 1 {INSERT INTO t1 VALUES($a,$b,$c);} 1 {CREATE TABLE t1(a,b,c);}} |
drh | e755072 | 2017-06-29 20:31:01 +0000 | [diff] [blame] | 38 | set x neon |
| 39 | set y event |
| 40 | set z future |
| 41 | do_execsql_test stmtvtab1-110 { |
| 42 | INSERT INTO t1 VALUES($a,$b,$c); |
drh | e83b847 | 2017-07-14 15:14:21 +0000 | [diff] [blame] | 43 | SELECT reprep,run,SQL FROM sqlite_stmt WHERE sql LIKE '%INSERT%' AND NOT busy; |
drh | e755072 | 2017-06-29 20:31:01 +0000 | [diff] [blame] | 44 | } {1 2 {INSERT INTO t1 VALUES($a,$b,$c);}} |
| 45 | set x network |
| 46 | set y fit |
| 47 | set z metal |
| 48 | do_execsql_test stmtvtab1-120 { |
| 49 | INSERT INTO t1 VALUES($a,$b,$c); |
drh | e83b847 | 2017-07-14 15:14:21 +0000 | [diff] [blame] | 50 | SELECT reprep,run,SQL FROM sqlite_stmt WHERE sql LIKE '%INSERT%' AND NOT busy; |
drh | e755072 | 2017-06-29 20:31:01 +0000 | [diff] [blame] | 51 | } {1 3 {INSERT INTO t1 VALUES($a,$b,$c);}} |
| 52 | set x history |
| 53 | set y detail |
| 54 | set z grace |
| 55 | do_execsql_test stmtvtab1-130 { |
| 56 | CREATE INDEX t1b ON t1(b); |
| 57 | INSERT INTO t1 VALUES($a,$b,$c); |
drh | e83b847 | 2017-07-14 15:14:21 +0000 | [diff] [blame] | 58 | SELECT reprep,run,SQL FROM sqlite_stmt WHERE sql LIKE '%INSERT%' AND NOT busy; |
drh | e755072 | 2017-06-29 20:31:01 +0000 | [diff] [blame] | 59 | } {2 4 {INSERT INTO t1 VALUES($a,$b,$c);}} |
| 60 | |
| 61 | # All statements are still in cache |
| 62 | # |
| 63 | do_execsql_test stmtvtab1-140 { |
drh | e83b847 | 2017-07-14 15:14:21 +0000 | [diff] [blame] | 64 | SELECT count(*) FROM sqlite_stmt WHERE NOT busy; |
drh | e755072 | 2017-06-29 20:31:01 +0000 | [diff] [blame] | 65 | } {6} |
| 66 | |
| 67 | # None of the prepared statements should use more than a couple thousand |
| 68 | # bytes of memory |
| 69 | # |
drh | e83b847 | 2017-07-14 15:14:21 +0000 | [diff] [blame] | 70 | #db eval {SELECT mem, sql FROM sqlite_stmt} {puts [format {%5d %s} $mem $sql]} |
drh | e755072 | 2017-06-29 20:31:01 +0000 | [diff] [blame] | 71 | do_execsql_test stmtvtab1-150 { |
drh | e83b847 | 2017-07-14 15:14:21 +0000 | [diff] [blame] | 72 | SELECT count(*) FROM sqlite_stmt WHERE mem>5000; |
drh | e755072 | 2017-06-29 20:31:01 +0000 | [diff] [blame] | 73 | } {0} |
| 74 | |
| 75 | # Flushing the cache clears all of the prepared statements. |
| 76 | # |
| 77 | db cache flush |
| 78 | do_execsql_test stmtvtab1-160 { |
drh | e83b847 | 2017-07-14 15:14:21 +0000 | [diff] [blame] | 79 | SELECT * FROM sqlite_stmt WHERE NOT busy; |
drh | e755072 | 2017-06-29 20:31:01 +0000 | [diff] [blame] | 80 | } {} |