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 / bind2.test

107 lines · 2829 bytes Raw Blame History
1# 2022 Feb 10
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 bind2
16
17
18# Test that using bind_value() on a REAL sqlite3_value that was stored
19# as an INTEGER works properly.
20#
21# 1.1: An IntReal value read from a table,
22# 1.2: IntReal values obtained via the sqlite3_preupdate_old|new()
23# interfaces.
24#
25do_execsql_test 1.0 {
26 CREATE TABLE t1(a REAL);
27 INSERT INTO t1 VALUES(42.0);
28 SELECT * FROM t1;
29} {42.0}
30
31do_test 1.1 {
32 set stmt [sqlite3_prepare db "SELECT ?" -1 tail]
33 sqlite3_bind_value_from_select $stmt 1 "SELECT a FROM t1"
34 sqlite3_step $stmt
35 sqlite3_column_text $stmt 0
36} {42.0}
37sqlite3_finalize $stmt
38
39
40# Bug 2026-10-18T20:41:57Z
41#
42# In a UTF-16 database, using sqlite3_bind_value() to copy a TEXT value
43# that begins with U+FEFF or U+FFFE should copy the value exactly. The
44# leading character is not a byte-order mark.
45#
46foreach enc {utf16le utf16be} {
47 forcedelete test.db3
48 sqlite3 db3 test.db3
49 do_execsql_test -db db3 2.$enc.0 "
50 PRAGMA encoding = '$enc';
51 CREATE TABLE t2(id INTEGER PRIMARY KEY, a TEXT);
52 INSERT INTO t2 VALUES
53 (1, char(0xfeff)||'abc'),
54 (2, char(0xfffe)||'xyz'),
55 (3, 'plain'),
56 (4, char(0xfeff)||printf('%.*c', 5000, 'a')),
57 (5, char(0xfffe)||printf('%.*c', 5000, 'b'));
58 "
59 foreach {id res} {
60 1 {4 65279 1}
61 2 {4 65534 1}
62 3 {5 112 1}
63 4 {5001 65279 1}
64 5 {5001 65534 1}
65 } {
66 do_test 2.$enc.$id {
67 set stmt [sqlite3_prepare db3 {
68 SELECT length(?1), unicode(?1), ?1=(SELECT a FROM t2 WHERE id=?2)
69 } -1 tail]
70 sqlite3_bind_int $stmt 2 $id
71 sqlite3_bind_value_from_select $stmt 1 "SELECT a FROM t2 WHERE id=$id"
72 sqlite3_step $stmt
73 set r [list [sqlite3_column_int $stmt 0] \
74 [sqlite3_column_int $stmt 1] \
75 [sqlite3_column_int $stmt 2]]
76 sqlite3_finalize $stmt
77 set r
78 } $res
79 }
80 db3 close
81}
82
83ifcapable !preupdate {
84 finish_test
85 return
86}
87
88proc preup {args} {
89 set stmt [sqlite3_prepare db "SELECT ?" -1 tail]
90 sqlite3_bind_value_from_preupdate $stmt 1 old 0
91 sqlite3_step $stmt
92 lappend ::reslist [sqlite3_column_text $stmt 0]
93 sqlite3_reset $stmt
94 sqlite3_bind_value_from_preupdate $stmt 1 new 0
95 sqlite3_step $stmt
96 lappend ::reslist [sqlite3_column_text $stmt 0]
97 sqlite3_finalize $stmt
98}
99db preupdate hook preup
100
101do_test 1.2 {
102 set ::reslist [list]
103 execsql { UPDATE t1 SET a=43; }
104 set ::reslist
105} {42.0 43.0}
106
107finish_test