SQLite

Check-in [c1ebcacd9b]
Login

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

Overview
Comment:Add experimental branch disallowing VACUUM when there are one or more active SQL statements.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | experimental
Files: files | file ages | folders
SHA1: c1ebcacd9b31239aee065c64c4b4596d56dc397f
User & Date: dan 2010-09-24 09:32:45.000
Context
2010-09-24
18:04
Add new file e_vacuum.test. Move part of e_select.test into e_select2.test. (Closed-Leaf check-in: 30801892c6 user: dan)
09:32
Add experimental branch disallowing VACUUM when there are one or more active SQL statements. (check-in: c1ebcacd9b user: dan tags: experimental)
08:00
Modify testable statement ids in a few test files to account for recent docsrc changes. (check-in: 7893e52595 user: dan tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/vacuum.c.
105
106
107
108
109
110
111




112
113
114
115
116
117
118
  int isMemDb;            /* True if vacuuming a :memory: database */
  int nRes;               /* Bytes of reserved space at the end of each page */
  int nDb;                /* Number of attached databases */

  if( !db->autoCommit ){
    sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction");
    return SQLITE_ERROR;




  }

  /* Save the current value of the database flags so that it can be 
  ** restored before returning. Then set the writable-schema flag, and
  ** disable CHECK and foreign key constraints.  */
  saved_flags = db->flags;
  saved_nChange = db->nChange;







>
>
>
>







105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
  int isMemDb;            /* True if vacuuming a :memory: database */
  int nRes;               /* Bytes of reserved space at the end of each page */
  int nDb;                /* Number of attached databases */

  if( !db->autoCommit ){
    sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction");
    return SQLITE_ERROR;
  }
  if( db->activeVdbeCnt>1 ){
    sqlite3SetString(pzErrMsg, db,"cannot VACUUM - SQL statements in progress");
    return SQLITE_ERROR;
  }

  /* Save the current value of the database flags so that it can be 
  ** restored before returning. Then set the writable-schema flag, and
  ** disable CHECK and foreign key constraints.  */
  saved_flags = db->flags;
  saved_nChange = db->nChange;
Changes to test/vacuum2.test.
177
178
179
180
181
182
183









































184
185
    db close
    sqlite3 db test.db
    execsql {
      pragma auto_vacuum;
    }
  } {2}
}










































finish_test







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


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
216
217
218
219
220
221
222
223
224
225
226
    db close
    sqlite3 db test.db
    execsql {
      pragma auto_vacuum;
    }
  } {2}
}


#-------------------------------------------------------------------------
# The following block of tests verify the behaviour of the library when
# a database is VACUUMed when there are one or more unfinalized SQL 
# statements reading the same database using the same db handle.
#
db close
forcedelete test.db
sqlite3 db test.db
do_execsql_test vacuum2-5.1 {
  CREATE TABLE t1(a PRIMARY KEY, b UNIQUE);
  INSERT INTO t1 VALUES(1, randomblob(500));
  INSERT INTO t1 SELECT a+1, randomblob(500) FROM t1;      -- 2
  INSERT INTO t1 SELECT a+2, randomblob(500) FROM t1;      -- 4 
  INSERT INTO t1 SELECT a+4, randomblob(500) FROM t1;      -- 8 
  INSERT INTO t1 SELECT a+8, randomblob(500) FROM t1;      -- 16 
} {}

do_test vacuum2-5.2 {
  list [catch {
    db eval {SELECT a, b FROM t1} { if {$a == 8} { execsql VACUUM } }
  } msg] $msg
} {1 {cannot VACUUM - SQL statements in progress}}

do_test vacuum2-5.3 {
  list [catch {
    db eval {SELECT 1, 2, 3} { execsql VACUUM }
  } msg] $msg
} {1 {cannot VACUUM - SQL statements in progress}}

do_test vacuum2-5.4 {
  set res ""
  set res2 ""
  db eval {SELECT a, b FROM t1 WHERE a<=10} {
    if {$a==6} { set res [catchsql VACUUM] }
    lappend res2 $a
  }
  lappend res2 $res
} {1 2 3 4 5 6 7 8 9 10 {1 {cannot VACUUM - SQL statements in progress}}}


finish_test