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