os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/enc3.test
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/enc3.test	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,107 @@
     1.4 +# 2002 May 24
     1.5 +#
     1.6 +# The author disclaims copyright to this source code.  In place of
     1.7 +# a legal notice, here is a blessing:
     1.8 +#
     1.9 +#    May you do good and not evil.
    1.10 +#    May you find forgiveness for yourself and forgive others.
    1.11 +#    May you share freely, never taking more than you give.
    1.12 +#
    1.13 +#***********************************************************************
    1.14 +# This file implements regression tests for SQLite library. 
    1.15 +#
    1.16 +# The focus of this file is testing of the proper handling of conversions
    1.17 +# to the native text representation.
    1.18 +#
    1.19 +# $Id: enc3.test,v 1.8 2008/01/22 01:48:09 drh Exp $
    1.20 +
    1.21 +set testdir [file dirname $argv0]
    1.22 +source $testdir/tester.tcl
    1.23 +
    1.24 +ifcapable {utf16} {
    1.25 +  do_test enc3-1.1 {
    1.26 +    execsql {
    1.27 +      PRAGMA encoding=utf16le;
    1.28 +      PRAGMA encoding;
    1.29 +    }
    1.30 +  } {UTF-16le}
    1.31 +}
    1.32 +do_test enc3-1.2 {
    1.33 +  execsql {
    1.34 +    CREATE TABLE t1(x,y);
    1.35 +    INSERT INTO t1 VALUES('abc''123',5);
    1.36 +    SELECT * FROM t1
    1.37 +  }
    1.38 +} {abc'123 5}
    1.39 +do_test enc3-1.3 {
    1.40 +  execsql {
    1.41 +    SELECT quote(x) || ' ' || quote(y) FROM t1
    1.42 +  }
    1.43 +} {{'abc''123' 5}}
    1.44 +ifcapable {bloblit} {
    1.45 +  do_test enc3-1.4 {
    1.46 +    execsql {
    1.47 +      DELETE FROM t1;
    1.48 +      INSERT INTO t1 VALUES(x'616263646566',NULL);
    1.49 +      SELECT * FROM t1
    1.50 +    }
    1.51 +  } {abcdef {}}
    1.52 +  do_test enc3-1.5 {
    1.53 +    execsql {
    1.54 +      SELECT quote(x) || ' ' || quote(y) FROM t1
    1.55 +    }
    1.56 +  } {{X'616263646566' NULL}}
    1.57 +}
    1.58 +ifcapable {bloblit && utf16} {
    1.59 +  do_test enc3-2.1 {
    1.60 +    execsql {
    1.61 +      PRAGMA encoding
    1.62 +    }
    1.63 +  } {UTF-16le}
    1.64 +  do_test enc3-2.2 {
    1.65 +    execsql {
    1.66 +      CREATE TABLE t2(a);
    1.67 +      INSERT INTO t2 VALUES(x'61006200630064006500');
    1.68 +      SELECT CAST(a AS text) FROM t2 WHERE a LIKE 'abc%';
    1.69 +    }
    1.70 +  } {abcde}
    1.71 +  do_test enc3-2.3 {
    1.72 +    execsql {
    1.73 +      SELECT CAST(x'61006200630064006500' AS text);
    1.74 +    }
    1.75 +  } {abcde}
    1.76 +  do_test enc3-2.4 {
    1.77 +    execsql {
    1.78 +      SELECT rowid FROM t2 WHERE a LIKE x'610062002500';
    1.79 +    }
    1.80 +  } {1}
    1.81 +}
    1.82 +
    1.83 +# Try to attach a database with a different encoding.
    1.84 +#
    1.85 +ifcapable {utf16 && shared_cache} {
    1.86 +  db close
    1.87 +  file delete -force test8.db test8.db-journal
    1.88 +  set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
    1.89 +  sqlite3 dbaux test8.db
    1.90 +  sqlite3 db test.db
    1.91 +  db eval {SELECT 1 FROM sqlite_master LIMIT 1}
    1.92 +  do_test enc3-3.1 {
    1.93 +    dbaux eval {
    1.94 +      PRAGMA encoding='utf8';
    1.95 +      CREATE TABLE t1(x);
    1.96 +      PRAGMA encoding
    1.97 +    }
    1.98 +  } {UTF-8}
    1.99 +  do_test enc3-3.2 {
   1.100 +    catchsql {
   1.101 +      ATTACH 'test.db' AS utf16;
   1.102 +      SELECT 1 FROM utf16.sqlite_master LIMIT 1;
   1.103 +    } dbaux
   1.104 +  } {1 {attached databases must use the same text encoding as main database}}
   1.105 +  dbaux close
   1.106 +  file delete -force test8.db test8.db-journal
   1.107 +  sqlite3_enable_shared_cache $::enable_shared_cache
   1.108 +}
   1.109 +
   1.110 +finish_test