2007-03-29 16:19:11 +04:00
|
|
|
# 2006 September 4
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
2009-07-16 22:21:17 +04:00
|
|
|
# $Id: misc7.test,v 1.29 2009/07/16 18:21:18 drh Exp $
|
2007-03-29 16:19:11 +04:00
|
|
|
|
|
|
|
set testdir [file dirname $argv0]
|
|
|
|
source $testdir/tester.tcl
|
2018-01-10 14:56:03 +03:00
|
|
|
set testprefix misc7
|
2007-03-29 16:19:11 +04:00
|
|
|
|
2014-01-23 18:44:08 +04:00
|
|
|
if {[clang_sanitize_address]==0} {
|
|
|
|
do_test misc7-1-misuse {
|
|
|
|
c_misuse_test
|
|
|
|
} {}
|
|
|
|
}
|
2007-03-29 16:19:11 +04:00
|
|
|
|
|
|
|
do_test misc7-2 {
|
|
|
|
c_realloc_test
|
|
|
|
} {}
|
|
|
|
|
|
|
|
do_test misc7-3 {
|
|
|
|
c_collation_test
|
|
|
|
} {}
|
|
|
|
|
2007-03-29 21:07:52 +04:00
|
|
|
# Try to open a directory:
|
|
|
|
#
|
|
|
|
do_test misc7-4 {
|
2011-08-02 04:57:34 +04:00
|
|
|
delete_file mydir
|
2007-03-29 21:07:52 +04:00
|
|
|
file mkdir mydir
|
|
|
|
set rc [catch {
|
|
|
|
sqlite3 db2 ./mydir
|
|
|
|
} msg]
|
|
|
|
list $rc $msg
|
|
|
|
} {1 {unable to open database file}}
|
|
|
|
|
2007-12-14 00:54:09 +03:00
|
|
|
# Try to open a file with a directory where its journal file should be.
|
2007-03-29 21:07:52 +04:00
|
|
|
#
|
2018-01-23 17:01:51 +03:00
|
|
|
if {[atomic_batch_write test.db]==0} {
|
|
|
|
do_test misc7-5 {
|
|
|
|
delete_file mydir
|
|
|
|
file mkdir mydir-journal
|
|
|
|
sqlite3 db2 ./mydir
|
|
|
|
catchsql {
|
|
|
|
CREATE TABLE abc(a, b, c);
|
|
|
|
} db2
|
|
|
|
} {1 {unable to open database file}}
|
|
|
|
db2 close
|
|
|
|
}
|
2007-03-29 21:07:52 +04:00
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
# The following tests, misc7-6.* test the libraries behaviour when
|
|
|
|
# it cannot open a file. To force this condition, we use up all the
|
|
|
|
# file-descriptors before running sqlite. This probably only works
|
|
|
|
# on unix.
|
|
|
|
#
|
|
|
|
|
|
|
|
proc use_up_files {} {
|
|
|
|
set ret [list]
|
|
|
|
catch {
|
|
|
|
while 1 { lappend ret [open test.db] }
|
|
|
|
}
|
|
|
|
return $ret
|
|
|
|
}
|
|
|
|
|
2007-03-30 21:11:12 +04:00
|
|
|
proc do_fileopen_test {prefix sql} {
|
|
|
|
set fd_list [use_up_files]
|
|
|
|
set ::go 1
|
|
|
|
set ::n 1
|
|
|
|
set ::sql $sql
|
|
|
|
while {$::go} {
|
|
|
|
catch {db close}
|
|
|
|
do_test ${prefix}.${::n} {
|
|
|
|
set rc [catch {
|
|
|
|
sqlite db test.db
|
|
|
|
db eval $::sql
|
|
|
|
} msg]
|
|
|
|
if {$rc == 0} {set ::go 0}
|
|
|
|
|
|
|
|
expr {$rc == 0 || ($rc == 1 && [string first unable $msg]==0)}
|
|
|
|
} 1
|
|
|
|
|
|
|
|
close [lindex $fd_list 0]
|
|
|
|
set fd_list [lrange $fd_list 1 end]
|
|
|
|
incr ::n
|
|
|
|
}
|
|
|
|
foreach fd $fd_list {
|
|
|
|
close $fd
|
|
|
|
}
|
|
|
|
db close
|
|
|
|
}
|
|
|
|
|
2007-03-29 21:07:52 +04:00
|
|
|
execsql { CREATE TABLE abc(a PRIMARY KEY, b, c); }
|
|
|
|
db close
|
2007-03-30 21:11:12 +04:00
|
|
|
|
2007-04-25 19:42:25 +04:00
|
|
|
if {$tcl_platform(platform)!="windows"} {
|
|
|
|
do_fileopen_test misc7-6.1 {
|
|
|
|
BEGIN;
|
|
|
|
INSERT INTO abc VALUES(1, 2, 3);
|
|
|
|
INSERT INTO abc VALUES(2, 3, 4);
|
|
|
|
INSERT INTO abc SELECT a+2, b, c FROM abc;
|
|
|
|
COMMIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
do_fileopen_test misc7-6.2 {
|
|
|
|
PRAGMA temp.cache_size = 1000;
|
|
|
|
}
|
2007-03-29 21:07:52 +04:00
|
|
|
}
|
2007-03-30 21:11:12 +04:00
|
|
|
|
2007-03-30 11:10:50 +04:00
|
|
|
#
|
|
|
|
# End of tests for out-of-file-descriptors condition.
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
|
2007-03-30 17:01:32 +04:00
|
|
|
sqlite3 db test.db
|
2007-04-25 19:42:25 +04:00
|
|
|
execsql {
|
|
|
|
DELETE FROM abc;
|
|
|
|
INSERT INTO abc VALUES(1, 2, 3);
|
|
|
|
INSERT INTO abc VALUES(2, 3, 4);
|
|
|
|
INSERT INTO abc SELECT a+2, b, c FROM abc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-30 11:10:50 +04:00
|
|
|
#--------------------------------------------------------------------
|
|
|
|
# Test that the sqlite3_busy_timeout call seems to delay approximately
|
|
|
|
# the right amount of time.
|
|
|
|
#
|
2007-03-30 21:11:12 +04:00
|
|
|
do_test misc7-7.0 {
|
2007-03-30 11:10:50 +04:00
|
|
|
sqlite3 db2 test.db
|
|
|
|
sqlite3_busy_timeout [sqlite3_connection_pointer db] 2000
|
|
|
|
execsql {
|
|
|
|
BEGIN EXCLUSIVE;
|
|
|
|
} db2
|
|
|
|
|
|
|
|
# Now db2 has an exclusive lock on the database file, and db has
|
|
|
|
# a busy-timeout of 2000 milliseconds. So check that trying to
|
|
|
|
# access the database using connection db delays for at least 1500 ms.
|
|
|
|
#
|
2007-03-30 17:01:32 +04:00
|
|
|
set tm [time {
|
|
|
|
set result [catchsql {
|
|
|
|
SELECT * FROM sqlite_master;
|
|
|
|
} db]
|
|
|
|
}]
|
|
|
|
set delay [lindex $tm 0] ;# In microseconds
|
2007-04-25 19:42:25 +04:00
|
|
|
lappend result [expr {$delay>1500000 && $delay<4000000}]
|
2007-03-30 17:01:32 +04:00
|
|
|
} {1 {database is locked} 1}
|
2007-03-30 11:10:50 +04:00
|
|
|
db2 close
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
# Test that nothing goes horribly wrong when attaching a database
|
|
|
|
# after the omit_readlock pragma has been exercised.
|
|
|
|
#
|
2012-01-17 19:29:14 +04:00
|
|
|
# Note: The PRAGMA omit_readlock was an early hack to disable the
|
|
|
|
# fcntl() calls for read-only databases so that read-only databases could
|
|
|
|
# be read on broken NFS systems. That pragma has now been removed.
|
|
|
|
# (Use the unix-none VFS as a replacement, if needed.) But these tests
|
|
|
|
# do not really depend on omit_readlock, so we left them in place.
|
|
|
|
#
|
2007-03-30 13:13:13 +04:00
|
|
|
do_test misc7-7.1 {
|
2011-08-02 04:57:34 +04:00
|
|
|
forcedelete test2.db
|
|
|
|
forcedelete test2.db-journal
|
2007-03-30 11:10:50 +04:00
|
|
|
execsql {
|
|
|
|
PRAGMA omit_readlock = 1;
|
|
|
|
ATTACH 'test2.db' AS aux;
|
|
|
|
CREATE TABLE aux.hello(world);
|
|
|
|
SELECT name FROM aux.sqlite_master;
|
|
|
|
}
|
|
|
|
} {hello}
|
2007-03-30 13:13:13 +04:00
|
|
|
do_test misc7-7.2 {
|
|
|
|
execsql {
|
|
|
|
DETACH aux;
|
|
|
|
}
|
|
|
|
} {}
|
2009-01-09 20:11:04 +03:00
|
|
|
do_test misc7-7.3 {
|
|
|
|
db close
|
|
|
|
sqlite3 db test.db -readonly 1
|
|
|
|
execsql {
|
|
|
|
PRAGMA omit_readlock = 1;
|
|
|
|
ATTACH 'test2.db' AS aux;
|
|
|
|
SELECT name FROM aux.sqlite_master;
|
|
|
|
SELECT name FROM aux.sqlite_master;
|
|
|
|
}
|
|
|
|
} {hello hello}
|
|
|
|
do_test misc7-7.3 {
|
|
|
|
db close
|
|
|
|
sqlite3 db test.db
|
|
|
|
set ::DB [sqlite3_connection_pointer db]
|
|
|
|
list
|
|
|
|
} {}
|
2007-03-30 11:10:50 +04:00
|
|
|
|
2007-04-02 09:07:47 +04:00
|
|
|
# Test the UTF-16 version of the "out of memory" message (used when
|
|
|
|
# malloc fails during sqlite3_open() ).
|
2007-03-30 11:10:50 +04:00
|
|
|
#
|
|
|
|
ifcapable utf16 {
|
|
|
|
do_test misc7-8 {
|
|
|
|
encoding convertfrom unicode [sqlite3_errmsg16 0x00000000]
|
|
|
|
} {out of memory}
|
|
|
|
}
|
|
|
|
|
2007-03-30 13:13:13 +04:00
|
|
|
do_test misc7-9 {
|
|
|
|
execsql {
|
|
|
|
SELECT *
|
|
|
|
FROM (SELECT name+1 AS one FROM sqlite_master LIMIT 1 OFFSET 1)
|
|
|
|
WHERE one LIKE 'hello%';
|
|
|
|
}
|
|
|
|
} {}
|
2007-03-30 11:10:50 +04:00
|
|
|
|
2007-03-30 13:13:13 +04:00
|
|
|
#--------------------------------------------------------------------
|
2007-03-30 18:56:34 +04:00
|
|
|
# Improve coverage for vtab code.
|
2007-03-30 13:13:13 +04:00
|
|
|
#
|
|
|
|
ifcapable vtab {
|
2007-03-30 18:56:34 +04:00
|
|
|
# Run some debug code to improve reported coverage
|
|
|
|
#
|
|
|
|
|
|
|
|
# set sqlite_where_trace 1
|
2007-03-30 13:13:13 +04:00
|
|
|
do_test misc7-10 {
|
|
|
|
register_echo_module [sqlite3_connection_pointer db]
|
|
|
|
execsql {
|
|
|
|
CREATE VIRTUAL TABLE t1 USING echo(abc);
|
|
|
|
SELECT a FROM t1 WHERE a = 1 ORDER BY b;
|
|
|
|
}
|
|
|
|
} {1}
|
2007-03-30 18:56:34 +04:00
|
|
|
set sqlite_where_trace 0
|
2019-01-05 02:39:37 +03:00
|
|
|
do_catchsql_test misc7-10.1 {
|
|
|
|
INSERT INTO t1(a,b,c) VALUES(12345,2,3) ON CONFLICT(a) DO NOTHING;
|
|
|
|
} {1 {UPSERT not implemented for virtual table "t1"}}
|
2007-03-30 18:56:34 +04:00
|
|
|
|
|
|
|
# Specify an ORDER BY clause that cannot be indexed.
|
|
|
|
do_test misc7-11 {
|
|
|
|
execsql {
|
|
|
|
SELECT t1.a, t2.a FROM t1, t1 AS t2 ORDER BY 2 LIMIT 1;
|
|
|
|
}
|
|
|
|
} {1 1}
|
|
|
|
|
|
|
|
# The whole point of this is to test an error code other than
|
|
|
|
# SQLITE_NOMEM from the vtab xBestIndex callback.
|
|
|
|
#
|
|
|
|
do_ioerr_test misc7-12 -tclprep {
|
|
|
|
sqlite3 db2 test.db
|
|
|
|
register_echo_module [sqlite3_connection_pointer db2]
|
|
|
|
db2 eval {
|
|
|
|
CREATE TABLE abc(a PRIMARY KEY, b, c);
|
|
|
|
INSERT INTO abc VALUES(1, 2, 3);
|
|
|
|
CREATE VIRTUAL TABLE t1 USING echo(abc);
|
|
|
|
}
|
|
|
|
db2 close
|
|
|
|
} -tclbody {
|
|
|
|
register_echo_module [sqlite3_connection_pointer db]
|
|
|
|
execsql {SELECT * FROM t1 WHERE a = 1;}
|
|
|
|
}
|
|
|
|
|
|
|
|
# The case where the virtual table module returns a very large number
|
|
|
|
# as the cost of a scan (greater than SQLITE_BIG_DOUBLE in the code).
|
|
|
|
#
|
|
|
|
do_test misc7-13 {
|
|
|
|
sqlite3 db test.db
|
|
|
|
register_echo_module [sqlite3_connection_pointer db]
|
|
|
|
set ::echo_module_cost 2.0e+99
|
|
|
|
execsql {SELECT * FROM t1 WHERE a = 1;}
|
|
|
|
} {1 2 3}
|
|
|
|
unset ::echo_module_cost
|
2007-03-30 13:13:13 +04:00
|
|
|
}
|
2007-03-29 21:07:52 +04:00
|
|
|
|
2007-03-30 21:11:12 +04:00
|
|
|
db close
|
2011-08-02 04:57:34 +04:00
|
|
|
forcedelete test.db
|
|
|
|
forcedelete test.db-journal
|
2007-03-30 21:11:12 +04:00
|
|
|
sqlite3 db test.db
|
|
|
|
|
|
|
|
ifcapable explain {
|
2018-05-29 17:06:55 +03:00
|
|
|
do_execsql_test misc7-14.0 {
|
2010-12-02 09:08:53 +03:00
|
|
|
CREATE TABLE abc(a PRIMARY KEY, b, c);
|
|
|
|
}
|
2018-05-29 17:06:55 +03:00
|
|
|
do_eqp_test misc7-14.1 {
|
|
|
|
SELECT * FROM abc AS t2 WHERE rowid = 1;
|
|
|
|
} {
|
|
|
|
QUERY PLAN
|
2021-03-23 22:39:27 +03:00
|
|
|
`--SEARCH t2 USING INTEGER PRIMARY KEY (rowid=?)
|
2018-05-29 17:06:55 +03:00
|
|
|
}
|
|
|
|
do_eqp_test misc7-14.2 {
|
|
|
|
SELECT * FROM abc AS t2 WHERE a = 1;
|
|
|
|
} {
|
|
|
|
QUERY PLAN
|
2021-03-23 22:39:27 +03:00
|
|
|
`--SEARCH t2 USING INDEX sqlite_autoindex_abc_1 (a=?)
|
2018-05-29 17:06:55 +03:00
|
|
|
}
|
|
|
|
do_eqp_test misc7-14.3 {
|
|
|
|
SELECT * FROM abc AS t2 ORDER BY a;
|
|
|
|
} {
|
|
|
|
QUERY PLAN
|
2021-03-23 22:39:27 +03:00
|
|
|
`--SCAN t2 USING INDEX sqlite_autoindex_abc_1
|
2018-05-29 17:06:55 +03:00
|
|
|
}
|
2007-03-30 21:11:12 +04:00
|
|
|
}
|
2007-03-30 18:56:34 +04:00
|
|
|
|
2007-03-30 22:21:52 +04:00
|
|
|
db close
|
2011-08-02 04:57:34 +04:00
|
|
|
forcedelete test.db
|
|
|
|
forcedelete test.db-journal
|
2007-03-30 22:21:52 +04:00
|
|
|
sqlite3 db test.db
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------
|
|
|
|
# This is all to force the pager_remove_from_stmt_list() function
|
|
|
|
# (inside pager.c) to remove a pager from the middle of the
|
|
|
|
# statement-list.
|
|
|
|
#
|
|
|
|
do_test misc7-15.1 {
|
|
|
|
execsql {
|
|
|
|
PRAGMA cache_size = 10;
|
|
|
|
BEGIN;
|
|
|
|
CREATE TABLE abc(a PRIMARY KEY, 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;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
expr {[file size test.db]>10240}
|
|
|
|
} {1}
|
|
|
|
do_test misc7-15.2 {
|
|
|
|
execsql {
|
|
|
|
DELETE FROM abc WHERE rowid > 12;
|
|
|
|
INSERT INTO abc SELECT
|
|
|
|
randstr(100,100), randstr(100,100), randstr(100,100) FROM abc;
|
|
|
|
}
|
|
|
|
} {}
|
|
|
|
|
2007-03-31 14:00:48 +04:00
|
|
|
db close
|
2011-08-02 04:57:34 +04:00
|
|
|
forcedelete test.db
|
|
|
|
forcedelete test.db-journal
|
2007-03-31 14:00:48 +04:00
|
|
|
sqlite3 db test.db
|
|
|
|
|
|
|
|
do_ioerr_test misc7-16 -sqlprep {
|
|
|
|
PRAGMA cache_size = 10;
|
|
|
|
PRAGMA default_cache_size = 10;
|
|
|
|
CREATE TABLE t3(a, b, UNIQUE(a, b));
|
|
|
|
INSERT INTO t3 VALUES( randstr(100, 100), randstr(100, 100) );
|
|
|
|
INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3;
|
|
|
|
INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3;
|
|
|
|
INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3;
|
|
|
|
INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3;
|
|
|
|
INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3;
|
|
|
|
UPDATE t3
|
|
|
|
SET b = 'hello world'
|
|
|
|
WHERE rowid >= (SELECT max(rowid)-1 FROM t3);
|
|
|
|
} -tclbody {
|
|
|
|
set rc [catch {db eval {
|
|
|
|
BEGIN;
|
|
|
|
PRAGMA cache_size = 10;
|
|
|
|
INSERT INTO t3 VALUES( randstr(100, 100), randstr(100, 100) );
|
|
|
|
UPDATE t3 SET a = b;
|
|
|
|
COMMIT;
|
|
|
|
}} msg]
|
|
|
|
|
2013-11-16 16:56:46 +04:00
|
|
|
if {!$rc || ($rc && [string first "UNIQUE" $msg]==0)} {
|
2007-03-31 14:00:48 +04:00
|
|
|
set msg
|
|
|
|
} else {
|
|
|
|
error $msg
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-02 09:07:47 +04:00
|
|
|
sqlite3 db test.db
|
2007-04-02 15:08:58 +04:00
|
|
|
|
|
|
|
do_test misc7-16.X {
|
|
|
|
execsql {
|
|
|
|
SELECT count(*) FROM t3;
|
|
|
|
}
|
|
|
|
} {32}
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
# Test the situation where a hot-journal is discovered but write-access
|
|
|
|
# to it is denied. This should return SQLITE_BUSY.
|
|
|
|
#
|
2007-04-25 19:42:25 +04:00
|
|
|
# These tests do not work on windows due to restrictions in the
|
|
|
|
# windows file system.
|
|
|
|
#
|
2012-06-21 19:09:20 +04:00
|
|
|
if {$tcl_platform(platform)!="windows"} {
|
2007-04-02 15:08:58 +04:00
|
|
|
|
2008-03-15 17:53:04 +03:00
|
|
|
# Some network filesystems (ex: AFP) do not support setting read-only
|
|
|
|
# permissions. Only run these tests if full unix permission setting
|
|
|
|
# capabilities are supported.
|
|
|
|
#
|
|
|
|
file attributes test.db -permissions rw-r--r--
|
|
|
|
if {[file attributes test.db -permissions]==0644} {
|
|
|
|
|
|
|
|
do_test misc7-17.1 {
|
|
|
|
execsql {
|
|
|
|
BEGIN;
|
|
|
|
DELETE FROM t3 WHERE (oid%3)==0;
|
|
|
|
}
|
2011-08-02 04:57:34 +04:00
|
|
|
forcecopy test.db bak.db
|
|
|
|
forcecopy test.db-journal bak.db-journal
|
2008-03-15 17:53:04 +03:00
|
|
|
execsql {
|
|
|
|
COMMIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
db close
|
2011-08-02 04:57:34 +04:00
|
|
|
forcecopy bak.db test.db
|
|
|
|
forcecopy bak.db-journal test.db-journal
|
2008-03-15 17:53:04 +03:00
|
|
|
sqlite3 db test.db
|
|
|
|
|
|
|
|
catch {file attributes test.db-journal -permissions r--------}
|
|
|
|
catch {file attributes test.db-journal -readonly 1}
|
|
|
|
catchsql {
|
|
|
|
SELECT count(*) FROM t3;
|
|
|
|
}
|
2008-10-30 18:03:15 +03:00
|
|
|
} {1 {unable to open database file}}
|
2008-03-15 17:53:04 +03:00
|
|
|
do_test misc7-17.2 {
|
|
|
|
# Note that the -readonly flag must be cleared before the -permissions
|
|
|
|
# are set. Otherwise, when using tcl 8.5 on mac, the fact that the
|
|
|
|
# -readonly flag is set causes the attempt to set the permissions
|
|
|
|
# to fail.
|
|
|
|
catch {file attributes test.db-journal -readonly 0}
|
|
|
|
catch {file attributes test.db-journal -permissions rw-------}
|
|
|
|
catchsql {
|
|
|
|
SELECT count(*) FROM t3;
|
|
|
|
}
|
|
|
|
} {0 32}
|
|
|
|
|
2009-02-10 08:45:41 +03:00
|
|
|
# sqlite3_test_control_pending_page [expr ($::sqlite_pending_byte / 1024) + 1]
|
|
|
|
set ::pending_byte_page [expr ($::sqlite_pending_byte / 1024) + 1]
|
|
|
|
sqlite3_test_control_pending_byte $::sqlite_pending_byte
|
2008-03-15 17:53:04 +03:00
|
|
|
do_test misc7-17.3 {
|
2018-11-07 17:41:08 +03:00
|
|
|
sqlite3_db_config db DEFENSIVE 0
|
2008-03-15 17:53:04 +03:00
|
|
|
db eval {
|
|
|
|
pragma writable_schema = true;
|
|
|
|
UPDATE sqlite_master
|
|
|
|
SET rootpage = $pending_byte_page
|
|
|
|
WHERE type = 'table' AND name = 't3';
|
|
|
|
}
|
|
|
|
execsql {
|
|
|
|
SELECT rootpage FROM sqlite_master WHERE type = 'table' AND name = 't3';
|
|
|
|
}
|
|
|
|
} $::pending_byte_page
|
|
|
|
|
|
|
|
do_test misc7-17.4 {
|
|
|
|
db close
|
|
|
|
sqlite3 db test.db
|
|
|
|
catchsql {
|
|
|
|
SELECT count(*) FROM t3;
|
|
|
|
}
|
2020-08-10 13:43:43 +03:00
|
|
|
} {1 {malformed database schema (t3) - invalid rootpage}}
|
2007-04-02 16:28:27 +04:00
|
|
|
}
|
2007-04-25 19:42:25 +04:00
|
|
|
}
|
2007-04-02 16:28:27 +04:00
|
|
|
|
2007-06-28 03:52:18 +04:00
|
|
|
# Ticket #2470
|
|
|
|
#
|
2020-08-10 13:43:43 +03:00
|
|
|
reset_db
|
2007-06-28 03:52:18 +04:00
|
|
|
do_test misc7-18.1 {
|
|
|
|
execsql {
|
|
|
|
CREATE TABLE table_1 (col_10);
|
|
|
|
CREATE TABLE table_2 (
|
|
|
|
col_1, col_2, col_3, col_4, col_5,
|
|
|
|
col_6, col_7, col_8, col_9, col_10
|
|
|
|
);
|
2008-07-11 17:53:54 +04:00
|
|
|
SELECT a.col_10
|
2007-06-28 03:52:18 +04:00
|
|
|
FROM
|
2008-07-11 17:53:54 +04:00
|
|
|
(SELECT table_1.col_10 AS col_10 FROM table_1) a,
|
2007-06-28 03:52:18 +04:00
|
|
|
(SELECT table_1.col_10, table_2.col_9 AS qcol_9
|
|
|
|
FROM table_1, table_2
|
|
|
|
GROUP BY table_1.col_10, qcol_9);
|
|
|
|
}
|
|
|
|
} {}
|
|
|
|
|
2008-07-09 20:51:51 +04:00
|
|
|
# Testing boundary conditions on sqlite3_status()
|
|
|
|
#
|
|
|
|
do_test misc7-19.1 {
|
|
|
|
sqlite3_status -1 0
|
|
|
|
} {21 0 0}
|
|
|
|
do_test misc7-19.2 {
|
|
|
|
sqlite3_status 1000 0
|
|
|
|
} {21 0 0}
|
|
|
|
|
|
|
|
|
2008-08-01 19:06:30 +04:00
|
|
|
# sqlite3_global_recover() is a no-op. But we might as well test it
|
|
|
|
# if only to get the test coverage.
|
|
|
|
#
|
|
|
|
do_test misc7-20.1 {
|
|
|
|
sqlite3_global_recover
|
|
|
|
} {SQLITE_OK}
|
|
|
|
|
2009-01-09 20:11:04 +03:00
|
|
|
# Try to open a really long file name.
|
|
|
|
#
|
|
|
|
do_test misc7-21.1 {
|
2012-03-09 00:00:36 +04:00
|
|
|
set zFile [file join [get_pwd] "[string repeat abcde 104].db"]
|
2009-01-09 20:11:04 +03:00
|
|
|
set rc [catch {sqlite3 db2 $zFile} msg]
|
|
|
|
list $rc $msg
|
|
|
|
} {1 {unable to open database file}}
|
|
|
|
|
2013-03-05 19:09:25 +04:00
|
|
|
# Try to do hot-journal rollback with a read-only connection. The
|
|
|
|
# error code should be SQLITE_READONLY_ROLLBACK.
|
|
|
|
#
|
|
|
|
do_test misc7-22.1 {
|
|
|
|
db close
|
|
|
|
forcedelete test.db copy.db-journal
|
|
|
|
sqlite3 db test.db
|
|
|
|
execsql {
|
|
|
|
CREATE TABLE t1(a, b);
|
|
|
|
INSERT INTO t1 VALUES(1, 2);
|
|
|
|
INSERT INTO t1 VALUES(3, 4);
|
|
|
|
}
|
|
|
|
db close
|
|
|
|
sqlite3 db test.db -readonly 1
|
|
|
|
catchsql {
|
|
|
|
INSERT INTO t1 VALUES(5, 6);
|
|
|
|
}
|
|
|
|
} {1 {attempt to write a readonly database}}
|
|
|
|
do_test misc7-22.2 { execsql { SELECT * FROM t1 } } {1 2 3 4}
|
|
|
|
do_test misc7-22.3 {
|
|
|
|
set fd [open test.db-journal w]
|
|
|
|
puts $fd [string repeat abc 1000]
|
|
|
|
close $fd
|
|
|
|
catchsql { SELECT * FROM t1 }
|
|
|
|
} {1 {attempt to write a readonly database}}
|
|
|
|
do_test misc7-22.4 {
|
|
|
|
sqlite3_extended_errcode db
|
|
|
|
} SQLITE_READONLY_ROLLBACK
|
2018-01-10 14:56:03 +03:00
|
|
|
catch { db close }
|
2011-08-02 04:57:34 +04:00
|
|
|
forcedelete test.db
|
2007-04-02 15:08:58 +04:00
|
|
|
|
2018-01-23 17:01:51 +03:00
|
|
|
if {$::tcl_platform(platform)=="unix"
|
|
|
|
&& [atomic_batch_write test.db]==0
|
|
|
|
} {
|
2018-01-10 14:56:03 +03:00
|
|
|
reset_db
|
|
|
|
do_execsql_test 23.0 {
|
|
|
|
CREATE TABLE t1(x, y);
|
|
|
|
INSERT INTO t1 VALUES(1, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
do_test 23.1 {
|
|
|
|
db close
|
|
|
|
forcedelete tst
|
|
|
|
file mkdir tst
|
|
|
|
forcecopy test.db tst/test.db
|
|
|
|
file attributes tst -permissions r-xr-xr-x
|
|
|
|
} {}
|
|
|
|
|
|
|
|
sqlite3 db tst/test.db
|
|
|
|
do_execsql_test 23.2 {
|
|
|
|
SELECT * FROM t1;
|
|
|
|
} {1 2}
|
|
|
|
|
|
|
|
do_catchsql_test 23.3 {
|
|
|
|
INSERT INTO t1 VALUES(3, 4);
|
|
|
|
} {1 {attempt to write a readonly database}}
|
|
|
|
|
|
|
|
do_test 23.4 {
|
|
|
|
sqlite3_extended_errcode db
|
|
|
|
} {SQLITE_READONLY_DIRECTORY}
|
|
|
|
|
|
|
|
do_test 23.5 {
|
|
|
|
db close
|
|
|
|
forcedelete tst
|
|
|
|
} {}
|
|
|
|
}
|
|
|
|
|
2007-03-29 16:19:11 +04:00
|
|
|
finish_test
|