Avoid a warning in fts5.c due to not using generated routine
[sqlite.git] / test / thread_common.tcl
blob6b17082ad4508528d2fd2d6686996c682bf7e89a
1 # 2007 September 10
3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
12 # $Id: thread_common.tcl,v 1.5 2009/03/26 14:48:07 danielk1977 Exp $
14 if {[info exists ::thread_procs]} {
15 return 0
18 # The following script is sourced by every thread spawned using
19 # [sqlthread spawn]:
20 set thread_procs {
22 # Execute the supplied SQL using database handle $::DB.
24 proc execsql {sql} {
26 set rc SQLITE_LOCKED
27 while {$rc eq "SQLITE_LOCKED"
28 || $rc eq "SQLITE_BUSY"
29 || $rc eq "SQLITE_SCHEMA"} {
30 set res [list]
32 enter_db_mutex $::DB
33 set err [catch {
34 set ::STMT [sqlite3_prepare_v2 $::DB $sql -1 dummy_tail]
35 } msg]
37 if {$err == 0} {
38 while {[set rc [sqlite3_step $::STMT]] eq "SQLITE_ROW"} {
39 for {set i 0} {$i < [sqlite3_column_count $::STMT]} {incr i} {
40 lappend res [sqlite3_column_text $::STMT 0]
43 set rc [sqlite3_finalize $::STMT]
44 } else {
45 if {[lindex $msg 0]=="(6)"} {
46 set rc SQLITE_LOCKED
47 } else {
48 set rc SQLITE_ERROR
52 if {[string first locked [sqlite3_errmsg $::DB]]>=0} {
53 set rc SQLITE_LOCKED
55 if {$rc ne "SQLITE_OK"} {
56 set errtxt "$rc - [sqlite3_errmsg $::DB] (debug1)"
58 leave_db_mutex $::DB
60 if {$rc eq "SQLITE_LOCKED" || $rc eq "SQLITE_BUSY"} {
61 #sqlthread parent "puts \"thread [sqlthread id] is busy. rc=$rc\""
62 after 200
63 } else {
64 #sqlthread parent "puts \"thread [sqlthread id] ran $sql\""
68 if {$rc ne "SQLITE_OK"} {
69 error $errtxt
71 set res
74 proc do_test {name script result} {
75 set res [eval $script]
76 if {$res ne $result} {
77 error "$name failed: expected \"$result\" got \"$res\""
82 proc thread_spawn {varname args} {
83 sqlthread spawn $varname [join $args {;}]
86 # Return true if this build can run the multi-threaded tests.
88 proc run_thread_tests {{print_warning 0}} {
89 ifcapable !mutex {
90 set zProblem "SQLite build is not threadsafe"
92 ifcapable mutex_noop {
93 set zProblem "SQLite build uses SQLITE_MUTEX_NOOP"
95 if {[info commands sqlthread] eq ""} {
96 set zProblem "SQLite build is not threadsafe"
98 if {![info exists ::tcl_platform(threaded)]} {
99 set zProblem "Linked against a non-threadsafe Tcl build"
101 if {[info exists zProblem]} {
102 puts "WARNING: Multi-threaded tests skipped: $zProblem"
103 return 0
105 set ::run_thread_tests_called 1
106 return 1;
109 return 0