fts1i.test 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. set testdir [file dirname $argv0]
  13. source $testdir/tester.tcl
  14. # If SQLITE_ENABLE_FTS1 is defined, omit this file.
  15. ifcapable !fts1 {
  16. finish_test
  17. return
  18. }
  19. # Return the UTF-16 representation of the supplied UTF-8 string $str.
  20. # If $nt is true, append two 0x00 bytes as a nul terminator.
  21. # NOTE(shess) Copied from capi3.test.
  22. proc utf16 {str {nt 1}} {
  23. set r [encoding convertto unicode $str]
  24. if {$nt} {
  25. append r "\x00\x00"
  26. }
  27. return $r
  28. }
  29. db eval {
  30. PRAGMA encoding = "UTF-16le";
  31. CREATE VIRTUAL TABLE t1 USING fts1(content);
  32. }
  33. do_test fts1i-1.0 {
  34. execsql {PRAGMA encoding}
  35. } {UTF-16le}
  36. do_test fts1i-1.1 {
  37. execsql {INSERT INTO t1 (rowid, content) VALUES(1, 'one')}
  38. execsql {SELECT content FROM t1 WHERE rowid = 1}
  39. } {one}
  40. do_test fts1i-1.2 {
  41. set sql "INSERT INTO t1 (rowid, content) VALUES(2, 'two')"
  42. set STMT [sqlite3_prepare $DB $sql -1 TAIL]
  43. sqlite3_step $STMT
  44. sqlite3_finalize $STMT
  45. execsql {SELECT content FROM t1 WHERE rowid = 2}
  46. } {two}
  47. do_test fts1i-1.3 {
  48. set sql "INSERT INTO t1 (rowid, content) VALUES(3, 'three')"
  49. set STMT [sqlite3_prepare $DB $sql -1 TAIL]
  50. sqlite3_step $STMT
  51. sqlite3_finalize $STMT
  52. set sql "UPDATE t1 SET content = 'trois' WHERE rowid = 3"
  53. set STMT [sqlite3_prepare $DB $sql -1 TAIL]
  54. sqlite3_step $STMT
  55. sqlite3_finalize $STMT
  56. execsql {SELECT content FROM t1 WHERE rowid = 3}
  57. } {trois}
  58. do_test fts1i-1.4 {
  59. set sql16 [utf16 {INSERT INTO t1 (rowid, content) VALUES(4, 'four')}]
  60. set STMT [sqlite3_prepare16 $DB $sql16 -1 TAIL]
  61. sqlite3_step $STMT
  62. sqlite3_finalize $STMT
  63. execsql {SELECT content FROM t1 WHERE rowid = 4}
  64. } {four}
  65. do_test fts1i-1.5 {
  66. set sql16 [utf16 {INSERT INTO t1 (rowid, content) VALUES(5, 'five')}]
  67. set STMT [sqlite3_prepare16 $DB $sql16 -1 TAIL]
  68. sqlite3_step $STMT
  69. sqlite3_finalize $STMT
  70. set sql "UPDATE t1 SET content = 'cinq' WHERE rowid = 5"
  71. set STMT [sqlite3_prepare $DB $sql -1 TAIL]
  72. sqlite3_step $STMT
  73. sqlite3_finalize $STMT
  74. execsql {SELECT content FROM t1 WHERE rowid = 5}
  75. } {cinq}
  76. finish_test