Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | file format change (CVS 122) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
b7b90237945d3577caba3a2f5595e52b |
User & Date: | drh 2000-08-02 13:47:42.000 |
Context
2000-08-03
| ||
15:09 | bug fix (CVS 123) (check-in: 4dabf5e4e6 user: drh tags: trunk) | |
2000-08-02
| ||
13:47 | file format change (CVS 122) (check-in: b7b9023794 user: drh tags: trunk) | |
12:37 | file format change (CVS 121) (check-in: 4110936f11 user: drh tags: trunk) | |
Changes
Changes to src/build.c.
︙ | ︙ | |||
29 30 31 32 33 34 35 | ** DROP TABLE ** CREATE INDEX ** DROP INDEX ** creating expressions and ID lists ** COPY ** VACUUM ** | | | 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | ** DROP TABLE ** CREATE INDEX ** DROP INDEX ** creating expressions and ID lists ** COPY ** VACUUM ** ** $Id: build.c,v 1.22 2000/08/02 13:47:42 drh Exp $ */ #include "sqliteInt.h" /* ** This routine is called after a single SQL statement has been ** parsed and we want to execute the VDBE code to implement ** that statement. Prior action routines should have already |
︙ | ︙ | |||
315 316 317 318 319 320 321 322 323 324 325 326 | ** the master table because we just connected to the database, so ** the entry for this table already exists in the master table. ** We do not want to create it again. */ void sqliteEndTable(Parse *pParse, Token *pEnd){ Table *p; int h; if( pParse->nErr ) return; /* Add the table to the in-memory representation of the database */ | > > > | > > > | > > > > > > > > > > | 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 | ** the master table because we just connected to the database, so ** the entry for this table already exists in the master table. ** We do not want to create it again. */ void sqliteEndTable(Parse *pParse, Token *pEnd){ Table *p; int h; int addVersion; /* True to insert a "file format" meta record */ if( pParse->nErr ) return; p = pParse->pNewTable; addVersion = p!=0 && pParse->db->nTable==1; /* Add the table to the in-memory representation of the database */ if( p!=0 && pParse->explain==0 ){ h = sqliteHashNoCase(p->zName, 0) % N_HASH; p->pHash = pParse->db->apTblHash[h]; pParse->db->apTblHash[h] = p; pParse->pNewTable = 0; pParse->db->nTable++; } /* If not initializing, then create the table on disk. */ if( !pParse->initFlag ){ static VdbeOp addTable[] = { { OP_Open, 0, 1, MASTER_NAME }, { OP_New, 0, 0, 0}, { OP_String, 0, 0, "table" }, { OP_String, 0, 0, 0}, /* 3 */ { OP_String, 0, 0, 0}, /* 4 */ { OP_String, 0, 0, 0}, /* 5 */ { OP_MakeRecord, 4, 0, 0}, { OP_Put, 0, 0, 0}, }; static VdbeOp addVersion[] = { { OP_New, 0, 0, 0}, { OP_String, 0, 0, "meta" }, { OP_String, 0, 0, "" }, { OP_String, 0, 0, "" }, { OP_String, 0, 0, "file format 2" }, { OP_MakeRecord, 4, 0, 0}, { OP_Put, 0, 0, 0}, }; int n, base; Vdbe *v; v = sqliteGetVdbe(pParse); if( v==0 ) return; n = (int)pEnd->z - (int)pParse->sFirstToken.z + 1; base = sqliteVdbeAddOpList(v, ArraySize(addTable), addTable); sqliteVdbeChangeP3(v, base+3, p->zName, 0); sqliteVdbeChangeP3(v, base+4, p->zName, 0); sqliteVdbeChangeP3(v, base+5, pParse->sFirstToken.z, n); if( addVersion ){ sqliteVdbeAddOpList(v, ArraySize(addVersion), addVersion); } sqliteVdbeAddOp(v, OP_Close, 0, 0, 0, 0); } } /* ** Given a token, look up a table with that name. If not found, leave ** an error for the parser to find and return NULL. */ |
︙ | ︙ | |||
436 437 438 439 440 441 442 443 444 445 446 447 448 449 | }else{ Table *p; for(p=pParse->db->apTblHash[h]; p && p->pHash!=pTable; p=p->pHash){} if( p && p->pHash==pTable ){ p->pHash = pTable->pHash; } } sqliteDeleteTable(pParse->db, pTable); } } /* ** Create a new index for an SQL table. pIndex is the name of the index ** and pTable is the name of the table that is to be indexed. Both will | > | 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | }else{ Table *p; for(p=pParse->db->apTblHash[h]; p && p->pHash!=pTable; p=p->pHash){} if( p && p->pHash==pTable ){ p->pHash = pTable->pHash; } } pParse->db->nTable--; sqliteDeleteTable(pParse->db, pTable); } } /* ** Create a new index for an SQL table. pIndex is the name of the index ** and pTable is the name of the table that is to be indexed. Both will |
︙ | ︙ |
Changes to src/main.c.
︙ | ︙ | |||
22 23 24 25 26 27 28 | ** ************************************************************************* ** Main file for the SQLite library. The routines in this file ** implement the programmer interface to the library. Routines in ** other files are for internal use by SQLite and should not be ** accessed by users of the library. ** | | > > > > > > > > > > > > | 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | ** ************************************************************************* ** Main file for the SQLite library. The routines in this file ** implement the programmer interface to the library. Routines in ** other files are for internal use by SQLite and should not be ** accessed by users of the library. ** ** $Id: main.c,v 1.16 2000/08/02 13:47:42 drh Exp $ */ #include "sqliteInt.h" /* ** This is the callback routine for the code that initializes the ** database. Each callback contains text of a CREATE TABLE or ** CREATE INDEX statement that must be parsed to yield the internal ** structures that describe the tables. ** ** This callback is also called with argc==2 when there is meta ** information in the sqlite_master file. The meta information is ** contained in argv[1]. Typical meta information is the file format ** version. */ static int sqliteOpenCb(void *pDb, int argc, char **argv, char **azColName){ sqlite *db = (sqlite*)pDb; Parse sParse; int nErr; if( argc==2 ){ if( sscanf(argv[1],"file format %d",&db->file_format)==1 ){ return 0; } /* Unknown meta information. Ignore it. */ return 0; } if( argc!=1 ) return 0; memset(&sParse, 0, sizeof(sParse)); sParse.db = db; sParse.initFlag = 1; nErr = sqliteRunParser(&sParse, argv[0], 0); return nErr; } |
︙ | ︙ | |||
79 80 81 82 83 84 85 | /* The following program is used to initialize the internal ** structure holding the tables and indexes of the database. ** The database contains a special table named "sqlite_master" ** defined as follows: ** ** CREATE TABLE sqlite_master ( | | > > > > > | | > > > > > > > > > | | | | | | > > > > | 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | /* The following program is used to initialize the internal ** structure holding the tables and indexes of the database. ** The database contains a special table named "sqlite_master" ** defined as follows: ** ** CREATE TABLE sqlite_master ( ** type text, -- Either "table" or "index" or "meta" ** name text, -- Name of table or index ** tbl_name text, -- Associated table ** sql text -- The CREATE statement for this object ** ); ** ** The sqlite_master table contains a single entry for each table ** and each index. The "type" column tells whether the entry is ** a table or index. The "name" column is the name of the object. ** The "tbl_name" is the name of the associated table. For tables, ** the tbl_name column is always the same as name. For indices, the ** tbl_name column contains the name of the table that the index ** indexes. Finally, the "sql" column contains the complete text of ** the CREATE TABLE or CREATE INDEX statement that originally created ** the table or index. ** ** 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. ** ** The following program invokes its callback on the SQL for each ** table then goes back and invokes the callback on the ** SQL for each index. The callback will invoke the ** parser to build the internal representation of the ** database scheme. */ static VdbeOp initProg[] = { { OP_Open, 0, 0, MASTER_NAME}, { OP_Next, 0, 9, 0}, /* 1 */ { OP_Field, 0, 0, 0}, { OP_String, 0, 0, "meta"}, { OP_Ne, 0, 1, 0}, { OP_Field, 0, 0, 0}, { OP_Field, 0, 3, 0}, { OP_Callback, 2, 0, 0}, { OP_Goto, 0, 1, 0}, { OP_Rewind, 0, 0, 0}, /* 9 */ { OP_Next, 0, 17, 0}, /* 10 */ { OP_Field, 0, 0, 0}, { OP_String, 0, 0, "table"}, { OP_Ne, 0, 10, 0}, { OP_Field, 0, 3, 0}, { OP_Callback, 1, 0, 0}, { OP_Goto, 0, 10, 0}, { OP_Rewind, 0, 0, 0}, /* 17 */ { OP_Next, 0, 25, 0}, /* 18 */ { OP_Field, 0, 0, 0}, { OP_String, 0, 0, "index"}, { OP_Ne, 0, 18, 0}, { OP_Field, 0, 3, 0}, { OP_Callback, 1, 0, 0}, { OP_Goto, 0, 18, 0}, { OP_Halt, 0, 0, 0}, /* 25 */ }; /* Create a virtual machine to run the initialization program. Run ** the program. The delete the virtual machine. */ vdbe = sqliteVdbeCreate(db->pBe); if( vdbe==0 ){ sqliteSetString(pzErrMsg, "out of memory",0); return 1; } sqliteVdbeAddOpList(vdbe, sizeof(initProg)/sizeof(initProg[0]), initProg); rc = sqliteVdbeExec(vdbe, sqliteOpenCb, db, pzErrMsg, db->pBusyArg, db->xBusyCallback); sqliteVdbeDelete(vdbe); if( rc==SQLITE_OK && db->file_format<2 && db->nTable>0 ){ sqliteSetString(pzErrMsg, "obsolete file format", 0); rc = SQLITE_ERROR; } if( rc==SQLITE_OK ){ Table *pTab; char *azArg[2]; azArg[0] = master_schema; azArg[1] = 0; sqliteOpenCb(db, 1, azArg, 0); pTab = sqliteFindTable(db, MASTER_NAME); |
︙ | ︙ | |||
179 180 181 182 183 184 185 186 187 188 189 190 191 192 | /* Open the backend database driver */ db->pBe = sqliteDbbeOpen(zFilename, (mode&0222)!=0, mode!=0, pzErrMsg); if( db->pBe==0 ){ sqliteStrRealloc(pzErrMsg); sqliteFree(db); return 0; } /* Attempt to read the schema */ rc = sqliteInit(db, pzErrMsg); if( rc!=SQLITE_OK && rc!=SQLITE_BUSY ){ sqlite_close(db); return 0; }else{ | > > > | 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | /* Open the backend database driver */ db->pBe = sqliteDbbeOpen(zFilename, (mode&0222)!=0, mode!=0, pzErrMsg); if( db->pBe==0 ){ sqliteStrRealloc(pzErrMsg); sqliteFree(db); return 0; } /* Assume file format 1 unless the database says otherwise */ db->file_format = 1; /* Attempt to read the schema */ rc = sqliteInit(db, pzErrMsg); if( rc!=SQLITE_OK && rc!=SQLITE_BUSY ){ sqlite_close(db); return 0; }else{ |
︙ | ︙ |
Changes to src/shell.c.
︙ | ︙ | |||
20 21 22 23 24 25 26 | ** drh@hwaci.com ** http://www.hwaci.com/drh/ ** ************************************************************************* ** This file contains code to implement the "sqlite" command line ** utility for accessing SQLite databases. ** | | | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | ** drh@hwaci.com ** http://www.hwaci.com/drh/ ** ************************************************************************* ** This file contains code to implement the "sqlite" command line ** utility for accessing SQLite databases. ** ** $Id: shell.c,v 1.19 2000/08/02 13:47:42 drh Exp $ */ #include <stdlib.h> #include <string.h> #include <stdio.h> #include "sqlite.h" #include <unistd.h> #include <ctype.h> |
︙ | ︙ | |||
435 436 437 438 439 440 441 442 443 444 445 446 447 | c = azArg[0][0]; if( c=='d' && strncmp(azArg[0], "dump", n)==0 ){ char *zErrMsg = 0; char zSql[1000]; if( nArg==1 ){ sprintf(zSql, "SELECT name, type, sql FROM sqlite_master " "ORDER BY tbl_name, type DESC, name"); sqlite_exec(db, zSql, dump_callback, p, &zErrMsg); }else{ int i; for(i=1; i<nArg && zErrMsg==0; i++){ sprintf(zSql, "SELECT name, type, sql FROM sqlite_master " | > | | 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 | c = azArg[0][0]; if( c=='d' && strncmp(azArg[0], "dump", n)==0 ){ char *zErrMsg = 0; char zSql[1000]; if( nArg==1 ){ sprintf(zSql, "SELECT name, type, sql FROM sqlite_master " "WHERE type!='meta' " "ORDER BY tbl_name, type DESC, name"); sqlite_exec(db, zSql, dump_callback, p, &zErrMsg); }else{ int i; for(i=1; i<nArg && zErrMsg==0; i++){ sprintf(zSql, "SELECT name, type, sql FROM sqlite_master " "WHERE tbl_name LIKE '%.800s' AND type!='meta' " "ORDER BY type DESC, name", azArg[i]); sqlite_exec(db, zSql, dump_callback, p, &zErrMsg); } } if( zErrMsg ){ fprintf(stderr,"Error: %s\n", zErrMsg); |
︙ | ︙ | |||
547 548 549 550 551 552 553 | char *zErrMsg = 0; char zSql[1000]; memcpy(&data, p, sizeof(data)); data.showHeader = 0; data.mode = MODE_List; if( nArg>1 ){ sprintf(zSql, "SELECT sql FROM sqlite_master " | | > | 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 | char *zErrMsg = 0; char zSql[1000]; memcpy(&data, p, sizeof(data)); data.showHeader = 0; data.mode = MODE_List; if( nArg>1 ){ sprintf(zSql, "SELECT sql FROM sqlite_master " "WHERE tbl_name LIKE '%.800s' AND type!='meta'" "ORDER BY type DESC, name", azArg[1]); }else{ sprintf(zSql, "SELECT sql FROM sqlite_master " "WHERE type!='meta' " "ORDER BY tbl_name, type DESC, name"); } sqlite_exec(db, zSql, callback, &data, &zErrMsg); if( zErrMsg ){ fprintf(stderr,"Error: %s\n", zErrMsg); free(zErrMsg); } |
︙ | ︙ |
Changes to src/sqliteInt.h.
︙ | ︙ | |||
19 20 21 22 23 24 25 | ** Author contact information: ** drh@hwaci.com ** http://www.hwaci.com/drh/ ** ************************************************************************* ** Internal interface definitions for SQLite. ** | | | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | ** Author contact information: ** drh@hwaci.com ** http://www.hwaci.com/drh/ ** ************************************************************************* ** Internal interface definitions for SQLite. ** ** @(#) $Id: sqliteInt.h,v 1.29 2000/08/02 13:47:42 drh Exp $ */ #include "sqlite.h" #include "dbbe.h" #include "vdbe.h" #include "parse.h" #include <gdbm.h> #include <stdio.h> |
︙ | ︙ | |||
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | /* ** Each database is an instance of the following structure */ struct sqlite { Dbbe *pBe; /* The backend driver */ int flags; /* Miscellanous flags */ void *pBusyArg; /* 1st Argument to the busy callback */ int (*xBusyCallback)(void *,const char*,int); /* The busy callback */ Table *apTblHash[N_HASH]; /* All tables of the database */ Index *apIdxHash[N_HASH]; /* All indices of the database */ }; /* ** Possible values for the sqlite.flags. */ #define SQLITE_VdbeTrace 0x00000001 #define SQLITE_Initialized 0x00000002 /* ** information about each column of an SQL table is held in an instance ** of this structure. */ struct Column { char *zName; /* Name of this column */ char *zDflt; /* Default value of this column */ | > > > > > > > | 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | /* ** Each database is an instance of the following structure */ struct sqlite { Dbbe *pBe; /* The backend driver */ int flags; /* Miscellanous flags */ int file_format; /* What file format version is this database? */ int nTable; /* Number of tables in the database */ void *pBusyArg; /* 1st Argument to the busy callback */ int (*xBusyCallback)(void *,const char*,int); /* The busy callback */ Table *apTblHash[N_HASH]; /* All tables of the database */ Index *apIdxHash[N_HASH]; /* All indices of the database */ }; /* ** Possible values for the sqlite.flags. */ #define SQLITE_VdbeTrace 0x00000001 #define SQLITE_Initialized 0x00000002 /* ** Current file format version */ #define SQLITE_FileFormat 2 /* ** information about each column of an SQL table is held in an instance ** of this structure. */ struct Column { char *zName; /* Name of this column */ char *zDflt; /* Default value of this column */ |
︙ | ︙ |
Changes to test/index.test.
︙ | ︙ | |||
19 20 21 22 23 24 25 | # drh@hwaci.com # http://www.hwaci.com/drh/ # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this file is testing the CREATE INDEX statement. # | | | | | | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | # drh@hwaci.com # http://www.hwaci.com/drh/ # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this file is testing the CREATE INDEX statement. # # $Id: index.test,v 1.7 2000/08/02 13:47:42 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # Create a basic index and verify it is added to sqlite_master # do_test index-1.1 { execsql {CREATE TABLE test1(f1 int, f2 int, f3 int)} execsql {CREATE INDEX index1 ON test1(f1)} execsql {SELECT name FROM sqlite_master WHERE type!='meta' ORDER BY name} } {index1 test1} do_test index-1.1b { execsql {SELECT name, sql, tbl_name, type FROM sqlite_master WHERE name='index1'} } {index1 {CREATE INDEX index1 ON test1(f1)} test1 index} do_test index-1.1c { db close sqlite db testdb execsql {SELECT name, sql, tbl_name, type FROM sqlite_master WHERE name='index1'} } {index1 {CREATE INDEX index1 ON test1(f1)} test1 index} do_test index-1.1d { db close sqlite db testdb execsql {SELECT name FROM sqlite_master WHERE type!='meta' ORDER BY name} } {index1 test1} # Verify that the index dies with the table # do_test index-1.2 { execsql {DROP TABLE test1} execsql {SELECT name FROM sqlite_master WHERE type!='meta' ORDER BY name} } {} # Try adding an index to a table that does not exist # do_test index-2.1 { set v [catch {execsql {CREATE INDEX index1 ON test1(f1)}} msg] lappend v $msg |
︙ | ︙ | |||
133 134 135 136 137 138 139 | do_test index-4.1 { execsql {CREATE TABLE test1(cnt int, power int)} for {set i 1} {$i<20} {incr i} { execsql "INSERT INTO test1 VALUES($i,[expr {int(pow(2,$i))}])" } execsql {CREATE INDEX index9 ON test1(cnt)} execsql {CREATE INDEX indext ON test1(power)} | | | 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | do_test index-4.1 { execsql {CREATE TABLE test1(cnt int, power int)} for {set i 1} {$i<20} {incr i} { execsql "INSERT INTO test1 VALUES($i,[expr {int(pow(2,$i))}])" } execsql {CREATE INDEX index9 ON test1(cnt)} execsql {CREATE INDEX indext ON test1(power)} execsql {SELECT name FROM sqlite_master WHERE type!='meta' ORDER BY name} } {index9 indext test1} do_test index-4.2 { execsql {SELECT cnt FROM test1 WHERE power=4} } {2} do_test index-4.3 { execsql {SELECT cnt FROM test1 WHERE power=1024} } {10} |
︙ | ︙ | |||
174 175 176 177 178 179 180 | execsql {SELECT power FROM test1 WHERE cnt=6} } {64} do_test index-4.12 { execsql {SELECT cnt FROM test1 WHERE power=1024} } {10} do_test index-4.13 { execsql {DROP TABLE test1} | | | | | | | | 174 175 176 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 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | execsql {SELECT power FROM test1 WHERE cnt=6} } {64} do_test index-4.12 { execsql {SELECT cnt FROM test1 WHERE power=1024} } {10} do_test index-4.13 { execsql {DROP TABLE test1} execsql {SELECT name FROM sqlite_master WHERE type!='meta' ORDER BY name} } {} # Do not allow indices to be added to sqlite_master # do_test index-5.1 { set v [catch {execsql {CREATE INDEX index1 ON sqlite_master(name)}} msg] lappend v $msg } {1 {table sqlite_master may not have new indices added}} do_test index-5.2 { execsql {SELECT name FROM sqlite_master WHERE type!='meta'} } {} # Do not allow indices with duplicate names to be added # do_test index-6.1 { execsql {CREATE TABLE test1(f1 int, f2 int)} execsql {CREATE TABLE test2(g1 real, g2 real)} execsql {CREATE INDEX index1 ON test1(f1)} set v [catch {execsql {CREATE INDEX index1 ON test2(g1)}} msg] lappend v $msg } {1 {index index1 already exists}} do_test index-6.1b { execsql {SELECT name FROM sqlite_master WHERE type!='meta' ORDER BY name} } {index1 test1 test2} do_test index-6.2 { set v [catch {execsql {CREATE INDEX test1 ON test2(g1)}} msg] lappend v $msg } {1 {there is already a table named test1}} do_test index-6.2b { execsql {SELECT name FROM sqlite_master WHERE type!='meta' ORDER BY name} } {index1 test1 test2} do_test index-6.3 { execsql {DROP TABLE test1} execsql {DROP TABLE test2} execsql {SELECT name FROM sqlite_master WHERE type!='meta' ORDER BY name} } {} # Create a primary key # do_test index-7.1 { execsql {CREATE TABLE test1(f1 int, f2 int primary key)} for {set i 1} {$i<20} {incr i} { execsql "INSERT INTO test1 VALUES($i,[expr {int(pow(2,$i))}])" } lsort -dictionary [glob testdb/test1*.tbl] } {testdb/test1.tbl testdb/test1__primary_key.tbl} do_test index-7.2 { execsql {SELECT f1 FROM test1 WHERE f2=65536} } {16} do_test index-7.3 { set code [execsql {EXPLAIN SELECT f1 FROM test1 WHERE f2=65536}] expr {[lsearch $code test1__primary_key]>0} } {1} do_test index-7.4 { execsql {DROP table test1} execsql {SELECT name FROM sqlite_master WHERE type!='meta'} } {} # Make sure we cannot drop a non-existant index. # do_test index-8.1 { set v [catch {execsql {DROP INDEX index1}} msg] lappend v $msg |
︙ | ︙ |
Changes to test/table.test.
︙ | ︙ | |||
19 20 21 22 23 24 25 | # drh@hwaci.com # http://www.hwaci.com/drh/ # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this file is testing the CREATE TABLE statement. # | | | | | | | | | | | | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | # drh@hwaci.com # http://www.hwaci.com/drh/ # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this file is testing the CREATE TABLE statement. # # $Id: table.test,v 1.6 2000/08/02 13:47:43 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # Create a basic table and verify it is added to sqlite_master # do_test table-1.1 { execsql { CREATE TABLE test1 ( one varchar(10), two text ) } execsql { SELECT sql FROM sqlite_master WHERE type!='meta' } } {{CREATE TABLE test1 ( one varchar(10), two text )}} # Verify that both table files exists in the database directory # do_test table-1.2 { execsql {INSERT INTO test1 VALUES('hi', 'y''all')} lsort [glob -nocomplain testdb/*.tbl] } {testdb/sqlite_master.tbl testdb/test1.tbl} # Verify the other fields of the sqlite_master file. # do_test table-1.3 { execsql {SELECT name, tbl_name, type FROM sqlite_master WHERE type!='meta'} } {test1 test1 table} # Close and reopen the database. Verify that everything is # still the same. # do_test table-1.4 { db close sqlite db testdb execsql {SELECT name, tbl_name, type from sqlite_master WHERE type!='meta'} } {test1 test1 table} # Drop the database and make sure it disappears. # do_test table-1.5 { execsql {DROP TABLE test1} execsql {SELECT * FROM sqlite_master WHERE type!='meta'} } {} # Verify that the file associated with the database is gone. # do_test table-1.5 { lsort [glob -nocomplain testdb/*.tbl] } {testdb/sqlite_master.tbl} # Close and reopen the database. Verify that the table is # still gone. # do_test table-1.6 { db close sqlite db testdb execsql {SELECT name FROM sqlite_master WHERE type!='meta'} } {} # Repeat the above steps, but this time quote the table name. # do_test table-1.10 { execsql {CREATE TABLE "create" (f1 int)} execsql {SELECT name FROM sqlite_master WHERE type!='meta'} } {create} do_test table-1.11 { execsql {DROP TABLE "create"} execsql {SELECT name FROM "sqlite_master" WHERE type!='meta'} } {} do_test table-1.12 { execsql {CREATE TABLE test1("f1 ho" int)} execsql {SELECT name as "X" FROM sqlite_master WHERE type!='meta'} } {test1} do_test table-1.13 { execsql {DROP TABLE "TEST1"} execsql {SELECT name FROM "sqlite_master" WHERE type!='meta'} } {} # Verify that we cannot make two tables with the same name # do_test table-2.1 { |
︙ | ︙ | |||
124 125 126 127 128 129 130 | do_test table-2.1c { db close sqlite db testdb set v [catch {execsql {CREATE TABLE sqlite_master(two text)}} msg] lappend v $msg } {1 {table sqlite_master already exists}} do_test table-2.1d { | | | 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | do_test table-2.1c { db close sqlite db testdb set v [catch {execsql {CREATE TABLE sqlite_master(two text)}} msg] lappend v $msg } {1 {table sqlite_master already exists}} do_test table-2.1d { execsql {DROP TABLE test2; SELECT name FROM sqlite_master WHERE type!='meta'} } {} # Verify that we cannot make a table with the same name as an index # do_test table-2.2a { execsql {CREATE TABLE test2(one text); CREATE INDEX test3 ON test2(one)} set v [catch {execsql {CREATE TABLE test3(two text)}} msg] |
︙ | ︙ | |||
146 147 148 149 150 151 152 | } {1 {there is already an index named test3}} do_test table-2.2c { execsql {DROP INDEX test3} set v [catch {execsql {CREATE TABLE test3(two text)}} msg] lappend v $msg } {0 {}} do_test table-2.2d { | | | | 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | } {1 {there is already an index named test3}} do_test table-2.2c { execsql {DROP INDEX test3} set v [catch {execsql {CREATE TABLE test3(two text)}} msg] lappend v $msg } {0 {}} do_test table-2.2d { execsql {SELECT name FROM sqlite_master WHERE type!='meta' ORDER BY name} } {test2 test3} do_test table-2.2e { execsql {DROP TABLE test2; DROP TABLE test3} execsql {SELECT name FROM sqlite_master WHERE type!='meta' ORDER BY name} } {} # Create a table with many field names # set big_table \ {CREATE TABLE big( f1 varchar(20), |
︙ | ︙ | |||
180 181 182 183 184 185 186 | f17 text, f18 text, f19 text, f20 text )} do_test table-3.1 { execsql $big_table | | | 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | f17 text, f18 text, f19 text, f20 text )} do_test table-3.1 { execsql $big_table execsql {SELECT sql FROM sqlite_master WHERE type!='meta'} } \{$big_table\} do_test table-3.2 { set v [catch {execsql {CREATE TABLE BIG(xyz foo)}} msg] lappend v $msg } {1 {table BIG already exists}} do_test table-3.3 { set v [catch {execsql {CREATE TABLE biG(xyz foo)}} msg] |
︙ | ︙ | |||
202 203 204 205 206 207 208 | db close sqlite db testdb set v [catch {execsql {CREATE TABLE Big(xyz foo)}} msg] lappend v $msg } {1 {table Big already exists}} do_test table-3.6 { execsql {DROP TABLE big} | | | | | | | | | 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 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | db close sqlite db testdb set v [catch {execsql {CREATE TABLE Big(xyz foo)}} msg] lappend v $msg } {1 {table Big already exists}} do_test table-3.6 { execsql {DROP TABLE big} execsql {SELECT name FROM sqlite_master WHERE type!='meta'} } {} # Try creating large numbers of tables # set r {} for {set i 1} {$i<=100} {incr i} { lappend r test$i } do_test table-4.1 { for {set i 1} {$i<=100} {incr i} { set sql "CREATE TABLE test$i (" for {set k 1} {$k<$i} {incr k} { append sql "field$k text," } append sql "last_field text)" execsql $sql } execsql {SELECT name FROM sqlite_master WHERE type!='meta' ORDER BY name} } $r do_test table-4.1b { db close sqlite db testdb execsql {SELECT name FROM sqlite_master WHERE type!='meta' ORDER BY name} } $r # Drop the even number tables # set r {} for {set i 1} {$i<=100} {incr i 2} { lappend r test$i } do_test table-4.2 { for {set i 2} {$i<=100} {incr i 2} { set sql "DROP TABLE TEST$i" execsql $sql } execsql {SELECT name FROM sqlite_master WHERE type!='meta' ORDER BY name} } $r # Drop the odd number tables # do_test table-4.3 { for {set i 1} {$i<=100} {incr i 2} { set sql "DROP TABLE test$i" execsql $sql } execsql {SELECT name FROM sqlite_master WHERE type!='meta' ORDER BY name} } {} # Try to drop a table that does not exist # do_test table-5.1 { set v [catch {execsql {DROP TABLE test9}} msg] lappend v $msg } {1 {no such table: test9}} # Try to drop sqlite_master # do_test table-5.2 { set v [catch {execsql {DROP TABLE sqlite_master}} msg] lappend v $msg } {1 {table sqlite_master may not be dropped}} # Make sure an EXPLAIN does not really create a new table # do_test table-5.3 { execsql {EXPLAIN CREATE TABLE test1(f1 int)} execsql {SELECT name FROM sqlite_master WHERE type!='meta'} } {} # Make sure an EXPLAIN does not really drop an existing table # do_test table-5.4 { execsql {CREATE TABLE test1(f1 int)} execsql {EXPLAIN DROP TABLE test1} execsql {SELECT name FROM sqlite_master WHERE type!='meta'} } {test1} # Create a table with a goofy name # do_test table-6.1 { execsql {CREATE TABLE 'Spaces In This Name!'(x int)} execsql {INSERT INTO 'spaces in this name!' VALUES(1)} set list [glob -nocomplain testdb/spaces*.tbl] } {testdb/spaces+in+this+name+.tbl} finish_test |