1# 2020-11-17 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# This file implements tests for CARRAY extension 13# 14 15set testdir [file dirname $argv0] 16source $testdir/tester.tcl 17set testprefix carray01 18 19ifcapable !vtab { 20 finish_test 21 return 22} 23load_static_extension db carray 24 25# Parameter $stmt must be a prepared statement created using 26# the sqlite3_prepare_v2 command and with parameters fullly bound. 27# This routine simply runs the statement, gathers the result, and 28# returns a list containing the result. 29# 30# If the optional second argument is true, then the stmt is finalized 31# after it is run. 32# 33proc run_stmt {stmt {finalizeFlag 0}} { 34 set r {} 35 while {[sqlite3_step $stmt]=="SQLITE_ROW"} { 36 for {set i 0} {$i<[sqlite3_data_count $stmt]} {incr i} { 37 lappend r [sqlite3_column_text $stmt $i] 38 } 39 } 40 if {$finalizeFlag} { 41 sqlite3_finalize $stmt 42 } else { 43 sqlite3_reset $stmt 44 } 45 return $r 46} 47 48do_test 100 { 49 set STMT [sqlite3_prepare_v2 db {SELECT 5 IN carray(?3)} -1] 50 sqlite3_carray_bind $STMT 3 1 2 3 4 5 6 7 51 run_stmt $STMT 0 52} {1} 53do_test 101 { 54 sqlite3_carray_bind -static $STMT 3 1 2 3 4 5 6 7 55 run_stmt $STMT 0 56} {1} 57do_test 110 { 58 sqlite3_carray_bind $STMT 3 1 2 3 4 6 7 59 run_stmt $STMT 0 60} {0} 61do_test 120 { 62 sqlite3_carray_bind -int64 $STMT 3 1 2 3 4 5 6 7 63 run_stmt $STMT 0 64} {1} 65do_test 121 { 66 sqlite3_carray_bind -int64 -transient $STMT 3 1 2 3 4 5 6 7 67 run_stmt $STMT 0 68} {1} 69do_test 122 { 70 sqlite3_carray_bind -int64 -static $STMT 3 1 2 3 4 5 6 7 71 run_stmt $STMT 0 72} {1} 73do_test 123 { 74 sqlite3_carray_bind -int32 -transient $STMT 3 1 2 3 4 5 6 7 75 run_stmt $STMT 0 76} {1} 77do_test 124 { 78 sqlite3_carray_bind -int32 -static $STMT 3 1 2 3 4 5 6 7 79 run_stmt $STMT 0 80} {1} 81do_test 125 { 82 sqlite3_carray_bind -int32 $STMT 3 1 2 3 4 5 6 7 83 run_stmt $STMT 0 84} {1} 85do_test 130 { 86 sqlite3_carray_bind -int64 $STMT 3 1 2 3 4 6 7 87 run_stmt $STMT 0 88} {0} 89do_test 131 { 90 sqlite3_carray_bind -int64 -transient $STMT 3 1 2 3 4 6 7 91 run_stmt $STMT 0 92} {0} 93do_test 131 { 94 sqlite3_carray_bind -int64 -static $STMT 3 1 2 3 4 6 7 95 run_stmt $STMT 0 96} {0} 97do_test 140 { 98 sqlite3_carray_bind -double $STMT 3 1 2 3 4 5 6 7 99 run_stmt $STMT 0 100} {1} 101do_test 141 { 102 sqlite3_carray_bind -double -transient $STMT 3 1 2 3 4 5 6 7 103 run_stmt $STMT 0 104} {1} 105do_test 142 { 106 sqlite3_carray_bind -double -static $STMT 3 1 2 3 4 5 6 7 107 run_stmt $STMT 0 108} {1} 109do_test 150 { 110 sqlite3_carray_bind -double $STMT 3 1 2 3 4 6 7 111 run_stmt $STMT 0 112} {0} 113do_test 160 { 114 sqlite3_carray_bind -double $STMT 3 1 2 3 4 5 6 7 115 run_stmt $STMT 0 116} {1} 117do_test 170 { 118 sqlite3_carray_bind -text -static $STMT 3 1 2 3 4 6 7 119 run_stmt $STMT 0 120} {0} 121do_test 180 { 122 sqlite3_carray_bind -text -transient $STMT 3 1 2 3 4 5 6 7 123 run_stmt $STMT 0 124} {0} 125do_test 190 { 126 sqlite3_carray_bind $STMT 3 127 run_stmt $STMT 0 128} {0} 129 130sqlite3_finalize $STMT 131 132finish_test 133