SQLite

Check-in [3a54a33dcb]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Test suite fixes for builds that define OMIT symbols. (CVS 2962)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 3a54a33dcb7e765ee3773397407e8929a8cfe1a9
User & Date: danielk1977 2006-01-17 09:35:02.000
Context
2006-01-17
13:21
Various fixes that allow the malloc() failure tests to pass again. (CVS 2963) (check-in: 0505405fb9 user: danielk1977 tags: trunk)
09:35
Test suite fixes for builds that define OMIT symbols. (CVS 2962) (check-in: 3a54a33dcb user: danielk1977 tags: trunk)
2006-01-16
16:24
Test file fixes for libaries compiled with various SQLITE_OMIT_ macros. (CVS 2961) (check-in: c058f483a5 user: danielk1977 tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to test/alter.test.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 2004 November 10
#
# 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 script is testing the ALTER TABLE statement.
#
# $Id: alter.test,v 1.15 2006/01/15 14:11:49 danielk1977 Exp $
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
ifcapable !altertable {













|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 2004 November 10
#
# 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 script is testing the ALTER TABLE statement.
#
# $Id: alter.test,v 1.16 2006/01/17 09:35:02 danielk1977 Exp $
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
ifcapable !altertable {
563
564
565
566
567
568
569
570
571
572

573
574
575
576
577
578
579
580
581
582
583
584

585
586
587
588
589
590
591
592

593
594
595
596
597
598
599
600
601

602
603
604
605
606
607
608
609
610
611
612

613
614
615
616
617
618
619
620
621
622
  string length $::tbl_name
} {7}
do_test alter-6.2 {
  execsql "
    CREATE TABLE ${tbl_name}(a, b, c);
  "
  set ::oid [execsql {SELECT max(oid) FROM sqlite_master}]
  execsql {
    SELECT sql FROM sqlite_master WHERE oid = $::oid;
  }

} "{CREATE TABLE ${::tbl_name}(a, b, c)}"
execsql "
  SELECT * FROM ${::tbl_name}
"
set ::tbl_name2 "abcXdef"
do_test alter-6.3 {
  execsql "
    ALTER TABLE $::tbl_name RENAME TO $::tbl_name2 
  "
  execsql {
    SELECT sql FROM sqlite_master WHERE oid = $::oid;
  }

} "{CREATE TABLE '${::tbl_name2}'(a, b, c)}"
do_test alter-6.4 {
  execsql "
    ALTER TABLE $::tbl_name2 RENAME TO $::tbl_name
  "
  execsql {
    SELECT sql FROM sqlite_master WHERE oid = $::oid;
  }

} "{CREATE TABLE '${::tbl_name}'(a, b, c)}"
set ::col_name ghi\1234\jkl
do_test alter-6.5 {
  execsql "
    ALTER TABLE $::tbl_name ADD COLUMN $::col_name VARCHAR
  "
  execsql {
    SELECT sql FROM sqlite_master WHERE oid = $::oid;
  }

} "{CREATE TABLE '${::tbl_name}'(a, b, c, $::col_name VARCHAR)}"
set ::col_name2 B\3421\A
do_test alter-6.6 {
  db close
  sqlite3 db test.db
  execsql "
    ALTER TABLE $::tbl_name ADD COLUMN $::col_name2
  "
  execsql {
    SELECT sql FROM sqlite_master WHERE oid = $::oid;
  }

} "{CREATE TABLE '${::tbl_name}'(a, b, c, $::col_name VARCHAR, $::col_name2)}"
do_test alter-6.7 {
  execsql "
    INSERT INTO ${::tbl_name} VALUES(1, 2, 3, 4, 5);
    SELECT $::col_name, $::col_name2 FROM $::tbl_name;
  "
} {4 5}

finish_test








|

<
>









|
|
<
>





|
|
<
>






|
|
<
>








|
|
<
>










563
564
565
566
567
568
569
570
571

572
573
574
575
576
577
578
579
580
581
582
583

584
585
586
587
588
589
590
591

592
593
594
595
596
597
598
599
600

601
602
603
604
605
606
607
608
609
610
611

612
613
614
615
616
617
618
619
620
621
622
  string length $::tbl_name
} {7}
do_test alter-6.2 {
  execsql "
    CREATE TABLE ${tbl_name}(a, b, c);
  "
  set ::oid [execsql {SELECT max(oid) FROM sqlite_master}]
  execsql "
    SELECT sql FROM sqlite_master WHERE oid = $::oid;

  "
} "{CREATE TABLE ${::tbl_name}(a, b, c)}"
execsql "
  SELECT * FROM ${::tbl_name}
"
set ::tbl_name2 "abcXdef"
do_test alter-6.3 {
  execsql "
    ALTER TABLE $::tbl_name RENAME TO $::tbl_name2 
  "
  execsql "
    SELECT sql FROM sqlite_master WHERE oid = $::oid

  "
} "{CREATE TABLE '${::tbl_name2}'(a, b, c)}"
do_test alter-6.4 {
  execsql "
    ALTER TABLE $::tbl_name2 RENAME TO $::tbl_name
  "
  execsql "
    SELECT sql FROM sqlite_master WHERE oid = $::oid

  "
} "{CREATE TABLE '${::tbl_name}'(a, b, c)}"
set ::col_name ghi\1234\jkl
do_test alter-6.5 {
  execsql "
    ALTER TABLE $::tbl_name ADD COLUMN $::col_name VARCHAR
  "
  execsql "
    SELECT sql FROM sqlite_master WHERE oid = $::oid

  "
} "{CREATE TABLE '${::tbl_name}'(a, b, c, $::col_name VARCHAR)}"
set ::col_name2 B\3421\A
do_test alter-6.6 {
  db close
  sqlite3 db test.db
  execsql "
    ALTER TABLE $::tbl_name ADD COLUMN $::col_name2
  "
  execsql "
    SELECT sql FROM sqlite_master WHERE oid = $::oid

  "
} "{CREATE TABLE '${::tbl_name}'(a, b, c, $::col_name VARCHAR, $::col_name2)}"
do_test alter-6.7 {
  execsql "
    INSERT INTO ${::tbl_name} VALUES(1, 2, 3, 4, 5);
    SELECT $::col_name, $::col_name2 FROM $::tbl_name;
  "
} {4 5}

finish_test

Changes to test/alter3.test.
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#
#*************************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this script is testing that SQLite can handle a subtle 
# file format change that may be used in the future to implement
# "ALTER TABLE ... ADD COLUMN".
#
# $Id: alter3.test,v 1.8 2006/01/16 16:24:25 danielk1977 Exp $
#

set testdir [file dirname $argv0]

source $testdir/tester.tcl

# If SQLITE_OMIT_ALTERTABLE is defined, omit this file.







|







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#
#*************************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this script is testing that SQLite can handle a subtle 
# file format change that may be used in the future to implement
# "ALTER TABLE ... ADD COLUMN".
#
# $Id: alter3.test,v 1.9 2006/01/17 09:35:02 danielk1977 Exp $
#

set testdir [file dirname $argv0]

source $testdir/tester.tcl

# If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
139
140
141
142
143
144
145

146
147
148
149
150
151
152
153

154
155
156
157
158
159
160
  }
} {1 {Cannot add a NOT NULL column with default value NULL}}
do_test alter3-2.4 {
  catchsql {
    ALTER TABLE t1 ADD c NOT NULL DEFAULT 10;
  }
} {0 {}}

do_test alter3-2.5 {
  execsql {
    CREATE VIEW v1 AS SELECT * FROM t1;
  }
  catchsql {
    alter table v1 add column d;
  }
} {1 {Cannot add a column to a view}}

do_test alter3-2.6 {
  catchsql {
    alter table t1 add column d DEFAULT CURRENT_TIME;
  }
} {1 {Cannot add a column with non-constant default}}
do_test alter3-2.99 {
  execsql {







>
|
|
|
|
|
|
|
|
>







139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
  }
} {1 {Cannot add a NOT NULL column with default value NULL}}
do_test alter3-2.4 {
  catchsql {
    ALTER TABLE t1 ADD c NOT NULL DEFAULT 10;
  }
} {0 {}}
ifcapable view {
  do_test alter3-2.5 {
    execsql {
      CREATE VIEW v1 AS SELECT * FROM t1;
    }
    catchsql {
      alter table v1 add column d;
    }
  } {1 {Cannot add a column to a view}}
}
do_test alter3-2.6 {
  catchsql {
    alter table t1 add column d DEFAULT CURRENT_TIME;
  }
} {1 {Cannot add a column with non-constant default}}
do_test alter3-2.99 {
  execsql {
182
183
184
185
186
187
188

189
190
191
192
193

194
195
196
197
198
199
200
  }
} {1 100 {} 2 300 {}}
if {!$has_codec} {
  do_test alter3-3.3 {
    get_file_format
  } {3}
}

do_test alter3-3.4 {
  execsql {
    PRAGMA schema_version;
  }
} {11}


do_test alter3-4.1 {
  db close
  file delete -force test.db
  set ::DB [sqlite3 db test.db]
  execsql {
    CREATE TABLE t1(a, b);







>
|
|
|
|
|
>







184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
  }
} {1 100 {} 2 300 {}}
if {!$has_codec} {
  do_test alter3-3.3 {
    get_file_format
  } {3}
}
ifcapable schema_version {
  do_test alter3-3.4 {
    execsql {
      PRAGMA schema_version;
    }
  } {11}
}

do_test alter3-4.1 {
  db close
  file delete -force test.db
  set ::DB [sqlite3 db test.db]
  execsql {
    CREATE TABLE t1(a, b);
215
216
217
218
219
220
221

222
223
224
225
226

227
228
229
230
231
232
233
  }
} {1 100 {hello world} 2 300 {hello world}}
if {!$has_codec} {
  do_test alter3-4.3 {
    get_file_format
  } {3}
}

do_test alter3-4.4 {
  execsql {
    PRAGMA schema_version;
  }
} {21}

do_test alter3-4.99 {
  execsql {
    DROP TABLE t1;
  }
} {}

do_test alter3-5.1 {







>
|
|
|
|
|
>







219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
  }
} {1 100 {hello world} 2 300 {hello world}}
if {!$has_codec} {
  do_test alter3-4.3 {
    get_file_format
  } {3}
}
ifcapable schema_version {
  do_test alter3-4.4 {
    execsql {
      PRAGMA schema_version;
    }
  } {21}
}
do_test alter3-4.99 {
  execsql {
    DROP TABLE t1;
  }
} {}

do_test alter3-5.1 {
250
251
252
253
254
255
256

257
258
259
260
261

262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277

278
279
280
281
282

283
284
285
286
287
288
289
  }
} {{CREATE TABLE t1(a,b, c VARCHAR(128))}}
do_test alter3-5.3 {
  execsql {
    SELECT * FROM aux.t1;
  }
} {1 one {} 2 two {}}

do_test alter3-5.4 {
  execsql {
    PRAGMA aux.schema_version;
  }
} {31}

if {!$has_codec} {
  do_test alter3-5.5 {
    list [get_file_format test2.db] [get_file_format]
  } {2 3}
}
do_test alter3-5.6 {
  execsql {
    ALTER TABLE aux.t1 ADD COLUMN d DEFAULT 1000;
    SELECT sql FROM aux.sqlite_master;
  }
} {{CREATE TABLE t1(a,b, c VARCHAR(128), d DEFAULT 1000)}}
do_test alter3-5.7 {
  execsql {
    SELECT * FROM aux.t1;
  }
} {1 one {} 1000 2 two {} 1000}

do_test alter3-5.8 {
  execsql {
    PRAGMA aux.schema_version;
  }
} {32}

do_test alter3-5.9 {
  execsql {
    SELECT * FROM t1;
  }
} {1 one 2 two}
do_test alter3-5.99 {
  execsql {







>
|
|
|
|
|
>
















>
|
|
|
|
|
>







256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
  }
} {{CREATE TABLE t1(a,b, c VARCHAR(128))}}
do_test alter3-5.3 {
  execsql {
    SELECT * FROM aux.t1;
  }
} {1 one {} 2 two {}}
ifcapable schema_version {
  do_test alter3-5.4 {
    execsql {
      PRAGMA aux.schema_version;
    }
  } {31}
}
if {!$has_codec} {
  do_test alter3-5.5 {
    list [get_file_format test2.db] [get_file_format]
  } {2 3}
}
do_test alter3-5.6 {
  execsql {
    ALTER TABLE aux.t1 ADD COLUMN d DEFAULT 1000;
    SELECT sql FROM aux.sqlite_master;
  }
} {{CREATE TABLE t1(a,b, c VARCHAR(128), d DEFAULT 1000)}}
do_test alter3-5.7 {
  execsql {
    SELECT * FROM aux.t1;
  }
} {1 one {} 1000 2 two {} 1000}
ifcapable schema_version {
  do_test alter3-5.8 {
    execsql {
      PRAGMA aux.schema_version;
    }
  } {32}
}
do_test alter3-5.9 {
  execsql {
    SELECT * FROM t1;
  }
} {1 one 2 two}
do_test alter3-5.99 {
  execsql {
Changes to test/auth.test.
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this script is testing the ATTACH and DETACH commands
# and related functionality.
#
# $Id: auth.test,v 1.32 2006/01/16 16:24:25 danielk1977 Exp $
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# disable this test if the SQLITE_OMIT_AUTHORIZATION macro is
# defined during compilation.







|







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this script is testing the ATTACH and DETACH commands
# and related functionality.
#
# $Id: auth.test,v 1.33 2006/01/17 09:35:02 danielk1977 Exp $
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# disable this test if the SQLITE_OMIT_AUTHORIZATION macro is
# defined during compilation.
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
  }
  catchsql {SELECT * FROM t2, t3}
} {0 {11 2 33 {} 55 66 7 8 9 {} 55 66}}

