1
0
mirror of https://github.com/sqlite/sqlite.git synced 2026-10-23 21:49:02 +03:00
Files
sqlite/test/fts1i.test
shess 3ad202dd17 http://www.sqlite.org/cvstrac/tktview?tn=2166,35
Calling UPDATE against an fts table in a UTF-16 database inserts
corrupted data into the database.  The UTF-8 data is being inserted
directly.  This appears to happen because sqlite3_ value_text()
destructively coerces a value to UTF-8, and it's never converted back
when updating the table. This works around the problem by rearranging
things so that the update happens before the coercion. (CVS 3596)

FossilOrigin-Name: 4f2ab4b6320ffc621900049b41f50bc30d76d7f5
2007-01-19 22:59:56 +00:00

82 lines
2.2 KiB
Plaintext

# 2007 January 17
#
# The author disclaims copyright to this source code.
#
#*************************************************************************
# This file implements regression tests for SQLite fts1 library. The
# focus here is testing handling of UPDATE when using UTF-16-encoded
# databases.
#
# $Id: fts1i.test,v 1.1 2007/01/19 22:59:57 shess Exp $
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# Return the UTF-16 representation of the supplied UTF-8 string $str.
# If $nt is true, append two 0x00 bytes as a nul terminator.
# NOTE(shess) Copied from capi3.test.
proc utf16 {str {nt 1}} {
set r [encoding convertto unicode $str]
if {$nt} {
append r "\x00\x00"
}
return $r
}
db eval {
PRAGMA encoding = "UTF-16le";
CREATE VIRTUAL TABLE t1 USING fts1(content);
}
do_test fts1i-1.0 {
execsql {PRAGMA encoding}
} {UTF-16le}
do_test fts1i-1.1 {
execsql {INSERT INTO t1 (rowid, content) VALUES(1, 'one')}
execsql {SELECT content FROM t1 WHERE rowid = 1}
} {one}
do_test fts1i-1.2 {
set sql "INSERT INTO t1 (rowid, content) VALUES(2, 'two')"
set STMT [sqlite3_prepare $DB $sql -1 TAIL]
sqlite3_step $STMT
sqlite3_finalize $STMT
execsql {SELECT content FROM t1 WHERE rowid = 2}
} {two}
do_test fts1i-1.3 {
set sql "INSERT INTO t1 (rowid, content) VALUES(3, 'three')"
set STMT [sqlite3_prepare $DB $sql -1 TAIL]
sqlite3_step $STMT
sqlite3_finalize $STMT
set sql "UPDATE t1 SET content = 'trois' WHERE rowid = 3"
set STMT [sqlite3_prepare $DB $sql -1 TAIL]
sqlite3_step $STMT
sqlite3_finalize $STMT
execsql {SELECT content FROM t1 WHERE rowid = 3}
} {trois}
do_test fts1i-1.4 {
set sql16 [utf16 {INSERT INTO t1 (rowid, content) VALUES(4, 'four')}]
set STMT [sqlite3_prepare16 $DB $sql16 -1 TAIL]
sqlite3_step $STMT
sqlite3_finalize $STMT
execsql {SELECT content FROM t1 WHERE rowid = 4}
} {four}
do_test fts1i-1.5 {
set sql16 [utf16 {INSERT INTO t1 (rowid, content) VALUES(5, 'five')}]
set STMT [sqlite3_prepare16 $DB $sql16 -1 TAIL]
sqlite3_step $STMT
sqlite3_finalize $STMT
set sql "UPDATE t1 SET content = 'cinq' WHERE rowid = 5"
set STMT [sqlite3_prepare $DB $sql -1 TAIL]
sqlite3_step $STMT
sqlite3_finalize $STMT
execsql {SELECT content FROM t1 WHERE rowid = 5}
} {cinq}
finish_test