os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/reindex.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/reindex.test	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,171 @@
     1.4 +# 2004 November 5
     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 +# This file implements tests for the REINDEX command.
    1.16 +#
    1.17 +# $Id: reindex.test,v 1.4 2008/07/12 14:52:20 drh Exp $
    1.18 +
    1.19 +set testdir [file dirname $argv0]
    1.20 +source $testdir/tester.tcl
    1.21 +
    1.22 +# There is nothing to test if REINDEX is disable for this build.
    1.23 +#
    1.24 +ifcapable {!reindex} {
    1.25 +  finish_test
    1.26 +  return
    1.27 +}
    1.28 +
    1.29 +# Basic sanity checks.
    1.30 +#
    1.31 +do_test reindex-1.1 {
    1.32 +  execsql {
    1.33 +    CREATE TABLE t1(a,b);
    1.34 +    INSERT INTO t1 VALUES(1,2);
    1.35 +    INSERT INTO t1 VALUES(3,4);
    1.36 +    CREATE INDEX i1 ON t1(a);
    1.37 +    REINDEX;
    1.38 +  }
    1.39 +} {}
    1.40 +integrity_check reindex-1.2
    1.41 +do_test reindex-1.3 {
    1.42 +  execsql {
    1.43 +    REINDEX t1;
    1.44 +  }
    1.45 +} {}
    1.46 +integrity_check reindex-1.4
    1.47 +do_test reindex-1.5 {
    1.48 +  execsql {
    1.49 +    REINDEX i1;
    1.50 +  }
    1.51 +} {}
    1.52 +integrity_check reindex-1.6
    1.53 +do_test reindex-1.7 {
    1.54 +  execsql {
    1.55 +    REINDEX main.t1;
    1.56 +  }
    1.57 +} {}
    1.58 +do_test reindex-1.8 {
    1.59 +  execsql {
    1.60 +    REINDEX main.i1;
    1.61 +  }
    1.62 +} {}
    1.63 +do_test reindex-1.9 {
    1.64 +  catchsql {
    1.65 +    REINDEX bogus
    1.66 +  }
    1.67 +} {1 {unable to identify the object to be reindexed}}
    1.68 +
    1.69 +# Set up a table for testing that includes several different collating
    1.70 +# sequences including some that we can modify.
    1.71 +#
    1.72 +do_test reindex-2.1 {
    1.73 +  proc c1 {a b} {
    1.74 +    return [expr {-[string compare $a $b]}]
    1.75 +  }
    1.76 +  proc c2 {a b} {
    1.77 +    return [expr {-[string compare [string tolower $a] [string tolower $b]]}]
    1.78 +  }
    1.79 +  db collate c1 c1
    1.80 +  db collate c2 c2
    1.81 +  execsql {
    1.82 +    CREATE TABLE t2(
    1.83 +      a TEXT PRIMARY KEY COLLATE c1,
    1.84 +      b TEXT UNIQUE COLLATE c2,
    1.85 +      c TEXT COLLATE nocase,
    1.86 +      d TEST COLLATE binary
    1.87 +    );
    1.88 +    INSERT INTO t2 VALUES('abc','abc','abc','abc');
    1.89 +    INSERT INTO t2 VALUES('ABCD','ABCD','ABCD','ABCD');
    1.90 +    INSERT INTO t2 VALUES('bcd','bcd','bcd','bcd');
    1.91 +    INSERT INTO t2 VALUES('BCDE','BCDE','BCDE','BCDE');
    1.92 +    SELECT a FROM t2 ORDER BY a;
    1.93 +  }
    1.94 +} {bcd abc BCDE ABCD}
    1.95 +do_test reindex-2.2 {
    1.96 +  execsql {
    1.97 +    SELECT b FROM t2 ORDER BY b;
    1.98 +  }
    1.99 +} {BCDE bcd ABCD abc}
   1.100 +do_test reindex-2.3 {
   1.101 +  execsql {
   1.102 +    SELECT c FROM t2 ORDER BY c;
   1.103 +  }
   1.104 +} {abc ABCD bcd BCDE}
   1.105 +do_test reindex-2.4 {
   1.106 +  execsql {
   1.107 +    SELECT d FROM t2 ORDER BY d;
   1.108 +  }
   1.109 +} {ABCD BCDE abc bcd}
   1.110 +
   1.111 +# Change a collating sequence function.  Verify that REINDEX rebuilds
   1.112 +# the index.
   1.113 +#
   1.114 +do_test reindex-2.5 {
   1.115 +  proc c1 {a b} {
   1.116 +    return [string compare $a $b]
   1.117 +  }
   1.118 +  execsql {
   1.119 +    SELECT a FROM t2 ORDER BY a;
   1.120 +  }
   1.121 +} {bcd abc BCDE ABCD}
   1.122 +ifcapable {integrityck} {
   1.123 +  do_test reindex-2.5.1 {
   1.124 +    string equal ok [execsql {PRAGMA integrity_check}]
   1.125 +  } {0}
   1.126 +}
   1.127 +do_test reindex-2.6 {
   1.128 +  execsql {
   1.129 +    REINDEX c2;
   1.130 +    SELECT a FROM t2 ORDER BY a;
   1.131 +  }
   1.132 +} {bcd abc BCDE ABCD}
   1.133 +do_test reindex-2.7 {
   1.134 +  execsql {
   1.135 +    REINDEX t1;
   1.136 +    SELECT a FROM t2 ORDER BY a;
   1.137 +  }
   1.138 +} {bcd abc BCDE ABCD}
   1.139 +do_test reindex-2.8 {
   1.140 +  execsql {
   1.141 +    REINDEX c1;
   1.142 +    SELECT a FROM t2 ORDER BY a;
   1.143 +  }
   1.144 +} {ABCD BCDE abc bcd}
   1.145 +integrity_check reindex-2.8.1
   1.146 +
   1.147 +# Try to REINDEX an index for which the collation sequence is not available.
   1.148 +#
   1.149 +do_test reindex-3.1 {
   1.150 +  sqlite3 db2 test.db
   1.151 +  catchsql {
   1.152 +    REINDEX c1;
   1.153 +  } db2
   1.154 +} {1 {no such collation sequence: c1}}
   1.155 +do_test reindex-3.2 {
   1.156 +  proc need_collate {collation} {
   1.157 +    db2 collate c1 c1
   1.158 +  }
   1.159 +  db2 collation_needed need_collate
   1.160 +  catchsql {
   1.161 +    REINDEX c1;
   1.162 +  } db2
   1.163 +} {0 {}}
   1.164 +do_test reindex-3.3 {
   1.165 +  catchsql {
   1.166 +    REINDEX;
   1.167 +  } db2
   1.168 +} {1 {no such collation sequence: c2}}
   1.169 +
   1.170 +do_test reindex-3.99 {
   1.171 +  db2 close
   1.172 +} {}
   1.173 +
   1.174 +finish_test