xref: /sqlite-3.40.0/test/enc3.test (revision 9c5e1e40)
17cf8c55aSdrh# 2002 May 24
27cf8c55aSdrh#
37cf8c55aSdrh# The author disclaims copyright to this source code.  In place of
47cf8c55aSdrh# a legal notice, here is a blessing:
57cf8c55aSdrh#
67cf8c55aSdrh#    May you do good and not evil.
77cf8c55aSdrh#    May you find forgiveness for yourself and forgive others.
87cf8c55aSdrh#    May you share freely, never taking more than you give.
97cf8c55aSdrh#
107cf8c55aSdrh#***********************************************************************
117cf8c55aSdrh# This file implements regression tests for SQLite library.
127cf8c55aSdrh#
137cf8c55aSdrh# The focus of this file is testing of the proper handling of conversions
147cf8c55aSdrh# to the native text representation.
157cf8c55aSdrh#
167cf8c55aSdrh
177cf8c55aSdrhset testdir [file dirname $argv0]
187cf8c55aSdrhsource $testdir/tester.tcl
197cf8c55aSdrh
206c62608fSdrhifcapable {utf16} {
217cf8c55aSdrh  do_test enc3-1.1 {
227cf8c55aSdrh    execsql {
237cf8c55aSdrh      PRAGMA encoding=utf16le;
247cf8c55aSdrh      PRAGMA encoding;
257cf8c55aSdrh    }
267cf8c55aSdrh  } {UTF-16le}
276c62608fSdrh}
287cf8c55aSdrhdo_test enc3-1.2 {
297cf8c55aSdrh  execsql {
307cf8c55aSdrh    CREATE TABLE t1(x,y);
317cf8c55aSdrh    INSERT INTO t1 VALUES('abc''123',5);
327cf8c55aSdrh    SELECT * FROM t1
337cf8c55aSdrh  }
347cf8c55aSdrh} {abc'123 5}
357cf8c55aSdrhdo_test enc3-1.3 {
367cf8c55aSdrh  execsql {
377cf8c55aSdrh    SELECT quote(x) || ' ' || quote(y) FROM t1
387cf8c55aSdrh  }
397cf8c55aSdrh} {{'abc''123' 5}}
40a71aa001Sdrhifcapable {bloblit} {
41cc195879Sdrh  do_test enc3-1.4 {
42cc195879Sdrh    execsql {
43cc195879Sdrh      DELETE FROM t1;
44cc195879Sdrh      INSERT INTO t1 VALUES(x'616263646566',NULL);
45cc195879Sdrh      SELECT * FROM t1
46cc195879Sdrh    }
47cc195879Sdrh  } {abcdef {}}
48cc195879Sdrh  do_test enc3-1.5 {
49cc195879Sdrh    execsql {
50cc195879Sdrh      SELECT quote(x) || ' ' || quote(y) FROM t1
51cc195879Sdrh    }
52cc195879Sdrh  } {{X'616263646566' NULL}}
53a71aa001Sdrh}
54f1f6c587Sdrhifcapable {bloblit && utf16} {
55f1f6c587Sdrh  do_test enc3-2.1 {
56f1f6c587Sdrh    execsql {
57f1f6c587Sdrh      PRAGMA encoding
58f1f6c587Sdrh    }
59f1f6c587Sdrh  } {UTF-16le}
60f1f6c587Sdrh  do_test enc3-2.2 {
61f1f6c587Sdrh    execsql {
62f1f6c587Sdrh      CREATE TABLE t2(a);
63f1f6c587Sdrh      INSERT INTO t2 VALUES(x'61006200630064006500');
64*41d2e66eSdrh      SELECT CAST(a AS text) FROM t2 WHERE CAST(a AS text) LIKE 'abc%';
65f1f6c587Sdrh    }
66f1f6c587Sdrh  } {abcde}
67e718efe1Sdrh  do_test enc3-2.3 {
68e718efe1Sdrh    execsql {
69e718efe1Sdrh      SELECT CAST(x'61006200630064006500' AS text);
70e718efe1Sdrh    }
71e718efe1Sdrh  } {abcde}
72e718efe1Sdrh  do_test enc3-2.4 {
73e718efe1Sdrh    execsql {
74*41d2e66eSdrh      SELECT rowid FROM t2
75*41d2e66eSdrh       WHERE CAST(a AS text) LIKE CAST(x'610062002500' AS text);
76e718efe1Sdrh    }
77e718efe1Sdrh  } {1}
78f1f6c587Sdrh}
797cf8c55aSdrh
80de4fcfddSdrh# Try to attach a database with a different encoding.
81de4fcfddSdrh#
82c4dd3fd2Sdrhifcapable {utf16 && shared_cache} {
83c4dd3fd2Sdrh  db close
84fda06befSmistachkin  forcedelete test8.db test8.db-journal
85c4dd3fd2Sdrh  set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
86de4fcfddSdrh  sqlite3 dbaux test8.db
87c4dd3fd2Sdrh  sqlite3 db test.db
88c4dd3fd2Sdrh  db eval {SELECT 1 FROM sqlite_master LIMIT 1}
89de4fcfddSdrh  do_test enc3-3.1 {
90de4fcfddSdrh    dbaux eval {
91de4fcfddSdrh      PRAGMA encoding='utf8';
92de4fcfddSdrh      CREATE TABLE t1(x);
93de4fcfddSdrh      PRAGMA encoding
94de4fcfddSdrh    }
95de4fcfddSdrh  } {UTF-8}
96de4fcfddSdrh  do_test enc3-3.2 {
97de4fcfddSdrh    catchsql {
98de4fcfddSdrh      ATTACH 'test.db' AS utf16;
99de4fcfddSdrh      SELECT 1 FROM utf16.sqlite_master LIMIT 1;
100de4fcfddSdrh    } dbaux
101de4fcfddSdrh  } {1 {attached databases must use the same text encoding as main database}}
102c4dd3fd2Sdrh  dbaux close
103fda06befSmistachkin  forcedelete test8.db test8.db-journal
104c4dd3fd2Sdrh  sqlite3_enable_shared_cache $::enable_shared_cache
105de4fcfddSdrh}
1067cf8c55aSdrh
1077cf8c55aSdrhfinish_test
108