fts5blob.test 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. # 2024 July 30
  2. #
  3. # The author disclaims copyright to this source code. In place of
  4. # a legal notice, here is a blessing:
  5. #
  6. # May you do good and not evil.
  7. # May you find forgiveness for yourself and forgive others.
  8. # May you share freely, never taking more than you give.
  9. #
  10. #***********************************************************************
  11. #
  12. # This file verifies that:
  13. #
  14. # * blob values may be written to locale=0 tables.
  15. #
  16. # * blob values - other than fts5_locale() values - may not be written
  17. # to locale=0 tables. This is an SQLITE_MISMATCH error
  18. #
  19. # * blob values may be returned by queries on the external-content table
  20. # of a locale=0 table.
  21. #
  22. # * blob values not may be returned by queries on the external-content
  23. # table of a locale=1 table, apart from fts5_locale() blobs. This is an
  24. # SQLITE_MISMATCH error.
  25. #
  26. source [file join [file dirname [info script]] fts5_common.tcl]
  27. set testprefix fts5blob
  28. # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
  29. ifcapable !fts5 {
  30. finish_test
  31. return
  32. }
  33. # Test that blobs may be stored in normal locale=0 tables.
  34. #
  35. foreach {tn enc} {
  36. 1 utf8
  37. 2 utf16
  38. } {
  39. reset_db
  40. fts5_aux_test_functions db
  41. execsql "PRAGMA encoding = $enc"
  42. execsql "
  43. CREATE VIRTUAL TABLE t1 USING fts5(x, y);
  44. "
  45. do_execsql_test 1.$tn.0 {
  46. CREATE VIRTUAL TABLE tt USING fts5vocab('t1', 'instance');
  47. INSERT INTO t1(rowid, x, y) VALUES(1, 555, X'0000000041424320444546');
  48. INSERT INTO t1(rowid, x, y) VALUES(2, 666, X'41424300444546');
  49. INSERT INTO t1(rowid, x, y) VALUES(3, 777, 'xyz');
  50. }
  51. do_execsql_test 1.$tn.1 {
  52. SELECT rowid, quote(x), quote(y) FROM t1
  53. } {
  54. 1 555 X'0000000041424320444546'
  55. 2 666 X'41424300444546'
  56. 3 777 'xyz'
  57. }
  58. do_execsql_test 1.$tn.2 {
  59. DELETE FROM t1 WHERE rowid=2;
  60. DELETE FROM t1 WHERE rowid=1;
  61. }
  62. do_execsql_test 1.$tn.3 {
  63. PRAGMA integrity_check;
  64. } {ok}
  65. }
  66. #--------------------------------------------------------------------------
  67. # Test that a blob may be stored and retrieved in an unindexed column of
  68. # a regular table with locale=1.
  69. #
  70. reset_db
  71. do_execsql_test 2.0 {
  72. CREATE VIRTUAL TABLE t1 USING fts5(x, y UNINDEXED, locale=1);
  73. INSERT INTO t1(rowid, x, y) VALUES(12, 'twelve', X'0000000041424320444546');
  74. }
  75. do_execsql_test 2.1 {
  76. select rowid, x, quote(y) FROM t1
  77. } {
  78. 12 twelve X'0000000041424320444546'
  79. }
  80. #--------------------------------------------------------------------------
  81. # Test that blobs may not be written to any type of table with locale=1
  82. # set. Except, they may be written to UNINDEXED columns.
  83. #
  84. reset_db
  85. do_execsql_test 3.0 {
  86. CREATE TABLE t1(a, b);
  87. CREATE VIRTUAL TABLE x1 USING fts5(a, b, locale=1);
  88. CREATE VIRTUAL TABLE x2 USING fts5(a, b, locale=1, content=t2);
  89. CREATE VIRTUAL TABLE x3 USING fts5(a, b, locale=1, content=);
  90. }
  91. do_catchsql_test 3.1 {
  92. INSERT INTO x1(rowid, a, b) VALUES(113, 'hello world', X'123456');
  93. } {0 {}}
  94. do_catchsql_test 3.2 {
  95. INSERT INTO x2(rowid, a, b) VALUES(113, 'hello world', X'123456');
  96. } {0 {}}
  97. do_catchsql_test 3.3 {
  98. INSERT INTO x3(rowid, a, b) VALUES(113, 'hello world', X'123456');
  99. } {0 {}}
  100. #--------------------------------------------------------------------------
  101. # Test that fts5_locale() values may not be written to any type of table
  102. # without locale=1 set. Even to an UNINDEXED column.
  103. #
  104. reset_db
  105. do_execsql_test 3.0 {
  106. CREATE TABLE t1(a, b);
  107. CREATE VIRTUAL TABLE x1 USING fts5(a, b);
  108. CREATE VIRTUAL TABLE x2 USING fts5(a, b, content=t2);
  109. CREATE VIRTUAL TABLE x3 USING fts5(a, b, content=);
  110. CREATE VIRTUAL TABLE x4 USING fts5(a, b, c UNINDEXED);
  111. }
  112. do_catchsql_test 3.1 {
  113. INSERT INTO x1(rowid, a, b)
  114. VALUES(113, 'hello world', fts5_locale('en_AU', 'abc'));
  115. } {1 {fts5_locale() requires locale=1}}
  116. do_catchsql_test 3.2 {
  117. INSERT INTO x2(rowid, a, b)
  118. VALUES(113, 'hello world', fts5_locale('en_AU', 'abc'));
  119. } {1 {fts5_locale() requires locale=1}}
  120. do_catchsql_test 3.3 {
  121. INSERT INTO x3(rowid, a, b)
  122. VALUES(113, 'hello world', fts5_locale('en_AU', 'abc'));
  123. } {1 {fts5_locale() requires locale=1}}
  124. do_catchsql_test 3.4 {
  125. INSERT INTO x4(rowid, a, b, c)
  126. VALUES(113, 'hello world', 'yesno', fts5_locale('en_AU', 'abc'));
  127. } {1 {fts5_locale() requires locale=1}}
  128. #-------------------------------------------------------------------------
  129. #
  130. reset_db
  131. do_execsql_test 4.0 {
  132. CREATE VIRTUAL TABLE x1 USING fts5(x);
  133. }
  134. foreach {tn sql} {
  135. 1 { INSERT INTO x1(rowid, x) VALUES(4.5, 'abcd') }
  136. 2 { INSERT INTO x1(rowid, x) VALUES('xyz', 'abcd') }
  137. 3 { INSERT INTO x1(rowid, x) VALUES(X'001122', 'abcd') }
  138. } {
  139. do_catchsql_test 4.1.$tn $sql {1 {datatype mismatch}}
  140. }
  141. finish_test