2001-09-16 04:13:26 +04:00
|
|
|
# 2001 September 15
|
2001-04-11 18:29:21 +04:00
|
|
|
#
|
2001-09-16 04:13:26 +04:00
|
|
|
# The author disclaims copyright to this source code. In place of
|
|
|
|
# a legal notice, here is a blessing:
|
2001-04-11 18:29:21 +04:00
|
|
|
#
|
2001-09-16 04:13:26 +04:00
|
|
|
# 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.
|
2001-04-11 18:29:21 +04:00
|
|
|
#
|
|
|
|
#***********************************************************************
|
|
|
|
#
|
2007-08-23 00:18:21 +04:00
|
|
|
# This file attempts to check the behavior of the SQLite library in
|
|
|
|
# an out-of-memory situation. When compiled with -DSQLITE_DEBUG=1,
|
|
|
|
# the SQLite library accepts a special command (sqlite3_memdebug_fail N C)
|
|
|
|
# which causes the N-th malloc to fail. This special feature is used
|
|
|
|
# to see what happens in the library if a malloc were to really fail
|
|
|
|
# due to an out-of-memory situation.
|
|
|
|
#
|
2009-06-24 17:13:45 +04:00
|
|
|
# $Id: malloc.test,v 1.81 2009/06/24 13:13:45 drh Exp $
|
2001-04-11 18:29:21 +04:00
|
|
|
|
|
|
|
set testdir [file dirname $argv0]
|
|
|
|
source $testdir/tester.tcl
|
|
|
|
|
2008-06-19 22:17:49 +04:00
|
|
|
|
2001-04-11 18:29:21 +04:00
|
|
|
# Only run these tests if memory debugging is turned on.
|
|
|
|
#
|
2008-02-19 01:24:57 +03:00
|
|
|
source $testdir/malloc_common.tcl
|
|
|
|
if {!$MEMDEBUG} {
|
2005-12-06 15:52:59 +03:00
|
|
|
puts "Skipping malloc tests: not compiled with -DSQLITE_MEMDEBUG..."
|
2001-04-11 18:29:21 +04:00
|
|
|
finish_test
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2008-01-20 02:50:26 +03:00
|
|
|
# Do a couple of memory dumps just to exercise the memory dump logic
|
|
|
|
# that that we can say that we have.
|
|
|
|
#
|
|
|
|
puts stderr "This is a test. Ignore the error that follows:"
|
|
|
|
sqlite3_memdebug_dump $testdir
|
|
|
|
puts "Memory dump to file memdump.txt..."
|
|
|
|
sqlite3_memdebug_dump memdump.txt
|
|
|
|
|
2007-09-12 21:01:45 +04:00
|
|
|
ifcapable bloblit&&subquery {
|
|
|
|
do_malloc_test 1 -tclprep {
|
|
|
|
db close
|
|
|
|
} -tclbody {
|
|
|
|
if {[catch {sqlite3 db test.db}]} {
|
|
|
|
error "out of memory"
|
|
|
|
}
|
2007-10-03 12:46:44 +04:00
|
|
|
sqlite3_extended_result_codes db 1
|
2007-09-12 21:01:45 +04:00
|
|
|
} -sqlbody {
|
|
|
|
DROP TABLE IF EXISTS t1;
|
|
|
|
CREATE TABLE t1(
|
|
|
|
a int, b float, c double, d text, e varchar(20),
|
|
|
|
primary key(a,b,c)
|
|
|
|
);
|
|
|
|
CREATE INDEX i1 ON t1(a,b);
|
|
|
|
INSERT INTO t1 VALUES(1,2.3,4.5,'hi',x'746865726500');
|
|
|
|
INSERT INTO t1 VALUES(6,7.0,0.8,'hello','out yonder');
|
|
|
|
SELECT * FROM t1;
|
|
|
|
SELECT avg(b) FROM t1 GROUP BY a HAVING b>20.0;
|
|
|
|
DELETE FROM t1 WHERE a IN (SELECT min(a) FROM t1);
|
2007-11-29 01:36:40 +03:00
|
|
|
SELECT count(*), group_concat(e) FROM t1;
|
2008-01-23 18:44:51 +03:00
|
|
|
SELECT b FROM t1 ORDER BY 1 COLLATE nocase;
|
2007-09-12 21:01:45 +04:00
|
|
|
}
|
|
|
|
}
|
2001-04-13 03:21:58 +04:00
|
|
|
|
2004-06-26 17:51:33 +04:00
|
|
|
# Ensure that no file descriptors were leaked.
|
|
|
|
do_test malloc-1.X {
|
|
|
|
catch {db close}
|
|
|
|
set sqlite_open_file_count
|
|
|
|
} {0}
|
|
|
|
|
2007-09-12 21:01:45 +04:00
|
|
|
ifcapable subquery {
|
|
|
|
do_malloc_test 2 -sqlbody {
|
|
|
|
CREATE TABLE t1(a int, b int default 'abc', c int default 1);
|
|
|
|
CREATE INDEX i1 ON t1(a,b);
|
|
|
|
INSERT INTO t1 VALUES(1,1,'99 abcdefghijklmnopqrstuvwxyz');
|
|
|
|
INSERT INTO t1 VALUES(2,4,'98 abcdefghijklmnopqrstuvwxyz');
|
|
|
|
INSERT INTO t1 VALUES(3,9,'97 abcdefghijklmnopqrstuvwxyz');
|
|
|
|
INSERT INTO t1 VALUES(4,16,'96 abcdefghijklmnopqrstuvwxyz');
|
|
|
|
INSERT INTO t1 VALUES(5,25,'95 abcdefghijklmnopqrstuvwxyz');
|
|
|
|
INSERT INTO t1 VALUES(6,36,'94 abcdefghijklmnopqrstuvwxyz');
|
|
|
|
SELECT 'stuff', count(*) as 'other stuff', max(a+10) FROM t1;
|
|
|
|
UPDATE t1 SET b=b||b||b||b;
|
|
|
|
UPDATE t1 SET b=a WHERE a in (10,12,22);
|
|
|
|
INSERT INTO t1(c,b,a) VALUES(20,10,5);
|
|
|
|
INSERT INTO t1 SELECT * FROM t1
|
|
|
|
WHERE a IN (SELECT a FROM t1 WHERE a<10);
|
|
|
|
DELETE FROM t1 WHERE a>=10;
|
|
|
|
DROP INDEX i1;
|
|
|
|
DELETE FROM t1;
|
|
|
|
}
|
|
|
|
}
|
2001-10-22 06:58:08 +04:00
|
|
|
|
2004-06-26 17:51:33 +04:00
|
|
|
# Ensure that no file descriptors were leaked.
|
|
|
|
do_test malloc-2.X {
|
|
|
|
catch {db close}
|
|
|
|
set sqlite_open_file_count
|
|
|
|
} {0}
|
|
|
|
|
2005-01-13 16:35:57 +03:00
|
|
|
do_malloc_test 3 -sqlbody {
|
|
|
|
BEGIN TRANSACTION;
|
|
|
|
CREATE TABLE t1(a int, b int, c int);
|
|
|
|
CREATE INDEX i1 ON t1(a,b);
|
|
|
|
INSERT INTO t1 VALUES(1,1,99);
|
|
|
|
INSERT INTO t1 VALUES(2,4,98);
|
|
|
|
INSERT INTO t1 VALUES(3,9,97);
|
|
|
|
INSERT INTO t1 VALUES(4,16,96);
|
|
|
|
INSERT INTO t1 VALUES(5,25,95);
|
|
|
|
INSERT INTO t1 VALUES(6,36,94);
|
|
|
|
INSERT INTO t1(c,b,a) VALUES(20,10,5);
|
|
|
|
DELETE FROM t1 WHERE a>=10;
|
|
|
|
DROP INDEX i1;
|
|
|
|
DELETE FROM t1;
|
|
|
|
ROLLBACK;
|
|
|
|
}
|
|
|
|
|
2004-06-26 17:51:33 +04:00
|
|
|
|
|
|
|
# Ensure that no file descriptors were leaked.
|
|
|
|
do_test malloc-3.X {
|
|
|
|
catch {db close}
|
|
|
|
set sqlite_open_file_count
|
|
|
|
} {0}
|
|
|
|
|
2007-09-12 21:01:45 +04:00
|
|
|
ifcapable subquery {
|
|
|
|
do_malloc_test 4 -sqlbody {
|
|
|
|
BEGIN TRANSACTION;
|
|
|
|
CREATE TABLE t1(a int, b int, c int);
|
|
|
|
CREATE INDEX i1 ON t1(a,b);
|
|
|
|
INSERT INTO t1 VALUES(1,1,99);
|
|
|
|
INSERT INTO t1 VALUES(2,4,98);
|
|
|
|
INSERT INTO t1 VALUES(3,9,97);
|
|
|
|
INSERT INTO t1 VALUES(4,16,96);
|
|
|
|
INSERT INTO t1 VALUES(5,25,95);
|
|
|
|
INSERT INTO t1 VALUES(6,36,94);
|
|
|
|
UPDATE t1 SET b=a WHERE a in (10,12,22);
|
|
|
|
INSERT INTO t1 SELECT * FROM t1
|
|
|
|
WHERE a IN (SELECT a FROM t1 WHERE a<10);
|
|
|
|
DROP INDEX i1;
|
|
|
|
DELETE FROM t1;
|
|
|
|
COMMIT;
|
|
|
|
}
|
|
|
|
}
|
2004-06-26 17:51:33 +04:00
|
|
|
|
|
|
|
# Ensure that no file descriptors were leaked.
|
|
|
|
do_test malloc-4.X {
|
|
|
|
catch {db close}
|
|
|
|
set sqlite_open_file_count
|
|
|
|
} {0}
|
|
|
|
|
2007-09-12 21:01:45 +04:00
|
|
|
ifcapable trigger {
|
|
|
|
do_malloc_test 5 -sqlbody {
|
|
|
|
BEGIN TRANSACTION;
|
|
|
|
CREATE TABLE t1(a,b);
|
|
|
|
CREATE TABLE t2(x,y);
|
2007-11-16 17:55:46 +03:00
|
|
|
CREATE TRIGGER r1 AFTER INSERT ON t1 WHEN new.a = 2 BEGIN
|
2007-09-12 21:01:45 +04:00
|
|
|
INSERT INTO t2(x,y) VALUES(new.rowid,1);
|
|
|
|
INSERT INTO t2(x,y) SELECT * FROM t2;
|
|
|
|
INSERT INTO t2 SELECT * FROM t2;
|
|
|
|
UPDATE t2 SET y=y+1 WHERE x=new.rowid;
|
|
|
|
SELECT 123;
|
|
|
|
DELETE FROM t2 WHERE x=new.rowid;
|
|
|
|
END;
|
|
|
|
INSERT INTO t1(a,b) VALUES(2,3);
|
|
|
|
COMMIT;
|
|
|
|
}
|
|
|
|
}
|
2004-06-26 17:51:33 +04:00
|
|
|
|
|
|
|
# Ensure that no file descriptors were leaked.
|
|
|
|
do_test malloc-5.X {
|
|
|
|
catch {db close}
|
|
|
|
set sqlite_open_file_count
|
|
|
|
} {0}
|
|
|
|
|
2007-09-12 21:01:45 +04:00
|
|
|
ifcapable vacuum {
|
|
|
|
do_malloc_test 6 -sqlprep {
|
|
|
|
BEGIN TRANSACTION;
|
|
|
|
CREATE TABLE t1(a);
|
|
|
|
INSERT INTO t1 VALUES(1);
|
|
|
|
INSERT INTO t1 SELECT a*2 FROM t1;
|
|
|
|
INSERT INTO t1 SELECT a*2 FROM t1;
|
|
|
|
INSERT INTO t1 SELECT a*2 FROM t1;
|
|
|
|
INSERT INTO t1 SELECT a*2 FROM t1;
|
|
|
|
INSERT INTO t1 SELECT a*2 FROM t1;
|
|
|
|
INSERT INTO t1 SELECT a*2 FROM t1;
|
|
|
|
INSERT INTO t1 SELECT a*2 FROM t1;
|
|
|
|
INSERT INTO t1 SELECT a*2 FROM t1;
|
|
|
|
INSERT INTO t1 SELECT a*2 FROM t1;
|
|
|
|
INSERT INTO t1 SELECT a*2 FROM t1;
|
|
|
|
DELETE FROM t1 where rowid%5 = 0;
|
|
|
|
COMMIT;
|
|
|
|
} -sqlbody {
|
|
|
|
VACUUM;
|
|
|
|
}
|
|
|
|
}
|
2004-06-30 13:49:22 +04:00
|
|
|
|
2009-04-09 05:23:49 +04:00
|
|
|
autoinstall_test_functions
|
2005-01-13 16:35:57 +03:00
|
|
|
do_malloc_test 7 -sqlprep {
|
|
|
|
CREATE TABLE t1(a, b);
|
|
|
|
INSERT INTO t1 VALUES(1, 2);
|
|
|
|
INSERT INTO t1 VALUES(3, 4);
|
|
|
|
INSERT INTO t1 VALUES(5, 6);
|
|
|
|
INSERT INTO t1 VALUES(7, randstr(1200,1200));
|
|
|
|
} -sqlbody {
|
|
|
|
SELECT min(a) FROM t1 WHERE a<6 GROUP BY b;
|
|
|
|
SELECT a FROM t1 WHERE a<6 ORDER BY a;
|
|
|
|
SELECT b FROM t1 WHERE a>6;
|
2007-08-23 00:18:21 +04:00
|
|
|
}
|
2005-01-11 16:02:33 +03:00
|
|
|
|
2005-01-12 10:15:04 +03:00
|
|
|
# This block is designed to test that some malloc failures that may
|
|
|
|
# occur in vdbeapi.c. Specifically, if a malloc failure that occurs
|
|
|
|
# when converting UTF-16 text to integers and real numbers is handled
|
|
|
|
# correctly.
|
|
|
|
#
|
2005-01-12 12:10:39 +03:00
|
|
|
# This is done by retrieving a string from the database engine and
|
|
|
|
# manipulating it using the sqlite3_column_*** APIs. This doesn't
|
|
|
|
# actually return an error to the user when a malloc() fails.. That
|
|
|
|
# could be viewed as a bug.
|
|
|
|
#
|
|
|
|
# These tests only run if UTF-16 support is compiled in.
|
2005-01-12 10:15:04 +03:00
|
|
|
#
|
2007-09-12 21:01:45 +04:00
|
|
|
ifcapable utf16 {
|
2007-08-23 00:18:21 +04:00
|
|
|
set ::STMT {}
|
2005-01-13 16:35:57 +03:00
|
|
|
do_malloc_test 8 -tclprep {
|
|
|
|
set sql "SELECT '[string repeat abc 20]', '[string repeat def 20]', ?"
|
2007-08-23 00:18:21 +04:00
|
|
|
set ::STMT [sqlite3_prepare db $sql -1 X]
|
2005-01-13 16:35:57 +03:00
|
|
|
sqlite3_step $::STMT
|
|
|
|
if { $::tcl_platform(byteOrder)=="littleEndian" } {
|
|
|
|
set ::bomstr "\xFF\xFE"
|
|
|
|
} else {
|
|
|
|
set ::bomstr "\xFE\xFF"
|
|
|
|
}
|
2009-06-06 20:08:22 +04:00
|
|
|
append ::bomstr [encoding convertto unicode "123456789_123456789_123456789"]
|
2005-01-13 16:35:57 +03:00
|
|
|
} -tclbody {
|
|
|
|
sqlite3_column_text16 $::STMT 0
|
|
|
|
sqlite3_column_int $::STMT 0
|
|
|
|
sqlite3_column_text16 $::STMT 1
|
|
|
|
sqlite3_column_double $::STMT 1
|
2007-08-29 16:31:25 +04:00
|
|
|
set rc [sqlite3_reset $::STMT]
|
|
|
|
if {$rc eq "SQLITE_NOMEM"} {error "out of memory"}
|
2005-01-13 16:35:57 +03:00
|
|
|
sqlite3_bind_text16 $::STMT 1 $::bomstr 60
|
2007-08-23 00:18:21 +04:00
|
|
|
#catch {sqlite3_finalize $::STMT}
|
|
|
|
#if {[lindex [sqlite_malloc_stat] 2]<=0} {
|
|
|
|
# error "out of memory"
|
|
|
|
#}
|
2005-01-13 16:35:57 +03:00
|
|
|
} -cleanup {
|
2007-08-23 00:18:21 +04:00
|
|
|
if {$::STMT!=""} {
|
|
|
|
sqlite3_finalize $::STMT
|
|
|
|
set ::STMT {}
|
|
|
|
}
|
2005-01-13 16:35:57 +03:00
|
|
|
}
|
2005-01-12 10:15:04 +03:00
|
|
|
}
|
|
|
|
|
2005-01-12 12:10:39 +03:00
|
|
|
# This block tests that malloc() failures that occur whilst commiting
|
|
|
|
# a multi-file transaction are handled correctly.
|
|
|
|
#
|
2005-01-12 15:44:03 +03:00
|
|
|
do_malloc_test 9 -sqlprep {
|
|
|
|
ATTACH 'test2.db' as test2;
|
|
|
|
CREATE TABLE abc1(a, b, c);
|
|
|
|
CREATE TABLE test2.abc2(a, b, c);
|
|
|
|
} -sqlbody {
|
|
|
|
BEGIN;
|
|
|
|
INSERT INTO abc1 VALUES(1, 2, 3);
|
|
|
|
INSERT INTO abc2 VALUES(1, 2, 3);
|
|
|
|
COMMIT;
|
|
|
|
}
|
2005-01-12 12:10:39 +03:00
|
|
|
|
2005-01-12 15:44:03 +03:00
|
|
|
# This block tests malloc() failures that occur while opening a
|
|
|
|
# connection to a database.
|
2007-09-04 05:25:48 +04:00
|
|
|
do_malloc_test 10 -tclprep {
|
|
|
|
catch {db2 close}
|
|
|
|
db close
|
|
|
|
file delete -force test.db test.db-journal
|
|
|
|
sqlite3 db test.db
|
2007-10-03 12:46:44 +04:00
|
|
|
sqlite3_extended_result_codes db 1
|
2007-09-04 05:25:48 +04:00
|
|
|
db eval {CREATE TABLE abc(a, b, c)}
|
2005-01-12 15:44:03 +03:00
|
|
|
} -tclbody {
|
2007-03-26 16:26:27 +04:00
|
|
|
db close
|
2006-01-17 16:21:40 +03:00
|
|
|
sqlite3 db2 test.db
|
2007-10-03 12:46:44 +04:00
|
|
|
sqlite3_extended_result_codes db2 1
|
2005-01-12 15:44:03 +03:00
|
|
|
db2 eval {SELECT * FROM sqlite_master}
|
|
|
|
db2 close
|
2008-01-16 20:46:38 +03:00
|
|
|
}
|
2005-01-12 15:44:03 +03:00
|
|
|
|
|
|
|
# This block tests malloc() failures that occur within calls to
|
|
|
|
# sqlite3_create_function().
|
2007-08-23 00:18:21 +04:00
|
|
|
do_malloc_test 11 -tclbody {
|
|
|
|
set rc [sqlite3_create_function db]
|
2007-09-03 15:04:22 +04:00
|
|
|
if {[string match $rc SQLITE_OK]} {
|
|
|
|
set rc [sqlite3_create_aggregate db]
|
|
|
|
}
|
2005-01-13 05:14:23 +03:00
|
|
|
if {[string match $rc SQLITE_NOMEM]} {
|
2005-01-12 15:44:03 +03:00
|
|
|
error "out of memory"
|
|
|
|
}
|
2005-01-12 12:10:39 +03:00
|
|
|
}
|
|
|
|
|
2005-01-12 15:44:03 +03:00
|
|
|
do_malloc_test 12 -tclbody {
|
|
|
|
set sql16 [encoding convertto unicode "SELECT * FROM sqlite_master"]
|
|
|
|
append sql16 "\00\00"
|
2007-08-23 00:18:21 +04:00
|
|
|
set ::STMT [sqlite3_prepare16 db $sql16 -1 DUMMY]
|
2005-01-12 15:44:03 +03:00
|
|
|
sqlite3_finalize $::STMT
|
2007-03-26 16:26:27 +04:00
|
|
|
}
|
2005-01-12 12:10:39 +03:00
|
|
|
|
2005-01-13 14:07:52 +03:00
|
|
|
# Test malloc errors when replaying two hot journals from a 2-file
|
2006-01-06 17:32:19 +03:00
|
|
|
# transaction.
|
2007-10-09 12:29:32 +04:00
|
|
|
ifcapable crashtest&&attach {
|
2005-01-13 14:07:52 +03:00
|
|
|
do_malloc_test 13 -tclprep {
|
2007-03-17 13:26:59 +03:00
|
|
|
set rc [crashsql -delay 1 -file test2.db {
|
2005-01-13 14:07:52 +03:00
|
|
|
ATTACH 'test2.db' as aux;
|
|
|
|
PRAGMA cache_size = 10;
|
|
|
|
BEGIN;
|
|
|
|
CREATE TABLE aux.t2(a, b, c);
|
|
|
|
CREATE TABLE t1(a, b, c);
|
|
|
|
COMMIT;
|
|
|
|
}]
|
|
|
|
if {$rc!="1 {child process exited abnormally}"} {
|
|
|
|
error "Wrong error message: $rc"
|
|
|
|
}
|
2006-01-18 08:51:57 +03:00
|
|
|
} -tclbody {
|
|
|
|
db eval {ATTACH 'test2.db' as aux;}
|
|
|
|
set rc [catch {db eval {
|
|
|
|
SELECT * FROM t1;
|
|
|
|
SELECT * FROM t2;
|
|
|
|
}} err]
|
|
|
|
if {$rc && $err!="no such table: t1"} {
|
|
|
|
error $err
|
|
|
|
}
|
2005-01-13 14:07:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-19 06:52:54 +03:00
|
|
|
if {$tcl_platform(platform)!="windows"} {
|
2006-01-18 07:26:07 +03:00
|
|
|
do_malloc_test 14 -tclprep {
|
|
|
|
catch {db close}
|
|
|
|
sqlite3 db2 test2.db
|
2007-10-03 12:46:44 +04:00
|
|
|
sqlite3_extended_result_codes db2 1
|
2006-01-18 07:26:07 +03:00
|
|
|
db2 eval {
|
2010-07-03 14:00:00 +04:00
|
|
|
PRAGMA journal_mode = DELETE; /* For inmemory_journal permutation */
|
2006-01-18 07:26:07 +03:00
|
|
|
PRAGMA synchronous = 0;
|
|
|
|
CREATE TABLE t1(a, b);
|
|
|
|
INSERT INTO t1 VALUES(1, 2);
|
|
|
|
BEGIN;
|
|
|
|
INSERT INTO t1 VALUES(3, 4);
|
|
|
|
}
|
|
|
|
copy_file test2.db test.db
|
|
|
|
copy_file test2.db-journal test.db-journal
|
|
|
|
db2 close
|
|
|
|
} -tclbody {
|
|
|
|
sqlite3 db test.db
|
2007-10-03 12:46:44 +04:00
|
|
|
sqlite3_extended_result_codes db 1
|
2008-09-23 20:41:29 +04:00
|
|
|
|
|
|
|
# If an out-of-memory occurs within a call to a VFS layer function during
|
|
|
|
# hot-journal rollback, sqlite will report SQLITE_CORRUPT. See commit
|
|
|
|
# [5668] for details.
|
|
|
|
set rc [catch {db eval { SELECT * FROM t1 }} msg]
|
|
|
|
if {$msg eq "database disk image is malformed"} { set msg "out of memory" }
|
|
|
|
if {$rc} { error $msg }
|
|
|
|
set msg
|
2005-01-13 14:07:52 +03:00
|
|
|
}
|
|
|
|
}
|
2006-01-18 07:26:07 +03:00
|
|
|
|
|
|
|
proc string_compare {a b} {
|
|
|
|
return [string compare $a $b]
|
|
|
|
}
|
|
|
|
|
|
|
|
# Test for malloc() failures in sqlite3_create_collation() and
|
|
|
|
# sqlite3_create_collation16().
|
2006-01-18 08:51:57 +03:00
|
|
|
#
|
2007-09-12 21:01:45 +04:00
|
|
|
ifcapable utf16 {
|
|
|
|
do_malloc_test 15 -start 4 -tclbody {
|
|
|
|
db collate string_compare string_compare
|
|
|
|
if {[catch {add_test_collate db 1 1 1} msg]} {
|
|
|
|
if {$msg=="SQLITE_NOMEM"} {set msg "out of memory"}
|
|
|
|
error $msg
|
|
|
|
}
|
|
|
|
|
|
|
|
db complete {SELECT "hello """||'world"' [microsoft], * FROM anicetable;}
|
|
|
|
db complete {-- Useful comment}
|
|
|
|
|
|
|
|
execsql {
|
|
|
|
CREATE TABLE t1(a, b COLLATE string_compare);
|
|
|
|
INSERT INTO t1 VALUES(10, 'string');
|
|
|
|
INSERT INTO t1 VALUES(10, 'string2');
|
|
|
|
}
|
2006-01-18 07:26:07 +03:00
|
|
|
}
|
2005-01-19 06:52:54 +03:00
|
|
|
}
|
2005-01-13 14:07:52 +03:00
|
|
|
|
2006-01-18 08:51:57 +03:00
|
|
|
# Also test sqlite3_complete(). There are (currently) no malloc()
|
|
|
|
# calls in this function, but test anyway against future changes.
|
|
|
|
#
|
|
|
|
do_malloc_test 16 -tclbody {
|
|
|
|
db complete {SELECT "hello """||'world"' [microsoft], * FROM anicetable;}
|
|
|
|
db complete {-- Useful comment}
|
|
|
|
db eval {
|
|
|
|
SELECT * FROM sqlite_master;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Test handling of malloc() failures in sqlite3_open16().
|
|
|
|
#
|
2007-09-12 21:01:45 +04:00
|
|
|
ifcapable utf16 {
|
|
|
|
do_malloc_test 17 -tclbody {
|
|
|
|
set DB2 0
|
|
|
|
set STMT 0
|
|
|
|
|
|
|
|
# open database using sqlite3_open16()
|
|
|
|
set filename [encoding convertto unicode test.db]
|
|
|
|
append filename "\x00\x00"
|
|
|
|
set DB2 [sqlite3_open16 $filename -unused]
|
|
|
|
if {0==$DB2} {
|
|
|
|
error "out of memory"
|
|
|
|
}
|
2007-10-03 12:46:44 +04:00
|
|
|
sqlite3_extended_result_codes $DB2 1
|
2007-09-12 21:01:45 +04:00
|
|
|
|
|
|
|
# Prepare statement
|
|
|
|
set rc [catch {sqlite3_prepare $DB2 {SELECT * FROM sqlite_master} -1 X} msg]
|
2007-10-03 12:46:44 +04:00
|
|
|
if {[sqlite3_errcode $DB2] eq "SQLITE_IOERR+12"} {
|
|
|
|
error "out of memory"
|
|
|
|
}
|
2008-08-27 23:01:57 +04:00
|
|
|
if {[regexp ".*automatic extension loading.*" [sqlite3_errmsg $DB2]]} {
|
|
|
|
error "out of memory"
|
|
|
|
}
|
2007-09-12 21:01:45 +04:00
|
|
|
if {$rc} {
|
|
|
|
error [string range $msg 4 end]
|
|
|
|
}
|
|
|
|
set STMT $msg
|
|
|
|
|
|
|
|
# Finalize statement
|
|
|
|
set rc [sqlite3_finalize $STMT]
|
|
|
|
if {$rc!="SQLITE_OK"} {
|
|
|
|
error [sqlite3_errmsg $DB2]
|
|
|
|
}
|
|
|
|
set STMT 0
|
|
|
|
|
|
|
|
# Close database
|
2006-01-18 08:51:57 +03:00
|
|
|
set rc [sqlite3_close $DB2]
|
2007-09-12 21:01:45 +04:00
|
|
|
if {$rc!="SQLITE_OK"} {
|
|
|
|
error [sqlite3_errmsg $DB2]
|
|
|
|
}
|
|
|
|
set DB2 0
|
|
|
|
} -cleanup {
|
|
|
|
if {$STMT!="0"} {
|
|
|
|
sqlite3_finalize $STMT
|
|
|
|
}
|
|
|
|
if {$DB2!="0"} {
|
|
|
|
set rc [sqlite3_close $DB2]
|
|
|
|
}
|
2006-01-18 08:51:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Test handling of malloc() failures in sqlite3_errmsg16().
|
|
|
|
#
|
2007-09-12 21:01:45 +04:00
|
|
|
ifcapable utf16 {
|
2007-10-03 12:46:44 +04:00
|
|
|
do_malloc_test 18 -tclprep {
|
2007-09-12 21:01:45 +04:00
|
|
|
catch {
|
|
|
|
db eval "SELECT [string repeat longcolumnname 10] FROM sqlite_master"
|
2007-10-03 12:46:44 +04:00
|
|
|
}
|
|
|
|
} -tclbody {
|
2007-09-12 21:01:45 +04:00
|
|
|
set utf16 [sqlite3_errmsg16 [sqlite3_connection_pointer db]]
|
|
|
|
binary scan $utf16 c* bytes
|
|
|
|
if {[llength $bytes]==0} {
|
|
|
|
error "out of memory"
|
|
|
|
}
|
2006-01-18 08:51:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-24 13:58:21 +03:00
|
|
|
# This test is aimed at coverage testing. Specificly, it is supposed to
|
|
|
|
# cause a malloc() only used when converting between the two utf-16
|
|
|
|
# encodings to fail (i.e. little-endian->big-endian). It only actually
|
|
|
|
# hits this malloc() on little-endian hosts.
|
|
|
|
#
|
|
|
|
set static_string "\x00h\x00e\x00l\x00l\x00o"
|
|
|
|
for {set l 0} {$l<10} {incr l} {
|
|
|
|
append static_string $static_string
|
|
|
|
}
|
|
|
|
append static_string "\x00\x00"
|
|
|
|
do_malloc_test 19 -tclprep {
|
|
|
|
execsql {
|
|
|
|
PRAGMA encoding = "UTF16be";
|
|
|
|
CREATE TABLE abc(a, b, c);
|
|
|
|
}
|
|
|
|
} -tclbody {
|
|
|
|
unset -nocomplain ::STMT
|
|
|
|
set r [catch {
|
2007-08-23 00:18:21 +04:00
|
|
|
set ::STMT [sqlite3_prepare db {SELECT ?} -1 DUMMY]
|
2006-01-24 13:58:21 +03:00
|
|
|
sqlite3_bind_text16 -static $::STMT 1 $static_string 112
|
|
|
|
} msg]
|
|
|
|
if {$r} {error [string range $msg 4 end]}
|
|
|
|
set msg
|
|
|
|
} -cleanup {
|
|
|
|
if {[info exists ::STMT]} {
|
|
|
|
sqlite3_finalize $::STMT
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unset static_string
|
|
|
|
|
2006-04-05 15:57:37 +04:00
|
|
|
# Make sure SQLITE_NOMEM is reported out on an ATTACH failure even
|
|
|
|
# when the malloc failure occurs within the nested parse.
|
|
|
|
#
|
2007-10-09 12:29:32 +04:00
|
|
|
ifcapable attach {
|
|
|
|
do_malloc_test 20 -tclprep {
|
|
|
|
db close
|
|
|
|
file delete -force test2.db test2.db-journal
|
|
|
|
sqlite3 db test2.db
|
|
|
|
sqlite3_extended_result_codes db 1
|
|
|
|
db eval {CREATE TABLE t1(x);}
|
|
|
|
db close
|
|
|
|
} -tclbody {
|
|
|
|
if {[catch {sqlite3 db test.db}]} {
|
|
|
|
error "out of memory"
|
|
|
|
}
|
|
|
|
sqlite3_extended_result_codes db 1
|
|
|
|
} -sqlbody {
|
|
|
|
ATTACH DATABASE 'test2.db' AS t2;
|
|
|
|
SELECT * FROM t1;
|
|
|
|
DETACH DATABASE t2;
|
|
|
|
}
|
|
|
|
}
|
2006-04-05 15:57:37 +04:00
|
|
|
|
2007-03-30 11:10:50 +04:00
|
|
|
# Test malloc failure whilst installing a foreign key.
|
2007-03-29 21:07:52 +04:00
|
|
|
#
|
2007-09-12 21:01:45 +04:00
|
|
|
ifcapable foreignkey {
|
|
|
|
do_malloc_test 21 -sqlbody {
|
|
|
|
CREATE TABLE abc(a, b, c, FOREIGN KEY(a) REFERENCES abc(b))
|
|
|
|
}
|
|
|
|
}
|
2007-03-29 21:07:52 +04:00
|
|
|
|
2007-04-19 15:09:01 +04:00
|
|
|
# Test malloc failure in an sqlite3_prepare_v2() call.
|
|
|
|
#
|
|
|
|
do_malloc_test 22 -tclbody {
|
|
|
|
set ::STMT ""
|
|
|
|
set r [catch {
|
|
|
|
set ::STMT [
|
2007-08-23 00:18:21 +04:00
|
|
|
sqlite3_prepare_v2 db "SELECT * FROM sqlite_master" -1 DUMMY
|
2007-04-19 15:09:01 +04:00
|
|
|
]
|
|
|
|
} msg]
|
|
|
|
if {$r} {error [string range $msg 4 end]}
|
|
|
|
} -cleanup {
|
|
|
|
if {$::STMT ne ""} {
|
|
|
|
sqlite3_finalize $::STMT
|
|
|
|
set ::STMT ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-03 19:02:40 +04:00
|
|
|
ifcapable {pager_pragmas} {
|
|
|
|
# This tests a special case - that an error that occurs while the pager
|
|
|
|
# is trying to recover from error-state in exclusive-access mode works.
|
|
|
|
#
|
|
|
|
do_malloc_test 23 -tclprep {
|
|
|
|
db eval {
|
|
|
|
PRAGMA cache_size = 10;
|
|
|
|
PRAGMA locking_mode = exclusive;
|
|
|
|
BEGIN;
|
|
|
|
CREATE TABLE abc(a, b, c);
|
|
|
|
CREATE INDEX abc_i ON abc(a, b, c);
|
|
|
|
INSERT INTO abc
|
|
|
|
VALUES(randstr(100,100), randstr(100,100), randstr(100,100));
|
|
|
|
INSERT INTO abc
|
|
|
|
SELECT randstr(100,100), randstr(100,100), randstr(100,100) FROM abc;
|
|
|
|
INSERT INTO abc
|
|
|
|
SELECT randstr(100,100), randstr(100,100), randstr(100,100) FROM abc;
|
|
|
|
INSERT INTO abc
|
|
|
|
SELECT randstr(100,100), randstr(100,100), randstr(100,100) FROM abc;
|
|
|
|
INSERT INTO abc
|
|
|
|
SELECT randstr(100,100), randstr(100,100), randstr(100,100) FROM abc;
|
|
|
|
INSERT INTO abc
|
|
|
|
SELECT randstr(100,100), randstr(100,100), randstr(100,100) FROM abc;
|
|
|
|
COMMIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
# This puts the pager into error state.
|
|
|
|
#
|
|
|
|
db eval BEGIN
|
|
|
|
db eval {UPDATE abc SET a = 0 WHERE oid%2}
|
|
|
|
set ::sqlite_io_error_pending 10
|
|
|
|
catch {db eval {ROLLBACK}} msg
|
|
|
|
|
2008-09-23 20:41:29 +04:00
|
|
|
} -tclbody {
|
|
|
|
# If an out-of-memory occurs within a call to a VFS layer function during
|
|
|
|
# hot-journal rollback, sqlite will report SQLITE_CORRUPT. See commit
|
|
|
|
# [5668] for details.
|
|
|
|
set rc [catch {db eval { SELECT * FROM abc LIMIT 10 }} msg]
|
|
|
|
if {$msg eq "database disk image is malformed"} { set msg "out of memory" }
|
|
|
|
if {$rc} { error $msg }
|
|
|
|
set msg
|
2007-10-03 19:02:40 +04:00
|
|
|
} -cleanup {
|
|
|
|
set e [db eval {PRAGMA integrity_check}]
|
|
|
|
if {$e ne "ok"} {error $e}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-23 20:13:40 +03:00
|
|
|
ifcapable compound {
|
2008-01-24 17:27:44 +03:00
|
|
|
do_malloc_test 24 -sqlprep {
|
2008-01-23 20:13:40 +03:00
|
|
|
CREATE TABLE t1(a, b, c)
|
|
|
|
} -sqlbody {
|
|
|
|
SELECT 1 FROM t1 UNION SELECT 2 FROM t1 ORDER BY 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-24 17:27:44 +03:00
|
|
|
ifcapable view&&trigger {
|
|
|
|
do_malloc_test 25 -sqlprep {
|
|
|
|
CREATE TABLE t1(a, b, c);
|
|
|
|
CREATE VIEW v1 AS SELECT * FROM t1;
|
|
|
|
CREATE TRIGGER v1t1 INSTEAD OF DELETE ON v1 BEGIN SELECT 1; END;
|
|
|
|
CREATE TRIGGER v1t2 INSTEAD OF INSERT ON v1 BEGIN SELECT 1; END;
|
|
|
|
CREATE TRIGGER v1t3 INSTEAD OF UPDATE ON v1 BEGIN SELECT 1; END;
|
|
|
|
} -sqlbody {
|
|
|
|
DELETE FROM v1 WHERE a = 1;
|
|
|
|
INSERT INTO v1 VALUES(1, 2, 3);
|
|
|
|
UPDATE v1 SET a = 1 WHERE b = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-07 18:56:56 +04:00
|
|
|
do_malloc_test 25 -sqlprep {
|
|
|
|
CREATE TABLE abc(a, b, c);
|
|
|
|
CREATE INDEX i1 ON abc(a, b);
|
|
|
|
INSERT INTO abc VALUES(1, 2, 3);
|
|
|
|
INSERT INTO abc VALUES(4, 5, 6);
|
|
|
|
} -tclbody {
|
|
|
|
# For each UPDATE executed, the cursor used for the SELECT statement
|
|
|
|
# must be "saved". Because the cursor is open on an index, this requires
|
|
|
|
# a malloc() to allocate space to save the index key. This test case is
|
|
|
|
# aimed at testing the response of the library to a failure in that
|
|
|
|
# particular malloc() call.
|
|
|
|
db eval {SELECT a FROM abc ORDER BY a} {
|
|
|
|
db eval {UPDATE abc SET b = b - 1 WHERE a = $a}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-05 09:02:46 +04:00
|
|
|
# This test is designed to test a specific juncture in the sqlite code.
|
|
|
|
# The database set up by -sqlprep script contains a single table B-Tree
|
|
|
|
# of height 2. In the -tclbody script, the existing database connection
|
|
|
|
# is closed and a new one opened and used to insert a new row into the
|
|
|
|
# table B-Tree. By using a new connection, the outcome of a malloc()
|
|
|
|
# failure while seeking to the right-hand side of the B-Tree to insert
|
|
|
|
# a new record can be tested.
|
|
|
|
#
|
|
|
|
do_malloc_test 26 -sqlprep {
|
|
|
|
BEGIN;
|
|
|
|
CREATE TABLE t1(a, b);
|
|
|
|
INSERT INTO t1 VALUES(1, randomblob(210));
|
|
|
|
INSERT INTO t1 VALUES(1, randomblob(210));
|
|
|
|
INSERT INTO t1 VALUES(1, randomblob(210));
|
|
|
|
INSERT INTO t1 VALUES(1, randomblob(210));
|
|
|
|
INSERT INTO t1 VALUES(1, randomblob(210));
|
|
|
|
COMMIT;
|
|
|
|
} -tclbody {
|
|
|
|
db close
|
|
|
|
sqlite3 db test.db
|
|
|
|
db eval { INSERT INTO t1 VALUES(1, randomblob(210)) }
|
|
|
|
}
|
|
|
|
|
2008-09-22 21:22:19 +04:00
|
|
|
# Test that no memory is leaked following a malloc() failure in
|
|
|
|
# sqlite3_initialize().
|
|
|
|
#
|
|
|
|
do_malloc_test 27 -tclprep {
|
|
|
|
db close
|
|
|
|
sqlite3_shutdown
|
|
|
|
} -tclbody {
|
|
|
|
set rc [sqlite3_initialize]
|
|
|
|
if {$rc == "SQLITE_NOMEM"} {
|
|
|
|
error "out of memory"
|
|
|
|
}
|
|
|
|
}
|
2009-04-09 05:23:49 +04:00
|
|
|
autoinstall_test_functions
|
2008-09-22 21:22:19 +04:00
|
|
|
|
2008-10-06 09:32:18 +04:00
|
|
|
# Test that malloc failures that occur while processing INDEXED BY
|
|
|
|
# clauses are handled correctly.
|
|
|
|
do_malloc_test 28 -sqlprep {
|
|
|
|
CREATE TABLE t1(a, b);
|
|
|
|
CREATE INDEX i1 ON t1(a);
|
|
|
|
CREATE VIEW v1 AS SELECT * FROM t1 INDEXED BY i1 WHERE a = 10;
|
|
|
|
} -sqlbody {
|
|
|
|
SELECT * FROM t1 INDEXED BY i1 ORDER BY a;
|
|
|
|
SELECT * FROM v1;
|
|
|
|
}
|
|
|
|
|
2008-11-03 12:39:45 +03:00
|
|
|
do_malloc_test 29 -sqlprep {
|
|
|
|
CREATE TABLE t1(a TEXT, b TEXT);
|
|
|
|
} -sqlbody {
|
|
|
|
INSERT INTO t1 VALUES(1, -234);
|
2008-11-21 12:43:20 +03:00
|
|
|
INSERT INTO t1 SELECT * FROM t1 UNION ALL SELECT * FROM t1;
|
2008-11-03 12:39:45 +03:00
|
|
|
}
|
|
|
|
|
2009-01-10 19:15:09 +03:00
|
|
|
do_malloc_test 30 -tclprep {
|
2009-01-10 14:10:18 +03:00
|
|
|
db eval {
|
|
|
|
CREATE TABLE t1(x PRIMARY KEY);
|
|
|
|
INSERT INTO t1 VALUES(randstr(500,500));
|
|
|
|
INSERT INTO t1 VALUES(randstr(500,500));
|
|
|
|
INSERT INTO t1 VALUES(randstr(500,500));
|
|
|
|
}
|
|
|
|
db close
|
|
|
|
sqlite3 db test.db
|
|
|
|
|
|
|
|
# The DELETE command in the following block moves the overflow pages that
|
|
|
|
# are part of the primary key index to the free-list. But it does not
|
|
|
|
# actually load the content of the pages. This leads to the peculiar
|
|
|
|
# situation where cache entries exist, but are not populated with data.
|
|
|
|
# They are populated next time they are requested by the b-tree layer.
|
|
|
|
#
|
|
|
|
db eval {
|
|
|
|
BEGIN;
|
|
|
|
DELETE FROM t1;
|
|
|
|
ROLLBACK;
|
|
|
|
}
|
|
|
|
} -sqlbody {
|
2009-01-10 14:13:39 +03:00
|
|
|
-- This statement requires the 'no-content' pages loaded by the DELETE
|
|
|
|
-- statement above. When requesting the pages, the content is loaded
|
|
|
|
-- from the database file. The point of this test case is to test handling
|
|
|
|
-- of malloc errors (including SQLITE_IOERR_NOMEM errors) when loading
|
|
|
|
-- the content.
|
2009-01-10 14:10:18 +03:00
|
|
|
SELECT * FROM t1 ORDER BY x;
|
|
|
|
}
|
|
|
|
|
2009-01-10 19:15:09 +03:00
|
|
|
# After committing a transaction in persistent-journal mode, if a journal
|
|
|
|
# size limit is configured SQLite may attempt to truncate the journal file.
|
|
|
|
# This test verifies the libraries response to a malloc() failure during
|
|
|
|
# this operation.
|
|
|
|
#
|
|
|
|
do_malloc_test 31 -sqlprep {
|
|
|
|
PRAGMA journal_mode = persist;
|
|
|
|
PRAGMA journal_size_limit = 1024;
|
|
|
|
CREATE TABLE t1(a PRIMARY KEY, b);
|
|
|
|
} -sqlbody {
|
|
|
|
INSERT INTO t1 VALUES(1, 2);
|
|
|
|
}
|
2008-11-21 12:43:20 +03:00
|
|
|
|
2009-01-16 19:40:14 +03:00
|
|
|
# When written, this test provoked an obscure change-counter bug.
|
|
|
|
#
|
|
|
|
# If, when running in exclusive mode, a malloc() failure occurs
|
|
|
|
# after the database file change-counter has been written but
|
|
|
|
# before the transaction has been committed, then the transaction
|
|
|
|
# is automatically rolled back. However, internally the
|
|
|
|
# Pager.changeCounterDone flag was being left set. This means
|
|
|
|
# that if the same connection attempts another transaction following
|
|
|
|
# the malloc failure and rollback, the change counter will not
|
|
|
|
# be updated. This could corrupt another processes cache.
|
|
|
|
#
|
|
|
|
do_malloc_test 32 -tclprep {
|
|
|
|
# Build a small database containing an indexed table.
|
|
|
|
#
|
|
|
|
db eval {
|
2009-02-04 11:17:57 +03:00
|
|
|
PRAGMA locking_mode = normal;
|
2009-01-16 19:40:14 +03:00
|
|
|
BEGIN;
|
|
|
|
CREATE TABLE t1(a PRIMARY KEY, b);
|
|
|
|
INSERT INTO t1 VALUES(1, 'one');
|
|
|
|
INSERT INTO t1 VALUES(2, 'two');
|
|
|
|
INSERT INTO t1 VALUES(3, 'three');
|
|
|
|
COMMIT;
|
|
|
|
PRAGMA locking_mode = exclusive;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Open a second database connection. Load the table (but not index)
|
|
|
|
# into the second connections pager cache.
|
|
|
|
#
|
|
|
|
sqlite3 db2 test.db
|
2009-02-04 11:17:57 +03:00
|
|
|
db2 eval {
|
|
|
|
PRAGMA locking_mode = normal;
|
|
|
|
SELECT b FROM t1;
|
|
|
|
}
|
2009-01-16 19:40:14 +03:00
|
|
|
|
|
|
|
} -tclbody {
|
|
|
|
# Running in exclusive mode, perform a database transaction that
|
|
|
|
# modifies both the database table and index. For iterations where
|
|
|
|
# the malloc failure occurs after updating the change counter but
|
|
|
|
# before committing the transaction, this should result in the
|
|
|
|
# transaction being rolled back but the changeCounterDone flag
|
|
|
|
# left set.
|
|
|
|
#
|
|
|
|
db eval { UPDATE t1 SET a = a + 3 }
|
|
|
|
} -cleanup {
|
|
|
|
|
|
|
|
# Perform another transaction using the first connection. Unlock
|
|
|
|
# the database after doing so. If this is one of the right iterations,
|
|
|
|
# then this should result in the database contents being updated but
|
|
|
|
# the change-counter left as it is.
|
|
|
|
#
|
|
|
|
db eval {
|
|
|
|
PRAGMA locking_mode = normal;
|
|
|
|
UPDATE t1 SET a = a + 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Now do an integrity check with the second connection. The second
|
|
|
|
# connection still has the database table in its cache. If this is
|
|
|
|
# one of the magic iterations and the change counter was not modified,
|
|
|
|
# then it won't realize that the cached data is out of date. Since
|
|
|
|
# the cached data won't match the up to date index data read from
|
|
|
|
# the database file, the integrity check should fail.
|
|
|
|
#
|
|
|
|
set zRepeat "transient"
|
|
|
|
if {$::iRepeat} {set zRepeat "persistent"}
|
|
|
|
do_test malloc-32.$zRepeat.${::n}.integrity {
|
|
|
|
execsql {PRAGMA integrity_check} db2
|
|
|
|
} {ok}
|
|
|
|
db2 close
|
|
|
|
}
|
|
|
|
|
2009-02-25 11:56:47 +03:00
|
|
|
# The following two OOM tests verify that OOM handling works in the
|
|
|
|
# code used to optimize "SELECT count(*) FROM <tbl>".
|
|
|
|
#
|
|
|
|
do_malloc_test 33 -tclprep {
|
|
|
|
db eval { PRAGMA cache_size = 10 }
|
|
|
|
db transaction {
|
|
|
|
db eval { CREATE TABLE abc(a, b) }
|
|
|
|
for {set i 0} {$i<500} {incr i} {
|
|
|
|
db eval {INSERT INTO abc VALUES(randstr(100,100), randstr(1000,1000))}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} -sqlbody {
|
|
|
|
SELECT count(*) FROM abc;
|
|
|
|
}
|
|
|
|
do_malloc_test 34 -tclprep {
|
|
|
|
db eval { PRAGMA cache_size = 10 }
|
|
|
|
db transaction {
|
|
|
|
db eval { CREATE TABLE abc(a PRIMARY KEY, b) }
|
|
|
|
for {set i 0} {$i<500} {incr i} {
|
|
|
|
db eval {INSERT INTO abc VALUES(randstr(100,100), randstr(1000,1000))}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} -sqlbody {
|
|
|
|
SELECT count(*) FROM abc;
|
|
|
|
}
|
|
|
|
|
2009-03-19 21:51:06 +03:00
|
|
|
proc f {args} { error "Quite a long error!" }
|
|
|
|
do_malloc_test 35 -tclprep {
|
|
|
|
db func f f
|
|
|
|
set ::STMT [sqlite3_prepare db "SELECT f()" -1 DUMMY]
|
|
|
|
sqlite3_step $::STMT
|
|
|
|
} -tclbody {
|
|
|
|
sqlite3_finalize $::STMT
|
|
|
|
} -cleanup {
|
|
|
|
# At one point an assert( !db->mallocFailed ) could fail in the following
|
|
|
|
# call to sqlite3_errmsg(). Because sqlite3_finalize() had failed to clear
|
|
|
|
# the flag before returning.
|
|
|
|
sqlite3_errmsg16 db
|
|
|
|
}
|
|
|
|
|
|
|
|
do_malloc_test 36 -sqlprep {
|
|
|
|
CREATE TABLE t1(a, b);
|
|
|
|
INSERT INTO t1 VALUES(1, 2);
|
|
|
|
INSERT INTO t1 VALUES(3, 4);
|
|
|
|
} -sqlbody {
|
|
|
|
SELECT test_agg_errmsg16(), group_concat(a) FROM t1
|
|
|
|
}
|
|
|
|
|
2009-06-22 09:43:24 +04:00
|
|
|
# At one point, if an OOM occured immediately after obtaining a shared lock
|
|
|
|
# on the database file, the file remained locked. This test case ensures
|
2009-06-24 17:13:45 +04:00
|
|
|
# that bug has been fixed.i
|
|
|
|
if {[db eval {PRAGMA locking_mode}]!="exclusive"} {
|
|
|
|
do_malloc_test 37 -tclprep {
|
|
|
|
sqlite3 db2 test.db
|
|
|
|
execsql {
|
|
|
|
CREATE TABLE t1(a, b);
|
|
|
|
INSERT INTO t1 VALUES(1, 2);
|
|
|
|
} db2
|
|
|
|
} -sqlbody {
|
|
|
|
SELECT * FROM t1;
|
|
|
|
} -cleanup {
|
|
|
|
# Try to write to the database using connection [db2]. If connection [db]
|
|
|
|
# has correctly released the shared lock, this write attempt should
|
|
|
|
# succeed. If [db] has not released the lock, this should hit an
|
|
|
|
# SQLITE_BUSY error.
|
|
|
|
do_test malloc-36.$zRepeat.${::n}.unlocked {
|
|
|
|
execsql {INSERT INTO t1 VALUES(3, 4)} db2
|
|
|
|
} {}
|
|
|
|
db2 close
|
|
|
|
}
|
|
|
|
catch { db2 close }
|
2009-06-22 09:43:24 +04:00
|
|
|
}
|
|
|
|
|
2011-04-05 06:21:04 +04:00
|
|
|
ifcapable stat2&&utf16 {
|
2009-08-19 18:34:54 +04:00
|
|
|
do_malloc_test 38 -tclprep {
|
|
|
|
add_test_collate db 0 0 1
|
|
|
|
execsql {
|
|
|
|
ANALYZE;
|
|
|
|
CREATE TABLE t4(x COLLATE test_collate);
|
|
|
|
CREATE INDEX t4x ON t4(x);
|
|
|
|
INSERT INTO sqlite_stat2 VALUES('t4', 't4x', 0, 'aaa');
|
|
|
|
INSERT INTO sqlite_stat2 VALUES('t4', 't4x', 1, 'aaa');
|
|
|
|
INSERT INTO sqlite_stat2 VALUES('t4', 't4x', 2, 'aaa');
|
|
|
|
INSERT INTO sqlite_stat2 VALUES('t4', 't4x', 3, 'aaa');
|
|
|
|
INSERT INTO sqlite_stat2 VALUES('t4', 't4x', 4, 'aaa');
|
|
|
|
INSERT INTO sqlite_stat2 VALUES('t4', 't4x', 5, 'aaa');
|
|
|
|
INSERT INTO sqlite_stat2 VALUES('t4', 't4x', 6, 'aaa');
|
|
|
|
INSERT INTO sqlite_stat2 VALUES('t4', 't4x', 7, 'aaa');
|
|
|
|
INSERT INTO sqlite_stat2 VALUES('t4', 't4x', 8, 'aaa');
|
|
|
|
INSERT INTO sqlite_stat2 VALUES('t4', 't4x', 9, 'aaa');
|
|
|
|
}
|
|
|
|
db close
|
|
|
|
sqlite3 db test.db
|
|
|
|
sqlite3_db_config_lookaside db 0 0 0
|
|
|
|
add_test_collate db 0 0 1
|
|
|
|
} -sqlbody {
|
|
|
|
SELECT * FROM t4 AS t41, t4 AS t42 WHERE t41.x>'ddd' AND t42.x>'ccc'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-14 18:18:45 +04:00
|
|
|
# Test that if an OOM error occurs, aux-data is still correctly destroyed.
|
|
|
|
# This test case was causing either a memory-leak or an assert() failure
|
|
|
|
# at one point, depending on the configuration.
|
|
|
|
#
|
|
|
|
do_malloc_test 39 -tclprep {
|
|
|
|
sqlite3 db test.db
|
|
|
|
} -sqlbody {
|
|
|
|
SELECT test_auxdata('abc', 'def');
|
|
|
|
} -cleanup {
|
|
|
|
db close
|
|
|
|
}
|
|
|
|
|
2004-06-30 13:49:22 +04:00
|
|
|
# Ensure that no file descriptors were leaked.
|
2005-01-12 10:15:04 +03:00
|
|
|
do_test malloc-99.X {
|
2004-06-30 13:49:22 +04:00
|
|
|
catch {db close}
|
|
|
|
set sqlite_open_file_count
|
|
|
|
} {0}
|
|
|
|
|
2006-06-26 16:50:09 +04:00
|
|
|
puts open-file-count=$sqlite_open_file_count
|
2001-04-11 18:29:21 +04:00
|
|
|
finish_test
|