Home | History | Annotate | Download | only in test
      1 # 2007 January 17
      2 #
      3 # The author disclaims copyright to this source code.
      4 #
      5 #*************************************************************************
      6 # This file implements regression tests for SQLite fts1 library.  The
      7 # focus here is testing handling of UPDATE when using UTF-16-encoded
      8 # databases.
      9 #
     10 # $Id: fts1i.test,v 1.2 2007/01/24 03:43:20 drh Exp $
     11 #
     12 
     13 set testdir [file dirname $argv0]
     14 source $testdir/tester.tcl
     15 
     16 # If SQLITE_ENABLE_FTS1 is defined, omit this file.
     17 ifcapable !fts1 {
     18   finish_test
     19   return
     20 }
     21 
     22 
     23 # Return the UTF-16 representation of the supplied UTF-8 string $str.
     24 # If $nt is true, append two 0x00 bytes as a nul terminator.
     25 # NOTE(shess) Copied from capi3.test.
     26 proc utf16 {str {nt 1}} {
     27   set r [encoding convertto unicode $str]
     28   if {$nt} {
     29     append r "\x00\x00"
     30   }
     31   return $r
     32 }
     33 
     34 db eval {
     35   PRAGMA encoding = "UTF-16le";
     36   CREATE VIRTUAL TABLE t1 USING fts1(content);
     37 }
     38 
     39 do_test fts1i-1.0 {
     40   execsql {PRAGMA encoding}
     41 } {UTF-16le}
     42 
     43 do_test fts1i-1.1 {
     44   execsql {INSERT INTO t1 (rowid, content) VALUES(1, 'one')}
     45   execsql {SELECT content FROM t1 WHERE rowid = 1}
     46 } {one}
     47 
     48 do_test fts1i-1.2 {
     49   set sql "INSERT INTO t1 (rowid, content) VALUES(2, 'two')"
     50   set STMT [sqlite3_prepare $DB $sql -1 TAIL]
     51   sqlite3_step $STMT
     52   sqlite3_finalize $STMT
     53   execsql {SELECT content FROM t1 WHERE rowid = 2}
     54 } {two}
     55 
     56 do_test fts1i-1.3 {
     57   set sql "INSERT INTO t1 (rowid, content) VALUES(3, 'three')"
     58   set STMT [sqlite3_prepare $DB $sql -1 TAIL]
     59   sqlite3_step $STMT
     60   sqlite3_finalize $STMT
     61   set sql "UPDATE t1 SET content = 'trois' WHERE rowid = 3"
     62   set STMT [sqlite3_prepare $DB $sql -1 TAIL]
     63   sqlite3_step $STMT
     64   sqlite3_finalize $STMT
     65   execsql {SELECT content FROM t1 WHERE rowid = 3}
     66 } {trois}
     67 
     68 do_test fts1i-1.4 {
     69   set sql16 [utf16 {INSERT INTO t1 (rowid, content) VALUES(4, 'four')}]
     70   set STMT [sqlite3_prepare16 $DB $sql16 -1 TAIL]
     71   sqlite3_step $STMT
     72   sqlite3_finalize $STMT
     73   execsql {SELECT content FROM t1 WHERE rowid = 4}
     74 } {four}
     75 
     76 do_test fts1i-1.5 {
     77   set sql16 [utf16 {INSERT INTO t1 (rowid, content) VALUES(5, 'five')}]
     78   set STMT [sqlite3_prepare16 $DB $sql16 -1 TAIL]
     79   sqlite3_step $STMT
     80   sqlite3_finalize $STMT
     81   set sql "UPDATE t1 SET content = 'cinq' WHERE rowid = 5"
     82   set STMT [sqlite3_prepare $DB $sql -1 TAIL]
     83   sqlite3_step $STMT
     84   sqlite3_finalize $STMT
     85   execsql {SELECT content FROM t1 WHERE rowid = 5}
     86 } {cinq}
     87 
     88 finish_test
     89