blob: 1111a984b42d21553834593f7fe8c23f8d8974f9 [file] [log] [blame]
danielk1977180b56a2007-06-24 08:00:42 +00001# 2002 March 6
2#
3# The author disclaims copyright to this source code. In place of
4# a legal notice, here is a blessing:
5#
6# May you do good and not evil.
7# May you find forgiveness for yourself and forgive others.
8# May you share freely, never taking more than you give.
9#
10#***********************************************************************
11# This file implements regression tests for SQLite library.
12#
13# This file implements tests for the PRAGMA command.
14#
danielk19775a8f9372007-10-09 08:29:32 +000015# $Id: pragma2.test,v 1.4 2007/10/09 08:29:33 danielk1977 Exp $
danielk1977180b56a2007-06-24 08:00:42 +000016
17set testdir [file dirname $argv0]
18source $testdir/tester.tcl
19
20# Test organization:
21#
22# pragma2-1.*: Test freelist_count pragma on the main database.
23# pragma2-2.*: Test freelist_count pragma on an attached database.
24# pragma2-3.*: Test trying to write to the freelist_count is a no-op.
25#
26
danielk19774152e672007-09-12 17:01:45 +000027ifcapable !pragma||!schema_pragmas {
danielk1977180b56a2007-06-24 08:00:42 +000028 finish_test
29 return
30}
31
32# Delete the preexisting database to avoid the special setup
33# that the "all.test" script does.
34#
35db close
mistachkinfda06be2011-08-02 00:57:34 +000036delete_file test.db test.db-journal
37delete_file test3.db test3.db-journal
danielk1977180b56a2007-06-24 08:00:42 +000038sqlite3 db test.db; set DB [sqlite3_connection_pointer db]
drh5db82812007-06-27 10:20:00 +000039db eval {PRAGMA auto_vacuum=0}
danielk1977180b56a2007-06-24 08:00:42 +000040
41do_test pragma2-1.1 {
42 execsql {
43 PRAGMA freelist_count;
44 }
45} {0}
46do_test pragma2-1.2 {
47 execsql {
48 CREATE TABLE abc(a, b, c);
49 PRAGMA freelist_count;
50 }
51} {0}
52do_test pragma2-1.3 {
53 execsql {
54 DROP TABLE abc;
55 PRAGMA freelist_count;
56 }
57} {1}
58do_test pragma2-1.4 {
59 execsql {
60 PRAGMA main.freelist_count;
61 }
62} {1}
63
mistachkinfda06be2011-08-02 00:57:34 +000064forcedelete test2.db
65forcedelete test2.db-journal
danielk1977180b56a2007-06-24 08:00:42 +000066
danielk19775a8f9372007-10-09 08:29:32 +000067ifcapable attach {
68 do_test pragma2-2.1 {
69 execsql {
70 ATTACH 'test2.db' AS aux;
71 PRAGMA aux.auto_vacuum=OFF;
72 PRAGMA aux.freelist_count;
73 }
74 } {0}
75 do_test pragma2-2.2 {
76 execsql {
77 CREATE TABLE aux.abc(a, b, c);
78 PRAGMA aux.freelist_count;
79 }
80 } {0}
81 do_test pragma2-2.3 {
82 set ::val [string repeat 0123456789 1000]
83 execsql {
84 INSERT INTO aux.abc VALUES(1, 2, $::val);
85 PRAGMA aux.freelist_count;
86 }
87 } {0}
88 do_test pragma2-2.4 {
89 expr {[file size test2.db] / 1024}
90 } {11}
91 do_test pragma2-2.5 {
92 execsql {
93 DELETE FROM aux.abc;
94 PRAGMA aux.freelist_count;
95 }
96 } {9}
97
98 do_test pragma2-3.1 {
99 execsql {
100 PRAGMA aux.freelist_count;
101 PRAGMA main.freelist_count;
102 PRAGMA freelist_count;
103 }
104 } {9 1 1}
105 do_test pragma2-3.2 {
106 execsql {
107 PRAGMA freelist_count = 500;
108 PRAGMA freelist_count;
109 }
110 } {1 1}
111 do_test pragma2-3.3 {
112 execsql {
113 PRAGMA aux.freelist_count = 500;
114 PRAGMA aux.freelist_count;
115 }
116 } {9 9}
117}
danielk1977180b56a2007-06-24 08:00:42 +0000118
119finish_test