1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-05 15:55:57 +03:00

Change the SQLITE_MASTER format to version 2 in preparation for adding views. (CVS 386)

FossilOrigin-Name: b2a9807fed544e83002366149b9a363759338c5d
This commit is contained in:
drh
2002-02-21 12:01:27 +00:00
parent 2af0b2d78f
commit 17f7193434
11 changed files with 304 additions and 184 deletions

View File

@@ -14,7 +14,7 @@
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: main.c,v 1.60 2002/02/19 22:42:05 drh Exp $
** $Id: main.c,v 1.61 2002/02/21 12:01:27 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@@ -51,13 +51,14 @@ static int sqliteOpenCb(void *pDb, int argc, char **argv, char **azColName){
db->next_cookie = db->schema_cookie;
break;
}
case 'v':
case 'i':
case 't': { /* CREATE TABLE and CREATE INDEX statements */
case 't': { /* CREATE TABLE, CREATE INDEX, or CREATE VIEW statements */
if( argv[3] && argv[3][0] ){
/* Call the parser to process a CREATE TABLE or CREATE INDEX statement.
/* Call the parser to process a CREATE TABLE, INDEX or VIEW.
** But because sParse.initFlag is set to 1, no VDBE code is generated
** or executed. All the parser does is build the internal data
** structures that describe the table or index.
** structures that describe the table, index, or view.
*/
memset(&sParse, 0, sizeof(sParse));
sParse.db = db;
@@ -149,10 +150,15 @@ static int sqliteInit(sqlite *db, char **pzErrMsg){
** was created to fulfill a PRIMARY KEY or UNIQUE constraint on a table,
** then the "sql" column is NULL.
**
** If the "type" column has the value "meta", then the "sql" column
** contains extra information about the database, such as the
** file format version number. All meta information must be processed
** before any tables or indices are constructed.
** In format 1, entries in the sqlite_master table are in a random
** order. Two passes must be made through the table to initialize
** internal data structures. The first pass reads table definitions
** and the second pass read index definitions. Having two passes
** insures that indices appear after their tables.
**
** In format 2, entries appear in chronological order. Only a single
** pass needs to be made through the table since everything will be
** in the write order. VIEWs may only occur in format 2.
**
** The following program invokes its callback on the SQL for each
** table then goes back and invokes the callback on the
@@ -161,38 +167,70 @@ static int sqliteInit(sqlite *db, char **pzErrMsg){
** database scheme.
*/
static VdbeOp initProg[] = {
/* Send the file format to the callback routine
*/
{ OP_Open, 0, 2, 0},
{ OP_String, 0, 0, "file-format"},
{ OP_String, 0, 0, 0},
{ OP_String, 0, 0, 0},
{ OP_ReadCookie, 0, 1, 0},
{ OP_Callback, 4, 0, 0},
/* Send the initial schema cookie to the callback
*/
{ OP_String, 0, 0, "schema_cookie"},
{ OP_String, 0, 0, 0},
{ OP_String, 0, 0, 0},
{ OP_ReadCookie, 0, 0, 0},
{ OP_Callback, 4, 0, 0},
{ OP_Rewind, 0, 31, 0},
{ OP_Column, 0, 0, 0}, /* 12 */
/* Check the file format. If the format number is 2 or more,
** then do a single pass through the SQLITE_MASTER table. For
** a format number of less than 2, jump forward to a different
** algorithm that makes two passes through the SQLITE_MASTER table,
** once for tables and a second time for indices.
*/
{ OP_ReadCookie, 0, 1, 0},
{ OP_Integer, 2, 0, 0},
{ OP_Lt, 0, 23, 0},
/* This is the code for doing a single scan through the SQLITE_MASTER
** table. This code runs for format 2 and greater.
*/
{ OP_Rewind, 0, 21, 0},
{ OP_Column, 0, 0, 0}, /* 15 */
{ OP_Column, 0, 1, 0},
{ OP_Column, 0, 3, 0},
{ OP_Column, 0, 4, 0},
{ OP_Callback, 4, 0, 0},
{ OP_Next, 0, 15, 0},
{ OP_Close, 0, 0, 0}, /* 21 */
{ OP_Halt, 0, 0, 0},
/* This is the code for doing two passes through SQLITE_MASTER. This
** code runs for file format 1.
*/
{ OP_Rewind, 0, 43, 0}, /* 23 */
{ OP_Column, 0, 0, 0}, /* 24 */
{ OP_String, 0, 0, "table"},
{ OP_Ne, 0, 20, 0},
{ OP_Ne, 0, 32, 0},
{ OP_Column, 0, 0, 0},
{ OP_Column, 0, 1, 0},
{ OP_Column, 0, 3, 0},
{ OP_Column, 0, 4, 0},
{ OP_Callback, 4, 0, 0},
{ OP_Next, 0, 12, 0}, /* 20 */
{ OP_Rewind, 0, 31, 0}, /* 21 */
{ OP_Column, 0, 0, 0}, /* 22 */
{ OP_Next, 0, 24, 0}, /* 32 */
{ OP_Rewind, 0, 43, 0}, /* 33 */
{ OP_Column, 0, 0, 0}, /* 34 */
{ OP_String, 0, 0, "index"},
{ OP_Ne, 0, 30, 0},
{ OP_Ne, 0, 42, 0},
{ OP_Column, 0, 0, 0},
{ OP_Column, 0, 1, 0},
{ OP_Column, 0, 3, 0},
{ OP_Column, 0, 4, 0},
{ OP_Callback, 4, 0, 0},
{ OP_Next, 0, 22, 0}, /* 30 */
{ OP_Close, 0, 0, 0}, /* 31 */
{ OP_Next, 0, 34, 0}, /* 42 */
{ OP_Close, 0, 0, 0}, /* 43 */
{ OP_Halt, 0, 0, 0},
};
@@ -209,9 +247,9 @@ static int sqliteInit(sqlite *db, char **pzErrMsg){
db->pBusyArg, db->xBusyCallback);
sqliteVdbeDelete(vdbe);
if( rc==SQLITE_OK && db->nTable==0 ){
db->file_format = FILE_FORMAT;
db->file_format = 2;
}
if( rc==SQLITE_OK && db->file_format>FILE_FORMAT ){
if( rc==SQLITE_OK && db->file_format>2 ){
sqliteSetString(pzErrMsg, "unsupported file format", 0);
rc = SQLITE_ERROR;
}