OLD | NEW |
1 /* | 1 /* |
2 ** 2003 April 6 | 2 ** 2003 April 6 |
3 ** | 3 ** |
4 ** The author disclaims copyright to this source code. In place of | 4 ** The author disclaims copyright to this source code. In place of |
5 ** a legal notice, here is a blessing: | 5 ** a legal notice, here is a blessing: |
6 ** | 6 ** |
7 ** May you do good and not evil. | 7 ** May you do good and not evil. |
8 ** May you find forgiveness for yourself and forgive others. | 8 ** May you find forgiveness for yourself and forgive others. |
9 ** May you share freely, never taking more than you give. | 9 ** May you share freely, never taking more than you give. |
10 ** | 10 ** |
11 ************************************************************************* | 11 ************************************************************************* |
12 ** This file contains code used to implement the VACUUM command. | 12 ** This file contains code used to implement the VACUUM command. |
13 ** | 13 ** |
14 ** Most of the code in this file may be omitted by defining the | 14 ** Most of the code in this file may be omitted by defining the |
15 ** SQLITE_OMIT_VACUUM macro. | 15 ** SQLITE_OMIT_VACUUM macro. |
16 ** | |
17 ** $Id: vacuum.c,v 1.91 2009/07/02 07:47:33 danielk1977 Exp $ | |
18 */ | 16 */ |
19 #include "sqliteInt.h" | 17 #include "sqliteInt.h" |
20 #include "vdbeInt.h" | 18 #include "vdbeInt.h" |
21 | 19 |
22 #if !defined(SQLITE_OMIT_VACUUM) && !defined(SQLITE_OMIT_ATTACH) | 20 #if !defined(SQLITE_OMIT_VACUUM) && !defined(SQLITE_OMIT_ATTACH) |
23 /* | 21 /* |
| 22 ** Finalize a prepared statement. If there was an error, store the |
| 23 ** text of the error message in *pzErrMsg. Return the result code. |
| 24 */ |
| 25 static int vacuumFinalize(sqlite3 *db, sqlite3_stmt *pStmt, char **pzErrMsg){ |
| 26 int rc; |
| 27 rc = sqlite3VdbeFinalize((Vdbe*)pStmt); |
| 28 if( rc ){ |
| 29 sqlite3SetString(pzErrMsg, db, sqlite3_errmsg(db)); |
| 30 } |
| 31 return rc; |
| 32 } |
| 33 |
| 34 /* |
24 ** Execute zSql on database db. Return an error code. | 35 ** Execute zSql on database db. Return an error code. |
25 */ | 36 */ |
26 static int execSql(sqlite3 *db, const char *zSql){ | 37 static int execSql(sqlite3 *db, char **pzErrMsg, const char *zSql){ |
27 sqlite3_stmt *pStmt; | 38 sqlite3_stmt *pStmt; |
28 VVA_ONLY( int rc; ) | 39 VVA_ONLY( int rc; ) |
29 if( !zSql ){ | 40 if( !zSql ){ |
30 return SQLITE_NOMEM; | 41 return SQLITE_NOMEM; |
31 } | 42 } |
32 if( SQLITE_OK!=sqlite3_prepare(db, zSql, -1, &pStmt, 0) ){ | 43 if( SQLITE_OK!=sqlite3_prepare(db, zSql, -1, &pStmt, 0) ){ |
| 44 sqlite3SetString(pzErrMsg, db, sqlite3_errmsg(db)); |
33 return sqlite3_errcode(db); | 45 return sqlite3_errcode(db); |
34 } | 46 } |
35 VVA_ONLY( rc = ) sqlite3_step(pStmt); | 47 VVA_ONLY( rc = ) sqlite3_step(pStmt); |
36 assert( rc!=SQLITE_ROW ); | 48 assert( rc!=SQLITE_ROW ); |
37 return sqlite3_finalize(pStmt); | 49 return vacuumFinalize(db, pStmt, pzErrMsg); |
38 } | 50 } |
39 | 51 |
40 /* | 52 /* |
41 ** Execute zSql on database db. The statement returns exactly | 53 ** Execute zSql on database db. The statement returns exactly |
42 ** one column. Execute this as SQL on the same database. | 54 ** one column. Execute this as SQL on the same database. |
43 */ | 55 */ |
44 static int execExecSql(sqlite3 *db, const char *zSql){ | 56 static int execExecSql(sqlite3 *db, char **pzErrMsg, const char *zSql){ |
45 sqlite3_stmt *pStmt; | 57 sqlite3_stmt *pStmt; |
46 int rc; | 58 int rc; |
47 | 59 |
48 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0); | 60 rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0); |
49 if( rc!=SQLITE_OK ) return rc; | 61 if( rc!=SQLITE_OK ) return rc; |
50 | 62 |
51 while( SQLITE_ROW==sqlite3_step(pStmt) ){ | 63 while( SQLITE_ROW==sqlite3_step(pStmt) ){ |
52 rc = execSql(db, (char*)sqlite3_column_text(pStmt, 0)); | 64 rc = execSql(db, pzErrMsg, (char*)sqlite3_column_text(pStmt, 0)); |
53 if( rc!=SQLITE_OK ){ | 65 if( rc!=SQLITE_OK ){ |
54 sqlite3_finalize(pStmt); | 66 vacuumFinalize(db, pStmt, pzErrMsg); |
55 return rc; | 67 return rc; |
56 } | 68 } |
57 } | 69 } |
58 | 70 |
59 return sqlite3_finalize(pStmt); | 71 return vacuumFinalize(db, pStmt, pzErrMsg); |
60 } | 72 } |
61 | 73 |
62 /* | 74 /* |
63 ** The non-standard VACUUM command is used to clean up the database, | 75 ** The non-standard VACUUM command is used to clean up the database, |
64 ** collapse free space, etc. It is modelled after the VACUUM command | 76 ** collapse free space, etc. It is modelled after the VACUUM command |
65 ** in PostgreSQL. | 77 ** in PostgreSQL. |
66 ** | 78 ** |
67 ** In version 1.0.x of SQLite, the VACUUM command would call | 79 ** In version 1.0.x of SQLite, the VACUUM command would call |
68 ** gdbm_reorganize() on all the database tables. But beginning | 80 ** gdbm_reorganize() on all the database tables. But beginning |
69 ** with 2.0.0, SQLite no longer uses GDBM so this command has | 81 ** with 2.0.0, SQLite no longer uses GDBM so this command has |
(...skipping 11 matching lines...) Expand all Loading... |
81 ** This routine implements the OP_Vacuum opcode of the VDBE. | 93 ** This routine implements the OP_Vacuum opcode of the VDBE. |
82 */ | 94 */ |
83 int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){ | 95 int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){ |
84 int rc = SQLITE_OK; /* Return code from service routines */ | 96 int rc = SQLITE_OK; /* Return code from service routines */ |
85 Btree *pMain; /* The database being vacuumed */ | 97 Btree *pMain; /* The database being vacuumed */ |
86 Btree *pTemp; /* The temporary database we vacuum into */ | 98 Btree *pTemp; /* The temporary database we vacuum into */ |
87 char *zSql = 0; /* SQL statements */ | 99 char *zSql = 0; /* SQL statements */ |
88 int saved_flags; /* Saved value of the db->flags */ | 100 int saved_flags; /* Saved value of the db->flags */ |
89 int saved_nChange; /* Saved value of db->nChange */ | 101 int saved_nChange; /* Saved value of db->nChange */ |
90 int saved_nTotalChange; /* Saved value of db->nTotalChange */ | 102 int saved_nTotalChange; /* Saved value of db->nTotalChange */ |
| 103 void (*saved_xTrace)(void*,const char*); /* Saved db->xTrace */ |
91 Db *pDb = 0; /* Database to detach at end of vacuum */ | 104 Db *pDb = 0; /* Database to detach at end of vacuum */ |
92 int isMemDb; /* True if vacuuming a :memory: database */ | 105 int isMemDb; /* True if vacuuming a :memory: database */ |
93 int nRes; | 106 int nRes; /* Bytes of reserved space at the end of each page */ |
| 107 int nDb; /* Number of attached databases */ |
94 | 108 |
95 if( !db->autoCommit ){ | 109 if( !db->autoCommit ){ |
96 sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction"); | 110 sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction"); |
97 return SQLITE_ERROR; | 111 return SQLITE_ERROR; |
98 } | 112 } |
| 113 if( db->activeVdbeCnt>1 ){ |
| 114 sqlite3SetString(pzErrMsg, db,"cannot VACUUM - SQL statements in progress"); |
| 115 return SQLITE_ERROR; |
| 116 } |
99 | 117 |
100 /* Save the current value of the write-schema flag before setting it. */ | 118 /* Save the current value of the database flags so that it can be |
| 119 ** restored before returning. Then set the writable-schema flag, and |
| 120 ** disable CHECK and foreign key constraints. */ |
101 saved_flags = db->flags; | 121 saved_flags = db->flags; |
102 saved_nChange = db->nChange; | 122 saved_nChange = db->nChange; |
103 saved_nTotalChange = db->nTotalChange; | 123 saved_nTotalChange = db->nTotalChange; |
104 db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks; | 124 saved_xTrace = db->xTrace; |
| 125 db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks | SQLITE_PreferBuiltin; |
| 126 db->flags &= ~(SQLITE_ForeignKeys | SQLITE_ReverseOrder); |
| 127 db->xTrace = 0; |
105 | 128 |
106 pMain = db->aDb[0].pBt; | 129 pMain = db->aDb[0].pBt; |
107 isMemDb = sqlite3PagerIsMemdb(sqlite3BtreePager(pMain)); | 130 isMemDb = sqlite3PagerIsMemdb(sqlite3BtreePager(pMain)); |
108 | 131 |
109 /* Attach the temporary database as 'vacuum_db'. The synchronous pragma | 132 /* Attach the temporary database as 'vacuum_db'. The synchronous pragma |
110 ** can be set to 'off' for this file, as it is not recovered if a crash | 133 ** can be set to 'off' for this file, as it is not recovered if a crash |
111 ** occurs anyway. The integrity of the database is maintained by a | 134 ** occurs anyway. The integrity of the database is maintained by a |
112 ** (possibly synchronous) transaction opened on the main database before | 135 ** (possibly synchronous) transaction opened on the main database before |
113 ** sqlite3BtreeCopyFile() is called. | 136 ** sqlite3BtreeCopyFile() is called. |
114 ** | 137 ** |
115 ** An optimisation would be to use a non-journaled pager. | 138 ** An optimisation would be to use a non-journaled pager. |
116 ** (Later:) I tried setting "PRAGMA vacuum_db.journal_mode=OFF" but | 139 ** (Later:) I tried setting "PRAGMA vacuum_db.journal_mode=OFF" but |
117 ** that actually made the VACUUM run slower. Very little journalling | 140 ** that actually made the VACUUM run slower. Very little journalling |
118 ** actually occurs when doing a vacuum since the vacuum_db is initially | 141 ** actually occurs when doing a vacuum since the vacuum_db is initially |
119 ** empty. Only the journal header is written. Apparently it takes more | 142 ** empty. Only the journal header is written. Apparently it takes more |
120 ** time to parse and run the PRAGMA to turn journalling off than it does | 143 ** time to parse and run the PRAGMA to turn journalling off than it does |
121 ** to write the journal header file. | 144 ** to write the journal header file. |
122 */ | 145 */ |
123 zSql = "ATTACH '' AS vacuum_db;"; | 146 nDb = db->nDb; |
124 rc = execSql(db, zSql); | 147 if( sqlite3TempInMemory(db) ){ |
| 148 zSql = "ATTACH ':memory:' AS vacuum_db;"; |
| 149 }else{ |
| 150 zSql = "ATTACH '' AS vacuum_db;"; |
| 151 } |
| 152 rc = execSql(db, pzErrMsg, zSql); |
| 153 if( db->nDb>nDb ){ |
| 154 pDb = &db->aDb[db->nDb-1]; |
| 155 assert( strcmp(pDb->zName,"vacuum_db")==0 ); |
| 156 } |
125 if( rc!=SQLITE_OK ) goto end_of_vacuum; | 157 if( rc!=SQLITE_OK ) goto end_of_vacuum; |
126 pDb = &db->aDb[db->nDb-1]; | |
127 assert( strcmp(db->aDb[db->nDb-1].zName,"vacuum_db")==0 ); | |
128 pTemp = db->aDb[db->nDb-1].pBt; | 158 pTemp = db->aDb[db->nDb-1].pBt; |
129 | 159 |
| 160 /* The call to execSql() to attach the temp database has left the file |
| 161 ** locked (as there was more than one active statement when the transaction |
| 162 ** to read the schema was concluded. Unlock it here so that this doesn't |
| 163 ** cause problems for the call to BtreeSetPageSize() below. */ |
| 164 sqlite3BtreeCommit(pTemp); |
| 165 |
130 nRes = sqlite3BtreeGetReserve(pMain); | 166 nRes = sqlite3BtreeGetReserve(pMain); |
131 | 167 |
132 /* A VACUUM cannot change the pagesize of an encrypted database. */ | 168 /* A VACUUM cannot change the pagesize of an encrypted database. */ |
133 #ifdef SQLITE_HAS_CODEC | 169 #ifdef SQLITE_HAS_CODEC |
134 if( db->nextPagesize ){ | 170 if( db->nextPagesize ){ |
135 extern void sqlite3CodecGetKey(sqlite3*, int, void**, int*); | 171 extern void sqlite3CodecGetKey(sqlite3*, int, void**, int*); |
136 int nKey; | 172 int nKey; |
137 char *zKey; | 173 char *zKey; |
138 sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey); | 174 sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey); |
139 if( nKey ) db->nextPagesize = 0; | 175 if( nKey ) db->nextPagesize = 0; |
140 } | 176 } |
141 #endif | 177 #endif |
142 | 178 |
| 179 /* Do not attempt to change the page size for a WAL database */ |
| 180 if( sqlite3PagerGetJournalMode(sqlite3BtreePager(pMain)) |
| 181 ==PAGER_JOURNALMODE_WAL ){ |
| 182 db->nextPagesize = 0; |
| 183 } |
| 184 |
143 if( sqlite3BtreeSetPageSize(pTemp, sqlite3BtreeGetPageSize(pMain), nRes, 0) | 185 if( sqlite3BtreeSetPageSize(pTemp, sqlite3BtreeGetPageSize(pMain), nRes, 0) |
144 || (!isMemDb && sqlite3BtreeSetPageSize(pTemp, db->nextPagesize, nRes, 0)) | 186 || (!isMemDb && sqlite3BtreeSetPageSize(pTemp, db->nextPagesize, nRes, 0)) |
145 || NEVER(db->mallocFailed) | 187 || NEVER(db->mallocFailed) |
146 ){ | 188 ){ |
147 rc = SQLITE_NOMEM; | 189 rc = SQLITE_NOMEM; |
148 goto end_of_vacuum; | 190 goto end_of_vacuum; |
149 } | 191 } |
150 rc = execSql(db, "PRAGMA vacuum_db.synchronous=OFF"); | 192 rc = execSql(db, pzErrMsg, "PRAGMA vacuum_db.synchronous=OFF"); |
151 if( rc!=SQLITE_OK ){ | 193 if( rc!=SQLITE_OK ){ |
152 goto end_of_vacuum; | 194 goto end_of_vacuum; |
153 } | 195 } |
154 | 196 |
155 #ifndef SQLITE_OMIT_AUTOVACUUM | 197 #ifndef SQLITE_OMIT_AUTOVACUUM |
156 sqlite3BtreeSetAutoVacuum(pTemp, db->nextAutovac>=0 ? db->nextAutovac : | 198 sqlite3BtreeSetAutoVacuum(pTemp, db->nextAutovac>=0 ? db->nextAutovac : |
157 sqlite3BtreeGetAutoVacuum(pMain)); | 199 sqlite3BtreeGetAutoVacuum(pMain)); |
158 #endif | 200 #endif |
159 | 201 |
160 /* Begin a transaction */ | 202 /* Begin a transaction */ |
161 rc = execSql(db, "BEGIN EXCLUSIVE;"); | 203 rc = execSql(db, pzErrMsg, "BEGIN EXCLUSIVE;"); |
162 if( rc!=SQLITE_OK ) goto end_of_vacuum; | 204 if( rc!=SQLITE_OK ) goto end_of_vacuum; |
163 | 205 |
164 /* Query the schema of the main database. Create a mirror schema | 206 /* Query the schema of the main database. Create a mirror schema |
165 ** in the temporary database. | 207 ** in the temporary database. |
166 */ | 208 */ |
167 rc = execExecSql(db, | 209 rc = execExecSql(db, pzErrMsg, |
168 "SELECT 'CREATE TABLE vacuum_db.' || substr(sql,14) " | 210 "SELECT 'CREATE TABLE vacuum_db.' || substr(sql,14) " |
169 " FROM sqlite_master WHERE type='table' AND name!='sqlite_sequence'" | 211 " FROM sqlite_master WHERE type='table' AND name!='sqlite_sequence'" |
170 " AND rootpage>0" | 212 " AND rootpage>0" |
171 ); | 213 ); |
172 if( rc!=SQLITE_OK ) goto end_of_vacuum; | 214 if( rc!=SQLITE_OK ) goto end_of_vacuum; |
173 rc = execExecSql(db, | 215 rc = execExecSql(db, pzErrMsg, |
174 "SELECT 'CREATE INDEX vacuum_db.' || substr(sql,14)" | 216 "SELECT 'CREATE INDEX vacuum_db.' || substr(sql,14)" |
175 " FROM sqlite_master WHERE sql LIKE 'CREATE INDEX %' "); | 217 " FROM sqlite_master WHERE sql LIKE 'CREATE INDEX %' "); |
176 if( rc!=SQLITE_OK ) goto end_of_vacuum; | 218 if( rc!=SQLITE_OK ) goto end_of_vacuum; |
177 rc = execExecSql(db, | 219 rc = execExecSql(db, pzErrMsg, |
178 "SELECT 'CREATE UNIQUE INDEX vacuum_db.' || substr(sql,21) " | 220 "SELECT 'CREATE UNIQUE INDEX vacuum_db.' || substr(sql,21) " |
179 " FROM sqlite_master WHERE sql LIKE 'CREATE UNIQUE INDEX %'"); | 221 " FROM sqlite_master WHERE sql LIKE 'CREATE UNIQUE INDEX %'"); |
180 if( rc!=SQLITE_OK ) goto end_of_vacuum; | 222 if( rc!=SQLITE_OK ) goto end_of_vacuum; |
181 | 223 |
182 /* Loop through the tables in the main database. For each, do | 224 /* Loop through the tables in the main database. For each, do |
183 ** an "INSERT INTO vacuum_db.xxx SELECT * FROM xxx;" to copy | 225 ** an "INSERT INTO vacuum_db.xxx SELECT * FROM main.xxx;" to copy |
184 ** the contents to the temporary database. | 226 ** the contents to the temporary database. |
185 */ | 227 */ |
186 rc = execExecSql(db, | 228 rc = execExecSql(db, pzErrMsg, |
187 "SELECT 'INSERT INTO vacuum_db.' || quote(name) " | 229 "SELECT 'INSERT INTO vacuum_db.' || quote(name) " |
188 "|| ' SELECT * FROM ' || quote(name) || ';'" | 230 "|| ' SELECT * FROM main.' || quote(name) || ';'" |
189 "FROM sqlite_master " | 231 "FROM main.sqlite_master " |
190 "WHERE type = 'table' AND name!='sqlite_sequence' " | 232 "WHERE type = 'table' AND name!='sqlite_sequence' " |
191 " AND rootpage>0" | 233 " AND rootpage>0" |
192 | |
193 ); | 234 ); |
194 if( rc!=SQLITE_OK ) goto end_of_vacuum; | 235 if( rc!=SQLITE_OK ) goto end_of_vacuum; |
195 | 236 |
196 /* Copy over the sequence table | 237 /* Copy over the sequence table |
197 */ | 238 */ |
198 rc = execExecSql(db, | 239 rc = execExecSql(db, pzErrMsg, |
199 "SELECT 'DELETE FROM vacuum_db.' || quote(name) || ';' " | 240 "SELECT 'DELETE FROM vacuum_db.' || quote(name) || ';' " |
200 "FROM vacuum_db.sqlite_master WHERE name='sqlite_sequence' " | 241 "FROM vacuum_db.sqlite_master WHERE name='sqlite_sequence' " |
201 ); | 242 ); |
202 if( rc!=SQLITE_OK ) goto end_of_vacuum; | 243 if( rc!=SQLITE_OK ) goto end_of_vacuum; |
203 rc = execExecSql(db, | 244 rc = execExecSql(db, pzErrMsg, |
204 "SELECT 'INSERT INTO vacuum_db.' || quote(name) " | 245 "SELECT 'INSERT INTO vacuum_db.' || quote(name) " |
205 "|| ' SELECT * FROM ' || quote(name) || ';' " | 246 "|| ' SELECT * FROM main.' || quote(name) || ';' " |
206 "FROM vacuum_db.sqlite_master WHERE name=='sqlite_sequence';" | 247 "FROM vacuum_db.sqlite_master WHERE name=='sqlite_sequence';" |
207 ); | 248 ); |
208 if( rc!=SQLITE_OK ) goto end_of_vacuum; | 249 if( rc!=SQLITE_OK ) goto end_of_vacuum; |
209 | 250 |
210 | 251 |
211 /* Copy the triggers, views, and virtual tables from the main database | 252 /* Copy the triggers, views, and virtual tables from the main database |
212 ** over to the temporary database. None of these objects has any | 253 ** over to the temporary database. None of these objects has any |
213 ** associated storage, so all we have to do is copy their entries | 254 ** associated storage, so all we have to do is copy their entries |
214 ** from the SQLITE_MASTER table. | 255 ** from the SQLITE_MASTER table. |
215 */ | 256 */ |
216 rc = execSql(db, | 257 rc = execSql(db, pzErrMsg, |
217 "INSERT INTO vacuum_db.sqlite_master " | 258 "INSERT INTO vacuum_db.sqlite_master " |
218 " SELECT type, name, tbl_name, rootpage, sql" | 259 " SELECT type, name, tbl_name, rootpage, sql" |
219 " FROM sqlite_master" | 260 " FROM main.sqlite_master" |
220 " WHERE type='view' OR type='trigger'" | 261 " WHERE type='view' OR type='trigger'" |
221 " OR (type='table' AND rootpage=0)" | 262 " OR (type='table' AND rootpage=0)" |
222 ); | 263 ); |
223 if( rc ) goto end_of_vacuum; | 264 if( rc ) goto end_of_vacuum; |
224 | 265 |
225 /* At this point, unless the main db was completely empty, there is now a | 266 /* At this point, unless the main db was completely empty, there is now a |
226 ** transaction open on the vacuum database, but not on the main database. | 267 ** transaction open on the vacuum database, but not on the main database. |
227 ** Open a btree level transaction on the main database. This allows a | 268 ** Open a btree level transaction on the main database. This allows a |
228 ** call to sqlite3BtreeCopyFile(). The main database btree level | 269 ** call to sqlite3BtreeCopyFile(). The main database btree level |
229 ** transaction is then committed, so the SQL level never knows it was | 270 ** transaction is then committed, so the SQL level never knows it was |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 } | 310 } |
270 | 311 |
271 assert( rc==SQLITE_OK ); | 312 assert( rc==SQLITE_OK ); |
272 rc = sqlite3BtreeSetPageSize(pMain, sqlite3BtreeGetPageSize(pTemp), nRes,1); | 313 rc = sqlite3BtreeSetPageSize(pMain, sqlite3BtreeGetPageSize(pTemp), nRes,1); |
273 | 314 |
274 end_of_vacuum: | 315 end_of_vacuum: |
275 /* Restore the original value of db->flags */ | 316 /* Restore the original value of db->flags */ |
276 db->flags = saved_flags; | 317 db->flags = saved_flags; |
277 db->nChange = saved_nChange; | 318 db->nChange = saved_nChange; |
278 db->nTotalChange = saved_nTotalChange; | 319 db->nTotalChange = saved_nTotalChange; |
| 320 db->xTrace = saved_xTrace; |
| 321 sqlite3BtreeSetPageSize(pMain, -1, -1, 1); |
279 | 322 |
280 /* Currently there is an SQL level transaction open on the vacuum | 323 /* Currently there is an SQL level transaction open on the vacuum |
281 ** database. No locks are held on any other files (since the main file | 324 ** database. No locks are held on any other files (since the main file |
282 ** was committed at the btree level). So it safe to end the transaction | 325 ** was committed at the btree level). So it safe to end the transaction |
283 ** by manually setting the autoCommit flag to true and detaching the | 326 ** by manually setting the autoCommit flag to true and detaching the |
284 ** vacuum database. The vacuum_db journal file is deleted when the pager | 327 ** vacuum database. The vacuum_db journal file is deleted when the pager |
285 ** is closed by the DETACH. | 328 ** is closed by the DETACH. |
286 */ | 329 */ |
287 db->autoCommit = 1; | 330 db->autoCommit = 1; |
288 | 331 |
289 if( pDb ){ | 332 if( pDb ){ |
290 sqlite3BtreeClose(pDb->pBt); | 333 sqlite3BtreeClose(pDb->pBt); |
291 pDb->pBt = 0; | 334 pDb->pBt = 0; |
292 pDb->pSchema = 0; | 335 pDb->pSchema = 0; |
293 } | 336 } |
294 | 337 |
295 sqlite3ResetInternalSchema(db, 0); | 338 /* This both clears the schemas and reduces the size of the db->aDb[] |
| 339 ** array. */ |
| 340 sqlite3ResetInternalSchema(db, -1); |
296 | 341 |
297 return rc; | 342 return rc; |
298 } | 343 } |
| 344 |
299 #endif /* SQLITE_OMIT_VACUUM && SQLITE_OMIT_ATTACH */ | 345 #endif /* SQLITE_OMIT_VACUUM && SQLITE_OMIT_ATTACH */ |
OLD | NEW |