# Make sure the OLD and NEW pseudo-tables of a trigger get authorized.
#
ifcapable trigger {
do_test auth-3.1 {
  proc auth {code arg1 arg2 arg3 arg4} {
    return SQLITE_OK
  }
  execsql {
    CREATE TABLE tx(a1,a2,b1,b2,c1,c2);
    CREATE TRIGGER r1 AFTER UPDATE ON t2 FOR EACH ROW BEGIN
      INSERT INTO tx VALUES(OLD.a,NEW.a,OLD.b,NEW.b,OLD.c,NEW.c);
    END;
    UPDATE t2 SET a=a+1;
    SELECT * FROM tx;
  }
} {11 12 2 2 33 33 7 8 8 8 9 9}
do_test auth-3.2 {
  proc auth {code arg1 arg2 arg3 arg4} {
    if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="c"} {
      return SQLITE_IGNORE
    }
    return SQLITE_OK
  }
  execsql {
    DELETE FROM tx;
    UPDATE t2 SET a=a+100;
    SELECT * FROM tx;
  }
} {12 112 2 2 {} {} 8 108 8 8 {} {}}
} ;# ifcapable trigger

# Make sure the names of views and triggers are passed on on arg4.
#
ifcapable trigger {
do_test auth-4.1 {
  proc auth {code arg1 arg2 arg3 arg4} {







|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|







2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
  }
  catchsql {SELECT * FROM t2, t3}
} {0 {11 2 33 {} 55 66 7 8 9 {} 55 66}}

# Make sure the OLD and NEW pseudo-tables of a trigger get authorized.
#
ifcapable trigger {
  do_test auth-3.1 {
    proc auth {code arg1 arg2 arg3 arg4} {
      return SQLITE_OK
    }
    execsql {
      CREATE TABLE tx(a1,a2,b1,b2,c1,c2);
      CREATE TRIGGER r1 AFTER UPDATE ON t2 FOR EACH ROW BEGIN
        INSERT INTO tx VALUES(OLD.a,NEW.a,OLD.b,NEW.b,OLD.c,NEW.c);
      END;
      UPDATE t2 SET a=a+1;
      SELECT * FROM tx;
    }
  } {11 12 2 2 33 33 7 8 8 8 9 9}
  do_test auth-3.2 {
    proc auth {code arg1 arg2 arg3 arg4} {
      if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="c"} {
        return SQLITE_IGNORE
      }
      return SQLITE_OK
    }
    execsql {
      DELETE FROM tx;
      UPDATE t2 SET a=a+100;
      SELECT * FROM tx;
    }
  } {12 112 2 2 {} {} 8 108 8 8 {} {}}
} ;# ifcapable trigger

# Make sure the names of views and triggers are passed on on arg4.
#
ifcapable trigger {
do_test auth-4.1 {
  proc auth {code arg1 arg2 arg3 arg4} {
2206
2207
2208
2209
2210
2211
2212
2213










2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
  execsql {
    SELECT count(a) AS cnt FROM t4 ORDER BY cnt
  }
} {1}

# Ticket #1607
#
ifcapable compound {










  do_test auth-5.2 {
    execsql {
      SELECT name FROM (
        SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master)
      WHERE type='table'
      ORDER BY name
    }
  } {sqlite_stat1 t1 t2 t3 t4 tx v1chng}
}


rename proc {}
rename proc_real proc


finish_test







|
>
>
>
>
>
>
>
>
>
>







|








2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
  execsql {
    SELECT count(a) AS cnt FROM t4 ORDER BY cnt
  }
} {1}

# Ticket #1607
#
ifcapable compound&&subquery {
  ifcapable trigger {
    execsql {
      DROP TABLE tx;
    }
    ifcapable view {
      execsql {
        DROP TABLE v1chng;
      }
    }
  }
  do_test auth-5.2 {
    execsql {
      SELECT name FROM (
        SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master)
      WHERE type='table'
      ORDER BY name
    }
  } {sqlite_stat1 t1 t2 t3 t4}
}


rename proc {}
rename proc_real proc


finish_test
Changes to test/avtrans.test.
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.  This
# file is a copy of "trans.test" modified to run under autovacuum mode.
# the point is to stress the autovacuum logic and try to get it to fail.
#
# $Id: avtrans.test,v 1.1 2005/12/09 02:35:54 drh Exp $


set testdir [file dirname $argv0]
source $testdir/tester.tcl


# Create several tables to work with.







|







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.  This
# file is a copy of "trans.test" modified to run under autovacuum mode.
# the point is to stress the autovacuum logic and try to get it to fail.
#
# $Id: avtrans.test,v 1.2 2006/01/17 09:35:02 danielk1977 Exp $


set testdir [file dirname $argv0]
source $testdir/tester.tcl


# Create several tables to work with.
892
893
894
895
896
897
898

899
900
901





902
903
904
905
906
907
908
         INSERT INTO t3 SELECT randstr(10,400) FROM t3 WHERE random()%10==0;
       }
    } {}
    if {$tcl_platform(platform)=="unix"} {
      do_test avtrans-9.$i.4-$cnt {
         expr {$sqlite_sync_count>0}
      } 1

      do_test avtrans-9.$i.5-$cnt {
         expr {$sqlite_fullsync_count>0}
      } [expr {$i%2==0}]





    }
  }
  set ::pager_old_format 0
}
integrity_check avtrans-10.1
   
finish_test







>
|
|
|
>
>
>
>
>







892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
         INSERT INTO t3 SELECT randstr(10,400) FROM t3 WHERE random()%10==0;
       }
    } {}
    if {$tcl_platform(platform)=="unix"} {
      do_test avtrans-9.$i.4-$cnt {
         expr {$sqlite_sync_count>0}
      } 1
      ifcapable pager_pragmas {
        do_test avtrans-9.$i.5-$cnt {
           expr {$sqlite_fullsync_count>0}
        } [expr {$i%2==0}]
      } else {
        do_test avtrans-9.$i.5-$cnt {
           expr {$sqlite_fullsync_count>0}
        } {1}
      }
    }
  }
  set ::pager_old_format 0
}
integrity_check avtrans-10.1
   
finish_test
Changes to test/between.test.
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31


32





33
34
35
36
37
38
39
#    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 the use of indices in WHERE clauses
# when the WHERE clause contains the BETWEEN operator.
#
# $Id: between.test,v 1.1 2005/07/28 23:12:08 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Build some test data
#
do_test between-1.0 {
  execsql {
    BEGIN;
    CREATE TABLE t1(w int, x int, y int, z int);
  }
  for {set i 1} {$i<=100} {incr i} {
    set w $i
    set x [expr {int(log($i)/log(2))}]
    set y [expr {$i*$i + 2*$i + 1}]
    set z [expr {$x+$y}]


    execsql {INSERT INTO t1 VALUES($::w,$::x,$::y,$::z)}





  }
  execsql {
    CREATE UNIQUE INDEX i1w ON t1(w);
    CREATE INDEX i1xy ON t1(x,y);
    CREATE INDEX i1zyx ON t1(z,y,x);
    COMMIT;
  }







|
















>
>
|
>
>
>
>
>







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#    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 the use of indices in WHERE clauses
# when the WHERE clause contains the BETWEEN operator.
#
# $Id: between.test,v 1.2 2006/01/17 09:35:02 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Build some test data
#
do_test between-1.0 {
  execsql {
    BEGIN;
    CREATE TABLE t1(w int, x int, y int, z int);
  }
  for {set i 1} {$i<=100} {incr i} {
    set w $i
    set x [expr {int(log($i)/log(2))}]
    set y [expr {$i*$i + 2*$i + 1}]
    set z [expr {$x+$y}]
    ifcapable tclvar {
      # Random unplanned test of the $varname variable syntax.
      execsql {INSERT INTO t1 VALUES($::w,$::x,$::y,$::z)}
    } else {
      # If the $varname syntax is not available, use the regular variable
      # declaration syntax.
      execsql {INSERT INTO t1 VALUES(:w,:x,:y,:z)}
    }
  }
  execsql {
    CREATE UNIQUE INDEX i1w ON t1(w);
    CREATE INDEX i1xy ON t1(x,y);
    CREATE INDEX i1zyx ON t1(z,y,x);
    COMMIT;
  }
Changes to test/capi3.test.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 2003 January 29
#
# 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 script testing the callback-free C/C++ API.
#
# $Id: capi3.test,v 1.38 2006/01/13 01:25:06 drh Exp $
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Return the UTF-16 representation of the supplied UTF-8 string $str.
# If $nt is true, append two 0x00 bytes as a nul terminator.













|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 2003 January 29
#
# 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 script testing the callback-free C/C++ API.
#
# $Id: capi3.test,v 1.39 2006/01/17 09:35:02 danielk1977 Exp $
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Return the UTF-16 representation of the supplied UTF-8 string $str.
# If $nt is true, append two 0x00 bytes as a nul terminator.
107
108
109
110
111
112
113


114
115
116
117
118
119
120
121
122
123
124
125


126
127
128
129
130
131
132
  } {1}
  do_test capi3-2.4 {
    sqlite3_errcode $DB
  } {SQLITE_ERROR}
  do_test capi3-2.5 {
    sqlite3_errmsg $DB
  } {no such column: namex}


  do_test capi3-2.6 {
    execsql {CREATE TABLE tablename(x)}
    set sql16 [utf16 {PRAGMA table_info("TableName")}]
    set STMT [sqlite3_prepare16 $DB $sql16 -1 TAIL]
    sqlite3_step $STMT
  } SQLITE_ROW
  do_test capi3-2.7 {
    sqlite3_step $STMT
  } SQLITE_DONE
  do_test capi3-2.8 {
    sqlite3_finalize $STMT
  } SQLITE_OK


} ;# endif utf16

# rename sqlite3_open sqlite3_open_old
# proc sqlite3_open {fname options} {sqlite3_open_new $fname $options}

do_test capi3-3.1 {
  set db2 [sqlite3_open test.db {}]







>
>
|
|
|
|
|
|
|
|
|
|
|
|
>
>







107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
  } {1}
  do_test capi3-2.4 {
    sqlite3_errcode $DB
  } {SQLITE_ERROR}
  do_test capi3-2.5 {
    sqlite3_errmsg $DB
  } {no such column: namex}

  ifcapable schema_pragmas {
    do_test capi3-2.6 {
      execsql {CREATE TABLE tablename(x)}
      set sql16 [utf16 {PRAGMA table_info("TableName")}]
      set STMT [sqlite3_prepare16 $DB $sql16 -1 TAIL]
      sqlite3_step $STMT
    } SQLITE_ROW
    do_test capi3-2.7 {
      sqlite3_step $STMT
    } SQLITE_DONE
    do_test capi3-2.8 {
      sqlite3_finalize $STMT
    } SQLITE_OK
  }

} ;# endif utf16

# rename sqlite3_open sqlite3_open_old
# proc sqlite3_open {fname options} {sqlite3_open_new $fname $options}

