interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / test / carrayfault.test

87 lines · 2019 bytes Raw Blame History
1# 2025-10-07
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
13set testdir [file dirname $argv0]
14source $testdir/tester.tcl
15set testprefix carrayfault
16
17ifcapable {!carray||!vtab} {
18 finish_test; return
19}
20
21sqlite3 db test.db
22
23do_execsql_test 2.0 {
24 CREATE TABLE t1(a);
25}
26
27set STMT [sqlite3_prepare_v2 db "SELECT value FROM carray(?)" -1 TAIL]
28
29# Test OOM faults in sqlite3_carray_bind() when binding an integer
30# array.
31#
32foreach {tn mem} {
33 1 -static
34 2 -transient
35 3 -malloc
36} {
37 do_faultsim_test 2.$tn -faults oom* -prep {
38 } -body {
39 sqlite3_carray_bind $::mem -int64 $::STMT 1 100 200 300 400
40 } -test {
41 faultsim_test_result {0 {}} {1 {out of memory}}
42 }
43}
44
45# Test OOM faults in sqlite3_carray_bind() when binding a text array.
46#
47do_faultsim_test 3 -faults oom* -prep {
48} -body {
49 sqlite3_carray_bind -transient -text $::STMT 1 "hello" "world"
50} -test {
51 faultsim_test_result {0 {}} {1 {initialization of carray failed: }}
52}
53
54sqlite3_finalize $STMT
55
56
57# Test OOM faults when running queries against carray.
58#
59do_faultsim_test 4 -faults oom* -prep {
60 set ::STMT [sqlite3_prepare_v2 db "SELECT value FROM carray(?)" -1 TAIL]
61 sqlite3_carray_bind -transient -text $::STMT 1 "hello" "world"
62} -body {
63 set myres [list]
64 while { "SQLITE_ROW"==[sqlite3_step $::STMT] } {
65 lappend myres [sqlite3_column_text $::STMT 1]
66 }
67 sqlite3_reset $::STMT
68} -test {
69 faultsim_test_result {0 SQLITE_OK} {0 SQLITE_NOMEM}
70 sqlite3_finalize $::STMT
71}
72
73# Test OOM faults when preparing queries against carray.
74#
75do_faultsim_test 5 -faults oom* -prep {
76 sqlite3 db test.db
77} -body {
78 execsql "SELECT value FROM carray(?)"
79} -test {
80 faultsim_test_result {0 {}}
81}
82
83
84
85sqlite3_carray_bind
86
87finish_test