intck_common.tcl 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. if {![info exists testdir]} {
  13. set testdir [file join [file dirname [info script]] .. .. test]
  14. }
  15. source $testdir/tester.tcl
  16. ifcapable !vtab||!pragma {
  17. proc return_if_no_intck {} {
  18. finish_test
  19. return -code return
  20. }
  21. return
  22. } else {
  23. proc return_if_no_intck {} {}
  24. }
  25. proc do_intck {db {bSuspend 0}} {
  26. set ic [sqlite3_intck $db main]
  27. set ret [list]
  28. while {"SQLITE_OK"==[$ic step]} {
  29. set msg [$ic message]
  30. if {$msg!=""} {
  31. lappend ret $msg
  32. }
  33. if {$bSuspend} {
  34. $ic unlock
  35. #puts "SQL: [$ic test_sql {}]"
  36. #execsql_pp "EXPLAIN query plan [$ic test_sql {}]"
  37. #explain_i [$ic test_sql {}]
  38. }
  39. }
  40. set err [$ic error]
  41. if {[lindex $err 0]!="SQLITE_OK"} {
  42. error $err
  43. }
  44. $ic close
  45. return $ret
  46. }
  47. proc intck_sql {db tbl} {
  48. set ic [sqlite3_intck $db main]
  49. set sql [$ic test_sql $tbl]
  50. $ic close
  51. return $sql
  52. }
  53. proc do_intck_test {tn expect} {
  54. uplevel [list do_test $tn.a [list do_intck db] [list {*}$expect]]
  55. uplevel [list do_test $tn.b [list do_intck db 1] [list {*}$expect]]
  56. }