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]} {
18 # The following script is sourced by every thread spawned using
22 # Execute the supplied SQL using database handle $::DB.
27 while {$rc eq
"SQLITE_LOCKED"
28 ||
$rc eq
"SQLITE_BUSY"
29 ||
$rc eq
"SQLITE_SCHEMA"} {
34 set ::STMT [sqlite3_prepare_v2
$::DB $sql -1 dummy_tail
]
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]
45 if {[lindex $msg 0]=="(6)"} {
52 if {[string first locked
[sqlite3_errmsg
$::DB]]>=0} {
55 if {$rc ne
"SQLITE_OK"} {
56 set errtxt
"$rc - [sqlite3_errmsg $::DB] (debug1)"
60 if {$rc eq
"SQLITE_LOCKED" ||
$rc eq
"SQLITE_BUSY"} {
61 #sqlthread parent "puts \"thread [sqlthread id] is busy. rc=$rc\""
64 #sqlthread parent "puts \"thread [sqlthread id] ran $sql\""
68 if {$rc ne
"SQLITE_OK"} {
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}} {
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"
105 set ::run_thread_tests_called 1