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

Fixed the support of UNIQUE and PRIMARY KEY. (CVS 268)

FossilOrigin-Name: 116fdad06868acf6aca9e75c2c3497c0511a42c3
This commit is contained in:
drh
2001-09-27 15:11:53 +00:00
parent 717e640294
commit adbca9cfde
13 changed files with 261 additions and 238 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.41 2001/09/23 20:17:55 drh Exp $
** $Id: main.c,v 1.42 2001/09/27 15:11:54 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@@ -26,8 +26,7 @@
** argv[0] = "meta" or "table" or "index"
** argv[1] = table or index name or meta statement type.
** argv[2] = root page number for table or index. NULL for meta.
** argv[3] = root page number of primary key for tables or NULL.
** argv[4] = SQL create statement for the table or index
** argv[3] = SQL create statement for the table or index
**
*/
static int sqliteOpenCb(void *pDb, int argc, char **argv, char **azColName){
@@ -38,25 +37,33 @@ static int sqliteOpenCb(void *pDb, int argc, char **argv, char **azColName){
/* TODO: Do some validity checks on all fields. In particular,
** make sure fields do not contain NULLs. */
assert( argc==5 );
assert( argc==4 );
switch( argv[0][0] ){
case 'm': { /* Meta information */
if( strcmp(argv[1],"file-format")==0 ){
db->file_format = atoi(argv[4]);
db->file_format = atoi(argv[3]);
}else if( strcmp(argv[1],"schema-cookie")==0 ){
db->schema_cookie = atoi(argv[4]);
db->schema_cookie = atoi(argv[3]);
db->next_cookie = db->schema_cookie;
}
break;
}
case 'i':
case 't': { /* CREATE TABLE and CREATE INDEX statements */
memset(&sParse, 0, sizeof(sParse));
sParse.db = db;
sParse.initFlag = 1;
sParse.newTnum = atoi(argv[2]);
sParse.newKnum = argv[3] ? atoi(argv[3]) : 0;
nErr = sqliteRunParser(&sParse, argv[4], 0);
if( argv[3] && argv[3][0] ){
memset(&sParse, 0, sizeof(sParse));
sParse.db = db;
sParse.initFlag = 1;
sParse.newTnum = atoi(argv[2]);
nErr = sqliteRunParser(&sParse, argv[3], 0);
}else{
Index *pIndex = sqliteFindIndex(db, argv[1]);
if( pIndex==0 || pIndex->tnum!=0 ){
nErr++;
}else{
pIndex->tnum = atoi(argv[2]);
}
}
break;
}
default: {
@@ -92,8 +99,7 @@ static int sqliteInit(sqlite *db, char **pzErrMsg){
" type text,\n"
" name text,\n"
" tbl_name text,\n"
" tnum integer,\n"
" knum integer,\n"
" rootpage integer,\n"
" sql text\n"
")"
;
@@ -107,8 +113,7 @@ static int sqliteInit(sqlite *db, char **pzErrMsg){
** type text, -- Either "table" or "index" or "meta"
** name text, -- Name of table or index
** tbl_name text, -- Associated table
** tnum integer, -- The integer page number of root page
** knum integer, -- Root page of primary key, or NULL
** rootpage integer, -- The integer page number of root page
** sql text -- The CREATE statement for this object
** );
**
@@ -136,47 +141,43 @@ static int sqliteInit(sqlite *db, char **pzErrMsg){
static VdbeOp initProg[] = {
{ OP_Open, 0, 2, 0},
{ OP_Rewind, 0, 0, 0},
{ OP_Next, 0, 13, 0}, /* 2 */
{ OP_Next, 0, 12, 0}, /* 2 */
{ OP_Column, 0, 0, 0},
{ OP_String, 0, 0, "meta"},
{ OP_Ne, 0, 2, 0},
{ OP_Column, 0, 0, 0},
{ OP_Column, 0, 1, 0},
{ OP_Column, 0, 3, 0},
{ OP_Null, 0, 0, 0},
{ OP_Column, 0, 5, 0},
{ OP_Callback, 5, 0, 0},
{ OP_Column, 0, 4, 0},
{ OP_Callback, 4, 0, 0},
{ OP_Goto, 0, 2, 0},
{ OP_Rewind, 0, 0, 0}, /* 13 */
{ OP_Next, 0, 25, 0}, /* 14 */
{ OP_Rewind, 0, 0, 0}, /* 12 */
{ OP_Next, 0, 23, 0}, /* 13 */
{ OP_Column, 0, 0, 0},
{ OP_String, 0, 0, "table"},
{ OP_Ne, 0, 14, 0},
{ OP_Ne, 0, 13, 0},
{ OP_Column, 0, 0, 0},
{ OP_Column, 0, 1, 0},
{ OP_Column, 0, 3, 0},
{ OP_Column, 0, 4, 0},
{ OP_Column, 0, 5, 0},
{ OP_Callback, 5, 0, 0},
{ OP_Goto, 0, 14, 0},
{ OP_Rewind, 0, 0, 0}, /* 25 */
{ OP_Next, 0, 37, 0}, /* 26 */
{ OP_Callback, 4, 0, 0},
{ OP_Goto, 0, 13, 0},
{ OP_Rewind, 0, 0, 0}, /* 23 */
{ OP_Next, 0, 34, 0}, /* 24 */
{ OP_Column, 0, 0, 0},
{ OP_String, 0, 0, "index"},
{ OP_Ne, 0, 26, 0},
{ OP_Ne, 0, 24, 0},
{ OP_Column, 0, 0, 0},
{ OP_Column, 0, 1, 0},
{ OP_Column, 0, 3, 0},
{ OP_Null, 0, 0, 0},
{ OP_Column, 0, 5, 0},
{ OP_Callback, 5, 0, 0},
{ OP_Goto, 0, 26, 0},
{ OP_String, 0, 0, "meta"}, /* 37 */
{ OP_Column, 0, 4, 0},
{ OP_Callback, 4, 0, 0},
{ OP_Goto, 0, 24, 0},
{ OP_String, 0, 0, "meta"}, /* 34 */
{ OP_String, 0, 0, "schema-cookie"},
{ OP_Null, 0, 0, 0},
{ OP_Null, 0, 0, 0},
{ OP_ReadCookie,0,0, 0},
{ OP_Callback, 5, 0, 0},
{ OP_Callback, 4, 0, 0},
{ OP_Close, 0, 0, 0},
{ OP_Halt, 0, 0, 0},
};
@@ -203,10 +204,9 @@ static int sqliteInit(sqlite *db, char **pzErrMsg){
azArg[0] = "table";
azArg[1] = MASTER_NAME;
azArg[2] = "2";
azArg[3] = 0;
azArg[4] = master_schema;
azArg[5] = 0;
sqliteOpenCb(db, 5, azArg, 0);
azArg[3] = master_schema;
azArg[4] = 0;
sqliteOpenCb(db, 4, azArg, 0);
pTab = sqliteFindTable(db, MASTER_NAME);
if( pTab ){
pTab->readOnly = 1;