os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/misc1.test
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
# 2001 September 15.
sl@0
     2
#
sl@0
     3
# The author disclaims copyright to this source code.  In place of
sl@0
     4
# a legal notice, here is a blessing:
sl@0
     5
#
sl@0
     6
#    May you do good and not evil.
sl@0
     7
#    May you find forgiveness for yourself and forgive others.
sl@0
     8
#    May you share freely, never taking more than you give.
sl@0
     9
#
sl@0
    10
#***********************************************************************
sl@0
    11
# This file implements regression tests for SQLite library.
sl@0
    12
#
sl@0
    13
# This file implements tests for miscellanous features that were
sl@0
    14
# left out of other test files.
sl@0
    15
#
sl@0
    16
# $Id: misc1.test,v 1.42 2007/11/05 14:58:23 drh Exp $
sl@0
    17
sl@0
    18
set testdir [file dirname $argv0]
sl@0
    19
source $testdir/tester.tcl
sl@0
    20
sl@0
    21
# Mimic the SQLite 2 collation type NUMERIC.
sl@0
    22
db collate numeric numeric_collate
sl@0
    23
proc numeric_collate {lhs rhs} {
sl@0
    24
  if {$lhs == $rhs} {return 0} 
sl@0
    25
  return [expr ($lhs>$rhs)?1:-1]
sl@0
    26
}
sl@0
    27
sl@0
    28
# Mimic the SQLite 2 collation type TEXT.
sl@0
    29
db collate text text_collate
sl@0
    30
proc numeric_collate {lhs rhs} {
sl@0
    31
  return [string compare $lhs $rhs]
sl@0
    32
}
sl@0
    33
sl@0
    34
# Test the creation and use of tables that have a large number
sl@0
    35
# of columns.
sl@0
    36
#
sl@0
    37
do_test misc1-1.1 {
sl@0
    38
  set cmd "CREATE TABLE manycol(x0 text"
sl@0
    39
  for {set i 1} {$i<=99} {incr i} {
sl@0
    40
    append cmd ",x$i text"
sl@0
    41
  }
sl@0
    42
  append cmd ")";
sl@0
    43
  execsql $cmd
sl@0
    44
  set cmd "INSERT INTO manycol VALUES(0"
sl@0
    45
  for {set i 1} {$i<=99} {incr i} {
sl@0
    46
    append cmd ",$i"
sl@0
    47
  }
sl@0
    48
  append cmd ")";
sl@0
    49
  execsql $cmd
sl@0
    50
  execsql "SELECT x99 FROM manycol"
sl@0
    51
} 99
sl@0
    52
do_test misc1-1.2 {
sl@0
    53
  execsql {SELECT x0, x10, x25, x50, x75 FROM manycol}
sl@0
    54
} {0 10 25 50 75}
sl@0
    55
do_test misc1-1.3.1 {
sl@0
    56
  for {set j 100} {$j<=1000} {incr j 100} {
sl@0
    57
    set cmd "INSERT INTO manycol VALUES($j"
sl@0
    58
    for {set i 1} {$i<=99} {incr i} {
sl@0
    59
      append cmd ",[expr {$i+$j}]"
sl@0
    60
    }
sl@0
    61
    append cmd ")"
sl@0
    62
    execsql $cmd
sl@0
    63
  }
sl@0
    64
  execsql {SELECT x50 FROM manycol ORDER BY x80+0}
sl@0
    65
} {50 150 250 350 450 550 650 750 850 950 1050}
sl@0
    66
do_test misc1-1.3.2 {
sl@0
    67
  execsql {SELECT x50 FROM manycol ORDER BY x80}
sl@0
    68
} {1050 150 250 350 450 550 650 750 50 850 950}
sl@0
    69
do_test misc1-1.4 {
sl@0
    70
  execsql {SELECT x75 FROM manycol WHERE x50=350}
sl@0
    71
} 375
sl@0
    72
do_test misc1-1.5 {
sl@0
    73
  execsql {SELECT x50 FROM manycol WHERE x99=599}
sl@0
    74
} 550
sl@0
    75
