diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/alter.c | 1 | ||||
-rw-r--r-- | src/build.c | 22 | ||||
-rw-r--r-- | src/main.c | 3 | ||||
-rw-r--r-- | src/pragma.c | 6 | ||||
-rw-r--r-- | src/select.c | 9 | ||||
-rw-r--r-- | src/sqliteInt.h | 4 | ||||
-rw-r--r-- | src/util.c | 8 | ||||
-rw-r--r-- | src/vtab.c | 4 |
8 files changed, 35 insertions, 22 deletions
diff --git a/src/alter.c b/src/alter.c index 9edd7fff3..642c1fb67 100644 --- a/src/alter.c +++ b/src/alter.c @@ -786,7 +786,6 @@ void sqlite3AlterBeginAddColumn(Parse *pParse, SrcList *pSrc){ Column *pCol = &pNew->aCol[i]; pCol->zName = sqlite3DbStrDup(db, pCol->zName); pCol->zColl = 0; - pCol->zType = 0; pCol->pDflt = 0; } pNew->pSchema = db->aDb[iDb].pSchema; diff --git a/src/build.c b/src/build.c index ec8770a45..a32dfbd02 100644 --- a/src/build.c +++ b/src/build.c @@ -571,7 +571,6 @@ void sqlite3DeleteColumnNames(sqlite3 *db, Table *pTable){ for(i=0; i<pTable->nCol; i++, pCol++){ sqlite3DbFree(db, pCol->zName); sqlite3ExprDelete(db, pCol->pDflt); - sqlite3DbFree(db, pCol->zType); sqlite3DbFree(db, pCol->zColl); } sqlite3DbFree(db, pTable->aCol); @@ -1042,6 +1041,7 @@ void sqlite3AddColumn(Parse *pParse, Token *pName, Token *pType){ Table *p; int i; char *z; + char *zType; Column *pCol; sqlite3 *db = pParse->db; if( (p = pParse->pNewTable)==0 ) return; @@ -1051,8 +1051,14 @@ void sqlite3AddColumn(Parse *pParse, Token *pName, Token *pType){ return; } #endif - z = sqlite3NameFromToken(db, pName); + z = sqlite3DbMallocRaw(db, pName->n + pType->n + 2); if( z==0 ) return; + memcpy(z, pName->z, pName->n); + z[pName->n] = 0; + sqlite3Dequote(z); + zType = z + sqlite3Strlen30(z) + 1; + memcpy(zType, pType->z, pType->n); + zType[pType->n] = 0; for(i=0; i<p->nCol; i++){ if( sqlite3_stricmp(z, p->aCol[i].zName)==0 ){ sqlite3ErrorMsg(pParse, "duplicate column name: %s", z); @@ -1080,8 +1086,7 @@ void sqlite3AddColumn(Parse *pParse, Token *pName, Token *pType){ pCol->affinity = SQLITE_AFF_BLOB; pCol->szEst = 1; }else{ - pCol->zType = sqlite3NameFromToken(pParse->db, pType); - pCol->affinity = sqlite3AffinityType(pCol->zType, &pCol->szEst); + pCol->affinity = sqlite3AffinityType(zType, &pCol->szEst); } p->nCol++; pParse->constraintName.n = 0; @@ -1277,7 +1282,7 @@ void sqlite3AddPrimaryKey( int sortOrder /* SQLITE_SO_ASC or SQLITE_SO_DESC */ ){ Table *pTab = pParse->pNewTable; - char *zType = 0; + const char *zName = 0; int iCol = -1, i; int nTerm; if( pTab==0 || IN_DECLARE_VTAB ) goto primary_key_exit; @@ -1290,7 +1295,7 @@ void sqlite3AddPrimaryKey( if( pList==0 ){ iCol = pTab->nCol - 1; pTab->aCol[iCol].colFlags |= COLFLAG_PRIMKEY; - zType = pTab->aCol[iCol].zType; + zName = pTab->aCol[iCol].zName; nTerm = 1; }else{ nTerm = pList->nExpr; @@ -1303,7 +1308,7 @@ void sqlite3AddPrimaryKey( for(iCol=0; iCol<pTab->nCol; iCol++){ if( sqlite3StrICmp(zCName, pTab->aCol[iCol].zName)==0 ){ pTab->aCol[iCol].colFlags |= COLFLAG_PRIMKEY; - zType = pTab->aCol[iCol].zType; + zName = pTab->aCol[iCol].zName; break; } } @@ -1311,7 +1316,8 @@ void sqlite3AddPrimaryKey( } } if( nTerm==1 - && zType && sqlite3StrICmp(zType, "INTEGER")==0 + && zName + && sqlite3StrICmp(sqlite3StrNext(zName), "INTEGER")==0 && sortOrder!=SQLITE_SO_DESC ){ pTab->iPKey = iCol; diff --git a/src/main.c b/src/main.c index 2a258da66..3ba5972fa 100644 --- a/src/main.c +++ b/src/main.c @@ -3335,7 +3335,8 @@ int sqlite3_table_column_metadata( ** explicitly declared column. Copy meta information from *pCol. */ if( pCol ){ - zDataType = pCol->zType; + zDataType = sqlite3StrNext(pCol->zName); + if( zDataType[0]==0 ) zDataType = 0; zCollSeq = pCol->zColl; notnull = pCol->notNull!=0; primarykey = (pCol->colFlags & COLFLAG_PRIMKEY)!=0; diff --git a/src/pragma.c b/src/pragma.c index 0460f663f..1d6291431 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -1065,6 +1065,7 @@ void sqlite3Pragma( setAllColumnNames(v, 6, azCol); assert( 6==ArraySize(azCol) ); sqlite3ViewGetColumnNames(pParse, pTab); for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){ + const char *zName; if( IsHiddenColumn(pCol) ){ nHidden++; continue; @@ -1077,10 +1078,11 @@ void sqlite3Pragma( for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){} } assert( pCol->pDflt==0 || pCol->pDflt->op==TK_SPAN ); + zName = pCol->zName; sqlite3VdbeMultiLoad(v, 1, "issisi", i-nHidden, - pCol->zName, - pCol->zType ? pCol->zType : "", + zName, + sqlite3StrNext(zName), pCol->notNull ? 1 : 0, pCol->pDflt ? pCol->pDflt->u.zToken : 0, k); diff --git a/src/select.c b/src/select.c index aa1f21485..c9bc389b2 100644 --- a/src/select.c +++ b/src/select.c @@ -1429,8 +1429,8 @@ static const char *columnTypeImpl( zType = "INTEGER"; zOrigCol = "rowid"; }else{ - zType = pTab->aCol[iCol].zType; zOrigCol = pTab->aCol[iCol].zName; + zType = sqlite3StrNext(zOrigCol); estWidth = pTab->aCol[iCol].szEst; } zOrigTab = pTab->zName; @@ -1442,7 +1442,7 @@ static const char *columnTypeImpl( if( iCol<0 ){ zType = "INTEGER"; }else{ - zType = pTab->aCol[iCol].zType; + zType = sqlite3StrNext(pTab->aCol[iCol].zName); estWidth = pTab->aCol[iCol].szEst; } #endif @@ -1727,10 +1727,7 @@ static void selectAddColumnTypeAndCollation( a = pSelect->pEList->a; for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){ p = a[i].pExpr; - if( pCol->zType==0 ){ - pCol->zType = sqlite3DbStrDup(db, - columnType(&sNC, p,0,0,0, &pCol->szEst)); - } + columnType(&sNC, p, 0, 0, 0, &pCol->szEst); szAll += pCol->szEst; pCol->affinity = sqlite3ExprAffinity(p); if( pCol->affinity==0 ) pCol->affinity = SQLITE_AFF_BLOB; diff --git a/src/sqliteInt.h b/src/sqliteInt.h index d6acc3227..a37da33ed 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1543,9 +1543,8 @@ struct Module { ** of this structure. */ struct Column { - char *zName; /* Name of this column */ + char *zName; /* Name of this column, \000, then the type */ Expr *pDflt; /* Default value of this column */ - char *zType; /* Data type for this column */ char *zColl; /* Collating sequence. If NULL, use the default */ u8 notNull; /* An OE_ code for handling a NOT NULL constraint */ char affinity; /* One of the SQLITE_AFF_... values */ @@ -3258,6 +3257,7 @@ int sqlite3IsIdChar(u8); */ int sqlite3StrICmp(const char*,const char*); int sqlite3Strlen30(const char*); +const char *sqlite3StrNext(const char*); #define sqlite3StrNICmp sqlite3_strnicmp int sqlite3MallocInit(void); diff --git a/src/util.c b/src/util.c index d00a739e5..81274260f 100644 --- a/src/util.c +++ b/src/util.c @@ -110,6 +110,14 @@ int sqlite3Strlen30(const char *z){ } /* +** The string z[] is followed immediately by another string. Return +** a poiner to that other string. +*/ +const char *sqlite3StrNext(const char *z){ + return z + strlen(z) + 1; +} + +/* ** Set the current error code to err_code and clear any prior error message. */ void sqlite3Error(sqlite3 *db, int err_code){ diff --git a/src/vtab.c b/src/vtab.c index fa1954819..ad8caef3b 100644 --- a/src/vtab.c +++ b/src/vtab.c @@ -564,10 +564,10 @@ static int vtabCallConstructor( pTab->pVTable = pVTable; for(iCol=0; iCol<pTab->nCol; iCol++){ - char *zType = pTab->aCol[iCol].zType; + char *zType = (char*)sqlite3StrNext(pTab->aCol[iCol].zName); int nType; int i = 0; - if( !zType ){ + if( !zType[0] ){ pTab->tabFlags |= oooHidden; continue; } |