sl@0: # 2002 May 24 sl@0: # sl@0: # The author disclaims copyright to this source code. In place of sl@0: # a legal notice, here is a blessing: sl@0: # sl@0: # May you do good and not evil. sl@0: # May you find forgiveness for yourself and forgive others. sl@0: # May you share freely, never taking more than you give. sl@0: # sl@0: #*********************************************************************** sl@0: # This file implements regression tests for SQLite library. sl@0: # sl@0: # The focus of this file is testing of the proper handling of conversions sl@0: # to the native text representation. sl@0: # sl@0: # $Id: enc3.test,v 1.8 2008/01/22 01:48:09 drh Exp $ sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: ifcapable {utf16} { sl@0: do_test enc3-1.1 { sl@0: execsql { sl@0: PRAGMA encoding=utf16le; sl@0: PRAGMA encoding; sl@0: } sl@0: } {UTF-16le} sl@0: } sl@0: do_test enc3-1.2 { sl@0: execsql { sl@0: CREATE TABLE t1(x,y); sl@0: INSERT INTO t1 VALUES('abc''123',5); sl@0: SELECT * FROM t1 sl@0: } sl@0: } {abc'123 5} sl@0: do_test enc3-1.3 { sl@0: execsql { sl@0: SELECT quote(x) || ' ' || quote(y) FROM t1 sl@0: } sl@0: } {{'abc''123' 5}} sl@0: ifcapable {bloblit} { sl@0: do_test enc3-1.4 { sl@0: execsql { sl@0: DELETE FROM t1; sl@0: INSERT INTO t1 VALUES(x'616263646566',NULL); sl@0: SELECT * FROM t1 sl@0: } sl@0: } {abcdef {}} sl@0: do_test enc3-1.5 { sl@0: execsql { sl@0: SELECT quote(x) || ' ' || quote(y) FROM t1 sl@0: } sl@0: } {{X'616263646566' NULL}} sl@0: } sl@0: ifcapable {bloblit && utf16} { sl@0: do_test enc3-2.1 { sl@0: execsql { sl@0: PRAGMA encoding sl@0: } sl@0: } {UTF-16le} sl@0: do_test enc3-2.2 { sl@0: execsql { sl@0: CREATE TABLE t2(a); sl@0: INSERT INTO t2 VALUES(x'61006200630064006500'); sl@0: SELECT CAST(a AS text) FROM t2 WHERE a LIKE 'abc%'; sl@0: } sl@0: } {abcde} sl@0: do_test enc3-2.3 { sl@0: execsql { sl@0: SELECT CAST(x'61006200630064006500' AS text); sl@0: } sl@0: } {abcde} sl@0: do_test enc3-2.4 { sl@0: execsql { sl@0: SELECT rowid FROM t2 WHERE a LIKE x'610062002500'; sl@0: } sl@0: } {1} sl@0: } sl@0: sl@0: # Try to attach a database with a different encoding. sl@0: # sl@0: ifcapable {utf16 && shared_cache} { sl@0: db close sl@0: file delete -force test8.db test8.db-journal sl@0: set ::enable_shared_cache [sqlite3_enable_shared_cache 1] sl@0: sqlite3 dbaux test8.db sl@0: sqlite3 db test.db sl@0: db eval {SELECT 1 FROM sqlite_master LIMIT 1} sl@0: do_test enc3-3.1 { sl@0: dbaux eval { sl@0: PRAGMA encoding='utf8'; sl@0: CREATE TABLE t1(x); sl@0: PRAGMA encoding sl@0: } sl@0: } {UTF-8} sl@0: do_test enc3-3.2 { sl@0: catchsql { sl@0: ATTACH 'test.db' AS utf16; sl@0: SELECT 1 FROM utf16.sqlite_master LIMIT 1; sl@0: } dbaux sl@0: } {1 {attached databases must use the same text encoding as main database}} sl@0: dbaux close sl@0: file delete -force test8.db test8.db-journal sl@0: sqlite3_enable_shared_cache $::enable_shared_cache sl@0: } sl@0: sl@0: finish_test