do_test capi3-3.1 {
  set db2 [sqlite3_open test.db {}]
Changes to test/check.test.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 2005 November 2
#
# 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 CHECK constraints
#
# $Id: check.test,v 1.7 2006/01/14 08:02:28 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Only run these tests if the build includes support for CHECK constraints
ifcapable !check {
  finish_test













|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 2005 November 2
#
# 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 CHECK constraints
#
# $Id: check.test,v 1.8 2006/01/17 09:35:02 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Only run these tests if the build includes support for CHECK constraints
ifcapable !check {
  finish_test
268
269
270
271
272
273
274

275
276
277
278
279

280
281
282
283
284
285
286
} {0 1}
do_test check-4.8 {
  catchsql {
    PRAGMA ignore_check_constraints=OFF;
    UPDATE t4 SET x=0, y=2;
  }
} {1 {constraint failed}}

do_test check_4.9 {
  catchsql {
    VACUUM
  }
} {0 {}}


do_test check-5.1 {
  catchsql {
    CREATE TABLE t5(x, y,
      CHECK( x*y<:abc )
    );
  }







>
|
|
|
|
|
>







268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
} {0 1}
do_test check-4.8 {
  catchsql {
    PRAGMA ignore_check_constraints=OFF;
    UPDATE t4 SET x=0, y=2;
  }
} {1 {constraint failed}}
ifcapable vacuum {
  do_test check_4.9 {
    catchsql {
      VACUUM
    }
  } {0 {}}
}

do_test check-5.1 {
  catchsql {
    CREATE TABLE t5(x, y,
      CHECK( x*y<:abc )
    );
  }
Changes to test/conflict.test.
9
10
11
12
13
14
15
16
17
18
19





20
21
22
23
24
25
26
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests for the conflict resolution extension
# to SQLite.
#
# $Id: conflict.test,v 1.26 2005/09/25 01:13:09 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl






# Create tables for the first group of tests.
#
do_test conflict-1.0 {
  execsql {
    CREATE TABLE t1(a, b, c, UNIQUE(a,b));
    CREATE TABLE t2(x);







|



>
>
>
>
>







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests for the conflict resolution extension
# to SQLite.
#
# $Id: conflict.test,v 1.27 2006/01/17 09:35:02 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable !conflict {
  finish_test
  return
}

# Create tables for the first group of tests.
#
do_test conflict-1.0 {
  execsql {
    CREATE TABLE t1(a, b, c, UNIQUE(a,b));
    CREATE TABLE t2(x);
Changes to test/hook.test.
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#
# The focus of the tests in this file is the  following interface:
#
#      sqlite_commit_hook    (tests hook-1..hook-3 inclusive)
#      sqlite_update_hook    (tests hook-4-*)
#      sqlite_rollback_hook  (tests hook-5.*)
#
# $Id: hook.test,v 1.10 2006/01/16 16:24:25 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

do_test hook-1.2 {
  db commit_hook
} {}







|







13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#
# The focus of the tests in this file is the  following interface:
#
#      sqlite_commit_hook    (tests hook-1..hook-3 inclusive)
#      sqlite_update_hook    (tests hook-4-*)
#      sqlite_rollback_hook  (tests hook-5.*)
#
# $Id: hook.test,v 1.11 2006/01/17 09:35:02 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

do_test hook-1.2 {
  db commit_hook
} {}
134
135
136
137
138
139
140

141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169




170


171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189






190
191
192
193
194
195
196
197
198
199
200
201
202
203
    UPDATE main t1 3 \
    DELETE main t1 1 \
    DELETE main t1 3 \
    DELETE main t1 4 \
]

set ::update_hook {}

do_test hook-4.2.1 {
  catchsql {
    DROP TABLE t2;
  }
  execsql {
    CREATE TABLE t2(c INTEGER PRIMARY KEY, d);
    CREATE TRIGGER t1_trigger AFTER INSERT ON t1 BEGIN
      INSERT INTO t2 VALUES(new.a, new.b);
      UPDATE t2 SET d = d || ' via trigger' WHERE new.a = c;
      DELETE FROM t2 WHERE new.a = c;
    END;
  }
} {}
do_test hook-4.2.2 {
  execsql {
    INSERT INTO t1 VALUES(1, 'one');
    INSERT INTO t1 VALUES(2, 'two');
  }
  set ::update_hook
} [list \
    INSERT main t1 1 \
    INSERT main t2 1 \
    UPDATE main t2 1 \
    DELETE main t2 1 \
    INSERT main t1 2 \
    INSERT main t2 2 \
    UPDATE main t2 2 \
    DELETE main t2 2 \
]







# Triggers + ATTACH
set ::update_hook {}
do_test hook-4.2.3 {
  file delete -force test2.db
  execsql {
    ATTACH 'test2.db' AS aux;
    CREATE TABLE aux.t3(a INTEGER PRIMARY KEY, b);
    INSERT INTO aux.t3 SELECT * FROM t1;
    UPDATE t3 SET b = 'two or so' WHERE a = 2;
    DELETE FROM t3 WHERE 1; -- Avoid the truncate optimization (for now)
  }
  set ::update_hook
} [list \
    INSERT aux t3 1 \
    INSERT aux t3 2 \
    UPDATE aux t3 2 \
    DELETE aux t3 1 \
    DELETE aux t3 2 \
]







# Test that other vdbe operations involving btree structures do not 
# incorrectly invoke the update-hook.
set ::update_hook {}
do_test hook-4.3.1 {
  execsql {
    DROP TRIGGER t1_trigger;
    CREATE INDEX t1_i ON t1(b);
    INSERT INTO t1 VALUES(3, 'three');
    UPDATE t1 SET b = '';
    DELETE FROM t1 WHERE a > 1;
  }
  set ::update_hook
} [list \







>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
|
>
>
|


















>
>
>
>
>
>






<







134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208

209
210
211
212
213
214
215
    UPDATE main t1 3 \
    DELETE main t1 1 \
    DELETE main t1 3 \
    DELETE main t1 4 \
]

set ::update_hook {}
ifcapable trigger {
  do_test hook-4.2.1 {
    catchsql {
      DROP TABLE t2;
    }
    execsql {
      CREATE TABLE t2(c INTEGER PRIMARY KEY, d);
      CREATE TRIGGER t1_trigger AFTER INSERT ON t1 BEGIN
        INSERT INTO t2 VALUES(new.a, new.b);
        UPDATE t2 SET d = d || ' via trigger' WHERE new.a = c;
        DELETE FROM t2 WHERE new.a = c;
      END;
    }
  } {}
  do_test hook-4.2.2 {
    execsql {
      INSERT INTO t1 VALUES(1, 'one');
      INSERT INTO t1 VALUES(2, 'two');
    }
    set ::update_hook
  } [list \
      INSERT main t1 1 \
      INSERT main t2 1 \
      UPDATE main t2 1 \
      DELETE main t2 1 \
      INSERT main t1 2 \
      INSERT main t2 2 \
      UPDATE main t2 2 \
      DELETE main t2 2 \
  ]
} else {
  execsql {
    INSERT INTO t1 VALUES(1, 'one');
    INSERT INTO t1 VALUES(2, 'two');
  }
}

# Update-hook + ATTACH
set ::update_hook {}
do_test hook-4.2.3 {
  file delete -force test2.db
  execsql {
    ATTACH 'test2.db' AS aux;
    CREATE TABLE aux.t3(a INTEGER PRIMARY KEY, b);
    INSERT INTO aux.t3 SELECT * FROM t1;
    UPDATE t3 SET b = 'two or so' WHERE a = 2;
    DELETE FROM t3 WHERE 1; -- Avoid the truncate optimization (for now)
  }
  set ::update_hook
} [list \
    INSERT aux t3 1 \
    INSERT aux t3 2 \
    UPDATE aux t3 2 \
    DELETE aux t3 1 \
    DELETE aux t3 2 \
]

ifcapable trigger {
  execsql {
    DROP TRIGGER t1_trigger;
  }
}

# Test that other vdbe operations involving btree structures do not 
# incorrectly invoke the update-hook.
set ::update_hook {}
do_test hook-4.3.1 {
  execsql {

    CREATE INDEX t1_i ON t1(b);
    INSERT INTO t1 VALUES(3, 'three');
    UPDATE t1 SET b = '';
    DELETE FROM t1 WHERE a > 1;
  }
  set ::update_hook
} [list \
Changes to test/index.test.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 2001 September 15
#
# 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 the CREATE INDEX statement.
#
# $Id: index.test,v 1.40 2006/01/04 15:54:37 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Create a basic index and verify it is added to sqlite_master
#
do_test index-1.1 {













|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 2001 September 15
#
# 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 the CREATE INDEX statement.
#
# $Id: index.test,v 1.41 2006/01/17 09:35:02 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Create a basic index and verify it is added to sqlite_master
#
do_test index-1.1 {
636
637
638
639
640
641
642

643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682

683
684
685
686
687
688
689
  execsql {
    DROP TABLE t7;
  }
} {}

# These tests ensure that if multiple table definition constraints are
# implemented by a single indice, the correct ON CONFLICT policy applies.

do_test index-19.1 {
  execsql {
    CREATE TABLE t7(a UNIQUE PRIMARY KEY);
    CREATE TABLE t8(a UNIQUE PRIMARY KEY ON CONFLICT ROLLBACK);
    INSERT INTO t7 VALUES(1);
    INSERT INTO t8 VALUES(1);
  }
} {}
do_test index-19.2 {
  catchsql {
    BEGIN;
    INSERT INTO t7 VALUES(1);
  }
} {1 {column a is not unique}}
do_test index-19.3 {
  catchsql {
    BEGIN;
  }
} {1 {cannot start a transaction within a transaction}}
do_test index-19.4 {
  catchsql {
    INSERT INTO t8 VALUES(1);
  }
} {1 {column a is not unique}}
do_test index-19.5 {
  catchsql {
    BEGIN;
    COMMIT;
  }
} {0 {}}
do_test index-19.6 {
  catchsql {
    DROP TABLE t7;
    DROP TABLE t8;
    CREATE TABLE t7(
       a PRIMARY KEY ON CONFLICT FAIL, 
       UNIQUE(a) ON CONFLICT IGNORE
    );
  }
} {1 {conflicting ON CONFLICT clauses specified}}


ifcapable {reindex} {
  do_test index-19.7 {
    execsql REINDEX
  } {}
}
integrity_check index-19.8







>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>







636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
  execsql {
    DROP TABLE t7;
  }
} {}

# These tests ensure that if multiple table definition constraints are
# implemented by a single indice, the correct ON CONFLICT policy applies.
ifcapable conflict {
  do_test index-19.1 {
    execsql {
      CREATE TABLE t7(a UNIQUE PRIMARY KEY);
      CREATE TABLE t8(a UNIQUE PRIMARY KEY ON CONFLICT ROLLBACK);
      INSERT INTO t7 VALUES(1);
      INSERT INTO t8 VALUES(1);
    }
  } {}
  do_test index-19.2 {
    catchsql {
      BEGIN;
      INSERT INTO t7 VALUES(1);
    }
  } {1 {column a is not unique}}
  do_test index-19.3 {
    catchsql {
      BEGIN;
    }
  } {1 {cannot start a transaction within a transaction}}
  do_test index-19.4 {
    catchsql {
      INSERT INTO t8 VALUES(1);
    }
  } {1 {column a is not unique}}
  do_test index-19.5 {
    catchsql {
      BEGIN;
      COMMIT;
    }
  } {0 {}}
  do_test index-19.6 {
    catchsql {
      DROP TABLE t7;
      DROP TABLE t8;
      CREATE TABLE t7(
         a PRIMARY KEY ON CONFLICT FAIL, 
         UNIQUE(a) ON CONFLICT IGNORE
      );
    }
  } {1 {conflicting ON CONFLICT clauses specified}}
} ; # end of "ifcapable conflict" block

ifcapable {reindex} {
  do_test index-19.7 {
    execsql REINDEX
  } {}
}
integrity_check index-19.8
Changes to test/insert.test.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 2001 September 15
#
# 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 the INSERT statement.
#
# $Id: insert.test,v 1.28 2006/01/16 16:24:25 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Try to insert into a non-existant table.
#
do_test insert-1.1 {













|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 2001 September 15
#
# 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 the INSERT statement.
#
# $Id: insert.test,v 1.29 2006/01/17 09:35:02 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Try to insert into a non-existant table.
#
do_test insert-1.1 {
284
285
286
287
288
289
290



291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318






319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
      expr {[lsearch $x OpenTemp]>0}
    } {0}
  }
}

# Ticket #334:  REPLACE statement corrupting indices.
#



do_test insert-6.1 {
  execsql {
    CREATE TABLE t1(a INTEGER PRIMARY KEY, b UNIQUE);
    INSERT INTO t1 VALUES(1,2);
    INSERT INTO t1 VALUES(2,3);
    SELECT b FROM t1 WHERE b=2;
  }
} {2}
do_test insert-6.2 {
  execsql {
    REPLACE INTO t1 VALUES(1,4);
    SELECT b FROM t1 WHERE b=2;
  }
} {}
do_test insert-6.3 {
  execsql {
    UPDATE OR REPLACE t1 SET a=2 WHERE b=4;
    SELECT * FROM t1 WHERE b=4;
  }
} {2 4}
do_test insert-6.4 {
  execsql {
    SELECT * FROM t1 WHERE b=3;
  }
} {}
ifcapable {reindex} {
  do_test insert-6.7 {
    execsql REINDEX






  } {}
}

# Test that the special optimization for queries of the form 
# "SELECT max(x) FROM tbl" where there is an index on tbl(x) works with 
# INSERT statments.
do_test insert-7.1 {
  execsql {
    DROP TABLE t1;
    CREATE TABLE t1(a);
    INSERT INTO t1 VALUES(1);
    INSERT INTO t1 VALUES(2);
    CREATE INDEX i1 ON t1(a);
  }
} {}
do_test insert-7.2 {







>
>
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
>
>








<







284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335

336
337
338
339
340
341
342
      expr {[lsearch $x OpenTemp]>0}
    } {0}
  }
}

# Ticket #334:  REPLACE statement corrupting indices.
#
ifcapable conflict {
  # The REPLACE command is not available if SQLITE_OMIT_CONFLICT is 
  # defined at compilation time.
  do_test insert-6.1 {
    execsql {
      CREATE TABLE t1(a INTEGER PRIMARY KEY, b UNIQUE);
      INSERT INTO t1 VALUES(1,2);
      INSERT INTO t1 VALUES(2,3);
      SELECT b FROM t1 WHERE b=2;
    }
  } {2}
  do_test insert-6.2 {
    execsql {
      REPLACE INTO t1 VALUES(1,4);
      SELECT b FROM t1 WHERE b=2;
    }
  } {}
  do_test insert-6.3 {
    execsql {
      UPDATE OR REPLACE t1 SET a=2 WHERE b=4;
      SELECT * FROM t1 WHERE b=4;
    }
  } {2 4}
  do_test insert-6.4 {
    execsql {
      SELECT * FROM t1 WHERE b=3;
    }
  } {}
  ifcapable {reindex} {
    do_test insert-6.5 {
      execsql REINDEX
    } {}
  }
  do_test insert-6.6 {
    execsql {
      DROP TABLE t1;
    }
  } {}
}

# Test that the special optimization for queries of the form 
# "SELECT max(x) FROM tbl" where there is an index on tbl(x) works with 
# INSERT statments.
do_test insert-7.1 {
  execsql {

    CREATE TABLE t1(a);
    INSERT INTO t1 VALUES(1);
    INSERT INTO t1 VALUES(2);
    CREATE INDEX i1 ON t1(a);
  }
} {}
do_test insert-7.2 {
Changes to test/like.test.
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this file is testing the LIKE and GLOB operators and
# in particular the optimizations that occur to help those operators
# run faster.
#
# $Id: like.test,v 1.3 2005/08/28 17:00:26 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Create some sample data to work with.
#
do_test like-1.0 {







|







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this file is testing the LIKE and GLOB operators and
# in particular the optimizations that occur to help those operators
# run faster.
#
# $Id: like.test,v 1.4 2006/01/17 09:35:02 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Create some sample data to work with.
#
do_test like-1.0 {
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
    bcd

    xyz
    ABC
    CDE
    {ABC abc xyz}
  } {
    db eval {INSERT INTO t1 VALUES($str)}
  }
  execsql {
    SELECT count(*) FROM t1;
  }
} {12}

# Test that both case sensitive and insensitive version of LIKE work.







|







36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
    bcd

    xyz
    ABC
    CDE
    {ABC abc xyz}
  } {
    db eval {INSERT INTO t1 VALUES(:str)}
  }
  execsql {
    SELECT count(*) FROM t1;
  }
} {12}

# Test that both case sensitive and insensitive version of LIKE work.
Changes to test/limit.test.
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#    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 the LIMIT ... OFFSET ... clause
#  of SELECT statements.
#
# $Id: limit.test,v 1.26 2006/01/08 18:10:18 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Build some test data
#
execsql {







|







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#    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 the LIMIT ... OFFSET ... clause
#  of SELECT statements.
#
# $Id: limit.test,v 1.27 2006/01/17 09:35:02 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Build some test data
#
execsql {
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
  } {1 {LIMIT clause should come after UNION not before}}
}

# Test LIMIT and OFFSET using SQL variables.
do_test limit-10.1 {
  set limit 10
  db eval {
    SELECT x FROM t1 LIMIT $limit;
  }
} {31 30 29 28 27 26 25 24 23 22}
do_test limit-10.2 {
  set limit 5
  set offset 5
  db eval {
    SELECT x FROM t1 LIMIT $limit OFFSET $offset;
  }
} {26 25 24 23 22}
do_test limit-10.3 {
  set limit -1
  db eval {
    SELECT x FROM t1 WHERE x<10 LIMIT $limit;
  }
} {9 8 7 6 5 4 3 2 1 0}
do_test limit-10.4 {
  set limit 1.5
  set rc [catch {
  db eval {
    SELECT x FROM t1 WHERE x<10 LIMIT $limit;
  } } msg]
  list $rc $msg
} {1 {datatype mismatch}}
do_test limit-10.5 {
  set limit "hello world"
  set rc [catch {
  db eval {
    SELECT x FROM t1 WHERE x<10 LIMIT $limit;
  } } msg]
  list $rc $msg
} {1 {datatype mismatch}}

finish_test







|






|





|






|







|





400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
  } {1 {LIMIT clause should come after UNION not before}}
}

