diff options
author | drh <drh@noemail.net> | 2016-03-22 20:05:09 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2016-03-22 20:05:09 +0000 |
commit | d7564865adc966c21fcdc10ea5ee5bb5910c46da (patch) | |
tree | 579f23798f115290d3fe3297beba51eb9e92598b /src | |
parent | 527b0435fabe2795865d52e4db827173a1cb2d65 (diff) | |
download | sqlite-d7564865adc966c21fcdc10ea5ee5bb5910c46da.tar.gz sqlite-d7564865adc966c21fcdc10ea5ee5bb5910c46da.zip |
The sqlite3_column_decltype() routine should return NULL, not an empty string,
if the column has no declared type.
FossilOrigin-Name: 605eba4a756e7185119088e2242f82691d078b01
Diffstat (limited to 'src')
-rw-r--r-- | src/build.c | 15 | ||||
-rw-r--r-- | src/main.c | 3 | ||||
-rw-r--r-- | src/pragma.c | 6 | ||||
-rw-r--r-- | src/select.c | 4 | ||||
-rw-r--r-- | src/sqliteInt.h | 3 | ||||
-rw-r--r-- | src/util.c | 12 | ||||
-rw-r--r-- | src/vtab.c | 20 |
7 files changed, 30 insertions, 33 deletions
diff --git a/src/build.c b/src/build.c index e89c74446..28eb55ab6 100644 --- a/src/build.c +++ b/src/build.c @@ -1087,6 +1087,7 @@ void sqlite3AddColumn(Parse *pParse, Token *pName, Token *pType){ pCol->szEst = 1; }else{ pCol->affinity = sqlite3AffinityType(zType, &pCol->szEst); + pCol->colFlags |= COLFLAG_HASTYPE; } p->nCol++; pParse->constraintName.n = 0; @@ -1282,7 +1283,7 @@ void sqlite3AddPrimaryKey( int sortOrder /* SQLITE_SO_ASC or SQLITE_SO_DESC */ ){ Table *pTab = pParse->pNewTable; - const char *zName = 0; + Column *pCol = 0; int iCol = -1, i; int nTerm; if( pTab==0 || IN_DECLARE_VTAB ) goto primary_key_exit; @@ -1294,8 +1295,8 @@ void sqlite3AddPrimaryKey( pTab->tabFlags |= TF_HasPrimaryKey; if( pList==0 ){ iCol = pTab->nCol - 1; - pTab->aCol[iCol].colFlags |= COLFLAG_PRIMKEY; - zName = pTab->aCol[iCol].zName; + pCol = &pTab->aCol[iCol]; + pCol->colFlags |= COLFLAG_PRIMKEY; nTerm = 1; }else{ nTerm = pList->nExpr; @@ -1307,8 +1308,8 @@ void sqlite3AddPrimaryKey( const char *zCName = pCExpr->u.zToken; for(iCol=0; iCol<pTab->nCol; iCol++){ if( sqlite3StrICmp(zCName, pTab->aCol[iCol].zName)==0 ){ - pTab->aCol[iCol].colFlags |= COLFLAG_PRIMKEY; - zName = pTab->aCol[iCol].zName; + pCol = &pTab->aCol[iCol]; + pCol->colFlags |= COLFLAG_PRIMKEY; break; } } @@ -1316,8 +1317,8 @@ void sqlite3AddPrimaryKey( } } if( nTerm==1 - && zName - && sqlite3StrICmp(sqlite3StrNext(zName), "INTEGER")==0 + && pCol + && sqlite3StrICmp(sqlite3ColumnType(pCol,""), "INTEGER")==0 && sortOrder!=SQLITE_SO_DESC ){ pTab->iPKey = iCol; diff --git a/src/main.c b/src/main.c index 2e5ba0839..0c4cfbbea 100644 --- a/src/main.c +++ b/src/main.c @@ -3343,8 +3343,7 @@ int sqlite3_table_column_metadata( ** explicitly declared column. Copy meta information from *pCol. */ if( pCol ){ - zDataType = sqlite3StrNext(pCol->zName); - if( zDataType[0]==0 ) zDataType = 0; + zDataType = sqlite3ColumnType(pCol,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 65c43ad1e..e0a0255ec 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -1066,7 +1066,6 @@ 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; @@ -1079,11 +1078,10 @@ 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, - zName, - sqlite3StrNext(zName), + pCol->zName, + sqlite3ColumnType(pCol,""), pCol->notNull ? 1 : 0, pCol->pDflt ? pCol->pDflt->u.zToken : 0, k); diff --git a/src/select.c b/src/select.c index a62581efc..ed76f621f 100644 --- a/src/select.c +++ b/src/select.c @@ -1430,7 +1430,7 @@ static const char *columnTypeImpl( zOrigCol = "rowid"; }else{ zOrigCol = pTab->aCol[iCol].zName; - zType = sqlite3StrNext(zOrigCol); + zType = sqlite3ColumnType(&pTab->aCol[iCol],0); estWidth = pTab->aCol[iCol].szEst; } zOrigTab = pTab->zName; @@ -1442,7 +1442,7 @@ static const char *columnTypeImpl( if( iCol<0 ){ zType = "INTEGER"; }else{ - zType = sqlite3StrNext(pTab->aCol[iCol].zName); + zType = sqlite3ColumnType(&pTab->aCol[iCol],0); estWidth = pTab->aCol[iCol].szEst; } #endif diff --git a/src/sqliteInt.h b/src/sqliteInt.h index d256262b0..242ae8e2c 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1604,6 +1604,7 @@ struct Column { */ #define COLFLAG_PRIMKEY 0x0001 /* Column is part of the primary key */ #define COLFLAG_HIDDEN 0x0002 /* A hidden column in a virtual table */ +#define COLFLAG_HASTYPE 0x0004 /* Type name follows column name */ /* ** A "Collating Sequence" is defined by an instance of the following @@ -3307,7 +3308,7 @@ int sqlite3IsIdChar(u8); */ int sqlite3StrICmp(const char*,const char*); int sqlite3Strlen30(const char*); -const char *sqlite3StrNext(const char*); +char *sqlite3ColumnType(Column*,char*); #define sqlite3StrNICmp sqlite3_strnicmp int sqlite3MallocInit(void); diff --git a/src/util.c b/src/util.c index 428dfd046..08b0c46a5 100644 --- a/src/util.c +++ b/src/util.c @@ -110,11 +110,15 @@ int sqlite3Strlen30(const char *z){ } /* -** The string z[] is followed immediately by another string. Return -** a poiner to that other string. +** Return the declared type of a column. Or return zDflt if the column +** has no declared type. +** +** The column type is an extra string stored after the zero-terminator on +** the column name if and only if the COLFLAG_HASTYPE flag is set. */ -const char *sqlite3StrNext(const char *z){ - return z + strlen(z) + 1; +char *sqlite3ColumnType(Column *pCol, char *zDflt){ + if( (pCol->colFlags & COLFLAG_HASTYPE)==0 ) return zDflt; + return pCol->zName + strlen(pCol->zName) + 1; } /* diff --git a/src/vtab.c b/src/vtab.c index ad8caef3b..802a8cac3 100644 --- a/src/vtab.c +++ b/src/vtab.c @@ -564,22 +564,16 @@ static int vtabCallConstructor( pTab->pVTable = pVTable; for(iCol=0; iCol<pTab->nCol; iCol++){ - char *zType = (char*)sqlite3StrNext(pTab->aCol[iCol].zName); + char *zType = sqlite3ColumnType(&pTab->aCol[iCol], ""); int nType; int i = 0; - if( !zType[0] ){ - pTab->tabFlags |= oooHidden; - continue; - } nType = sqlite3Strlen30(zType); - if( sqlite3StrNICmp("hidden", zType, 6)||(zType[6] && zType[6]!=' ') ){ - for(i=0; i<nType; i++){ - if( (0==sqlite3StrNICmp(" hidden", &zType[i], 7)) - && (zType[i+7]=='\0' || zType[i+7]==' ') - ){ - i++; - break; - } + for(i=0; i<nType; i++){ + if( 0==sqlite3StrNICmp("hidden", &zType[i], 6) + && (i==0 || zType[i-1]==' ') + && (zType[i+6]=='\0' || zType[i+6]==' ') + ){ + break; } } if( i<nType ){ |