2N/A#
pragma ident "%Z%%M% %I% %E% SMI" 2N/A** The author disclaims copyright to this source code. In place of 2N/A** a legal notice, here is a blessing: 2N/A** May you do good and not evil. 2N/A** May you find forgiveness for yourself and forgive others. 2N/A** May you share freely, never taking more than you give. 2N/A************************************************************************* 2N/A** This file contains code used to implement the VACUUM command. 2N/A** Most of the code in this file may be omitted by defining the 2N/A** SQLITE_OMIT_VACUUM macro. 2N/A** $Id: vacuum.c,v 1.13.2.2 2004/06/04 19:07:54 drh Exp $ 2N/A** A structure for holding a dynamic string - a string that can grow 2N/A char *z;
/* Text of the string in space obtained from sqliteMalloc() */ 2N/A int nAlloc;
/* Amount of space allocated to z[] */ 2N/A int nUsed;
/* Next unused slot in z[] */ 2N/A** A structure that holds the vacuum context 2N/A int rc;
/* Set to non-zero on an error */ 2N/A const char *
zTable;
/* Name of a table being copied */ 2N/A const char *
zPragma;
/* Pragma to execute with results */ 2N/A** Append text to a dynamic string 2N/A** Append text to a dynamic string, having first put the text in quotes. 2N/A** Execute statements of SQL. If an error occurs, write the error 2N/A** message into *pzErrMsg and return non-zero. 2N/A /* printf("***** executing *****\n%s\n", zSql); */ 2N/A** This is the second stage callback. Each invocation contains all the 2N/A** data for a single row of a single table in the original database. This 2N/A** routine must write that information into the new database. 2N/A** This is the first stage callback. Each invocation contains three 2N/A** arguments where are taken from the SQLITE_MASTER table of the original 2N/A** database: (1) the entry type, (2) the entry name, and (3) the SQL for 2N/A** the entry. In all cases, execute the SQL of the third argument. 2N/A** For tables, run a query to select all entries in that table and 2N/A** transfer them to the second-stage callback. 2N/A** This callback is used to transfer PRAGMA settings from one database 2N/A** to the other. The value in argv[0] should be passed to a pragma 2N/A** identified by ((vacuumStruct*)pArg)->zPragma. 2N/A** Generate a random name of 20 character in length. 2N/A "abcdefghijklmnopqrstuvwxyz" 2N/A for(i=0; i<
20; i++){
2N/A** The non-standard VACUUM command is used to clean up the database, 2N/A** collapse free space, etc. It is modelled after the VACUUM command 2N/A** In version 1.0.x of SQLite, the VACUUM command would call 2N/A** gdbm_reorganize() on all the database tables. But beginning 2N/A** with 2.0.0, SQLite no longer uses GDBM so this command has 2N/A** This routine implements the OP_Vacuum opcode of the VDBE. 2N/A const char *
zFilename;
/* full pathname of the database file */ 2N/A char *
zTemp = 0;
/* a temporary file in same directory as zFilename */ 2N/A int i;
/* Loop counter */ 2N/A /* These are all of the pragmas that need to be transferred over 2N/A ** to the new database */ 2N/A "default_synchronous",
2N/A "default_cache_size",
2N/A /* "default_temp_store", */ 2N/A /* Get the full pathname of the database file and create two 2N/A ** temporary filenames in the same directory as the original file. 2N/A /* This only happens with the in-memory database. VACUUM is a no-op 2N/A ** there, so just return */ 2N/A for(i=0; i<
10; i++){
2N/A "in the same directory as the original database", (
char*)0);
2N/A "SELECT type, name, sql FROM sqlite_master " 2N/A "WHERE sql NOT NULL AND type!='view' " 2N/A "SELECT type, name, sql FROM sqlite_master " 2N/A "WHERE sql NOT NULL AND type=='view'",