From: drh Date: Mon, 21 Oct 2013 02:14:45 +0000 (+0000) Subject: Simplification of the syntax: Merely append "WITHOUT rowid" to the end of X-Git-Tag: version-3.8.2~137^2~73 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5969da4a2c275c52fe830db0e60c0fee42af6ade;p=thirdparty%2Fsqlite.git Simplification of the syntax: Merely append "WITHOUT rowid" to the end of the table definition. FossilOrigin-Name: 131cc6e152abe1a2d48e6d8d40d2c2f8dbe723e7 --- diff --git a/manifest b/manifest index da1f50d532..c5c2651232 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Experimental\schanges\stoward\s"index\sonly"\stables.\s\sAdd\sthe\sability\sto\sspecify\noptions\son\sCREATE\sTABLE\sstatements\susing\sthe\sWITH\sclause\smodeled\safter\nPostgreSQL\sand\sSQL\sServer.\s\sOnly\sthe\s"omit_rowid"\soption\sis\scurrently\nrecognized\sand\sthat\soption\sis\scurrently\sa\sno-op. -D 2013-10-19T23:31:56.588 +C Simplification\sof\sthe\ssyntax:\s\sMerely\sappend\s"WITHOUT\srowid"\sto\sthe\send\sof\nthe\stable\sdefinition. +D 2013-10-21T02:14:45.234 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 0522b53cdc1fcfc18f3a98e0246add129136c654 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -168,7 +168,7 @@ F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7 F src/btree.c 509722ce305471b626d3401c0631a808fd33237b F src/btree.h bfe0e8c5759b4ec77b0d18390064a6ef3cdffaaf F src/btreeInt.h f038e818bfadf75afbd09819ed93c26a333d39e0 -F src/build.c 2adfe99b972f1f270e602c39f7c726fa8477343b +F src/build.c 34096edeeb606354dc7e4b3e5b5b4aa66552d64a F src/callback.c f99a8957ba2adf369645fac0db09ad8adcf1caa2 F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac F src/ctime.c ea4b7f3623a0fcb1146e7f245d7410033e86859c @@ -208,7 +208,7 @@ F src/os_unix.c 243fb37f47dc072fc59839ea241ff0a17c8d76e6 F src/os_win.c b159b5249d9f70607d961bbdd1dbba789c75812c F src/pager.c 2aa4444ffe86e9282d03bc349a4a5e49bd77c0e8 F src/pager.h f094af9f6ececfaa8a1e93876905a4f34233fb0c -F src/parse.y 909868a9a60caeaa94d439a8b321e5491f989111 +F src/parse.y 073a8294e1826f1b1656e84806b77e4199f4bb57 F src/pcache.c f8043b433a57aba85384a531e3937a804432a346 F src/pcache.h a5e4f5d9f5d592051d91212c5949517971ae6222 F src/pcache1.c a467393909a4ed7ca9de066d85ba5c5b04a5be63 @@ -223,7 +223,7 @@ F src/shell.c 6f11f0e9ded63d48e306f2c6858c521e568a47bb F src/sqlite.h.in 547a44dd4ff4d975e92a645ea2d609e543a83d0f F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc -F src/sqliteInt.h 64409173b3e74ae26c66e737fa36d0b792dd77f9 +F src/sqliteInt.h 426774ce055ff560525f53622c95267d49f42edd F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e @@ -298,7 +298,7 @@ F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 F test/aggnested.test 45c0201e28045ad38a530b5a144b73cd4aa2cfd6 F test/alias.test 4529fbc152f190268a15f9384a5651bbbabc9d87 F test/all.test 6ff7b43c2b4b905c74dc4a813d201d0fa64c5783 -F test/alter.test f128974fbafff7c57e9f5ff2b2ecdd1dd4c4f84d +F test/alter.test e88dfa77e020c2b48e52a8020c70171ab828e079 F test/alter2.test 7ea05c7d92ac99349a802ef7ada17294dd647060 F test/alter3.test 49c9d9fba2b8fcdce2dedeca97bbf1f369cc548d F test/alter4.test 8e93bf7a7e6919b14b0c9a6c1e4908bcf21b0165 @@ -824,7 +824,7 @@ F test/syscall.test a653783d985108c4912cc64d341ffbbb55ad2806 F test/sysfault.test fa776e60bf46bdd3ae69f0b73e46ee3977a58ae6 F test/table.test 30423211108121884588d24d6776c7f38702ad7b F test/tableapi.test 2674633fa95d80da917571ebdd759a14d9819126 -F test/tableopts.test 28c869c5590fac5469a6da0a3612485d8c64cd25 +F test/tableopts.test b0aa6ebab4341c1c460031c0c2349fa33f354d10 F test/tclsqlite.test 37a61c2da7e3bfe3b8c1a2867199f6b860df5d43 F test/tempdb.test 19d0f66e2e3eeffd68661a11c83ba5e6ace9128c F test/temptable.test d2c9b87a54147161bcd1822e30c1d1cd891e5b30 @@ -1092,7 +1092,7 @@ F tool/lemon.c 796930d5fc2036c7636f3f1ee12f9ae03719a2eb F tool/lempar.c 01ca97f87610d1dac6d8cd96ab109ab1130e76dc F tool/logest.c 7ad625cac3d54012b27d468b7af6612f78b9ba75 F tool/mkautoconfamal.sh f8d8dbf7d62f409ebed5134998bf5b51d7266383 -F tool/mkkeywordhash.c d29369d17069558affef8c4ed5c58ad6c0238c68 +F tool/mkkeywordhash.c 189d76644e373c7d0864c628deb8ce7b4f403591 F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e F tool/mkpragmatab.tcl 3fc52e00a234750675e8a569d2919ff48558e9eb F tool/mkspeedsql.tcl a1a334d288f7adfe6e996f2e712becf076745c97 @@ -1127,10 +1127,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P 4bd592c8f0e011e203443a6e88008a61d6926df5 -R fbf9e989e7ae142368f9794120af33f8 -T *branch * omit-rowid -T *sym-omit-rowid * -T -sym-trunk * +P 0248ec5e6e3797575388f046d8c27f7445fe2a39 +R e0ffffb04f34ea8648db0bbf67f5a7fc U drh -Z 7440405d7d57d4e7a838139e7bed4bdc +Z 31b116f5cf081a48ed8c95100c024626 diff --git a/manifest.uuid b/manifest.uuid index fe09693b03..5c592f0b91 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0248ec5e6e3797575388f046d8c27f7445fe2a39 \ No newline at end of file +131cc6e152abe1a2d48e6d8d40d2c2f8dbe723e7 \ No newline at end of file diff --git a/src/build.c b/src/build.c index f17683a9c6..8cee89200d 100644 --- a/src/build.c +++ b/src/build.c @@ -1556,9 +1556,8 @@ static void estimateIndexWidth(Index *pIdx){ void sqlite3EndTable( Parse *pParse, /* Parse context */ Token *pCons, /* The ',' token after the last column defn. */ - Token *pEnd1, /* The ')' before options in the CREATE TABLE */ - Token *pEnd2, /* The final ')' in the whole CREATE TABLE */ - IdList *pOpts, /* List of table options. May be NULL */ + Token *pEnd, /* The ')' before options in the CREATE TABLE */ + u8 tabOpts, /* Extra table options. Usually 0. */ Select *pSelect /* Select from a "CREATE ... AS SELECT" */ ){ Table *p; /* The new table */ @@ -1566,26 +1565,19 @@ void sqlite3EndTable( int iDb; /* Database in which the table lives */ Index *pIdx; /* An implied index of the table */ - if( (pEnd1==0 && pSelect==0) || db->mallocFailed ){ - goto end_table_exception; + if( (pEnd==0 && pSelect==0) || db->mallocFailed ){ + return; } p = pParse->pNewTable; - if( p==0 ) goto end_table_exception; + if( p==0 ) return; assert( !db->init.busy || !pSelect ); - if( pOpts ){ - int i; - for(i=0; inId; i++){ - if( sqlite3_stricmp(pOpts->a[i].zName, "omit_rowid")==0 ){ - p->tabFlags |= TF_WithoutRowid; - if( (p->tabFlags & TF_HasPrimaryKey)==0 ){ - sqlite3ErrorMsg(pParse, "no PRIMARY KEY for table %s", p->zName); - } - continue; - } - sqlite3ErrorMsg(pParse, "unknown table option: %s", pOpts->a[i].zName); + if( tabOpts & TF_WithoutRowid ){ + if( (p->tabFlags & TF_HasPrimaryKey)==0 ){ + sqlite3ErrorMsg(pParse, "no PRIMARY KEY for table %s", p->zName); } + p->tabFlags |= TF_WithoutRowid; } iDb = sqlite3SchemaToIndex(db, p->pSchema); @@ -1628,7 +1620,7 @@ void sqlite3EndTable( char *zStmt; /* Text of the CREATE TABLE or CREATE VIEW statement */ v = sqlite3GetVdbe(pParse); - if( NEVER(v==0) ) goto end_table_exception; + if( NEVER(v==0) ) return; sqlite3VdbeAddOp1(v, OP_Close, 0); @@ -1673,7 +1665,7 @@ void sqlite3EndTable( sqlite3VdbeAddOp1(v, OP_Close, 1); if( pParse->nErr==0 ){ pSelTab = sqlite3ResultSetOfSelect(pParse, pSelect); - if( pSelTab==0 ) goto end_table_exception; + if( pSelTab==0 ) return; assert( p->aCol==0 ); p->nCol = pSelTab->nCol; p->aCol = pSelTab->aCol; @@ -1687,7 +1679,8 @@ void sqlite3EndTable( if( pSelect ){ zStmt = createTableStmt(db, p); }else{ - n = (int)(pEnd2->z - pParse->sNameToken.z) + 1; + n = (int)(pParse->sLastToken.z - pParse->sNameToken.z); + if( pParse->sLastToken.z[0]!=';' ) n += pParse->sLastToken.n; zStmt = sqlite3MPrintf(db, "CREATE %s %.*s", zType2, n, pParse->sNameToken.z ); @@ -1745,7 +1738,7 @@ void sqlite3EndTable( if( pOld ){ assert( p==pOld ); /* Malloc must have failed inside HashInsert() */ db->mallocFailed = 1; - goto end_table_exception; + return; } pParse->pNewTable = 0; db->flags |= SQLITE_InternChanges; @@ -1754,19 +1747,15 @@ void sqlite3EndTable( if( !p->pSelect ){ const char *zName = (const char *)pParse->sNameToken.z; int nName; - assert( !pSelect && pCons && pEnd1 ); + assert( !pSelect && pCons && pEnd ); if( pCons->z==0 ){ - pCons = pEnd1; + pCons = pEnd; } nName = (int)((const char *)pCons->z - zName); p->addColOffset = 13 + sqlite3Utf8CharLen(zName, nName); } #endif } - -end_table_exception: - sqlite3IdListDelete(db, pOpts); - return; } #ifndef SQLITE_OMIT_VIEW @@ -1839,7 +1828,7 @@ void sqlite3CreateView( sEnd.n = 1; /* Use sqlite3EndTable() to add the view to the SQLITE_MASTER table */ - sqlite3EndTable(pParse, 0, &sEnd, &sEnd, 0, 0); + sqlite3EndTable(pParse, 0, &sEnd, 0, 0); return; } #endif /* SQLITE_OMIT_VIEW */ diff --git a/src/parse.y b/src/parse.y index 85569e2c07..07e607dcf9 100644 --- a/src/parse.y +++ b/src/parse.y @@ -163,17 +163,23 @@ ifnotexists(A) ::= IF NOT EXISTS. {A = 1;} temp(A) ::= TEMP. {A = 1;} %endif SQLITE_OMIT_TEMPDB temp(A) ::= . {A = 0;} -create_table_args ::= LP columnlist conslist_opt(X) RP(E1). { - sqlite3EndTable(pParse,&X,&E1,&E1,0,0); -} -create_table_args ::= LP columnlist conslist_opt(X) RP(E1) - WITH LP idlist(Z) RP(E2). { - sqlite3EndTable(pParse,&X,&E1,&E2,Z,0); +create_table_args ::= LP columnlist conslist_opt(X) RP(E) table_options(F). { + sqlite3EndTable(pParse,&X,&E,F,0); } create_table_args ::= AS select(S). { - sqlite3EndTable(pParse,0,0,0,0,S); + sqlite3EndTable(pParse,0,0,0,S); sqlite3SelectDelete(pParse->db, S); } +%type table_options {u8} +table_options(A) ::= . {A = 0;} +table_options(A) ::= WITHOUT nm(X). { + if( X.n==5 && sqlite3_strnicmp(X.z,"rowid",5)==0 ){ + A = TF_WithoutRowid; + }else{ + A = 0; + sqlite3ErrorMsg(pParse, "unknown table option: %.*s", X.n, X.z); + } +} columnlist ::= columnlist COMMA column. columnlist ::= column. @@ -209,7 +215,7 @@ id(A) ::= INDEXED(X). {A = X;} CONFLICT DATABASE DEFERRED DESC DETACH EACH END EXCLUSIVE EXPLAIN FAIL FOR IGNORE IMMEDIATE INITIALLY INSTEAD LIKE_KW MATCH NO PLAN QUERY KEY OF OFFSET PRAGMA RAISE RELEASE REPLACE RESTRICT ROW ROLLBACK - SAVEPOINT TEMP TRIGGER VACUUM VIEW VIRTUAL WITH + SAVEPOINT TEMP TRIGGER VACUUM VIEW VIRTUAL WITHOUT %ifdef SQLITE_OMIT_COMPOUND_SELECT EXCEPT INTERSECT UNION %endif SQLITE_OMIT_COMPOUND_SELECT diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 9f7215e815..e69f274bc4 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -2773,7 +2773,7 @@ void sqlite3AddCheckConstraint(Parse*, Expr*); void sqlite3AddColumnType(Parse*,Token*); void sqlite3AddDefaultValue(Parse*,ExprSpan*); void sqlite3AddCollateType(Parse*, Token*); -void sqlite3EndTable(Parse*,Token*,Token*,Token*,IdList*,Select*); +void sqlite3EndTable(Parse*,Token*,Token*,u8,Select*); int sqlite3ParseUri(const char*,const char*,unsigned int*, sqlite3_vfs**,char**,char **); Btree *sqlite3DbNameToBtree(sqlite3*,const char*); diff --git a/test/alter.test b/test/alter.test index 4ef5dd9406..557162f837 100644 --- a/test/alter.test +++ b/test/alter.test @@ -861,10 +861,10 @@ foreach {tn tbl} $system_table_list { } #------------------------------------------------------------------------ -# Verify that ALTER TABLE works on tables with WITH options. +# Verify that ALTER TABLE works on tables with the WITHOUT rowid option. # do_execsql_test alter-16.1 { - CREATE TABLE t16a(a TEXT, b REAL, c INT, PRIMARY KEY(a,b)) WITH (omit_rowid); + CREATE TABLE t16a(a TEXT, b REAL, c INT, PRIMARY KEY(a,b)) WITHOUT rowid; INSERT INTO t16a VALUES('abc',1.25,99); ALTER TABLE t16a ADD COLUMN d TEXT DEFAULT 'xyzzy'; INSERT INTO t16a VALUES('cba',5.5,98,'fizzle'); diff --git a/test/tableopts.test b/test/tableopts.test index ef1dae0a87..ffaf7f4bbf 100644 --- a/test/tableopts.test +++ b/test/tableopts.test @@ -19,27 +19,17 @@ source $testdir/tester.tcl do_test tableopt-1.1 { catchsql { - CREATE TABLE t1(a,b) WITH (omit_rowid); + CREATE TABLE t1(a,b) WITHOUT rowid; } } {1 {no PRIMARY KEY for table t1}} do_test tableopt-1.2 { catchsql { - CREATE TABLE t1(a,b) WITH (unknown1, unknown2); + CREATE TABLE t1(a,b) WITHOUT unknown2; } } {1 {unknown table option: unknown2}} -do_test tableopt-1.3 { - catchsql { - CREATE TABLE t1(a,b,c,PRIMARY KEY(a,b)) WITH (omit_rowid, unknown3); - } -} {1 {unknown table option: unknown3}} -do_test tableopt-1.4 { - catchsql { - CREATE TABLE t1(a,b,c,PRIMARY KEY(a,b)) WITH (unknown4, omit_rowid); - } -} {1 {unknown table option: unknown4}} do_execsql_test tableopt-2.1 { - CREATE TABLE t1(a, b, c, PRIMARY KEY(a,b)) WITH (omit_rowid); + CREATE TABLE t1(a, b, c, PRIMARY KEY(a,b)) WITHOUT rowid; INSERT INTO t1 VALUES(1,2,3),(2,3,4); SELECT c FROM t1 WHERE a IN (1,2) ORDER BY b; } {3 4} @@ -52,5 +42,15 @@ do_test tableopt-2.3 { db2 eval {SELECT c FROM t1 WHERE a IN (1,2) ORDER BY b;} } {3 4} db2 close + +# Make sure the "without" keyword is still usable as a table or +# column name. +# +do_execsql_test tableopt-3.1 { + CREATE TABLE without(x INTEGER PRIMARY KEY, without TEXT); + INSERT INTO without VALUES(1, 'xyzzy'), (2, 'fizzle'); + SELECT * FROM without WHERE without='xyzzy'; +} {1 xyzzy} + finish_test diff --git a/tool/mkkeywordhash.c b/tool/mkkeywordhash.c index 3e60d38599..f3ef73f394 100644 --- a/tool/mkkeywordhash.c +++ b/tool/mkkeywordhash.c @@ -262,7 +262,7 @@ static Keyword aKeywordTable[] = { { "VALUES", "TK_VALUES", ALWAYS }, { "VIEW", "TK_VIEW", VIEW }, { "VIRTUAL", "TK_VIRTUAL", VTAB }, - { "WITH", "TK_WITH", ALWAYS }, + { "WITHOUT", "TK_WITHOUT", ALWAYS }, { "WHEN", "TK_WHEN", ALWAYS }, { "WHERE", "TK_WHERE", ALWAYS }, };