# Test LIMIT and OFFSET using SQL variables.
do_test limit-10.1 {
  set limit 10
  db eval {
    SELECT x FROM t1 LIMIT :limit;
  }
} {31 30 29 28 27 26 25 24 23 22}
do_test limit-10.2 {
  set limit 5
  set offset 5
  db eval {
    SELECT x FROM t1 LIMIT :limit OFFSET :offset;
  }
} {26 25 24 23 22}
do_test limit-10.3 {
  set limit -1
  db eval {
    SELECT x FROM t1 WHERE x<10 LIMIT :limit;
  }
} {9 8 7 6 5 4 3 2 1 0}
do_test limit-10.4 {
  set limit 1.5
  set rc [catch {
  db eval {
    SELECT x FROM t1 WHERE x<10 LIMIT :limit;
  } } msg]
  list $rc $msg
} {1 {datatype mismatch}}
do_test limit-10.5 {
  set limit "hello world"
  set rc [catch {
  db eval {
    SELECT x FROM t1 WHERE x<10 LIMIT :limit;
  } } msg]
  list $rc $msg
} {1 {datatype mismatch}}

finish_test
Changes to test/memdb.test.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 2001 September 15
#
# 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 script is in-memory database backend.
#
# $Id: memdb.test,v 1.13 2005/01/21 04:25:47 danielk1977 Exp $