do_test misc1-1.6 {
sl@0
    76
  execsql {CREATE INDEX manycol_idx1 ON manycol(x99)}
sl@0
    77
  execsql {SELECT x50 FROM manycol WHERE x99=899}
sl@0
    78
} 850
sl@0
    79
do_test misc1-1.7 {
sl@0
    80
  execsql {SELECT count(*) FROM manycol}
sl@0
    81
} 11
sl@0
    82
do_test misc1-1.8 {
sl@0
    83
  execsql {DELETE FROM manycol WHERE x98=1234}
sl@0
    84
  execsql {SELECT count(*) FROM manycol}
sl@0
    85
} 11
sl@0
    86
do_test misc1-1.9 {
sl@0
    87
  execsql {DELETE FROM manycol WHERE x98=998}
sl@0
    88
  execsql {SELECT count(*) FROM manycol}
sl@0
    89
} 10
sl@0
    90
do_test misc1-1.10 {
sl@0
    91
  execsql {DELETE FROM manycol WHERE x99=500}
sl@0
    92
  execsql {SELECT count(*) FROM manycol}
sl@0
    93
} 10
sl@0
    94
do_test misc1-1.11 {
sl@0
    95
  execsql {DELETE FROM manycol WHERE x99=599}
sl@0
    96
  execsql {SELECT count(*) FROM manycol}
sl@0
    97
} 9
sl@0
    98
sl@0
    99
# Check GROUP BY expressions that name two or more columns.
sl@0
   100
#
sl@0
   101
do_test misc1-2.1 {
sl@0
   102
  execsql {
sl@0
   103
    BEGIN TRANSACTION;
sl@0
   104
    CREATE TABLE agger(one text, two text, three text, four text);
sl@0
   105
    INSERT INTO agger VALUES(1, 'one', 'hello', 'yes');
sl@0
   106
    INSERT INTO agger VALUES(2, 'two', 'howdy', 'no');
sl@0
   107
    INSERT INTO agger VALUES(3, 'thr', 'howareya', 'yes');
sl@0
   108
    INSERT INTO agger VALUES(4, 'two', 'lothere', 'yes');
sl@0
   109
    INSERT INTO agger VALUES(5, 'one', 'atcha', 'yes');
sl@0
   110
    INSERT INTO agger VALUES(6, 'two', 'hello', 'no');
sl@0
   111
    COMMIT
sl@0
   112
  }
sl@0
   113
  execsql {SELECT count(*) FROM agger}
sl@0
   114
} 6
sl@0
   115
do_test misc1-2.2 {
sl@0
   116
  execsql {SELECT sum(one), two, four FROM agger
sl@0
   117
           GROUP BY two, four ORDER BY sum(one) desc}
sl@0
   118
} {8 two no 6 one yes 4 two yes 3 thr yes}
sl@0
   119
do_test misc1-2.3 {
sl@0
   120
  execsql {SELECT sum((one)), (two), (four) FROM agger
sl@0
   121
           GROUP BY (two), (four) ORDER BY sum(one) desc}
sl@0
   122
} {8 two no 6 one yes 4 two yes 3 thr yes}
sl@0
   123
sl@0
   124
# Here's a test for a bug found by Joel Lucsy.  The code below
sl@0
   125
# was causing an assertion failure.
sl@0
   126
#
sl@0
   127
do_test misc1-3.1 {
sl@0
   128
  set r [execsql {
sl@0
   129
    CREATE TABLE t1(a);
sl@0
   130
    INSERT INTO t1 VALUES('hi');
sl@0
   131
    PRAGMA full_column_names=on;
sl@0
   132
    SELECT rowid, * FROM t1;
sl@0
   133
  }]
sl@0
   134
  lindex $r 1
sl@0
   135
} {hi}
sl@0
   136
sl@0
   137
# Here's a test for yet another bug found by Joel Lucsy.  The code
sl@0
   138
# below was causing an assertion failure.
sl@0
   139
#
sl@0
   140
