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