sqlite
[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.
Brought by drakestapleton
| 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 | |
| 15 | set testdir [file dirname $argv0] |
| 16 | source $testdir/tester.tcl |
| 17 | set testprefix carray01 |
| 18 | |
| 19 | ifcapable !vtab { |
| 20 | finish_test |
| 21 | return |
| 22 | } |
| 23 | #load_static_extension db carray |
| 24 | |
| 25 | # Parameter $stmt must be a prepared statement created using |
| 26 | # the sqlite3_prepare_v2 command and with parameters fully 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 | # |
| 33 | proc run_stmt {stmt} { |
| 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 | sqlite3_reset $stmt |
| 41 | return $r |
| 42 | } |
| 43 | |
| 44 | do_test 100 { |
| 45 | set STMT [sqlite3_prepare_v2 db {SELECT 5 IN carray(?3)} -1] |
| 46 | sqlite3_carray_bind $STMT 3 1 2 3 4 5 6 7 |
| 47 | run_stmt $STMT |
| 48 | } {1} |
| 49 | do_test 101 { |
| 50 | sqlite3_carray_bind -static $STMT 3 1 2 3 4 5 6 7 |
| 51 | run_stmt $STMT |
| 52 | } {1} |
| 53 | do_test 102 { |
| 54 | sqlite3_carray_bind -v2 -malloc $STMT 3 1 2 3 4 5 6 7 |
| 55 | run_stmt $STMT |
| 56 | } {1} |
| 57 | do_test 103 { |
| 58 | set STMT2 [sqlite3_prepare_v2 db { |
| 59 | SELECT DISTINCT typeof(value) FROM carray(?3)} -1] |
| 60 | sqlite3_carray_bind $STMT2 3 1 2 3 4 5 6 7 |
| 61 | run_stmt $STMT2 |
| 62 | } {integer} |
| 63 | do_test 110 { |
| 64 | sqlite3_carray_bind $STMT 3 1 2 3 4 6 7 |
| 65 | run_stmt $STMT |
| 66 | } {0} |
| 67 | do_test 120 { |
| 68 | sqlite3_carray_bind -int64 $STMT 3 1 2 3 4 5 6 7 |
| 69 | run_stmt $STMT |
| 70 | } {1} |
| 71 | do_test 120b { |
| 72 | sqlite3_carray_bind -int64 $STMT2 3 1 2 3 4 5 6 7 |
| 73 | run_stmt $STMT2 |
| 74 | } {integer} |
| 75 | do_test 121 { |
| 76 | sqlite3_carray_bind -int64 -transient $STMT 3 1 2 3 4 5 6 7 |
| 77 | run_stmt $STMT |
| 78 | } {1} |
| 79 | do_test 122 { |
| 80 | sqlite3_carray_bind -int64 -static $STMT 3 1 2 3 4 5 6 7 |
| 81 | run_stmt $STMT |
| 82 | } {1} |
| 83 | do_test 123 { |
| 84 | sqlite3_carray_bind -int32 -transient $STMT 3 1 2 3 4 5 6 7 |
| 85 | run_stmt $STMT |
| 86 | } {1} |
| 87 | do_test 124 { |
| 88 | sqlite3_carray_bind -int32 -static $STMT 3 1 2 3 4 5 6 7 |
| 89 | run_stmt $STMT |
| 90 | } {1} |
| 91 | do_test 125 { |
| 92 | sqlite3_carray_bind -int32 $STMT 3 1 2 3 4 5 6 7 |
| 93 | run_stmt $STMT |
| 94 | } {1} |
| 95 | do_test 130 { |
| 96 | sqlite3_carray_bind -int64 $STMT 3 1 2 3 4 6 7 |
| 97 | run_stmt $STMT |
| 98 | } {0} |
| 99 | do_test 131 { |
| 100 | sqlite3_carray_bind -int64 -transient $STMT 3 1 2 3 4 6 7 |
| 101 | run_stmt $STMT |
| 102 | } {0} |
| 103 | do_test 131 { |
| 104 | sqlite3_carray_bind -int64 -static $STMT 3 1 2 3 4 6 7 |
| 105 | run_stmt $STMT |
| 106 | } {0} |
| 107 | do_test 140 { |
| 108 | sqlite3_carray_bind -double $STMT 3 1 2 3 4 5 6 7 |
| 109 | run_stmt $STMT |
| 110 | } {1} |
| 111 | do_test 141 { |
| 112 | sqlite3_carray_bind -double -transient $STMT 3 1 2 3 4 5 6 7 |
| 113 | run_stmt $STMT |
| 114 | } {1} |
| 115 | do_test 142 { |
| 116 | sqlite3_carray_bind -double -static $STMT 3 1 2 3 4 5 6 7 |
| 117 | run_stmt $STMT |
| 118 | } {1} |
| 119 | do_test 143 { |
| 120 | sqlite3_carray_bind -double $STMT2 3 1 2 3 4 5 6 7 |
| 121 | run_stmt $STMT2 |
| 122 | } {real} |
| 123 | do_test 150 { |
| 124 | sqlite3_carray_bind -double $STMT 3 1 2 3 4 6 7 |
| 125 | run_stmt $STMT |
| 126 | } {0} |
| 127 | do_test 160 { |
| 128 | sqlite3_carray_bind -double $STMT 3 1 2 3 4 5 6 7 |
| 129 | run_stmt $STMT |
| 130 | } {1} |
| 131 | do_test 161 { |
| 132 | sqlite3_carray_bind -double -v2 $STMT 3 1 2 3 4 5 6 7 |
| 133 | run_stmt $STMT |
| 134 | } {1} |
| 135 | do_test 170 { |
| 136 | sqlite3_carray_bind -text -static $STMT 3 1 2 3 4 6 7 |
| 137 | run_stmt $STMT |
| 138 | } {0} |
| 139 | do_test 171 { |
| 140 | sqlite3_carray_bind -text -static $STMT2 3 1 2 3 4 6 7 |
| 141 | run_stmt $STMT2 |
| 142 | } {text} |
| 143 | do_test 180 { |
| 144 | sqlite3_carray_bind -text -transient $STMT 3 1 2 3 4 5 6 7 |
| 145 | run_stmt $STMT |
| 146 | } {0} |
| 147 | do_test 190 { |
| 148 | sqlite3_carray_bind -blob -static $STMT 3 1 2 3 4 5 6 7 |
| 149 | run_stmt $STMT |
| 150 | } {0} |
| 151 | do_test 191 { |
| 152 | sqlite3_carray_bind -blob -static $STMT2 3 1 2 3 4 5 6 7 |
| 153 | run_stmt $STMT2 |
| 154 | } {blob} |
| 155 | do_test 200 { |
| 156 | sqlite3_carray_bind -blob -transient $STMT 3 1 2 3 4 5 6 7 |
| 157 | run_stmt $STMT |
| 158 | } {0} |
| 159 | do_test 300 { |
| 160 | sqlite3_carray_bind $STMT 3 |
| 161 | run_stmt $STMT |
| 162 | } {0} |
| 163 | |
| 164 | sqlite3_finalize $STMT |
| 165 | sqlite3_finalize $STMT2 |
| 166 | |
| 167 | # 2026-05-31 dbsqlfuzz case 55c60cf7eb9e0f14c811b7c9227b8d2a0c32f022 |
| 168 | # 2026-06-01 dbsqlfuzz case 78e187a0fb61b19ff2e0cb76d4e8609df5248302 |
| 169 | # Probably also Bug 2026-06-01T07:23:11Z |
| 170 | do_catchsql_test 400 { |
| 171 | DROP TABLE IF EXISTS t1; |
| 172 | CREATE TABLE t1(a INT PRIMARY KEY, b INT) WITHOUT ROWID; |
| 173 | WITH c(x) AS ( |
| 174 | VALUES(1) |
| 175 | UNION |
| 176 | SELECT x+1 FROM (carray NATURAL FULL JOIN carray(t1.b)), t1, c |
| 177 | ) |
| 178 | SELECT * FROM c; |
| 179 | } {1 {table-function argument references tables to its right}} |
| 180 | |
| 181 | finish_test |