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