drh | 7cf8c55 | 2004-06-22 17:59:55 +0000 | [diff] [blame] | 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 | # |
drh | c4dd3fd | 2008-01-22 01:48:05 +0000 | [diff] [blame] | 16 | # $Id: enc3.test,v 1.8 2008/01/22 01:48:09 drh Exp $ |
drh | 7cf8c55 | 2004-06-22 17:59:55 +0000 | [diff] [blame] | 17 | |
| 18 | set testdir [file dirname $argv0] |
| 19 | source $testdir/tester.tcl |
| 20 | |
drh | 6c62608 | 2004-11-14 21:56:29 +0000 | [diff] [blame] | 21 | ifcapable {utf16} { |
| 22 | do_test enc3-1.1 { |
| 23 | execsql { |
| 24 | PRAGMA encoding=utf16le; |
| 25 | PRAGMA encoding; |
| 26 | } |
| 27 | } {UTF-16le} |
| 28 | } |
drh | 7cf8c55 | 2004-06-22 17:59:55 +0000 | [diff] [blame] | 29 | do_test enc3-1.2 { |
| 30 | execsql { |
| 31 | CREATE TABLE t1(x,y); |
| 32 | INSERT INTO t1 VALUES('abc''123',5); |
| 33 | SELECT * FROM t1 |
| 34 | } |
| 35 | } {abc'123 5} |
| 36 | do_test enc3-1.3 { |
| 37 | execsql { |
| 38 | SELECT quote(x) || ' ' || quote(y) FROM t1 |
| 39 | } |
| 40 | } {{'abc''123' 5}} |
drh | a71aa00 | 2004-11-03 13:59:04 +0000 | [diff] [blame] | 41 | ifcapable {bloblit} { |
| 42 | do_test enc3-1.4 { |
| 43 | execsql { |
| 44 | DELETE FROM t1; |
| 45 | INSERT INTO t1 VALUES(x'616263646566',NULL); |
| 46 | SELECT * FROM t1 |
| 47 | } |
| 48 | } {abcdef {}} |
| 49 | do_test enc3-1.5 { |
| 50 | execsql { |
| 51 | SELECT quote(x) || ' ' || quote(y) FROM t1 |
| 52 | } |
| 53 | } {{X'616263646566' NULL}} |
| 54 | } |
drh | f1f6c58 | 2006-01-12 19:42:41 +0000 | [diff] [blame] | 55 | ifcapable {bloblit && utf16} { |
| 56 | do_test enc3-2.1 { |
| 57 | execsql { |
| 58 | PRAGMA encoding |
| 59 | } |
| 60 | } {UTF-16le} |
| 61 | do_test enc3-2.2 { |
| 62 | execsql { |
| 63 | CREATE TABLE t2(a); |
| 64 | INSERT INTO t2 VALUES(x'61006200630064006500'); |
drh | 41d2e66 | 2015-12-01 21:23:07 +0000 | [diff] [blame] | 65 | SELECT CAST(a AS text) FROM t2 WHERE CAST(a AS text) LIKE 'abc%'; |
drh | f1f6c58 | 2006-01-12 19:42:41 +0000 | [diff] [blame] | 66 | } |
| 67 | } {abcde} |
drh | e718efe | 2007-05-10 21:14:03 +0000 | [diff] [blame] | 68 | do_test enc3-2.3 { |
| 69 | execsql { |
| 70 | SELECT CAST(x'61006200630064006500' AS text); |
| 71 | } |
| 72 | } {abcde} |
| 73 | do_test enc3-2.4 { |
| 74 | execsql { |
drh | 41d2e66 | 2015-12-01 21:23:07 +0000 | [diff] [blame] | 75 | SELECT rowid FROM t2 |
| 76 | WHERE CAST(a AS text) LIKE CAST(x'610062002500' AS text); |
drh | e718efe | 2007-05-10 21:14:03 +0000 | [diff] [blame] | 77 | } |
| 78 | } {1} |
drh | f1f6c58 | 2006-01-12 19:42:41 +0000 | [diff] [blame] | 79 | } |
drh | 7cf8c55 | 2004-06-22 17:59:55 +0000 | [diff] [blame] | 80 | |
drh | de4fcfd | 2008-01-19 23:50:26 +0000 | [diff] [blame] | 81 | # Try to attach a database with a different encoding. |
| 82 | # |
drh | c4dd3fd | 2008-01-22 01:48:05 +0000 | [diff] [blame] | 83 | ifcapable {utf16 && shared_cache} { |
| 84 | db close |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 85 | forcedelete test8.db test8.db-journal |
drh | c4dd3fd | 2008-01-22 01:48:05 +0000 | [diff] [blame] | 86 | set ::enable_shared_cache [sqlite3_enable_shared_cache 1] |
drh | de4fcfd | 2008-01-19 23:50:26 +0000 | [diff] [blame] | 87 | sqlite3 dbaux test8.db |
drh | c4dd3fd | 2008-01-22 01:48:05 +0000 | [diff] [blame] | 88 | sqlite3 db test.db |
| 89 | db eval {SELECT 1 FROM sqlite_master LIMIT 1} |
drh | de4fcfd | 2008-01-19 23:50:26 +0000 | [diff] [blame] | 90 | do_test enc3-3.1 { |
| 91 | dbaux eval { |
| 92 | PRAGMA encoding='utf8'; |
| 93 | CREATE TABLE t1(x); |
| 94 | PRAGMA encoding |
| 95 | } |
| 96 | } {UTF-8} |
| 97 | do_test enc3-3.2 { |
| 98 | catchsql { |
| 99 | ATTACH 'test.db' AS utf16; |
| 100 | SELECT 1 FROM utf16.sqlite_master LIMIT 1; |
| 101 | } dbaux |
| 102 | } {1 {attached databases must use the same text encoding as main database}} |
drh | c4dd3fd | 2008-01-22 01:48:05 +0000 | [diff] [blame] | 103 | dbaux close |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 104 | forcedelete test8.db test8.db-journal |
drh | c4dd3fd | 2008-01-22 01:48:05 +0000 | [diff] [blame] | 105 | sqlite3_enable_shared_cache $::enable_shared_cache |
drh | de4fcfd | 2008-01-19 23:50:26 +0000 | [diff] [blame] | 106 | } |
drh | 7cf8c55 | 2004-06-22 17:59:55 +0000 | [diff] [blame] | 107 | |
| 108 | finish_test |