do_test misc1-4.1 {
sl@0
   141
  execsql {
sl@0
   142
    BEGIN;
sl@0
   143
    CREATE TABLE t2(a);
sl@0
   144
    INSERT INTO t2 VALUES('This is a long string to use up a lot of disk -');
sl@0
   145
    UPDATE t2 SET a=a||a||a||a;
sl@0
   146
    INSERT INTO t2 SELECT '1 - ' || a FROM t2;
sl@0
   147
    INSERT INTO t2 SELECT '2 - ' || a FROM t2;
sl@0
   148
    INSERT INTO t2 SELECT '3 - ' || a FROM t2;
sl@0
   149
    INSERT INTO t2 SELECT '4 - ' || a FROM t2;
sl@0
   150
    INSERT INTO t2 SELECT '5 - ' || a FROM t2;
sl@0
   151
    INSERT INTO t2 SELECT '6 - ' || a FROM t2;
sl@0
   152
    COMMIT;
sl@0
   153
    SELECT count(*) FROM t2;
sl@0
   154
  }
sl@0
   155
} {64}
sl@0
   156
sl@0
   157
# Make sure we actually see a semicolon or end-of-file in the SQL input
sl@0
   158
# before executing a command.  Thus if "WHERE" is misspelled on an UPDATE,
sl@0
   159
# the user won't accidently update every record.
sl@0
   160
#
sl@0
   161
do_test misc1-5.1 {
sl@0
   162
  catchsql {
sl@0
   163
    CREATE TABLE t3(a,b);
sl@0
   164
    INSERT INTO t3 VALUES(1,2);
sl@0
   165
    INSERT INTO t3 VALUES(3,4);
sl@0
   166
    UPDATE t3 SET a=0 WHEREwww b=2;
sl@0
   167
  }
sl@0
   168
} {1 {near "WHEREwww": syntax error}}
sl@0
   169
do_test misc1-5.2 {
sl@0
   170
  execsql {
sl@0
   171
    SELECT * FROM t3 ORDER BY a;
sl@0
   172
  }
sl@0
   173
} {1 2 3 4}
sl@0
   174
sl@0
   175
# Certain keywords (especially non-standard keywords like "REPLACE") can
sl@0
   176
# also be used as identifiers.  The way this works in the parser is that
sl@0
   177
# the parser first detects a syntax error, the error handling routine
sl@0
   178
# sees that the special keyword caused the error, then replaces the keyword
sl@0
   179
# with "ID" and tries again.
sl@0
   180
#
sl@0
   181
# Check the operation of this logic.
sl@0
   182
#
sl@0
   183
do_test misc1-6.1 {
sl@0
   184
  catchsql {
sl@0
   185
    CREATE TABLE t4(
sl@0
   186
      abort, asc, begin, cluster, conflict, copy, delimiters, desc, end,
sl@0
   187
      explain, fail, ignore, key, offset, pragma, replace, temp,
sl@0
   188
      vacuum, view
sl@0
   189
    );
sl@0
   190
  }
sl@0
   191
} {0 {}}
sl@0
   192
do_test misc1-6.2 {
sl@0
   193
  catchsql {
sl@0
   194
    INSERT INTO t4
sl@0
   195
       VALUES(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19);
sl@0
   196
  }
sl@0
   197
} {0 {}}
sl@0
   198
do_test misc1-6.3 {
sl@0
   199
  execsql {
sl@0
   200
    SELECT * FROM t4
sl@0
   201
  }
sl@0
   202
} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19}
sl@0
   203
do_test misc1-6.4 {
sl@0
   204
  execsql {
sl@0
   205
    SELECT abort+asc,max(key,pragma,temp) FROM t4
sl@0
   206
  }
sl@0
   207
} {3 17}
sl@0
   208
sl@0
   209
# Test for multi-column primary keys, and for multiple primary keys.
sl@0
   210
#
sl@0
   211
do_test misc1-7.1 {
sl@0
   212
  catchsql {
sl@0
   213
    CREATE TABLE error1(
sl@0
   214
      a TYPE PRIMARY KEY,
sl@0
   215
      b TYPE PRIMARY KEY
sl@0
   216
    );
sl@0
   217
  }
sl@0
   218
} {1 {table "error1" has more than one primary key}}
sl@0
   219
