1
0
mirror of https://github.com/sqlite/sqlite.git synced 2026-10-23 21:49:02 +03:00
Files
sqlite/test/bind2.test
drh a4b453a1e6 The .recover command should not remove BOMs that are already inside the
database.
[bugs:/info/2026-10-18T20:41:57Z|Bug 2026-10-18T20:41:57Z]

FossilOrigin-Name: 69f4d423fa5538a555f862da3a1896e2fa3009dc650286042cb0beabe4dd2114
2026-10-23 15:52:17 +00:00

108 lines
2.8 KiB
Plaintext

# 2022 Feb 10
#
# 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.
#
#***********************************************************************
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix bind2
# Test that using bind_value() on a REAL sqlite3_value that was stored
# as an INTEGER works properly.
#
# 1.1: An IntReal value read from a table,
# 1.2: IntReal values obtained via the sqlite3_preupdate_old|new()
# interfaces.
#
do_execsql_test 1.0 {
CREATE TABLE t1(a REAL);
INSERT INTO t1 VALUES(42.0);
SELECT * FROM t1;
} {42.0}
do_test 1.1 {
set stmt [sqlite3_prepare db "SELECT ?" -1 tail]
sqlite3_bind_value_from_select $stmt 1 "SELECT a FROM t1"
sqlite3_step $stmt
sqlite3_column_text $stmt 0
} {42.0}
sqlite3_finalize $stmt
# Bug 2026-10-18T20:41:57Z
#
# In a UTF-16 database, using sqlite3_bind_value() to copy a TEXT value
# that begins with U+FEFF or U+FFFE should copy the value exactly. The
# leading character is not a byte-order mark.
#
foreach enc {utf16le utf16be} {
forcedelete test.db3
sqlite3 db3 test.db3
do_execsql_test -db db3 2.$enc.0 "
PRAGMA encoding = '$enc';
CREATE TABLE t2(id INTEGER PRIMARY KEY, a TEXT);
INSERT INTO t2 VALUES
(1, char(0xfeff)||'abc'),
(2, char(0xfffe)||'xyz'),
(3, 'plain'),
(4, char(0xfeff)||printf('%.*c', 5000, 'a')),
(5, char(0xfffe)||printf('%.*c', 5000, 'b'));
"
foreach {id res} {
1 {4 65279 1}
2 {4 65534 1}
3 {5 112 1}
4 {5001 65279 1}
5 {5001 65534 1}
} {
do_test 2.$enc.$id {
set stmt [sqlite3_prepare db3 {
SELECT length(?1), unicode(?1), ?1=(SELECT a FROM t2 WHERE id=?2)
} -1 tail]
sqlite3_bind_int $stmt 2 $id
sqlite3_bind_value_from_select $stmt 1 "SELECT a FROM t2 WHERE id=$id"
sqlite3_step $stmt
set r [list [sqlite3_column_int $stmt 0] \
[sqlite3_column_int $stmt 1] \
[sqlite3_column_int $stmt 2]]
sqlite3_finalize $stmt
set r
} $res
}
db3 close
}
ifcapable !preupdate {
finish_test
return
}
proc preup {args} {
set stmt [sqlite3_prepare db "SELECT ?" -1 tail]
sqlite3_bind_value_from_preupdate $stmt 1 old 0
sqlite3_step $stmt
lappend ::reslist [sqlite3_column_text $stmt 0]
sqlite3_reset $stmt
sqlite3_bind_value_from_preupdate $stmt 1 new 0
sqlite3_step $stmt
lappend ::reslist [sqlite3_column_text $stmt 0]
sqlite3_finalize $stmt
}
db preupdate hook preup
do_test 1.2 {
set ::reslist [list]
execsql { UPDATE t1 SET a=43; }
set ::reslist
} {42.0 43.0}
finish_test