summaryrefslogtreecommitdiffstats
path: root/test/carray01.test
blob: d6243eb2743bb0d7cf3c1b6934edee3381f6e2bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# 2020-11-17
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# 
# This file implements tests for CARRAY extension
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix carray01

ifcapable !vtab {
  finish_test
  return
}
load_static_extension db carray

# Parameter $stmt must be a prepared statement created using
# the sqlite3_prepare_v2 command and with parameters fullly bound.
# This routine simply runs the statement, gathers the result, and
# returns a list containing the result.
#
# If the optional second argument is true, then the stmt is finalized
# after it is run.
#
proc run_stmt {stmt {finalizeFlag 0}} {
  set r {}
  while {[sqlite3_step $stmt]=="SQLITE_ROW"} {
    for {set i 0} {$i<[sqlite3_data_count $stmt]} {incr i} {
      lappend r [sqlite3_column_text $stmt $i]
    }
  }
  if {$finalizeFlag} {
    sqlite3_finalize $stmt
  } else {
    sqlite3_reset $stmt
  }
  return $r
}

do_test 100 {
  set STMT [sqlite3_prepare_v2 db {SELECT 5 IN carray(?3)} -1]
  sqlite3_carray_bind $STMT 3 1 2 3 4 5 6 7
  run_stmt $STMT 0
} {1}
do_test 101 {
  sqlite3_carray_bind -static $STMT 3 1 2 3 4 5 6 7
  run_stmt $STMT 0
} {1}
do_test 110 {
  sqlite3_carray_bind $STMT 3 1 2 3 4 6 7
  run_stmt $STMT 0
} {0}
do_test 120 {
  sqlite3_carray_bind -int64 $STMT 3 1 2 3 4 5 6 7
  run_stmt $STMT 0
} {1}
do_test 121 {
  sqlite3_carray_bind -int64 -transient $STMT 3 1 2 3 4 5 6 7
  run_stmt $STMT 0
} {1}
do_test 122 {
  sqlite3_carray_bind -int64 -static $STMT 3 1 2 3 4 5 6 7
  run_stmt $STMT 0
} {1}
do_test 123 {
  sqlite3_carray_bind -int32 -transient $STMT 3 1 2 3 4 5 6 7
  run_stmt $STMT 0
} {1}
do_test 124 {
  sqlite3_carray_bind -int32 -static $STMT 3 1 2 3 4 5 6 7
  run_stmt $STMT 0
} {1}
do_test 125 {
  sqlite3_carray_bind -int32 $STMT 3 1 2 3 4 5 6 7
  run_stmt $STMT 0
} {1}
do_test 130 {
  sqlite3_carray_bind -int64 $STMT 3 1 2 3 4 6 7
  run_stmt $STMT 0
} {0}
do_test 131 {
  sqlite3_carray_bind -int64 -transient $STMT 3 1 2 3 4 6 7
  run_stmt $STMT 0
} {0}
do_test 131 {
  sqlite3_carray_bind -int64 -static $STMT 3 1 2 3 4 6 7
  run_stmt $STMT 0
} {0}
do_test 140 {
  sqlite3_carray_bind -double $STMT 3 1 2 3 4 5 6 7
  run_stmt $STMT 0
} {1}
do_test 141 {
  sqlite3_carray_bind -double -transient $STMT 3 1 2 3 4 5 6 7
  run_stmt $STMT 0
} {1}
do_test 142 {
  sqlite3_carray_bind -double -static $STMT 3 1 2 3 4 5 6 7
  run_stmt $STMT 0
} {1}
do_test 150 {
  sqlite3_carray_bind -double $STMT 3 1 2 3 4 6 7
  run_stmt $STMT 0
} {0}
do_test 160 {
  sqlite3_carray_bind -double $STMT 3 1 2 3 4 5 6 7
  run_stmt $STMT 0
} {1}
do_test 170 {
  sqlite3_carray_bind -text -static $STMT 3 1 2 3 4 6 7
  run_stmt $STMT 0
} {0}
do_test 180 {
  sqlite3_carray_bind -text -transient $STMT 3 1 2 3 4 5 6 7
  run_stmt $STMT 0
} {0}
do_test 190 {
  sqlite3_carray_bind $STMT 3
  run_stmt $STMT 0
} {0}

sqlite3_finalize $STMT

finish_test