do_test misc1-7.2 {
sl@0
   220
  catchsql {
sl@0
   221
    CREATE TABLE error1(
sl@0
   222
      a INTEGER PRIMARY KEY,
sl@0
   223
      b TYPE PRIMARY KEY
sl@0
   224
    );
sl@0
   225
  }
sl@0
   226
} {1 {table "error1" has more than one primary key}}
sl@0
   227
do_test misc1-7.3 {
sl@0
   228
  execsql {
sl@0
   229
    CREATE TABLE t5(a,b,c,PRIMARY KEY(a,b));
sl@0
   230
    INSERT INTO t5 VALUES(1,2,3);
sl@0
   231
    SELECT * FROM t5 ORDER BY a;
sl@0
   232
  }
sl@0
   233
} {1 2 3}
sl@0
   234
do_test misc1-7.4 {
sl@0
   235
  catchsql {
sl@0
   236
    INSERT INTO t5 VALUES(1,2,4);
sl@0
   237
  }
sl@0
   238
} {1 {columns a, b are not unique}}
sl@0
   239
do_test misc1-7.5 {
sl@0
   240
  catchsql {
sl@0
   241
    INSERT INTO t5 VALUES(0,2,4);
sl@0
   242
  }
sl@0
   243
} {0 {}}
sl@0
   244
do_test misc1-7.6 {
sl@0
   245
  execsql {
sl@0
   246
    SELECT * FROM t5 ORDER BY a;
sl@0
   247
  }
sl@0
   248
} {0 2 4 1 2 3}
sl@0
   249
sl@0
   250
do_test misc1-8.1 {
sl@0
   251
  catchsql {
sl@0
   252
    SELECT *;
sl@0
   253
  }
sl@0
   254
} {1 {no tables specified}}
sl@0
   255
do_test misc1-8.2 {
sl@0
   256
  catchsql {
sl@0
   257
    SELECT t1.*;
sl@0
   258
  }
sl@0
   259
} {1 {no such table: t1}}
sl@0
   260
sl@0
   261
execsql {
sl@0
   262
  DROP TABLE t1;
sl@0
   263
  DROP TABLE t2;
sl@0
   264
  DROP TABLE t3;
sl@0
   265
  DROP TABLE t4;
sl@0
   266
}
sl@0
   267
sl@0
   268
# 64-bit integers are represented exactly.
sl@0
   269
#
sl@0
   270
do_test misc1-9.1 {
sl@0
   271
  catchsql {
sl@0
   272
    CREATE TABLE t1(a unique not null, b unique not null);
sl@0
   273
    INSERT INTO t1 VALUES('a',1234567890123456789);
sl@0
   274
    INSERT INTO t1 VALUES('b',1234567891123456789);
sl@0
   275
    INSERT INTO t1 VALUES('c',1234567892123456789);
sl@0
   276
    SELECT * FROM t1;
sl@0
   277
  }
sl@0
   278
} {0 {a 1234567890123456789 b 1234567891123456789 c 1234567892123456789}}
sl@0
   279
sl@0
   280
# A WHERE clause is not allowed to contain more than 99 terms.  Check to
sl@0
   281
# make sure this limit is enforced.
sl@0
   282
#
sl@0
   283
# 2005-07-16: There is no longer a limit on the number of terms in a
sl@0
   284
# WHERE clause.  But keep these tests just so that we have some tests
sl@0
   285
# that use a large number of terms in the WHERE clause.
sl@0
   286
#
sl@0
   287
do_test misc1-10.0 {
sl@0
   288
  execsql {SELECT count(*) FROM manycol}
sl@0
   289
} {9}
sl@0
   290
do_test misc1-10.1 {
sl@0
   291
  set ::where {WHERE x0>=0}
sl@0
   292
  for {set i 1} {$i<=99} {incr i} {
sl@0
   293
    append ::where " AND x$i<>0"
sl@0
   294
  }
sl@0
   295
  catchsql "SELECT count(*) FROM manycol $::where"
sl@0
   296
} {0 9}
sl@0
   297
do_test misc1-10.2 {
sl@0
   298
  catchsql "SELECT count(*) FROM manycol $::where AND rowid>0"
sl@0
   299
} {0 9}
sl@0
   300
