sqlite
[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.
Brought by drakestapleton
sqlite / ext / intck / intck_common.tcl
| 1 | # 2024 Feb 18 |
| 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 | |
| 13 | if {![info exists testdir]} { |
| 14 | set testdir [file join [file dirname [info script]] .. .. test] |
| 15 | } |
| 16 | source $testdir/tester.tcl |
| 17 | |
| 18 | ifcapable !vtab||!pragma { |
| 19 | proc return_if_no_intck {} { |
| 20 | finish_test |
| 21 | return -code return |
| 22 | } |
| 23 | return |
| 24 | } else { |
| 25 | proc return_if_no_intck {} {} |
| 26 | } |
| 27 | |
| 28 | proc do_intck {db {bSuspend 0}} { |
| 29 | set ic [sqlite3_intck $db main] |
| 30 | |
| 31 | set ret [list] |
| 32 | while {"SQLITE_OK"==[$ic step]} { |
| 33 | set msg [$ic message] |
| 34 | if {$msg!=""} { |
| 35 | lappend ret $msg |
| 36 | } |
| 37 | if {$bSuspend} { |
| 38 | $ic unlock |
| 39 | #puts "SQL: [$ic test_sql {}]" |
| 40 | #execsql_pp "EXPLAIN query plan [$ic test_sql {}]" |
| 41 | #explain_i [$ic test_sql {}] |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | set err [$ic error] |
| 46 | if {[lindex $err 0]!="SQLITE_OK"} { |
| 47 | error $err |
| 48 | } |
| 49 | $ic close |
| 50 | |
| 51 | return $ret |
| 52 | } |
| 53 | |
| 54 | proc intck_sql {db tbl} { |
| 55 | set ic [sqlite3_intck $db main] |
| 56 | set sql [$ic test_sql $tbl] |
| 57 | $ic close |
| 58 | return $sql |
| 59 | } |
| 60 | |
| 61 | proc do_intck_test {tn expect} { |
| 62 | uplevel [list do_test $tn.a [list do_intck db] [list {*}$expect]] |
| 63 | uplevel [list do_test $tn.b [list do_intck db 1] [list {*}$expect]] |
| 64 | } |
| 65 | |
| 66 |