author | sl@SLION-WIN7.fritz.box |
Fri, 15 Jun 2012 03:10:57 +0200 | |
changeset 0 | bde4ae8d615e |
permissions | -rw-r--r-- |
sl@0 | 1 |
# 2008 June 18 |
sl@0 | 2 |
# |
sl@0 | 3 |
# The author disclaims copyright to this source code. In place of |
sl@0 | 4 |
# a legal notice, here is a blessing: |
sl@0 | 5 |
# |
sl@0 | 6 |
# May you do good and not evil. |
sl@0 | 7 |
# May you find forgiveness for yourself and forgive others. |
sl@0 | 8 |
# May you share freely, never taking more than you give. |
sl@0 | 9 |
# |
sl@0 | 10 |
#*********************************************************************** |
sl@0 | 11 |
# This file implements regression tests for SQLite library. |
sl@0 | 12 |
# |
sl@0 | 13 |
# This file is devoted to testing the sqlite3_next_stmt interface. |
sl@0 | 14 |
# |
sl@0 | 15 |
# $Id: capi3d.test,v 1.2 2008/07/14 15:11:20 drh Exp $ |
sl@0 | 16 |
# |
sl@0 | 17 |
|
sl@0 | 18 |
set testdir [file dirname $argv0] |
sl@0 | 19 |
source $testdir/tester.tcl |
sl@0 | 20 |
|
sl@0 | 21 |
# Create N prepared statements against database connection db |
sl@0 | 22 |
# and return a list of all the generated prepared statements. |
sl@0 | 23 |
# |
sl@0 | 24 |
proc make_prepared_statements {N} { |
sl@0 | 25 |
set plist {} |
sl@0 | 26 |
for {set i 0} {$i<$N} {incr i} { |
sl@0 | 27 |
set sql "SELECT $i FROM sqlite_master WHERE name LIKE '%$i%'" |
sl@0 | 28 |
if {rand()<0.33} { |
sl@0 | 29 |
set s [sqlite3_prepare_v2 db $sql -1 notused] |
sl@0 | 30 |
} else { |
sl@0 | 31 |
ifcapable utf16 { |
sl@0 | 32 |
if {rand()<0.5} { |
sl@0 | 33 |
set sql [encoding convertto unicode $sql]\x00\x00 |
sl@0 | 34 |
set s [sqlite3_prepare16 db $sql -1 notused] |
sl@0 | 35 |
} else { |
sl@0 | 36 |
set s [sqlite3_prepare db $sql -1 notused] |
sl@0 | 37 |
} |
sl@0 | 38 |
} |
sl@0 | 39 |
ifcapable !utf16 { |
sl@0 | 40 |
set s [sqlite3_prepare db $sql -1 notused] |
sl@0 | 41 |
} |
sl@0 | 42 |
} |
sl@0 | 43 |
lappend plist $s |
sl@0 | 44 |
} |
sl@0 | 45 |
return $plist |
sl@0 | 46 |
} |
sl@0 | 47 |
|
sl@0 | 48 |
|
sl@0 | 49 |
# Scramble the $inlist into a random order. |
sl@0 | 50 |
# |
sl@0 | 51 |
proc scramble {inlist} { |
sl@0 | 52 |
set y {} |
sl@0 | 53 |
foreach x $inlist { |
sl@0 | 54 |
lappend y [list [expr {rand()}] $x] |
sl@0 | 55 |
} |
sl@0 | 56 |
set y [lsort $y] |
sl@0 | 57 |
set outlist {} |
sl@0 | 58 |
foreach x $y { |
sl@0 | 59 |
lappend outlist [lindex $x 1] |
sl@0 | 60 |
} |
sl@0 | 61 |
return $outlist |
sl@0 | 62 |
} |
sl@0 | 63 |
|
sl@0 | 64 |
# Database initially has no prepared statements. |
sl@0 | 65 |
# |
sl@0 | 66 |
do_test capi3d-1.1 { |
sl@0 | 67 |
db cache flush |
sl@0 | 68 |
sqlite3_next_stmt db 0 |
sl@0 | 69 |
} {} |
sl@0 | 70 |
|
sl@0 | 71 |
# Run the following tests for between 1 and 100 prepared statements. |
sl@0 | 72 |
# |
sl@0 | 73 |
for {set i 1} {$i<=100} {incr i} { |
sl@0 | 74 |
set stmtlist [make_prepared_statements $i] |
sl@0 | 75 |
do_test capi3d-1.2.$i.1 { |
sl@0 | 76 |
set p [sqlite3_next_stmt db 0] |
sl@0 | 77 |
set x {} |
sl@0 | 78 |
while {$p!=""} { |
sl@0 | 79 |
lappend x $p |
sl@0 | 80 |
set p [sqlite3_next_stmt db $p] |
sl@0 | 81 |
} |
sl@0 | 82 |
lsort $x |
sl@0 | 83 |
} [lsort $stmtlist] |
sl@0 | 84 |
do_test capi3-1.2.$i.2 { |
sl@0 | 85 |
foreach p [scramble $::stmtlist] { |
sl@0 | 86 |
sqlite3_finalize $p |
sl@0 | 87 |
} |
sl@0 | 88 |
sqlite3_next_stmt db 0 |
sl@0 | 89 |
} {} |
sl@0 | 90 |
} |
sl@0 | 91 |
|
sl@0 | 92 |
|
sl@0 | 93 |
finish_test |