do_test misc1-10.3 {
sl@0
   301
  regsub "x0>=0" $::where "x0=0" ::where
sl@0
   302
  catchsql "DELETE FROM manycol $::where"
sl@0
   303
} {0 {}}
sl@0
   304
do_test misc1-10.4 {
sl@0
   305
  execsql {SELECT count(*) FROM manycol}
sl@0
   306
} {8}
sl@0
   307
do_test misc1-10.5 {
sl@0
   308
  catchsql "DELETE FROM manycol $::where AND rowid>0"
sl@0
   309
} {0 {}}
sl@0
   310
do_test misc1-10.6 {
sl@0
   311
  execsql {SELECT x1 FROM manycol WHERE x0=100}
sl@0
   312
} {101}
sl@0
   313
do_test misc1-10.7 {
sl@0
   314
  regsub "x0=0" $::where "x0=100" ::where
sl@0
   315
  catchsql "UPDATE manycol SET x1=x1+1 $::where"
sl@0
   316
} {0 {}}
sl@0
   317
do_test misc1-10.8 {
sl@0
   318
  execsql {SELECT x1 FROM manycol WHERE x0=100}
sl@0
   319
} {102}
sl@0
   320
do_test misc1-10.9 {
sl@0
   321
  catchsql "UPDATE manycol SET x1=x1+1 $::where AND rowid>0"
sl@0
   322
} {0 {}}
sl@0
   323
do_test misc1-10.10 {
sl@0
   324
  execsql {SELECT x1 FROM manycol WHERE x0=100}
sl@0
   325
} {103}
sl@0
   326
sl@0
   327
# Make sure the initialization works even if a database is opened while
sl@0
   328
# another process has the database locked.
sl@0
   329
#
sl@0
   330
# Update for v3: The BEGIN doesn't lock the database so the schema is read
sl@0
   331
# and the SELECT returns successfully.
sl@0
   332
do_test misc1-11.1 {
sl@0
   333
  execsql {BEGIN}
sl@0
   334
  execsql {UPDATE t1 SET a=0 WHERE 0}
sl@0
   335
  sqlite3 db2 test.db
sl@0
   336
  set rc [catch {db2 eval {SELECT count(*) FROM t1}} msg]
sl@0
   337
  lappend rc $msg
sl@0
   338
# v2 result: {1 {database is locked}}
sl@0
   339
} {0 3}
sl@0
   340
do_test misc1-11.2 {
sl@0
   341
  execsql {COMMIT}
sl@0
   342
  set rc [catch {db2 eval {SELECT count(*) FROM t1}} msg]
sl@0
   343
  db2 close
sl@0
   344
  lappend rc $msg
sl@0
   345
} {0 3}
sl@0
   346
sl@0
   347
# Make sure string comparisons really do compare strings in format4+.
sl@0
   348
# Similar tests in the format3.test file show that for format3 and earlier
sl@0
   349
# all comparisions where numeric if either operand looked like a number.
sl@0
   350
#
sl@0
   351
do_test misc1-12.1 {
sl@0
   352
  execsql {SELECT '0'=='0.0'}
sl@0
   353
} {0}
sl@0
   354
do_test misc1-12.2 {
sl@0
   355
  execsql {SELECT '0'==0.0}
sl@0
   356
} {0}
sl@0
   357
do_test misc1-12.3 {
sl@0
   358
  execsql {SELECT '12345678901234567890'=='12345678901234567891'}
sl@0
   359
} {0}
sl@0
   360
do_test misc1-12.4 {
sl@0
   361
  execsql {
sl@0
   362
    CREATE TABLE t6(a INT UNIQUE, b TEXT UNIQUE);
sl@0
   363
    INSERT INTO t6 VALUES('0','0.0');
sl@0
   364
    SELECT * FROM t6;
sl@0
   365
  }
sl@0
   366
} {0 0.0}
sl@0
   367
