1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-16 23:02:26 +03:00

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
This commit is contained in:
drh
2016-02-27 23:25:36 +00:00
parent 94fa9c414a
commit 2881ab6298
5 changed files with 26 additions and 47 deletions

View File

@@ -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.

View File

@@ -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);

View File

@@ -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*);