1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
# 2004 Jun 29
#
# 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.
#
# This file implements tests for the "sqlite3_trace()" API.
#
# $Id: trace.test,v 1.7 2008/01/12 21:35:57 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
ifcapable !trace {
finish_test
return
}
set ::stmtlist {}
do_test trace-1.1 {
set rc [catch {db trace 1 2 3} msg]
lappend rc $msg
} {1 {wrong # args: should be "db trace ?CALLBACK?"}}
proc trace_proc cmd {
lappend ::stmtlist [string trim $cmd]
}
do_test trace-1.2 {
db trace trace_proc
db trace
} {trace_proc}
do_test trace-1.3 {
execsql {
CREATE TABLE t1(a,b);
INSERT INTO t1 VALUES(1,2);
SELECT * FROM t1;
}
} {1 2}
do_test trace-1.4 {
set ::stmtlist
} {{CREATE TABLE t1(a,b);} {INSERT INTO t1 VALUES(1,2);} {SELECT * FROM t1;}}
do_test trace-1.5 {
db trace {}
db trace
} {}
# If we prepare a statement and execute it multiple times, the trace
# happens on each execution.
#
db close
sqlite3 db test.db; set DB [sqlite3_connection_pointer db]
do_test trace-2.1 {
set STMT [sqlite3_prepare $DB {INSERT INTO t1 VALUES(2,3)} -1 TAIL]
db trace trace_proc
proc trace_proc sql {
global TRACE_OUT
set TRACE_OUT $sql
}
set TRACE_OUT {}
sqlite3_step $STMT
set TRACE_OUT
} {INSERT INTO t1 VALUES(2,3)}
do_test trace-2.2 {
set TRACE_OUT {}
sqlite3_reset $STMT
set TRACE_OUT
} {}
do_test trace-2.3 {
sqlite3_step $STMT
set TRACE_OUT
} {INSERT INTO t1 VALUES(2,3)}
do_test trace-2.4 {
execsql {SELECT * FROM t1}
} {1 2 2 3 2 3}
do_test trace-2.5 {
set TRACE_OUT
} {SELECT * FROM t1}
catch {sqlite3_finalize $STMT}
# Similar tests, but this time for profiling.
#
do_test trace-3.1 {
set rc [catch {db profile 1 2 3} msg]
lappend rc $msg
} {1 {wrong # args: should be "db profile ?CALLBACK?"}}
set ::stmtlist {}
proc profile_proc {cmd tm} {
lappend ::stmtlist [string trim $cmd]
}
do_test trace-3.2 {
db trace {}
db profile profile_proc
db profile
} {profile_proc}
do_test trace-3.3 {
execsql {
CREATE TABLE t2(a,b);
INSERT INTO t2 VALUES(1,2);
SELECT * FROM t2;
}
} {1 2}
do_test trace-3.4 {
set ::stmtlist
} {{CREATE TABLE t2(a,b);} {INSERT INTO t2 VALUES(1,2);} {SELECT * FROM t2;}}
do_test trace-3.5 {
db profile {}
db profile
} {}
# If we prepare a statement and execute it multiple times, the profile
# happens on each execution.
#
db close
sqlite3 db test.db; set DB [sqlite3_connection_pointer db]
do_test trace-4.1 {
set STMT [sqlite3_prepare $DB {INSERT INTO t2 VALUES(2,3)} -1 TAIL]
db trace trace_proc
proc profile_proc {sql tm} {
global TRACE_OUT
set TRACE_OUT $sql
}
set TRACE_OUT {}
sqlite3_step $STMT
set TRACE_OUT
} {INSERT INTO t2 VALUES(2,3)}
do_test trace-4.2 {
set TRACE_OUT {}
sqlite3_reset $STMT
set TRACE_OUT
} {}
do_test trace-4.3 {
sqlite3_step $STMT
set TRACE_OUT
} {INSERT INTO t2 VALUES(2,3)}
do_test trace-4.4 {
execsql {SELECT * FROM t1}
} {1 2 2 3 2 3}
do_test trace-4.5 {
set TRACE_OUT
} {SELECT * FROM t1}
catch {sqlite3_finalize $STMT}
# Trigger tracing.
#
do_test trace-5.1 {
db eval {
CREATE TRIGGER r1t1 AFTER UPDATE ON t1 BEGIN
UPDATE t2 SET a=new.a WHERE rowid=new.rowid;
END;
CREATE TRIGGER r1t2 AFTER UPDATE ON t2 BEGIN
SELECT 'hello';
END;
}
set TRACE_OUT {}
proc trace_proc cmd {
lappend ::TRACE_OUT [string trim $cmd]
}
db eval {
UPDATE t1 SET a=a+1;
}
set TRACE_OUT
} {{UPDATE t1 SET a=a+1;} {-- TRIGGER r1t1} {-- TRIGGER r1t2} {-- TRIGGER r1t1} {-- TRIGGER r1t2} {-- TRIGGER r1t1} {-- TRIGGER r1t2}}
finish_test
|