ifcapable conflict {
sl@0
   368
  do_test misc1-12.5 {
sl@0
   369
    execsql {
sl@0
   370
      INSERT OR IGNORE INTO t6 VALUES(0.0,'x');
sl@0
   371
      SELECT * FROM t6;
sl@0
   372
    }
sl@0
   373
  } {0 0.0}
sl@0
   374
  do_test misc1-12.6 {
sl@0
   375
    execsql {
sl@0
   376
      INSERT OR IGNORE INTO t6 VALUES('y',0);
sl@0
   377
      SELECT * FROM t6;
sl@0
   378
    }
sl@0
   379
  } {0 0.0 y 0}
sl@0
   380
}
sl@0
   381
do_test misc1-12.7 {
sl@0
   382
  execsql {
sl@0
   383
    CREATE TABLE t7(x INTEGER, y TEXT, z);
sl@0
   384
    INSERT INTO t7 VALUES(0,0,1);
sl@0
   385
    INSERT INTO t7 VALUES(0.0,0,2);
sl@0
   386
    INSERT INTO t7 VALUES(0,0.0,3);
sl@0
   387
    INSERT INTO t7 VALUES(0.0,0.0,4);
sl@0
   388
    SELECT DISTINCT x, y FROM t7 ORDER BY z;
sl@0
   389
  }
sl@0
   390
} {0 0 0 0.0}
sl@0
   391
do_test misc1-12.8 {
sl@0
   392
  execsql {
sl@0
   393
    SELECT min(z), max(z), count(z) FROM t7 GROUP BY x ORDER BY 1;
sl@0
   394
  }
sl@0
   395
} {1 4 4}
sl@0
   396
do_test misc1-12.9 {
sl@0
   397
  execsql {
sl@0
   398
    SELECT min(z), max(z), count(z) FROM t7 GROUP BY y ORDER BY 1;
sl@0
   399
  }
sl@0
   400
} {1 2 2 3 4 2}
sl@0
   401
sl@0
   402
# This used to be an error.  But we changed the code so that arbitrary
sl@0
   403
# identifiers can be used as a collating sequence.  Collation is by text
sl@0
   404
# if the identifier contains "text", "blob", or "clob" and is numeric
sl@0
   405
# otherwise.
sl@0
   406
#
sl@0
   407
# Update: In v3, it is an error again.
sl@0
   408
#
sl@0
   409
#do_test misc1-12.10 {
sl@0
   410
#  catchsql {
sl@0
   411
#    SELECT * FROM t6 ORDER BY a COLLATE unknown;
sl@0
   412
#  }
sl@0
   413
#} {0 {0 0 y 0}}
sl@0
   414
do_test misc1-12.11 {
sl@0
   415
  execsql {
sl@0
   416
    CREATE TABLE t8(x TEXT COLLATE numeric, y INTEGER COLLATE text, z);
sl@0
   417
    INSERT INTO t8 VALUES(0,0,1);
sl@0
   418
    INSERT INTO t8 VALUES(0.0,0,2);
sl@0
   419
    INSERT INTO t8 VALUES(0,0.0,3);
sl@0
   420
    INSERT INTO t8 VALUES(0.0,0.0,4);
sl@0
   421
    SELECT DISTINCT x, y FROM t8 ORDER BY z;
sl@0
   422
  }
sl@0
   423
} {0 0 0.0 0}
sl@0
   424
do_test misc1-12.12 {
sl@0
   425
  execsql {
sl@0
   426
    SELECT min(z), max(z), count(z) FROM t8 GROUP BY x ORDER BY 1;
sl@0
   427
  }
sl@0
   428
} {1 3 2 2 4 2}
sl@0
   429
do_test misc1-12.13 {
sl@0
   430
  execsql {
sl@0
   431
    SELECT min(z), max(z), count(z) FROM t8 GROUP BY y ORDER BY 1;
sl@0
   432
  }
sl@0
   433
} {1 4 4}
sl@0
   434
sl@0
   435
# There was a problem with realloc() in the OP_MemStore operation of
sl@0
   436
# the VDBE.  A buffer was being reallocated but some pointers into 
sl@0
   437
# the old copy of the buffer were not being moved over to the new copy.
sl@0
   438
# The following code tests for the problem.
sl@0
   439
#
sl@0
   440