set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable memorydb {














|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 2001 September 15
#
# 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 script is in-memory database backend.
#
# $Id: memdb.test,v 1.14 2006/01/17 09:35:02 danielk1977 Exp $


set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable memorydb {

165
166
167
168
169
170
171





172
173
174
175
176
177
178
  2 {}       {INSERT OR IGNORE}      0 3   1
  3 {}       {INSERT OR REPLACE}     0 4   1
  4 {}       REPLACE                 0 4   1
  5 {}       {INSERT OR FAIL}        1 {}  1
  6 {}       {INSERT OR ABORT}       1 {}  1
  7 {}       {INSERT OR ROLLBACK}    1 {}  {}
} {





  do_test memdb-4.$i {
    if {$conf!=""} {set conf "ON CONFLICT $conf"}
    set r0 [catch {execsql [subst {
      DELETE FROM t1;
      DELETE FROM t2;
      INSERT INTO t1 VALUES(1,2,3);
      BEGIN $conf;







>
>
>
>
>







165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
  2 {}       {INSERT OR IGNORE}      0 3   1
  3 {}       {INSERT OR REPLACE}     0 4   1
  4 {}       REPLACE                 0 4   1
  5 {}       {INSERT OR FAIL}        1 {}  1
  6 {}       {INSERT OR ABORT}       1 {}  1
  7 {}       {INSERT OR ROLLBACK}    1 {}  {}
} {

  # All tests after test 1 depend on conflict resolution. So end the
  # loop if that is not available in this build.
  ifcapable !conflict {if {$i>1} break}

  do_test memdb-4.$i {
    if {$conf!=""} {set conf "ON CONFLICT $conf"}
    set r0 [catch {execsql [subst {
      DELETE FROM t1;
      DELETE FROM t2;
      INSERT INTO t1 VALUES(1,2,3);
      BEGIN $conf;
225
226
227
228
229
230
231






232
233
234
235
236
237
238
 11 ROLLBACK {}       {UPDATE OR IGNORE}      0 {6 7 3 9}   1
 12 {}       {}       {UPDATE OR IGNORE}      0 {6 7 3 9}  1
 13 {}       {}       {UPDATE OR REPLACE}     0 {7 6 9}    1
 14 {}       {}       {UPDATE OR FAIL}        1 {6 7 3 4}  1
 15 {}       {}       {UPDATE OR ABORT}       1 {1 2 3 4}  1
 16 {}       {}       {UPDATE OR ROLLBACK}    1 {1 2 3 4}  0
} {






  if {$t0} {set t1 {column a is not unique}}
  do_test memdb-5.$i {
    if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"}
    if {$conf2!=""} {set conf2 "ON CONFLICT $conf2"}
    set r0 [catch {execsql [subst {
      DROP TABLE t1;
      CREATE TABLE t1(a,b,c, UNIQUE(a) $conf1);







>
>
>
>
>
>







230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
 11 ROLLBACK {}       {UPDATE OR IGNORE}      0 {6 7 3 9}   1
 12 {}       {}       {UPDATE OR IGNORE}      0 {6 7 3 9}  1
 13 {}       {}       {UPDATE OR REPLACE}     0 {7 6 9}    1
 14 {}       {}       {UPDATE OR FAIL}        1 {6 7 3 4}  1
 15 {}       {}       {UPDATE OR ABORT}       1 {1 2 3 4}  1
 16 {}       {}       {UPDATE OR ROLLBACK}    1 {1 2 3 4}  0
} {
  # All tests after test 1 depend on conflict resolution. So end the
  # loop if that is not available in this build.
  ifcapable !conflict {
    if {$i>1} break
  }

  if {$t0} {set t1 {column a is not unique}}
  do_test memdb-5.$i {
    if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"}
    if {$conf2!=""} {set conf2 "ON CONFLICT $conf2"}
    set r0 [catch {execsql [subst {
      DROP TABLE t1;
      CREATE TABLE t1(a,b,c, UNIQUE(a) $conf1);
317
318
319
320
321
322
323


324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343


344
345
346
347
348
349
350
  }
} {}
do_test memdb-6.11 {
  execsql {
    SELECT * FROM t5 ORDER BY y DESC;
  }
} {}


do_test memdb-6.12 {
  execsql {
    INSERT INTO t5 VALUES(1,2);
    INSERT INTO t5 VALUES(3,4);
    REPLACE INTO t5 VALUES(1,4);
    SELECT rowid,* FROM t5;
  }
} {3 1 4}
do_test memdb-6.13 {
  execsql {
    DELETE FROM t5 WHERE x>5;
    SELECT * FROM t5;
  }
} {1 4}
do_test memdb-6.14 {
  execsql {
    DELETE FROM t5 WHERE y<3;
    SELECT * FROM t5;
  }
} {1 4}


do_test memdb-6.15 {
  execsql {
    DELETE FROM t5 WHERE x>0;
    SELECT * FROM t5;
  }
} {}








>
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>







328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
  }
} {}
do_test memdb-6.11 {
  execsql {
    SELECT * FROM t5 ORDER BY y DESC;
  }
} {}

ifcapable conflict {
  do_test memdb-6.12 {
    execsql {
      INSERT INTO t5 VALUES(1,2);
      INSERT INTO t5 VALUES(3,4);
      REPLACE INTO t5 VALUES(1,4);
      SELECT rowid,* FROM t5;
    }
  } {3 1 4}
  do_test memdb-6.13 {
    execsql {
      DELETE FROM t5 WHERE x>5;
      SELECT * FROM t5;
    }
  } {1 4}
  do_test memdb-6.14 {
    execsql {
      DELETE FROM t5 WHERE y<3;
      SELECT * FROM t5;
    }
  } {1 4}
}

do_test memdb-6.15 {
  execsql {
    DELETE FROM t5 WHERE x>0;
    SELECT * FROM t5;
  }
} {}

Changes to test/misc1.test.
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests for miscellanous features that were
# left out of other test files.
#
# $Id: misc1.test,v 1.39 2005/11/01 15:48:25 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Mimic the SQLite 2 collation type NUMERIC.
db collate numeric numeric_collate
proc numeric_collate {lhs rhs} {







|







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests for miscellanous features that were
# left out of other test files.
#
# $Id: misc1.test,v 1.40 2006/01/17 09:35:02 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Mimic the SQLite 2 collation type NUMERIC.
db collate numeric numeric_collate
proc numeric_collate {lhs rhs} {
360
361
362
363
364
365
366

367
368
369
370
371
372
373
374
375
376
377
378

379
380
381
382
383
384
385
do_test misc1-12.4 {
  execsql {
    CREATE TABLE t6(a INT UNIQUE, b TEXT UNIQUE);
    INSERT INTO t6 VALUES('0','0.0');
    SELECT * FROM t6;
  }
} {0 0.0}

do_test misc1-12.5 {
  execsql {
    INSERT OR IGNORE INTO t6 VALUES(0.0,'x');
    SELECT * FROM t6;
  }
} {0 0.0}
do_test misc1-12.6 {
  execsql {
    INSERT OR IGNORE INTO t6 VALUES('y',0);
    SELECT * FROM t6;
  }
} {0 0.0 y 0}

do_test misc1-12.7 {
  execsql {
    CREATE TABLE t7(x INTEGER, y TEXT, z);
    INSERT INTO t7 VALUES(0,0,1);
    INSERT INTO t7 VALUES(0.0,0,2);
    INSERT INTO t7 VALUES(0,0.0,3);
    INSERT INTO t7 VALUES(0.0,0.0,4);







>
|
|
|
|
|
|
|
|
|
|
|
|
>







360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
do_test misc1-12.4 {
  execsql {
    CREATE TABLE t6(a INT UNIQUE, b TEXT UNIQUE);
    INSERT INTO t6 VALUES('0','0.0');
    SELECT * FROM t6;
  }
} {0 0.0}
ifcapable conflict {
  do_test misc1-12.5 {
    execsql {
      INSERT OR IGNORE INTO t6 VALUES(0.0,'x');
      SELECT * FROM t6;
    }
  } {0 0.0}
  do_test misc1-12.6 {
    execsql {
      INSERT OR IGNORE INTO t6 VALUES('y',0);
      SELECT * FROM t6;
    }
  } {0 0.0 y 0}
}
do_test misc1-12.7 {
  execsql {
    CREATE TABLE t7(x INTEGER, y TEXT, z);
    INSERT INTO t7 VALUES(0,0,1);
    INSERT INTO t7 VALUES(0.0,0,2);
    INSERT INTO t7 VALUES(0,0.0,3);
    INSERT INTO t7 VALUES(0.0,0.0,4);
Changes to test/misc2.test.
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests for miscellanous features that were
# left out of other test files.
#
# $Id: misc2.test,v 1.23 2006/01/14 08:02:28 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable {trigger} {
# Test for ticket #360
#







|







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests for miscellanous features that were
# left out of other test files.
#
# $Id: misc2.test,v 1.24 2006/01/17 09:35:02 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable {trigger} {
# Test for ticket #360
#
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# Ticket #1229.  Sometimes when a "NEW.X" appears in a SELECT without
# a FROM clause deep within a trigger, the code generator is unable to
# trace the NEW.X back to an original table and thus figure out its
# declared datatype.
#
# The SQL code below was causing a segfault.
#
ifcapable subquery {
  do_test misc2-10.1 {
    execsql {
      CREATE TABLE t1229(x);
      CREATE TRIGGER r1229 BEFORE INSERT ON t1229 BEGIN
        INSERT INTO t1229 SELECT y FROM (SELECT new.x y);
      END;
      INSERT INTO t1229 VALUES(1);
    }
  } {}
}

finish_test







|












253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# Ticket #1229.  Sometimes when a "NEW.X" appears in a SELECT without
# a FROM clause deep within a trigger, the code generator is unable to
# trace the NEW.X back to an original table and thus figure out its
# declared datatype.
#
# The SQL code below was causing a segfault.
#
ifcapable subquery&&trigger {
  do_test misc2-10.1 {
    execsql {
      CREATE TABLE t1229(x);
      CREATE TRIGGER r1229 BEFORE INSERT ON t1229 BEGIN
        INSERT INTO t1229 SELECT y FROM (SELECT new.x y);
      END;
      INSERT INTO t1229 VALUES(1);
    }
  } {}
}

finish_test
Changes to test/misc5.test.
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests for miscellanous features that were
# left out of other test files.
#
# $Id: misc5.test,v 1.10 2006/01/16 16:24:25 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Build records using the MakeRecord opcode such that the size of the 
# header is at the transition point in the size of a varint.
#







|







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests for miscellanous features that were
# left out of other test files.
#
# $Id: misc5.test,v 1.11 2006/01/17 09:35:02 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Build records using the MakeRecord opcode such that the size of the 
# header is at the transition point in the size of a varint.
#
39
40
41
42
43
44
45

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61























62
63
64
65
66
67
68
    append sql2 {);}
    execsql $sql1$sql2
  } {}
}

# Make sure large integers are stored correctly.
#

do_test misc5-2.1 {
  execsql {
    create table t2(x unique);
    insert into t2 values(1);
    insert or ignore into t2 select x*2 from t2;
    insert or ignore into t2 select x*4 from t2;
    insert or ignore into t2 select x*16 from t2;
    insert or ignore into t2 select x*256 from t2;
    insert or ignore into t2 select x*65536 from t2;
    insert or ignore into t2 select x*2147483648 from t2;
    insert or ignore into t2 select x-1 from t2;
    insert or ignore into t2 select x+1 from t2;
    insert or ignore into t2 select -x from t2;
    select count(*) from t2;
  }
} 371























do_test misc5-2.2 {
  execsql {
    select x from t2 order by x;
  }
} \
"-4611686018427387905\
-4611686018427387904\







>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
    append sql2 {);}
    execsql $sql1$sql2
  } {}
}

# Make sure large integers are stored correctly.
#
ifcapable conflict {
  do_test misc5-2.1 {
    execsql {
      create table t2(x unique);
      insert into t2 values(1);
      insert or ignore into t2 select x*2 from t2;
      insert or ignore into t2 select x*4 from t2;
      insert or ignore into t2 select x*16 from t2;
      insert or ignore into t2 select x*256 from t2;
      insert or ignore into t2 select x*65536 from t2;
      insert or ignore into t2 select x*2147483648 from t2;
      insert or ignore into t2 select x-1 from t2;
      insert or ignore into t2 select x+1 from t2;
      insert or ignore into t2 select -x from t2;
      select count(*) from t2;
    }
  } 371
} else {
  do_test misc5-2.1 {
    execsql {
      BEGIN;
      create table t2(x unique);
      create table t2_temp(x);
      insert into t2_temp values(1);
      insert into t2_temp select x*2 from t2_temp;
      insert into t2_temp select x*4 from t2_temp;
      insert into t2_temp select x*16 from t2_temp;
      insert into t2_temp select x*256 from t2_temp;
      insert into t2_temp select x*65536 from t2_temp;
      insert into t2_temp select x*2147483648 from t2_temp;
      insert into t2_temp select x-1 from t2_temp;
      insert into t2_temp select x+1 from t2_temp;
      insert into t2_temp select -x from t2_temp;
      INSERT INTO t2 SELECT DISTINCT(x) FROM t2_temp;
      DROP TABLE t2_temp;
      COMMIT;
      select count(*) from t2;
    }
  } 371
}
do_test misc5-2.2 {
  execsql {
    select x from t2 order by x;
  }
} \
"-4611686018427387905\
-4611686018427387904\
Changes to test/notnull.test.
8
9
10
11
12
13
14
15
16
17
18





19
20
21
22
23
24
25
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests for the NOT NULL constraint.
#
# $Id: notnull.test,v 1.3 2003/01/29 18:46:54 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl






do_test notnull-1.0 {
  execsql {
    CREATE TABLE t1 (
      a NOT NULL,
      b NOT NULL DEFAULT 5,
      c NOT NULL ON CONFLICT REPLACE DEFAULT 6,







|



>
>
>
>
>







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests for the NOT NULL constraint.
#
# $Id: notnull.test,v 1.4 2006/01/17 09:35:02 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable !conflict {
  finish_test
  return
}

do_test notnull-1.0 {
  execsql {
    CREATE TABLE t1 (
      a NOT NULL,
      b NOT NULL DEFAULT 5,
      c NOT NULL ON CONFLICT REPLACE DEFAULT 6,
Changes to test/null.test.
158
159
160
161
162
163
164

165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184

185
186
187
188
189
190
191
    select b from t1 union select c from t1 order by c;
  }
} {{} 0 1}
} ;# ifcapable compound

# The UNIQUE constraint only applies to non-null values
#

do_test null-7.1 {
  execsql {
    create table t2(a, b unique on conflict ignore);
    insert into t2 values(1,1);
    insert into t2 values(2,null);
    insert into t2 values(3,null);
    insert into t2 values(4,1);
    select a from t2;
  }
} {1 2 3}
do_test null-7.2 {
  execsql {
    create table t3(a, b, c, unique(b,c) on conflict ignore);
    insert into t3 values(1,1,1);
    insert into t3 values(2,null,1);
    insert into t3 values(3,null,1);
    insert into t3 values(4,1,1);
    select a from t3;
  }
} {1 2 3}


# Ticket #461 - Make sure nulls are handled correctly when doing a
# lookup using an index.
#
do_test null-8.1 {
  execsql {
    CREATE TABLE t4(x,y);







>

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>







158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
    select b from t1 union select c from t1 order by c;
  }
} {{} 0 1}
} ;# ifcapable compound

# The UNIQUE constraint only applies to non-null values
#
ifcapable conflict {
do_test null-7.1 {
    execsql {
      create table t2(a, b unique on conflict ignore);
      insert into t2 values(1,1);
      insert into t2 values(2,null);
      insert into t2 values(3,null);
      insert into t2 values(4,1);
      select a from t2;
    }
  } {1 2 3}
  do_test null-7.2 {
    execsql {
      create table t3(a, b, c, unique(b,c) on conflict ignore);
      insert into t3 values(1,1,1);
      insert into t3 values(2,null,1);
      insert into t3 values(3,null,1);
      insert into t3 values(4,1,1);
      select a from t3;
    }
  } {1 2 3}
}

# Ticket #461 - Make sure nulls are handled correctly when doing a
# lookup using an index.
#
do_test null-8.1 {
  execsql {
    CREATE TABLE t4(x,y);
Changes to test/pagesize.test.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 2004 September 2
#
# 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.
# This file implements tests for the page_size PRAGMA.
#
# $Id: pagesize.test,v 1.10 2005/05/20 20:01:56 drh Exp $


set testdir [file dirname $argv0]
source $testdir/tester.tcl

# This test script depends entirely on "PRAGMA page_size". So if this
# pragma is not available, omit the whole file.













|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 2004 September 2
#
# 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.
# This file implements tests for the page_size PRAGMA.
#
# $Id: pagesize.test,v 1.11 2006/01/17 09:35:02 danielk1977 Exp $


set testdir [file dirname $argv0]
source $testdir/tester.tcl

# This test script depends entirely on "PRAGMA page_size". So if this
# pragma is not available, omit the whole file.
71
72
73
74
75
76
77

78
79
80
81
82
83

84
85
86
87
88
89
90
  execsql {
    PRAGMA page_size=1234;
    PRAGMA page_size
  }
} 8192

foreach PGSZ {512 2048 4096 8192} {

  do_test pagesize-2.$PGSZ.0 {
    db close
    sqlite3 db :memory:
    execsql "PRAGMA page_size=$PGSZ;"
    execsql {PRAGMA page_size}
  } 1024

  do_test pagesize-2.$PGSZ.1 {
    db close
    file delete -force test.db
    sqlite3 db test.db
    execsql "PRAGMA page_size=$PGSZ"
    execsql {
      CREATE TABLE t1(x);







>
|
|
|
|
|
|
>







71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
  execsql {
    PRAGMA page_size=1234;
    PRAGMA page_size
  }
} 8192

foreach PGSZ {512 2048 4096 8192} {
  ifcapable memorydb {
    do_test pagesize-2.$PGSZ.0 {
      db close
      sqlite3 db :memory:
      execsql "PRAGMA page_size=$PGSZ;"
      execsql {PRAGMA page_size}
    } 1024
  }
  do_test pagesize-2.$PGSZ.1 {
    db close
    file delete -force test.db
    sqlite3 db test.db
    execsql "PRAGMA page_size=$PGSZ"
    execsql {
      CREATE TABLE t1(x);
Changes to test/rollback.test.
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

34
35
36
37
38
39
40
41

42
43
44
45
46

47
48
49
50
51
52
53
54
55
56
57
58
59
60

61
62
63
64
65
66
67
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this file is verifying that a rollback in one statement
# caused by an ON CONFLICT ROLLBACK clause aborts any other pending
# statements.
#
# $Id: rollback.test,v 1.3 2006/01/03 00:33:50 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

set DB [sqlite3_connection_pointer db]

do_test rollback-1.1 {
  execsql {
    CREATE TABLE t1(a);
    INSERT INTO t1 VALUES(1);
    INSERT INTO t1 VALUES(2);
    INSERT INTO t1 VALUES(3);
    INSERT INTO t1 VALUES(4);
    SELECT * FROM t1;
  }
} {1 2 3 4}


do_test rollback-1.2 {
  execsql {
    CREATE TABLE t3(a unique on conflict rollback);
    INSERT INTO t3 SELECT a FROM t1;
    BEGIN;
    INSERT INTO t1 SELECT * FROM t1;
  }
} {}

do_test rollback-1.3 {
  set STMT [sqlite3_prepare $DB "SELECT a FROM t1" -1 TAIL]
  sqlite3_step $STMT
} {SQLITE_ROW}


# This causes a ROLLBACK, which deletes the table out from underneath the
# SELECT statement.
#
do_test rollback-1.4 {
  catchsql {
    INSERT INTO t3 SELECT a FROM t1;
  }
} {1 {column a is not unique}}

# Try to continue with the SELECT statement
#
do_test rollback-1.5 {
  sqlite3_step $STMT
} {SQLITE_ABORT}


# Restart the SELECT statement
#
do_test rollback-1.6 {
  sqlite3_reset $STMT
} {SQLITE_OK}
do_test rollback-1.7 {







|

















>
|
|
|
|
|
|
|
|
>





>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this file is verifying that a rollback in one statement
# caused by an ON CONFLICT ROLLBACK clause aborts any other pending
# statements.
#
# $Id: rollback.test,v 1.4 2006/01/17 09:35:02 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

set DB [sqlite3_connection_pointer db]

do_test rollback-1.1 {
  execsql {
    CREATE TABLE t1(a);
    INSERT INTO t1 VALUES(1);
    INSERT INTO t1 VALUES(2);
    INSERT INTO t1 VALUES(3);
    INSERT INTO t1 VALUES(4);
    SELECT * FROM t1;
  }
} {1 2 3 4}

ifcapable conflict {
  do_test rollback-1.2 {
    execsql {
      CREATE TABLE t3(a unique on conflict rollback);
      INSERT INTO t3 SELECT a FROM t1;
      BEGIN;
      INSERT INTO t1 SELECT * FROM t1;
    }
  } {}
}
do_test rollback-1.3 {
  set STMT [sqlite3_prepare $DB "SELECT a FROM t1" -1 TAIL]
  sqlite3_step $STMT
} {SQLITE_ROW}

ifcapable conflict {
  # This causes a ROLLBACK, which deletes the table out from underneath the
  # SELECT statement.
  #
  do_test rollback-1.4 {
    catchsql {
      INSERT INTO t3 SELECT a FROM t1;
    }
  } {1 {column a is not unique}}
  
  # Try to continue with the SELECT statement
  #
  do_test rollback-1.5 {
    sqlite3_step $STMT
  } {SQLITE_ABORT}
}

# Restart the SELECT statement
#
do_test rollback-1.6 {
  sqlite3_reset $STMT
} {SQLITE_OK}
do_test rollback-1.7 {
Changes to test/shared.test.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 2005 December 30
#
# 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.
#
#***********************************************************************
#
# $Id: shared.test,v 1.16 2006/01/16 16:24:25 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl
db close

ifcapable !shared_cache {
  finish_test











|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 2005 December 30
#
# 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.
#
#***********************************************************************
#
# $Id: shared.test,v 1.17 2006/01/17 09:35:02 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl
db close

ifcapable !shared_cache {
  finish_test
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
  execsql {PRAGMA read_uncommitted = 1} db2

  set ret [list]
  db2 eval {SELECT i FROM seq} {
    if {$i < 4} {
      set max [execsql {SELECT max(i) FROM seq}]
      db eval {
        INSERT INTO seq SELECT i + $max, x FROM seq;
      }
    }
    lappend ret $i
  }
  set ret
} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16}
do_test shared-$av.3.1.2 {
  # Another linear scan through table seq using a read-uncommitted connection.
  # This time, delete each row as it is read. Should not affect the results of
  # the scan, but the table should be empty after the scan is concluded 
  # (test 3.1.3 verifies this).
  set ret [list]
  db2 eval {SELECT i FROM seq} {
    db eval {DELETE FROM seq WHERE i = $i}
    lappend ret $i
  }
  set ret
} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16}
do_test shared-$av.3.1.3 {
  execsql {
    SELECT * FROM seq;







|













|







209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
  execsql {PRAGMA read_uncommitted = 1} db2

  set ret [list]
  db2 eval {SELECT i FROM seq} {
    if {$i < 4} {
      set max [execsql {SELECT max(i) FROM seq}]
      db eval {
        INSERT INTO seq SELECT i + :max, x FROM seq;
      }
    }
    lappend ret $i
  }
  set ret
} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16}
do_test shared-$av.3.1.2 {
  # Another linear scan through table seq using a read-uncommitted connection.
  # This time, delete each row as it is read. Should not affect the results of
  # the scan, but the table should be empty after the scan is concluded 
  # (test 3.1.3 verifies this).
  set ret [list]
  db2 eval {SELECT i FROM seq} {
    db eval {DELETE FROM seq WHERE i = :i}
    lappend ret $i
  }
  set ret
} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16}
do_test shared-$av.3.1.3 {
  execsql {
    SELECT * FROM seq;
408
409
410
411
412
413
414





415






416
417
418
419



420
421





422






423





424
425
426
427
428
429
430
431
432
433
434
435
    ATTACH 'test1.db' AS test1;
  } db2
} {}
do_test shared-$av.5.1.2 {
  execsql {
    CREATE TABLE test1.t1(a, b);
    CREATE INDEX test1.i1 ON t1(a, b);





    CREATE VIEW test1.v1 AS SELECT * FROM t1;






    CREATE TRIGGER test1.trig1 AFTER INSERT ON t1 BEGIN
      INSERT INTO t1 VALUES(new.a, new.b);
    END;
  } db1



  execsql {
    DROP INDEX i1;





    DROP VIEW v1;






    DROP TRIGGER trig1;





    DROP TABLE t1;
  } db2
} {}
ifcapable compound {
  do_test shared-$av.5.1.2 {
    execsql {
      SELECT * FROM sqlite_master UNION ALL SELECT * FROM test1.sqlite_master
    } db1
  } {}
}

#--------------------------------------------------------------------------







>
>
>
>
>
|
>
>
>
>
>
>
|
|
|
|
>
>
>


>
>
>
>
>
|
>
>
>
>
>
>
|
>
>
>
>
>




|







408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
    ATTACH 'test1.db' AS test1;
  } db2
} {}
do_test shared-$av.5.1.2 {
  execsql {
    CREATE TABLE test1.t1(a, b);
    CREATE INDEX test1.i1 ON t1(a, b);
  } db1
} {}
ifcapable view {
  do_test shared-$av.5.1.3 {
    execsql {
      CREATE VIEW test1.v1 AS SELECT * FROM t1;
    } db1
  } {}
}
ifcapable trigger {
  do_test shared-$av.5.1.4 {
    execsql {
      CREATE TRIGGER test1.trig1 AFTER INSERT ON t1 BEGIN
        INSERT INTO t1 VALUES(new.a, new.b);
      END;
    } db1
  } {}
}
do_test shared-$av.5.1.5 {
  execsql {
    DROP INDEX i1;
  } db2
} {}
ifcapable view {
  do_test shared-$av.5.1.6 {
    execsql {
      DROP VIEW v1;
    } db2
  } {}
}
ifcapable trigger {
  do_test shared-$av.5.1.7 {
    execsql {
      DROP TRIGGER trig1;
    } db2
  } {}
}
do_test shared-$av.5.1.8 {
  execsql {
    DROP TABLE t1;
  } db2
} {}
ifcapable compound {
  do_test shared-$av.5.1.9 {
    execsql {
      SELECT * FROM sqlite_master UNION ALL SELECT * FROM test1.sqlite_master
    } db1
  } {}
}

#--------------------------------------------------------------------------
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
    CREATE TABLE t2(a PRIMARY KEY, b);
  }
  set ::contents {}
  for {set i 0} {$i < 100} {incr i} {
    set a [string repeat "$i " 20]
    set b [string repeat "$i " 20]
    db eval {
      INSERT INTO t1 VALUES($a, $b);
    }
    lappend ::contents [list [expr $i+1] $a $b]
  }
  execsql {
    INSERT INTO t2 SELECT * FROM t1;
    COMMIT;
  }







|







544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
    CREATE TABLE t2(a PRIMARY KEY, b);
  }
  set ::contents {}
  for {set i 0} {$i < 100} {incr i} {
    set a [string repeat "$i " 20]
    set b [string repeat "$i " 20]
    db eval {
      INSERT INTO t1 VALUES(:a, :b);
    }
    lappend ::contents [list [expr $i+1] $a $b]
  }
  execsql {
    INSERT INTO t2 SELECT * FROM t1;
    COMMIT;
  }
576
577
578
579
580
581
582

583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630

631
632
633
634
635
636
637
unset -nocomplain contents

#--------------------------------------------------------------------------
# The following tests try to trick the shared-cache code into assuming
# the wrong encoding for a database.
#
file delete -force test.db test.db-journal

do_test shared-$av.8.1.1 {
  sqlite3 db test.db
  execsql {
    PRAGMA encoding = 'UTF-16';
    SELECT * FROM sqlite_master;
  }
} {}
do_test shared-$av.8.1.2 {
  string range [execsql {PRAGMA encoding;}] 0 end-2
} {UTF-16}
do_test shared-$av.8.1.3 {
  sqlite3 db2 test.db
  execsql {
    PRAGMA encoding = 'UTF-8';
    CREATE TABLE abc(a, b, c);
  } db2
} {}
do_test shared-$av.8.1.4 {
  execsql {
    SELECT * FROM sqlite_master;
  }
} "table abc abc [expr $AUTOVACUUM?3:2] {CREATE TABLE abc(a, b, c)}"
do_test shared-$av.8.1.5 {
  db2 close
  execsql {
    PRAGMA encoding;
  }
} {UTF-8}
file delete -force test2.db test2.db-journal
do_test shared-$av.8.2.1 {
  execsql {
    ATTACH 'test2.db' AS aux;
    SELECT * FROM aux.sqlite_master;
  }
} {}
do_test shared-$av.8.2.2 {
  sqlite3 db2 test2.db
  execsql {
    PRAGMA encoding = 'UTF-16';
    CREATE TABLE def(d, e, f);
  } db2
  string range [execsql {PRAGMA encoding;} db2] 0 end-2
} {UTF-16}
do_test shared-$av.8.2.3 {
  catchsql {
    SELECT * FROM aux.sqlite_master;
  }
} {1 {attached databases must use the same text encoding as main database}}


catch {db close}
catch {db2 close}
file delete -force test.db test2.db

#---------------------------------------------------------------------------
# The following tests - shared-9.* - test interactions between TEMP triggers







>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>







606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
unset -nocomplain contents

#--------------------------------------------------------------------------
# The following tests try to trick the shared-cache code into assuming
# the wrong encoding for a database.
#
file delete -force test.db test.db-journal
ifcapable utf16 {
  do_test shared-$av.8.1.1 {
    sqlite3 db test.db
    execsql {
      PRAGMA encoding = 'UTF-16';
      SELECT * FROM sqlite_master;
    }
  } {}
  do_test shared-$av.8.1.2 {
    string range [execsql {PRAGMA encoding;}] 0 end-2
  } {UTF-16}
  do_test shared-$av.8.1.3 {
    sqlite3 db2 test.db
    execsql {
      PRAGMA encoding = 'UTF-8';
      CREATE TABLE abc(a, b, c);
    } db2
  } {}
  do_test shared-$av.8.1.4 {
    execsql {
      SELECT * FROM sqlite_master;
    }
  } "table abc abc [expr $AUTOVACUUM?3:2] {CREATE TABLE abc(a, b, c)}"
  do_test shared-$av.8.1.5 {
    db2 close
    execsql {
      PRAGMA encoding;
    }
  } {UTF-8}
  file delete -force test2.db test2.db-journal
  do_test shared-$av.8.2.1 {
    execsql {
      ATTACH 'test2.db' AS aux;
      SELECT * FROM aux.sqlite_master;
    }
  } {}
  do_test shared-$av.8.2.2 {
    sqlite3 db2 test2.db
    execsql {
      PRAGMA encoding = 'UTF-16';
      CREATE TABLE def(d, e, f);
    } db2
    string range [execsql {PRAGMA encoding;} db2] 0 end-2
  } {UTF-16}
  do_test shared-$av.8.2.3 {
    catchsql {
      SELECT * FROM aux.sqlite_master;
    }
  } {1 {attached databases must use the same text encoding as main database}}
}

catch {db close}
catch {db2 close}
file delete -force test.db test2.db

#---------------------------------------------------------------------------
# The following tests - shared-9.* - test interactions between TEMP triggers
Changes to test/subquery.test.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 2005 January 19
#
# 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 script is testing correlated subqueries
#
# $Id: subquery.test,v 1.13 2005/09/08 10:37:01 drh Exp $
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable !subquery {
  finish_test













|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 2005 January 19
#
# 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 script is testing correlated subqueries
#
# $Id: subquery.test,v 1.14 2006/01/17 09:35:02 danielk1977 Exp $
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable !subquery {
  finish_test
265
266
267
268
269
270
271









272
273
274
275
276
277
278
      INSERT INTO t1 VALUES(1,2);
      CREATE VIEW v1 AS SELECT b FROM t1 WHERE a>0;
      CREATE TABLE t2(p,q);
      INSERT INTO t2 VALUES(2,9);
      SELECT * FROM v1 WHERE EXISTS(SELECT * FROM t2 WHERE p=v1.b);
    }
  } {2}









}

# Ticket 1084
do_test subquery-3.2 {
  catchsql {
    CREATE TABLE t1(a,b);
    INSERT INTO t1 VALUES(1,2);







>
>
>
>
>
>
>
>
>







265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
      INSERT INTO t1 VALUES(1,2);
      CREATE VIEW v1 AS SELECT b FROM t1 WHERE a>0;
      CREATE TABLE t2(p,q);
      INSERT INTO t2 VALUES(2,9);
      SELECT * FROM v1 WHERE EXISTS(SELECT * FROM t2 WHERE p=v1.b);
    }
  } {2}
} else {
  catchsql { DROP TABLE t1; }
  catchsql { DROP TABLE t2; }
  execsql {
    CREATE TABLE t1(a,b);
    INSERT INTO t1 VALUES(1,2);
    CREATE TABLE t2(p,q);
    INSERT INTO t2 VALUES(2,9);
  }
}

# Ticket 1084
do_test subquery-3.2 {
  catchsql {
    CREATE TABLE t1(a,b);
    INSERT INTO t1 VALUES(1,2);
Changes to test/sync.test.
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests to verify that fsync is disabled when
# pragma synchronous=off even for multi-database commits.
#
# $Id: sync.test,v 1.2 2005/11/25 10:38:22 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

#
# These tests are only applicable on unix when pager pragma are
# enabled.







|







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests to verify that fsync is disabled when
# pragma synchronous=off even for multi-database commits.
#
# $Id: sync.test,v 1.3 2006/01/17 09:35:02 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

#
# These tests are only applicable on unix when pager pragma are
# enabled.
39
40
41
42
43
44
45

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

61
62
63
64
65
66
67
68
69
70
71
72
73
74
75

76
77
78
79
80
81
82
83
84
85
86
87
88
89

90
    CREATE TABLE db2.t2(x,y);
  }
  ifcapable !dirsync {
    incr sqlite_sync_count 2
  }
  set sqlite_sync_count
} 8

do_test sync-1.2 {
  set sqlite_sync_count 0
  execsql {
    PRAGMA main.synchronous=on;
    PRAGMA db2.synchronous=on;
    BEGIN;
    INSERT INTO t1 VALUES(1,2);
    INSERT INTO t2 VALUES(3,4);
    COMMIT;
  }
  ifcapable !dirsync {
    incr sqlite_sync_count 3
  }
  set sqlite_sync_count
} 8

do_test sync-1.3 {
  set sqlite_sync_count 0
  execsql {
    PRAGMA main.synchronous=full;
    PRAGMA db2.synchronous=full;
    BEGIN;
    INSERT INTO t1 VALUES(3,4);
    INSERT INTO t2 VALUES(5,6);
    COMMIT;
  }
  ifcapable !dirsync {
    incr sqlite_sync_count 3
  }
  set sqlite_sync_count
} 10

do_test sync-1.4 {
  set sqlite_sync_count 0
  execsql {
    PRAGMA main.synchronous=off;
    PRAGMA db2.synchronous=off;
    BEGIN;
    INSERT INTO t1 VALUES(5,6);
    INSERT INTO t2 VALUES(7,8);
    COMMIT;
  }
  set sqlite_sync_count
} 0



finish_test







>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>















>
|
|
|
|
|
|
|
|
|
|
|
|
|

>

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
    CREATE TABLE db2.t2(x,y);
  }
  ifcapable !dirsync {
    incr sqlite_sync_count 2
  }
  set sqlite_sync_count
} 8
ifcapable pager_pragmas {
  do_test sync-1.2 {
    set sqlite_sync_count 0
    execsql {
      PRAGMA main.synchronous=on;
      PRAGMA db2.synchronous=on;
      BEGIN;
      INSERT INTO t1 VALUES(1,2);
      INSERT INTO t2 VALUES(3,4);
      COMMIT;
    }
    ifcapable !dirsync {
      incr sqlite_sync_count 3
    }
    set sqlite_sync_count
  } 8
}
do_test sync-1.3 {
  set sqlite_sync_count 0
  execsql {
    PRAGMA main.synchronous=full;
    PRAGMA db2.synchronous=full;
    BEGIN;
    INSERT INTO t1 VALUES(3,4);
    INSERT INTO t2 VALUES(5,6);
    COMMIT;
  }
  ifcapable !dirsync {
    incr sqlite_sync_count 3
  }
  set sqlite_sync_count
} 10
ifcapable pager_pragmas {
  do_test sync-1.4 {
    set sqlite_sync_count 0
    execsql {
      PRAGMA main.synchronous=off;
      PRAGMA db2.synchronous=off;
      BEGIN;
      INSERT INTO t1 VALUES(5,6);
      INSERT INTO t2 VALUES(7,8);
      COMMIT;
    }
    set sqlite_sync_count
  } 0
}


finish_test
Changes to test/tclsqlite.test.
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# This file implements regression tests for TCL interface to the
# SQLite library. 
#
# Actually, all tests are based on the TCL interface, so the main
# interface is pretty well tested.  This file contains some addition
# tests for fringe issues that the main test suite does not cover.
#
# $Id: tclsqlite.test,v 1.49 2006/01/05 15:50:07 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Check the error messages generated by tclsqlite
#
if {[sqlite3 -has-codec]} {







|







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# This file implements regression tests for TCL interface to the
# SQLite library. 
#
# Actually, all tests are based on the TCL interface, so the main
# interface is pretty well tested.  This file contains some addition
# tests for fringe issues that the main test suite does not cover.
#
# $Id: tclsqlite.test,v 1.50 2006/01/17 09:35:02 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Check the error messages generated by tclsqlite
#
if {[sqlite3 -has-codec]} {
331
332
333
334
335
336
337

338
339
340
341
342
343
344
345
346
347
348
349

350
351
352
353
354
355
356
do_test tcl-9.3 {
  db function ret_int {clock seconds}
  execsql {SELECT typeof(ret_int())}
} {integer}

# Recursive calls to the same user-defined function
#

do_test tcl-9.10 {
  proc userfunc_r1 {n} {
    if {$n<=0} {return 0}
    set nm1 [expr {$n-1}]
    return [expr {[db eval {SELECT r1($nm1)}]+$n}]
  }
  db function r1 userfunc_r1
  execsql {SELECT r1(10)}
} {55}
do_test tcl-9.11 {
  execsql {SELECT r1(100)}
} {5050}


# Tests for the new transaction method
#
do_test tcl-10.1 {
  db transaction {}
} {}
do_test tcl-10.2 {







>
|
|
|
|
|
|
|
|
|
|
|
|
>







331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
do_test tcl-9.3 {
  db function ret_int {clock seconds}
  execsql {SELECT typeof(ret_int())}
} {integer}

# Recursive calls to the same user-defined function
#
ifcapable tclvar {
  do_test tcl-9.10 {
    proc userfunc_r1 {n} {
      if {$n<=0} {return 0}
      set nm1 [expr {$n-1}]
      return [expr {[db eval {SELECT r1($nm1)}]+$n}]
    }
    db function r1 userfunc_r1
    execsql {SELECT r1(10)}
  } {55}
  do_test tcl-9.11 {
    execsql {SELECT r1(100)}
  } {5050}
}

# Tests for the new transaction method
#
do_test tcl-10.1 {
  db transaction {}
} {}
do_test tcl-10.2 {
Changes to test/tester.tcl.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 2001 September 15
#
# 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 some common TCL routines used for regression
# testing the SQLite library
#
# $Id: tester.tcl,v 1.60 2006/01/16 12:46:41 danielk1977 Exp $

# Make sure tclsqlite3 was compiled correctly.  Abort now with an
# error message if not.
#
if {[sqlite3 -tcl-uses-utf]} {
  if {"\u1234"=="u1234"} {
    puts stderr "***** BUILD PROBLEM *****"













|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 2001 September 15
#
# 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 some common TCL routines used for regression
# testing the SQLite library
#
# $Id: tester.tcl,v 1.61 2006/01/17 09:35:02 danielk1977 Exp $

# Make sure tclsqlite3 was compiled correctly.  Abort now with an
# error message if not.
#
if {[sqlite3 -tcl-uses-utf]} {
  if {"\u1234"=="u1234"} {
    puts stderr "***** BUILD PROBLEM *****"
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
  exit [expr {$nErr>0}]
}

# A procedure to execute SQL
#
proc execsql {sql {db db}} {
  # puts "SQL = $sql"
  return [$db eval $sql]
}

# Execute SQL and catch exceptions.
#
proc catchsql {sql {db db}} {
  # puts "SQL = $sql"
  set r [catch {$db eval $sql} msg]







|







174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
  exit [expr {$nErr>0}]
}

# A procedure to execute SQL
#
proc execsql {sql {db db}} {
  # puts "SQL = $sql"
  uplevel [list $db eval $sql]
}

# Execute SQL and catch exceptions.
#
proc catchsql {sql {db db}} {
  # puts "SQL = $sql"
  set r [catch {$db eval $sql} msg]
Changes to test/tkt1435.test.
10
11
12
13
14
15
16
17
18
19
20
21




22
23
24
25
26
27
28
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests to verify that ticket #1435 has been
# fixed.  
#
#
# $Id: tkt1435.test,v 1.1 2005/09/17 13:29:24 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl






# Construct the sample database.
#
do_test tkt1435-1.0 {
  sqlite3 db :memory:
  execsql {
    CREATE TABLE Instances(







|




>
>
>
>







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests to verify that ticket #1435 has been
# fixed.  
#
#
# $Id: tkt1435.test,v 1.2 2006/01/17 09:35:02 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable !memorydb {
  finish_test
  return
}

# Construct the sample database.
#
do_test tkt1435-1.0 {
  sqlite3 db :memory:
  execsql {
    CREATE TABLE Instances(
Changes to test/tkt1443.test.
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#
# NOTE:  Yes, in spite of the name of this file (tkt1443.test) this
# test is for ticket #1433 not #1443.  I mistyped the name when I was
# creating the file and I had already checked in the file by the wrong
# name be the time I noticed the error.  With CVS it is a really hassle
# to change filenames, so I'll just leave it as is.  No harm done.
#
# $Id: tkt1443.test,v 1.3 2006/01/14 08:02:29 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable !subquery {
  finish_test
  return
}

# Construct the sample database.
#
do_test tkt1443-1.0 {







|




|







30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#
# NOTE:  Yes, in spite of the name of this file (tkt1443.test) this
# test is for ticket #1433 not #1443.  I mistyped the name when I was
# creating the file and I had already checked in the file by the wrong
# name be the time I noticed the error.  With CVS it is a really hassle
# to change filenames, so I'll just leave it as is.  No harm done.
#
# $Id: tkt1443.test,v 1.4 2006/01/17 09:35:02 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable !subquery||!memorydb {
  finish_test
  return
}

# Construct the sample database.
#
do_test tkt1443-1.0 {
Changes to test/tkt1444.test.
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# This file implements tests to verify that ticket #1444 has been
# fixed.  
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable compound {
  finish_test
  return 
}

# The use of a VIEW that contained an ORDER BY clause within a UNION ALL
# was causing problems.  See ticket #1444.
#







|







13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# This file implements tests to verify that ticket #1444 has been
# fixed.  
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable !compound||!view {
  finish_test
  return 
}

# The use of a VIEW that contained an ORDER BY clause within a UNION ALL
# was causing problems.  See ticket #1444.
#
Changes to test/tkt1449.test.
13
14
15
16
17
18
19
20

21
22
23
24
25
26
27
28
29
# This file implements tests to verify that ticket #1449 has been
# fixed.  
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Somewhere in tkt1449-1.1 is a VIEW definition that uses a subquery.

# So we cannot run this file if subqueries are not available.
ifcapable !subquery {
  finish_test
  return
}

# The following schema generated problems in ticket #1449.  We've retained
# the original schema here because it is some unbelievably complex, it seemed
# like a good test case for SQLite.







|
>
|
|







13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# This file implements tests to verify that ticket #1449 has been
# fixed.  
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Somewhere in tkt1449-1.1 is a VIEW definition that uses a subquery and
# a compound SELECT. So we cannot run this file if any of these features
# are not available.
ifcapable !subquery||!compound||!view {
  finish_test
  return
}

# The following schema generated problems in ticket #1449.  We've retained
# the original schema here because it is some unbelievably complex, it seemed
# like a good test case for SQLite.
Changes to test/tkt1473.test.
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# This file implements tests to verify that ticket #1473 has been
# fixed.  
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable compound {
  finish_test
  return 
}

do_test tkt1473-1.1 {
  execsql {
    CREATE TABLE t1(a,b);







|







13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# This file implements tests to verify that ticket #1473 has been
# fixed.  
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable !compound {
  finish_test
  return 
}

do_test tkt1473-1.1 {
  execsql {
    CREATE TABLE t1(a,b);
Changes to test/tkt1501.test.
12
13
14
15
16
17
18





19
20
21
22
23
24
25
#
# This file implements tests to verify that ticket #1501 is
# fixed.  
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl






do_test tkt1501-1.1 {
  execsql {
    CREATE TABLE t1(a,b);
    INSERT INTO t1 VALUES(1,2);
    SELECT a, b, 'abc' FROM t1
      UNION







>
>
>
>
>







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#
# This file implements tests to verify that ticket #1501 is
# fixed.  
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable !compound {
  finish_test
  return
}

do_test tkt1501-1.1 {
  execsql {
    CREATE TABLE t1(a,b);
    INSERT INTO t1 VALUES(1,2);
    SELECT a, b, 'abc' FROM t1
      UNION
Changes to test/tkt1512.test.
12
13
14
15
16
17
18





19
20
21
22
23
24
25
#
# This file implements tests to verify that ticket #1512 is
# fixed.  
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl






do_test tkt1512-1.1 {
  execsql {
    CREATE TABLE t1(a,b);
    INSERT INTO t1 VALUES(1,2);
    INSERT INTO t1 VALUES(3,4);
    SELECT * FROM t1







>
>
>
>
>







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#
# This file implements tests to verify that ticket #1512 is
# fixed.  
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable !vacuum {
  finish_test
  return
}

do_test tkt1512-1.1 {
  execsql {
    CREATE TABLE t1(a,b);
    INSERT INTO t1 VALUES(1,2);
    INSERT INTO t1 VALUES(3,4);
    SELECT * FROM t1
Changes to test/trans.test.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 2001 September 15
#
# 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 script is database locks.
#
# $Id: trans.test,v 1.27 2005/12/30 16:28:02 danielk1977 Exp $


set testdir [file dirname $argv0]
source $testdir/tester.tcl


# Create several tables to work with.













|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 2001 September 15
#
# 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 script is database locks.
#
# $Id: trans.test,v 1.28 2006/01/17 09:35:03 danielk1977 Exp $


set testdir [file dirname $argv0]
source $testdir/tester.tcl


# Create several tables to work with.
892
893
894
895
896
897
898

899
900
901





902
903
904
905
906
907
         INSERT INTO t3 SELECT randstr(10,400) FROM t3 WHERE random()%10==0;
       }
    } {}
    if {$tcl_platform(platform)=="unix"} {
      do_test trans-9.$i.4-$cnt {
         expr {$sqlite_sync_count>0}
      } 1

      do_test trans-9.$i.5-$cnt {
         expr {$sqlite_fullsync_count>0}
      } [expr {$i%2==0}]





    }
  }
  set ::pager_old_format 0
}
   
finish_test







>
|
|
|
>
>
>
>
>






892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
         INSERT INTO t3 SELECT randstr(10,400) FROM t3 WHERE random()%10==0;
       }
    } {}
    if {$tcl_platform(platform)=="unix"} {
      do_test trans-9.$i.4-$cnt {
         expr {$sqlite_sync_count>0}
      } 1
      ifcapable pager_pragmas {
        do_test trans-9.$i.5-$cnt {
           expr {$sqlite_fullsync_count>0}
        } [expr {$i%2==0}]
      } else {
        do_test trans-9.$i.5-$cnt {
           expr {$sqlite_fullsync_count>0}
        } {1}
      }
    }
  }
  set ::pager_old_format 0
}
   
finish_test
Changes to test/trigger1.test.
438
439
440
441
442
443
444

445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492


493
494
495
496
497
498
499
do_test trigger1-8.6 {
  execsql {
    DROP TRIGGER [trigger];
    SELECT name FROM sqlite_master WHERE type='trigger';
  }
} {}


# Make sure REPLACE works inside of triggers.
#
# There are two versions of trigger-9.1 and trigger-9.2. One that uses
# compound SELECT statements, and another that does not.
ifcapable compound {
do_test trigger1-9.1 {
  execsql {
    CREATE TABLE t3(a,b);
    CREATE TABLE t4(x UNIQUE, b);
    CREATE TRIGGER r34 AFTER INSERT ON t3 BEGIN
      REPLACE INTO t4 VALUES(new.a,new.b);
    END;
    INSERT INTO t3 VALUES(1,2);
    SELECT * FROM t3 UNION ALL SELECT 99, 99 UNION ALL SELECT * FROM t4;
  }
} {1 2 99 99 1 2}
do_test trigger1-9.2 {
  execsql {
    INSERT INTO t3 VALUES(1,3);
    SELECT * FROM t3 UNION ALL SELECT 99, 99 UNION ALL SELECT * FROM t4;
  }
} {1 2 1 3 99 99 1 3}
}
ifcapable !compound {
do_test trigger1-9.1 {
  execsql {
    CREATE TABLE t3(a,b);
    CREATE TABLE t4(x UNIQUE, b);
    CREATE TRIGGER r34 AFTER INSERT ON t3 BEGIN
      REPLACE INTO t4 VALUES(new.a,new.b);
    END;
    INSERT INTO t3 VALUES(1,2);
    SELECT * FROM t3; SELECT 99, 99; SELECT * FROM t4;
  }
} {1 2 99 99 1 2}
do_test trigger1-9.2 {
  execsql {
    INSERT INTO t3 VALUES(1,3);
    SELECT * FROM t3; SELECT 99, 99; SELECT * FROM t4;
  }
} {1 2 1 3 99 99 1 3}
}

execsql {
  DROP TABLE t2;
  DROP TABLE t3;
  DROP TABLE t4;
}



# Ticket #764. At one stage TEMP triggers would fail to re-install when the
# schema was reloaded. The following tests ensure that TEMP triggers are
# correctly re-installed.
#
# Also verify that references within trigger programs are resolved at
# statement compile time, not trigger installation time. This means, for







>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
|
<
|
|
|
>
>







438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468

469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486

487

488
489
490
491
492
493
494
495
496
497
498
499
do_test trigger1-8.6 {
  execsql {
    DROP TRIGGER [trigger];
    SELECT name FROM sqlite_master WHERE type='trigger';
  }
} {}

ifcapable conflict {
  # Make sure REPLACE works inside of triggers.
  #
  # There are two versions of trigger-9.1 and trigger-9.2. One that uses
  # compound SELECT statements, and another that does not.
  ifcapable compound {
    do_test trigger1-9.1 {
      execsql {
        CREATE TABLE t3(a,b);
        CREATE TABLE t4(x UNIQUE, b);
        CREATE TRIGGER r34 AFTER INSERT ON t3 BEGIN
          REPLACE INTO t4 VALUES(new.a,new.b);
        END;
        INSERT INTO t3 VALUES(1,2);
        SELECT * FROM t3 UNION ALL SELECT 99, 99 UNION ALL SELECT * FROM t4;
      }
    } {1 2 99 99 1 2}
    do_test trigger1-9.2 {
      execsql {
        INSERT INTO t3 VALUES(1,3);
        SELECT * FROM t3 UNION ALL SELECT 99, 99 UNION ALL SELECT * FROM t4;
      }
    } {1 2 1 3 99 99 1 3}
  } else {

    do_test trigger1-9.1 {
      execsql {
        CREATE TABLE t3(a,b);
        CREATE TABLE t4(x UNIQUE, b);
        CREATE TRIGGER r34 AFTER INSERT ON t3 BEGIN
          REPLACE INTO t4 VALUES(new.a,new.b);
        END;
        INSERT INTO t3 VALUES(1,2);
        SELECT * FROM t3; SELECT 99, 99; SELECT * FROM t4;
      }
    } {1 2 99 99 1 2}
    do_test trigger1-9.2 {
      execsql {
        INSERT INTO t3 VALUES(1,3);
        SELECT * FROM t3; SELECT 99, 99; SELECT * FROM t4;
      }
    } {1 2 1 3 99 99 1 3}
  }

  execsql {

    DROP TABLE t3;
    DROP TABLE t4;
  }
}


# Ticket #764. At one stage TEMP triggers would fail to re-install when the
# schema was reloaded. The following tests ensure that TEMP triggers are
# correctly re-installed.
#
# Also verify that references within trigger programs are resolved at
# statement compile time, not trigger installation time. This means, for
Changes to test/trigger2.test.
469
470
471
472
473
474
475

476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588

589
590
591
592
593
594
595
  }
  db changes
} {1}
execsql {
  DROP TABLE tbl;
}


# Handling of ON CONFLICT by INSERT statements inside triggers
execsql {
  CREATE TABLE tbl (a primary key, b, c);
  CREATE TRIGGER ai_tbl AFTER INSERT ON tbl BEGIN
    INSERT OR IGNORE INTO tbl values (new.a, 0, 0);
  END;
}
do_test trigger2-6.1a {
  execsql {
    BEGIN;
    INSERT INTO tbl values (1, 2, 3);
    SELECT * from tbl;
  }
} {1 2 3}
do_test trigger2-6.1b {
  catchsql {
    INSERT OR ABORT INTO tbl values (2, 2, 3);
  }
} {1 {column a is not unique}}
do_test trigger2-6.1c {
  execsql {
    SELECT * from tbl;
  }
} {1 2 3}
do_test trigger2-6.1d {
  catchsql {
    INSERT OR FAIL INTO tbl values (2, 2, 3);
  }
} {1 {column a is not unique}}
do_test trigger2-6.1e {
  execsql {
    SELECT * from tbl;
  }
} {1 2 3 2 2 3}
do_test trigger2-6.1f {
  execsql {
    INSERT OR REPLACE INTO tbl values (2, 2, 3);
    SELECT * from tbl;
  }
} {1 2 3 2 0 0}
do_test trigger2-6.1g {
  catchsql {
    INSERT OR ROLLBACK INTO tbl values (3, 2, 3);
  }
} {1 {column a is not unique}}
do_test trigger2-6.1h {
  execsql {
    SELECT * from tbl;
  }
} {}
execsql {DELETE FROM tbl}


# Handling of ON CONFLICT by UPDATE statements inside triggers
execsql {
  INSERT INTO tbl values (4, 2, 3);
  INSERT INTO tbl values (6, 3, 4);
  CREATE TRIGGER au_tbl AFTER UPDATE ON tbl BEGIN
    UPDATE OR IGNORE tbl SET a = new.a, c = 10;
  END;
}
do_test trigger2-6.2a {
  execsql {
    BEGIN;
    UPDATE tbl SET a = 1 WHERE a = 4;
    SELECT * from tbl;
  }
} {1 2 10 6 3 4}
do_test trigger2-6.2b {
  catchsql {
    UPDATE OR ABORT tbl SET a = 4 WHERE a = 1;
  }
} {1 {column a is not unique}}
do_test trigger2-6.2c {
  execsql {
    SELECT * from tbl;
  }
} {1 2 10 6 3 4}
do_test trigger2-6.2d {
  catchsql {
    UPDATE OR FAIL tbl SET a = 4 WHERE a = 1;
  }
} {1 {column a is not unique}}
do_test trigger2-6.2e {
  execsql {
    SELECT * from tbl;
  }
} {4 2 10 6 3 4}
do_test trigger2-6.2f.1 {
  execsql {
    UPDATE OR REPLACE tbl SET a = 1 WHERE a = 4;
    SELECT * from tbl;
  }
} {1 3 10}
do_test trigger2-6.2f.2 {
  execsql {
    INSERT INTO tbl VALUES (2, 3, 4);
    SELECT * FROM tbl;
  }
} {1 3 10 2 3 4}
do_test trigger2-6.2g {
  catchsql {
    UPDATE OR ROLLBACK tbl SET a = 4 WHERE a = 1;
  }
} {1 {column a is not unique}}
do_test trigger2-6.2h {
  execsql {
    SELECT * from tbl;
  }
} {4 2 3 6 3 4}
execsql {
  DROP TABLE tbl;
}


# 7. Triggers on views
ifcapable view {

do_test trigger2-7.1 {
  execsql {
  CREATE TABLE ab(a, b);







>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>







469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
  }
  db changes
} {1}
execsql {
  DROP TABLE tbl;
}

ifcapable conflict {
  # Handling of ON CONFLICT by INSERT statements inside triggers
  execsql {
    CREATE TABLE tbl (a primary key, b, c);
    CREATE TRIGGER ai_tbl AFTER INSERT ON tbl BEGIN
      INSERT OR IGNORE INTO tbl values (new.a, 0, 0);
    END;
  }
  do_test trigger2-6.1a {
    execsql {
      BEGIN;
      INSERT INTO tbl values (1, 2, 3);
      SELECT * from tbl;
    }
  } {1 2 3}
  do_test trigger2-6.1b {
    catchsql {
      INSERT OR ABORT INTO tbl values (2, 2, 3);
    }
  } {1 {column a is not unique}}
  do_test trigger2-6.1c {
    execsql {
      SELECT * from tbl;
    }
  } {1 2 3}
  do_test trigger2-6.1d {
    catchsql {
      INSERT OR FAIL INTO tbl values (2, 2, 3);
    }
  } {1 {column a is not unique}}
  do_test trigger2-6.1e {
    execsql {
      SELECT * from tbl;
    }
  } {1 2 3 2 2 3}
  do_test trigger2-6.1f {
    execsql {
      INSERT OR REPLACE INTO tbl values (2, 2, 3);
      SELECT * from tbl;
    }
  } {1 2 3 2 0 0}
  do_test trigger2-6.1g {
    catchsql {
      INSERT OR ROLLBACK INTO tbl values (3, 2, 3);
    }
  } {1 {column a is not unique}}
  do_test trigger2-6.1h {
    execsql {
      SELECT * from tbl;
    }
  } {}
  execsql {DELETE FROM tbl}
  
  
  # Handling of ON CONFLICT by UPDATE statements inside triggers
  execsql {
    INSERT INTO tbl values (4, 2, 3);
    INSERT INTO tbl values (6, 3, 4);
    CREATE TRIGGER au_tbl AFTER UPDATE ON tbl BEGIN
      UPDATE OR IGNORE tbl SET a = new.a, c = 10;
    END;
  }
  do_test trigger2-6.2a {
    execsql {
      BEGIN;
      UPDATE tbl SET a = 1 WHERE a = 4;
      SELECT * from tbl;
    }
  } {1 2 10 6 3 4}
  do_test trigger2-6.2b {
    catchsql {
      UPDATE OR ABORT tbl SET a = 4 WHERE a = 1;
    }
  } {1 {column a is not unique}}
  do_test trigger2-6.2c {
    execsql {
      SELECT * from tbl;
    }
  } {1 2 10 6 3 4}
  do_test trigger2-6.2d {
    catchsql {
      UPDATE OR FAIL tbl SET a = 4 WHERE a = 1;
    }
  } {1 {column a is not unique}}
  do_test trigger2-6.2e {
    execsql {
      SELECT * from tbl;
    }
  } {4 2 10 6 3 4}
  do_test trigger2-6.2f.1 {
    execsql {
      UPDATE OR REPLACE tbl SET a = 1 WHERE a = 4;
      SELECT * from tbl;
    }
  } {1 3 10}
  do_test trigger2-6.2f.2 {
    execsql {
      INSERT INTO tbl VALUES (2, 3, 4);
      SELECT * FROM tbl;
    }
  } {1 3 10 2 3 4}
  do_test trigger2-6.2g {
    catchsql {
      UPDATE OR ROLLBACK tbl SET a = 4 WHERE a = 1;
    }
  } {1 {column a is not unique}}
  do_test trigger2-6.2h {
    execsql {
      SELECT * from tbl;
    }
  } {4 2 3 6 3 4}
  execsql {
    DROP TABLE tbl;
  }
} ; # ifcapable conflict

# 7. Triggers on views
ifcapable view {

do_test trigger2-7.1 {
  execsql {
  CREATE TABLE ab(a, b);
Changes to test/types3.test.
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#    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 the interaction of SQLite manifest types
# with Tcl dual-representations.
#
# $Id: types3.test,v 1.4 2006/01/16 16:24:25 danielk1977 Exp $
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# A variable with only a string representation comes in as TEXT
do_test types3-1.1 {
  set V {}
  append V {}
  concat [tcl_variable_type V] [execsql {SELECT typeof($::V)}]
} {string text}

# A variable with an integer representation comes in as INTEGER
do_test types3-1.2 {
  set V [expr {1+2}]
  concat [tcl_variable_type V] [execsql {SELECT typeof($::V)}]
} {int integer}
do_test types3-1.3 {
  set V [expr {1+123456789012345}]
  concat [tcl_variable_type V] [execsql {SELECT typeof($::V)}]
} {wideInt integer}

# A double variable comes in as REAL
do_test types3-1.4 {
  set V [expr {1.0+1}]
  concat [tcl_variable_type V] [execsql {SELECT typeof($::V)}]
} {double real}

# A byte-array variable comes in a BLOB if it has no string representation
# or as TEXT if there is a string representation.
#
do_test types3-1.5 {
  set V [binary format a3 abc]
  concat [tcl_variable_type V] [execsql {SELECT typeof($::V)}]
} {bytearray blob}
do_test types3-1.6 {
  set V "abc"
  binary scan $V a3 x
  concat [tcl_variable_type V] [execsql {SELECT typeof($::V)}]
} {bytearray text}

# Check to make sure return values are of the right types.
#
ifcapable bloblit {
  do_test types3-2.1 {
    set V [db one {SELECT x'616263'}]







|









|





|



|





|







|




|







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#    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 the interaction of SQLite manifest types
# with Tcl dual-representations.
#
# $Id: types3.test,v 1.5 2006/01/17 09:35:03 danielk1977 Exp $
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# A variable with only a string representation comes in as TEXT
do_test types3-1.1 {
  set V {}
  append V {}
  concat [tcl_variable_type V] [execsql {SELECT typeof(:V)}]
} {string text}

# A variable with an integer representation comes in as INTEGER
do_test types3-1.2 {
  set V [expr {1+2}]
  concat [tcl_variable_type V] [execsql {SELECT typeof(:V)}]
} {int integer}
do_test types3-1.3 {
  set V [expr {1+123456789012345}]
  concat [tcl_variable_type V] [execsql {SELECT typeof(:V)}]
} {wideInt integer}

# A double variable comes in as REAL
do_test types3-1.4 {
  set V [expr {1.0+1}]
  concat [tcl_variable_type V] [execsql {SELECT typeof(:V)}]
} {double real}

# A byte-array variable comes in a BLOB if it has no string representation
# or as TEXT if there is a string representation.
#
do_test types3-1.5 {
  set V [binary format a3 abc]
  concat [tcl_variable_type V] [execsql {SELECT typeof(:V)}]
} {bytearray blob}
do_test types3-1.6 {
  set V "abc"
  binary scan $V a3 x
  concat [tcl_variable_type V] [execsql {SELECT typeof(:V)}]
} {bytearray text}

# Check to make sure return values are of the right types.
#
ifcapable bloblit {
  do_test types3-2.1 {
    set V [db one {SELECT x'616263'}]
Changes to test/where2.test.
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

32



33
34
35
36
37
38
39
#    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 the use of indices in WHERE clauses
# based on recent changes to the optimizer.
#
# $Id: where2.test,v 1.7 2006/01/16 16:24:25 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Build some test data
#
do_test where2-1.0 {
  execsql {
    BEGIN;
    CREATE TABLE t1(w int, x int, y int, z int);
  }
  for {set i 1} {$i<=100} {incr i} {
    set w $i
    set x [expr {int(log($i)/log(2))}]
    set y [expr {$i*$i + 2*$i + 1}]
    set z [expr {$x+$y}]

    execsql {INSERT INTO t1 VALUES($::w,$::x,$::y,$::z)}



  }
  execsql {
    CREATE UNIQUE INDEX i1w ON t1(w);
    CREATE INDEX i1xy ON t1(x,y);
    CREATE INDEX i1zyx ON t1(z,y,x);
    COMMIT;
  }







|
















>
|
>
>
>







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#    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 the use of indices in WHERE clauses
# based on recent changes to the optimizer.
#
# $Id: where2.test,v 1.8 2006/01/17 09:35:03 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Build some test data
#
do_test where2-1.0 {
  execsql {
    BEGIN;
    CREATE TABLE t1(w int, x int, y int, z int);
  }
  for {set i 1} {$i<=100} {incr i} {
    set w $i
    set x [expr {int(log($i)/log(2))}]
    set y [expr {$i*$i + 2*$i + 1}]
    set z [expr {$x+$y}]
    ifcapable tclvar {
      execsql {INSERT INTO t1 VALUES($::w,$::x,$::y,$::z)}
    } else {
      execsql {INSERT INTO t1 VALUES(:w,:x,:y,:z)}
    }
  }
  execsql {
    CREATE UNIQUE INDEX i1w ON t1(w);
    CREATE INDEX i1xy ON t1(x,y);
    CREATE INDEX i1zyx ON t1(z,y,x);
    COMMIT;
  }