CoolFace
Modelpublic

AryaWu/sqlite

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
sqllog.test114 linesDownload Raw Back to test
1# 2015 November 132#3# The author disclaims copyright to this source code.  In place of4# 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# This file implements regression tests for SQLite library.  The12# focus of this file is testing the test_sqllog.c module.13#14 15set testdir [file dirname $argv0]16source $testdir/tester.tcl17set testprefix sqllog18 19ifcapable !sqllog {20  finish_test21  return22}23 24proc readfile {f} {25  set fd [open $f]26  set txt [read $fd]27  close $fd28  set txt29}30 31proc delete_all_sqllog_files {} {32  forcedelete {*}[glob -nocomplain sqllog_*.sql]33  forcedelete {*}[glob -nocomplain sqllog_*.db]34  forcedelete {*}[glob -nocomplain sqllog_*.idx]35}36 37proc touch {f} {38  set fd [open $f w+]39  close $fd40}41 42db close43sqlite3_shutdown44set ::env(SQLITE_SQLLOG_DIR) [pwd]45 46delete_all_sqllog_files47 48sqlite3 db test.db49set a a50set b b51do_execsql_test 1.0 {52  CREATE TABLE t1(x, y);53  INSERT INTO t1 VALUES(1, 2);54  INSERT INTO t1 VALUES($a, $b);55  SELECT * FROM t1;56} {1 2 a b}57db close58 59do_test 1.1 {60  readfile [lindex [glob sqllog_*.sql] 0]61} [string trimleft {62/-- Main database is '.*/sqllog_.*_0.db'63CREATE TABLE t1\(x, y\);; -- clock=064INSERT INTO t1 VALUES\(1, 2\);; -- clock=165INSERT INTO t1 VALUES\('a', 'b'\);; -- clock=266SELECT . FROM t1;; -- clock=367/}]68 69do_test 1.2 {70  file size [lindex [glob sqllog_*_0.db] 0]71} 102472 73#-------------------------------------------------------------------------74catch { db close }75sqlite3_shutdown76delete_all_sqllog_files77forcedelete test.db-sqllog78 79set ::env(SQLITE_SQLLOG_CONDITIONAL) 180sqlite3 db test.db81do_execsql_test 2.1 {82  INSERT INTO t1 VALUES(4, 5);83  SELECT * FROM t1;84} {1 2 a b 4 5}85 86do_test 2.2 {87  glob -nocomplain sqllog_*88} {}89 90db close91touch test.db-sqllog92sqlite3 db test.db93do_execsql_test 2.3 {94  INSERT INTO t1 VALUES(6, 7);95  SELECT * FROM t1;96} {1 2 a b 4 5 6 7}97db close98 99do_test 2.4 {100  readfile [lindex [glob sqllog_*.sql] 0]101} [string trimleft {102/-- Main database is '.*/sqllog_.*_0.db'103INSERT INTO t1 VALUES\(6, 7\);; -- clock=0104SELECT . FROM t1;; -- clock=1105/}]106 107catch { db close }108sqlite3_shutdown109unset ::env(SQLITE_SQLLOG_DIR)110unset ::env(SQLITE_SQLLOG_CONDITIONAL)111sqlite3_config_sqllog112sqlite3_initialize113finish_test114