ifcapable subquery {
sl@0
   441
  do_test misc1-13.1 {
sl@0
   442
     execsql {
sl@0
   443
       CREATE TABLE t9(x,y);
sl@0
   444
       INSERT INTO t9 VALUES('one',1);
sl@0
   445
       INSERT INTO t9 VALUES('two',2);
sl@0
   446
       INSERT INTO t9 VALUES('three',3);
sl@0
   447
       INSERT INTO t9 VALUES('four',4);
sl@0
   448
       INSERT INTO t9 VALUES('five',5);
sl@0
   449
       INSERT INTO t9 VALUES('six',6);
sl@0
   450
       INSERT INTO t9 VALUES('seven',7);
sl@0
   451
       INSERT INTO t9 VALUES('eight',8);
sl@0
   452
       INSERT INTO t9 VALUES('nine',9);
sl@0
   453
       INSERT INTO t9 VALUES('ten',10);
sl@0
   454
       INSERT INTO t9 VALUES('eleven',11);
sl@0
   455
       SELECT y FROM t9
sl@0
   456
       WHERE x=(SELECT x FROM t9 WHERE y=1)
sl@0
   457
          OR x=(SELECT x FROM t9 WHERE y=2)
sl@0
   458
          OR x=(SELECT x FROM t9 WHERE y=3)
sl@0
   459
          OR x=(SELECT x FROM t9 WHERE y=4)
sl@0
   460
          OR x=(SELECT x FROM t9 WHERE y=5)
sl@0
   461
          OR x=(SELECT x FROM t9 WHERE y=6)
sl@0
   462
          OR x=(SELECT x FROM t9 WHERE y=7)
sl@0
   463
          OR x=(SELECT x FROM t9 WHERE y=8)
sl@0
   464
          OR x=(SELECT x FROM t9 WHERE y=9)
sl@0
   465
          OR x=(SELECT x FROM t9 WHERE y=10)
sl@0
   466
          OR x=(SELECT x FROM t9 WHERE y=11)
sl@0
   467
          OR x=(SELECT x FROM t9 WHERE y=12)
sl@0
   468
          OR x=(SELECT x FROM t9 WHERE y=13)
sl@0
   469
          OR x=(SELECT x FROM t9 WHERE y=14)
sl@0
   470
       ;
sl@0
   471
     }
sl@0
   472
  } {1 2 3 4 5 6 7 8 9 10 11}
sl@0
   473
}
sl@0
   474
sl@0
   475
# Make sure a database connection still works after changing the
sl@0
   476
# working directory.
sl@0
   477
#
sl@0
   478
do_test misc1-14.1 {
sl@0
   479
  file mkdir tempdir
sl@0
   480
  cd tempdir
sl@0
   481
  execsql {BEGIN}
sl@0
   482
  file exists ./test.db-journal
sl@0
   483
} {0}
sl@0
   484
do_test misc1-14.2 {
sl@0
   485
  execsql {UPDATE t1 SET a=0 WHERE 0}
sl@0
   486
  file exists ../test.db-journal
sl@0
   487
} {1}
sl@0
   488
do_test misc1-14.3 {
sl@0
   489
  cd ..
sl@0
   490
  file delete -force tempdir
sl@0
   491
  execsql {COMMIT}
sl@0
   492
  file exists ./test.db-journal
sl@0
   493
} {0}
sl@0
   494
sl@0
   495
# A failed create table should not leave the table in the internal
sl@0
   496
# data structures.  Ticket #238.
sl@0
   497
#
sl@0
   498
do_test misc1-15.1.1 {
sl@0
   499
  catchsql {
sl@0
   500
    CREATE TABLE t10 AS SELECT c1;
sl@0
   501
  }
sl@0
   502
} {1 {no such column: c1}}
sl@0
   503
do_test misc1-15.1.2 {
sl@0
   504
  catchsql {
sl@0
   505
    CREATE TABLE t10 AS SELECT t9.c1;
sl@0
   506
  }
sl@0
   507
} {1 {no such column: t9.c1}}
sl@0
   508
