blob: 4937102091d157947ad241b46e47ff3c4eff521b [file] [log] [blame]
drhe7550722017-06-29 20:31:01 +00001# 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
18set testdir [file dirname $argv0]
19source $testdir/tester.tcl
20
21ifcapable !stmtvtab {
22 finish_test
23 return
24}
25
dan04ed43d2017-07-14 20:53:21 +000026db cache flush
drhe7550722017-06-29 20:31:01 +000027db cache size 20
28unset -nocomplain x y z
29set x giraffe
30set y mango
31set z alabama
32do_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);
drhe83b8472017-07-14 15:14:21 +000036 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);}}
drhe7550722017-06-29 20:31:01 +000038set x neon
39set y event
40set z future
41do_execsql_test stmtvtab1-110 {
42 INSERT INTO t1 VALUES($a,$b,$c);
drhe83b8472017-07-14 15:14:21 +000043 SELECT reprep,run,SQL FROM sqlite_stmt WHERE sql LIKE '%INSERT%' AND NOT busy;
drhe7550722017-06-29 20:31:01 +000044} {1 2 {INSERT INTO t1 VALUES($a,$b,$c);}}
45set x network
46set y fit
47set z metal
48do_execsql_test stmtvtab1-120 {
49 INSERT INTO t1 VALUES($a,$b,$c);
drhe83b8472017-07-14 15:14:21 +000050 SELECT reprep,run,SQL FROM sqlite_stmt WHERE sql LIKE '%INSERT%' AND NOT busy;
drhe7550722017-06-29 20:31:01 +000051} {1 3 {INSERT INTO t1 VALUES($a,$b,$c);}}
52set x history
53set y detail
54set z grace
55do_execsql_test stmtvtab1-130 {
56 CREATE INDEX t1b ON t1(b);
57 INSERT INTO t1 VALUES($a,$b,$c);
drhe83b8472017-07-14 15:14:21 +000058 SELECT reprep,run,SQL FROM sqlite_stmt WHERE sql LIKE '%INSERT%' AND NOT busy;
drhe7550722017-06-29 20:31:01 +000059} {2 4 {INSERT INTO t1 VALUES($a,$b,$c);}}
60
61# All statements are still in cache
62#
63do_execsql_test stmtvtab1-140 {
drhe83b8472017-07-14 15:14:21 +000064 SELECT count(*) FROM sqlite_stmt WHERE NOT busy;
drhe7550722017-06-29 20:31:01 +000065} {6}
66
67# None of the prepared statements should use more than a couple thousand
68# bytes of memory
69#
drhe83b8472017-07-14 15:14:21 +000070#db eval {SELECT mem, sql FROM sqlite_stmt} {puts [format {%5d %s} $mem $sql]}
drhe7550722017-06-29 20:31:01 +000071do_execsql_test stmtvtab1-150 {
drhe83b8472017-07-14 15:14:21 +000072 SELECT count(*) FROM sqlite_stmt WHERE mem>5000;
drhe7550722017-06-29 20:31:01 +000073} {0}
74
75# Flushing the cache clears all of the prepared statements.
76#
77db cache flush
78do_execsql_test stmtvtab1-160 {
drhe83b8472017-07-14 15:14:21 +000079 SELECT * FROM sqlite_stmt WHERE NOT busy;
drhe7550722017-06-29 20:31:01 +000080} {}