From 2881ab6298a431d2e37c7040a722b56c17a33ea6 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 27 Feb 2016 23:25:36 +0000 Subject: [PATCH] Update the parser so that it pulls out the column name and type all in one go, rather than using separate reductions. FossilOrigin-Name: ad3ffe2eec8e8ea2591a78c723d2665735553cb0 --- manifest | 19 +++++++++++-------- manifest.uuid | 2 +- src/build.c | 39 ++++++++++----------------------------- src/parse.y | 10 +++------- src/sqliteInt.h | 3 +-- 5 files changed, 26 insertions(+), 47 deletions(-) diff --git a/manifest b/manifest index 571cd071e6..ca7a05fd5c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Eliminate\sthe\sneed\sfor\sthe\sColumn.zDflt\s(using\sColumn.pDflt\sinstead)\sto\sreduce\nthe\samount\sof\smemory\sneeded\sto\shold\sthe\sschema. -D 2016-02-27T21:16:04.996 +C Update\sthe\sparser\sso\sthat\sit\spulls\sout\sthe\scolumn\sname\sand\stype\sall\sin\sone\ngo,\srather\sthan\susing\sseparate\sreductions. +D 2016-02-27T23:25:36.278 F Makefile.in 4e90dc1521879022aa9479268a4cd141d1771142 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 4f319afb7c049d40aff7af6e8c4e7cc2ba18e079 @@ -295,7 +295,7 @@ F src/btmutex.c bc87dd3b062cc26edfe79918de2200ccb8d41e73 F src/btree.c 7bb920c473c277380fcb3e8a8ee28ce1a48e0abc F src/btree.h a5008b9afe56e8e54ade6c436a910f112defcca9 F src/btreeInt.h c18b7d2a3494695133e4e60ee36061d37f45d9a5 -F src/build.c 6854e717e3257957b1bd87aadd6371d63937a023 +F src/build.c 8bde0b1cf0bfd94562398d31592b6b8b2b6ba719 F src/callback.c 2e76147783386374bf01b227f752c81ec872d730 F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e F src/ctime.c 60e135af364d777a9ab41c97e5e89cd224da6198 @@ -338,7 +338,7 @@ F src/os_win.c f0d7aa603eb6262143d7169a222aea07c4fca91d F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c d034c69b958c01289eb8070cbf902e1a68cd7e0b F src/pager.h e1d38a2f14849e219df0f91f8323504d134c8a56 -F src/parse.y c3ce2c4a7cbf0b699239be6b2a945c5cb51875e2 +F src/parse.y 3a29fc291600c48827ea94d5c630972db33e0b81 F src/pcache.c 647bb53a86b7bbcf55ad88089b3ea5a9170b90df F src/pcache.h 4d0ccaad264d360981ec5e6a2b596d6e85242545 F src/pcache1.c 72f644dc9e1468c72922eff5904048427b817051 @@ -354,7 +354,7 @@ F src/shell.c 5e0ab1e708dc294330ccd8230536e1801f60822e F src/sqlite.h.in 57d2a02b14c9ec4f7cb294153eaf62294dc5aa68 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h dfbe62ffd95b99afe2140d8c35b180d11924072d -F src/sqliteInt.h bcfbf4785436f318459cdbde07a8cce3de7e6f1a +F src/sqliteInt.h 01b43972162c2b5ed864060a23502af3abe0e4f4 F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 F src/status.c 70912d7be68e9e2dbc4010c93d344af61d4c59ba F src/table.c 5226df15ab9179b9ed558d89575ea0ce37b03fc9 @@ -1451,7 +1451,10 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P f681d800340e0e710f73d0f7c09101f899249183 -R 68cf98086fc7541dd6cf15ff81e4d2e2 +P d8c94a46dfa94930732c2de2aa79675c5087d36e +R 08160a7958aa5578e4603f69af85b704 +T *branch * schema-storage +T *sym-schema-storage * +T -sym-trunk * U drh -Z bde0bd56c07a366738817149aa7f9a7d +Z 64cdb714f146eadb7f54fce29197df77 diff --git a/manifest.uuid b/manifest.uuid index 629362c836..fea3e74ff6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d8c94a46dfa94930732c2de2aa79675c5087d36e \ No newline at end of file +ad3ffe2eec8e8ea2591a78c723d2665735553cb0 \ No newline at end of file diff --git a/src/build.c b/src/build.c index bcf71442de..a655c9a301 100644 --- a/src/build.c +++ b/src/build.c @@ -1038,7 +1038,7 @@ void sqlite3ColumnPropertiesFromName(Table *pTab, Column *pCol){ ** first to get things going. Then this routine is called for each ** column. */ -void sqlite3AddColumn(Parse *pParse, Token *pName){ +void sqlite3AddColumn(Parse *pParse, Token *pName, Token *pType){ Table *p; int i; char *z; @@ -1074,12 +1074,15 @@ void sqlite3AddColumn(Parse *pParse, Token *pName){ pCol->zName = z; sqlite3ColumnPropertiesFromName(p, pCol); - /* If there is no type specified, columns have the default affinity - ** 'BLOB'. If there is a type specified, then sqlite3AddColumnType() will - ** be called next to set pCol->affinity correctly. - */ - pCol->affinity = SQLITE_AFF_BLOB; - pCol->szEst = 1; + if( pType==0 ){ + /* If there is no type specified, columns have the default affinity + ** 'BLOB'. */ + pCol->affinity = SQLITE_AFF_BLOB; + pCol->szEst = 1; + }else{ + pCol->zType = sqlite3NameFromToken(pParse->db, pType); + pCol->affinity = sqlite3AffinityType(pCol->zType, &pCol->szEst); + } p->nCol++; } @@ -1183,28 +1186,6 @@ char sqlite3AffinityType(const char *zIn, u8 *pszEst){ return aff; } -/* -** This routine is called by the parser while in the middle of -** parsing a CREATE TABLE statement. The pFirst token is the first -** token in the sequence of tokens that describe the type of the -** column currently under construction. pLast is the last token -** in the sequence. Use this information to construct a string -** that contains the typename of the column and store that string -** in zType. -*/ -void sqlite3AddColumnType(Parse *pParse, Token *pType){ - Table *p; - Column *pCol; - - p = pParse->pNewTable; - if( p==0 || NEVER(p->nCol<1) ) return; - pCol = &p->aCol[p->nCol-1]; - assert( pCol->zType==0 || CORRUPT_DB ); - sqlite3DbFree(pParse->db, pCol->zType); - pCol->zType = sqlite3NameFromToken(pParse->db, pType); - pCol->affinity = sqlite3AffinityType(pCol->zType, &pCol->szEst); -} - /* ** The expression is the default value for the most recently added column ** of the table currently under construction. diff --git a/src/parse.y b/src/parse.y index e7e0d1d953..b8ae8c8dc1 100644 --- a/src/parse.y +++ b/src/parse.y @@ -198,13 +198,11 @@ columnlist ::= column. // datatype, and other keywords such as PRIMARY KEY, UNIQUE, REFERENCES, // NOT NULL and so forth. // -column(A) ::= columnid(A) type carglist. { +column(A) ::= columnname(A) carglist. { A.n = (int)(pParse->sLastToken.z-A.z) + pParse->sLastToken.n; } -columnid(A) ::= nm(A). { - sqlite3AddColumn(pParse,&A); - pParse->constraintName.n = 0; -} +columnname(A) ::= nm(A) typetoken(Y). {sqlite3AddColumn(pParse,&A,&Y);} +columnname(A) ::= nm(A). {sqlite3AddColumn(pParse,&A,0);} // An IDENTIFIER can be a generic identifier, or one of several @@ -269,8 +267,6 @@ nm(A) ::= JOIN_KW(A). // Multiple tokens are concatenated to form the value of the typetoken. // %type typetoken {Token} -type ::= . -type ::= typetoken(X). {sqlite3AddColumnType(pParse,&X);} typetoken(A) ::= typename(A). typetoken(A) ::= typename(A) LP signed RP(Y). { A.n = (int)(&Y.z[Y.n] - A.z); diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 7d1757e4d8..d6acc3227b 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -3413,11 +3413,10 @@ void sqlite3StartTable(Parse*,Token*,Token*,int,int,int,int); #else # define sqlite3ColumnPropertiesFromName(T,C) /* no-op */ #endif -void sqlite3AddColumn(Parse*,Token*); +void sqlite3AddColumn(Parse*,Token*,Token*); void sqlite3AddNotNull(Parse*, int); void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int, int); void sqlite3AddCheckConstraint(Parse*, Expr*); -void sqlite3AddColumnType(Parse*,Token*); void sqlite3AddDefaultValue(Parse*,ExprSpan*); void sqlite3AddCollateType(Parse*, Token*); void sqlite3EndTable(Parse*,Token*,Token*,u8,Select*);