do_test misc1-15.1.3 {
sl@0
   509
  catchsql {
sl@0
   510
    CREATE TABLE t10 AS SELECT main.t9.c1;
sl@0
   511
  }
sl@0
   512
} {1 {no such column: main.t9.c1}}
sl@0
   513
do_test misc1-15.2 {
sl@0
   514
  catchsql {
sl@0
   515
    CREATE TABLE t10 AS SELECT 1;
sl@0
   516
  }
sl@0
   517
  # The bug in ticket #238 causes the statement above to fail with
sl@0
   518
  # the error "table t10 alread exists"
sl@0
   519
} {0 {}}
sl@0
   520
sl@0
   521
# Test for memory leaks when a CREATE TABLE containing a primary key
sl@0
   522
# fails.  Ticket #249.
sl@0
   523
#
sl@0
   524
do_test misc1-16.1 {
sl@0
   525
  catchsql {SELECT name FROM sqlite_master LIMIT 1}
sl@0
   526
  catchsql {
sl@0
   527
    CREATE TABLE test(a integer, primary key(a));
sl@0
   528
  }
sl@0
   529
} {0 {}}
sl@0
   530
do_test misc1-16.2 {
sl@0
   531
  catchsql {
sl@0
   532
    CREATE TABLE test(a integer, primary key(a));
sl@0
   533
  }
sl@0
   534
} {1 {table test already exists}}
sl@0
   535
do_test misc1-16.3 {
sl@0
   536
  catchsql {
sl@0
   537
    CREATE TABLE test2(a text primary key, b text, primary key(a,b));
sl@0
   538
  }
sl@0
   539
} {1 {table "test2" has more than one primary key}}
sl@0
   540
do_test misc1-16.4 {
sl@0
   541
  execsql {
sl@0
   542
    INSERT INTO test VALUES(1);
sl@0
   543
    SELECT rowid, a FROM test;
sl@0
   544
  }
sl@0
   545
} {1 1}
sl@0
   546
do_test misc1-16.5 {
sl@0
   547
  execsql {
sl@0
   548
    INSERT INTO test VALUES(5);
sl@0
   549
    SELECT rowid, a FROM test;
sl@0
   550
  }
sl@0
   551
} {1 1 5 5}
sl@0
   552
do_test misc1-16.6 {
sl@0
   553
  execsql {
sl@0
   554
    INSERT INTO test VALUES(NULL);
sl@0
   555
    SELECT rowid, a FROM test;
sl@0
   556
  }
sl@0
   557
} {1 1 5 5 6 6}
sl@0
   558
sl@0
   559
ifcapable trigger&&tempdb {
sl@0
   560
# Ticket #333: Temp triggers that modify persistent tables.
sl@0
   561
#
sl@0
   562
do_test misc1-17.1 {
sl@0
   563
  execsql {
sl@0
   564
    BEGIN;
sl@0
   565
    CREATE TABLE RealTable(TestID INTEGER PRIMARY KEY, TestString TEXT);
sl@0
   566
    CREATE TEMP TABLE TempTable(TestID INTEGER PRIMARY KEY, TestString TEXT);
sl@0
   567
    CREATE TEMP TRIGGER trigTest_1 AFTER UPDATE ON TempTable BEGIN
sl@0
   568
      INSERT INTO RealTable(TestString) 
sl@0
   569
         SELECT new.TestString FROM TempTable LIMIT 1;
sl@0
   570
    END;
sl@0
   571
    INSERT INTO TempTable(TestString) VALUES ('1');
sl@0
   572
    INSERT INTO TempTable(TestString) VALUES ('2');
sl@0
   573
    UPDATE TempTable SET TestString = TestString + 1 WHERE TestID=1 OR TestId=2;
sl@0
   574
    COMMIT;
sl@0
   575
    SELECT TestString FROM RealTable ORDER BY 1;
sl@0
   576
  }
sl@0
   577
} {2 3}
sl@0
   578
}
sl@0
   579
sl@0
   580
do_test misc1-18.1 {
sl@0
   581
  set n [sqlite3_sleep 100]
sl@0
   582
  expr {$n>=100}
sl@0
   583
} {1}
sl@0
   584
sl@0
   585
finish_test