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