enc3.test 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. # 2002 May 24
  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. # This file implements regression tests for SQLite library.
  12. #
  13. # The focus of this file is testing of the proper handling of conversions
  14. # to the native text representation.
  15. #
  16. # $Id: enc3.test,v 1.8 2008/01/22 01:48:09 drh Exp $
  17. set testdir [file dirname $argv0]
  18. source $testdir/tester.tcl
  19. ifcapable {utf16} {
  20. do_test enc3-1.1 {
  21. execsql {
  22. PRAGMA encoding=utf16le;
  23. PRAGMA encoding;
  24. }
  25. } {UTF-16le}
  26. }
  27. do_test enc3-1.2 {
  28. execsql {
  29. CREATE TABLE t1(x,y);
  30. INSERT INTO t1 VALUES('abc''123',5);
  31. SELECT * FROM t1
  32. }
  33. } {abc'123 5}
  34. do_test enc3-1.3 {
  35. execsql {
  36. SELECT quote(x) || ' ' || quote(y) FROM t1
  37. }
  38. } {{'abc''123' 5}}
  39. ifcapable {bloblit} {
  40. do_test enc3-1.4 {
  41. execsql {
  42. DELETE FROM t1;
  43. INSERT INTO t1 VALUES(x'616263646566',NULL);
  44. SELECT * FROM t1
  45. }
  46. } {abcdef {}}
  47. do_test enc3-1.5 {
  48. execsql {
  49. SELECT quote(x) || ' ' || quote(y) FROM t1
  50. }
  51. } {{X'616263646566' NULL}}
  52. }
  53. ifcapable {bloblit && utf16} {
  54. do_test enc3-2.1 {
  55. execsql {
  56. PRAGMA encoding
  57. }
  58. } {UTF-16le}
  59. do_test enc3-2.2 {
  60. execsql {
  61. CREATE TABLE t2(a);
  62. INSERT INTO t2 VALUES(x'61006200630064006500');
  63. SELECT CAST(a AS text) FROM t2 WHERE a LIKE 'abc%';
  64. }
  65. } {abcde}
  66. do_test enc3-2.3 {
  67. execsql {
  68. SELECT CAST(x'61006200630064006500' AS text);
  69. }
  70. } {abcde}
  71. do_test enc3-2.4 {
  72. execsql {
  73. SELECT rowid FROM t2 WHERE a LIKE x'610062002500';
  74. }
  75. } {1}
  76. }
  77. # Try to attach a database with a different encoding.
  78. #
  79. ifcapable {utf16 && shared_cache} {
  80. db close
  81. forcedelete test8.db test8.db-journal
  82. set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
  83. sqlite3 dbaux test8.db
  84. sqlite3 db test.db
  85. db eval {SELECT 1 FROM sqlite_master LIMIT 1}
  86. do_test enc3-3.1 {
  87. dbaux eval {
  88. PRAGMA encoding='utf8';
  89. CREATE TABLE t1(x);
  90. PRAGMA encoding
  91. }
  92. } {UTF-8}
  93. do_test enc3-3.2 {
  94. catchsql {
  95. ATTACH 'test.db' AS utf16;
  96. SELECT 1 FROM utf16.sqlite_master LIMIT 1;
  97. } dbaux
  98. } {1 {attached databases must use the same text encoding as main database}}
  99. dbaux close
  100. forcedelete test8.db test8.db-journal
  101. sqlite3_enable_shared_cache $::enable_shared_cache
  102. }
  103. finish_test