diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/delete.c | 2 | ||||
-rw-r--r-- | src/fkey.c | 2 | ||||
-rw-r--r-- | src/insert.c | 13 | ||||
-rw-r--r-- | src/pragma.c | 2 | ||||
-rw-r--r-- | src/sqliteInt.h | 3 | ||||
-rw-r--r-- | src/update.c | 2 | ||||
-rw-r--r-- | src/where.c | 11 | ||||
-rw-r--r-- | src/wherecode.c | 2 |
8 files changed, 22 insertions, 15 deletions
diff --git a/src/delete.c b/src/delete.c index cff922cbb..5403224a8 100644 --- a/src/delete.c +++ b/src/delete.c @@ -444,7 +444,7 @@ void sqlite3DeleteFrom( iKey = ++pParse->nMem; nKey = 0; /* Zero tells OP_Found to use a composite key */ sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, iKey, - sqlite3IndexAffinityStr(v, pPk), nPk); + sqlite3IndexAffinityStr(pParse->db, pPk), nPk); sqlite3VdbeAddOp2(v, OP_IdxInsert, iEphCur, iKey); }else{ /* Get the rowid of the row to be deleted and remember it in the RowSet */ diff --git a/src/fkey.c b/src/fkey.c index 09513e462..9d448def6 100644 --- a/src/fkey.c +++ b/src/fkey.c @@ -416,7 +416,7 @@ static void fkLookupParent( } sqlite3VdbeAddOp4(v, OP_MakeRecord, regTemp, nCol, regRec, - sqlite3IndexAffinityStr(v,pIdx), nCol); + sqlite3IndexAffinityStr(pParse->db,pIdx), nCol); sqlite3VdbeAddOp4Int(v, OP_Found, iCur, iOk, regRec, 0); VdbeCoverage(v); sqlite3ReleaseTempReg(pParse, regRec); diff --git a/src/insert.c b/src/insert.c index ae2499130..6c70470ac 100644 --- a/src/insert.c +++ b/src/insert.c @@ -69,7 +69,7 @@ void sqlite3OpenTable( ** is managed along with the rest of the Index structure. It will be ** released when sqlite3DeleteIndex() is called. */ -const char *sqlite3IndexAffinityStr(Vdbe *v, Index *pIdx){ +const char *sqlite3IndexAffinityStr(sqlite3 *db, Index *pIdx){ if( !pIdx->zColAff ){ /* The first time a column affinity string for a particular index is ** required, it is allocated and populated here. It is then stored as @@ -81,7 +81,6 @@ const char *sqlite3IndexAffinityStr(Vdbe *v, Index *pIdx){ */ int n; Table *pTab = pIdx->pTable; - sqlite3 *db = sqlite3VdbeDb(v); pIdx->zColAff = (char *)sqlite3DbMallocRaw(0, pIdx->nColumn+1); if( !pIdx->zColAff ){ db->mallocFailed = 1; @@ -106,6 +105,16 @@ const char *sqlite3IndexAffinityStr(Vdbe *v, Index *pIdx){ } /* +** Return the affinity for a single column of an index. +*/ +char sqlite3IndexColumnAffinity(sqlite3 *db, Index *pIdx, int iCol){ + if( !pIdx->zColAff ){ + if( sqlite3IndexAffinityStr(db, pIdx)==0 ) return SQLITE_AFF_BLOB; + } + return pIdx->zColAff[iCol]; +} + +/* ** Compute the affinity string for table pTab, if it has not already been ** computed. As an optimization, omit trailing SQLITE_AFF_BLOB affinities. ** diff --git a/src/pragma.c b/src/pragma.c index 96ff136c2..96a0272de 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -1342,7 +1342,7 @@ void sqlite3Pragma( } if( pParent ){ sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, pFK->nCol, regKey, - sqlite3IndexAffinityStr(v,pIdx), pFK->nCol); + sqlite3IndexAffinityStr(db,pIdx), pFK->nCol); sqlite3VdbeAddOp4Int(v, OP_Found, i, addrOk, regKey, 0); VdbeCoverage(v); } diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 73bf83d3d..7dd0402dd 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -3553,7 +3553,8 @@ int sqlite3VarintLen(u64 v); #define putVarint sqlite3PutVarint -const char *sqlite3IndexAffinityStr(Vdbe *, Index *); +const char *sqlite3IndexAffinityStr(sqlite3*, Index*); +char sqlite3IndexColumnAffinity(sqlite3*, Index*, int); void sqlite3TableAffinity(Vdbe*, Table*, int); char sqlite3CompareAffinity(Expr *pExpr, char aff2); int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity); diff --git a/src/update.c b/src/update.c index cc9b69077..4b7431ef3 100644 --- a/src/update.c +++ b/src/update.c @@ -394,7 +394,7 @@ void sqlite3Update( regKey = iPk; }else{ sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, regKey, - sqlite3IndexAffinityStr(v, pPk), nPk); + sqlite3IndexAffinityStr(db, pPk), nPk); sqlite3VdbeAddOp2(v, OP_IdxInsert, iEph, regKey); } sqlite3WhereEnd(pWInfo); diff --git a/src/where.c b/src/where.c index bdcfeaa9a..deebed83b 100644 --- a/src/where.c +++ b/src/where.c @@ -1177,7 +1177,7 @@ static int whereRangeSkipScanEst( int nUpper = p->nSample+1; int rc = SQLITE_OK; int iCol = p->aiColumn[nEq]; - u8 aff = iCol>=0 ? p->pTable->aCol[iCol].affinity : SQLITE_AFF_INTEGER; + u8 aff = sqlite3IndexColumnAffinity(db, p, iCol); CollSeq *pColl; sqlite3_value *p1 = 0; /* Value extracted from pLower */ @@ -1325,11 +1325,8 @@ static int whereRangeScanEst( testcase( pRec->nField!=pBuilder->nRecValid ); pRec->nField = pBuilder->nRecValid; } - if( nEq==p->nKeyCol ){ - aff = SQLITE_AFF_INTEGER; - }else{ - aff = p->pTable->aCol[p->aiColumn[nEq]].affinity; - } + aff = sqlite3IndexColumnAffinity(pParse->db, p, nEq); + assert( nEq!=p->nKeyCol || aff==SQLITE_AFF_INTEGER ); /* Determine iLower and iUpper using ($P) only. */ if( nEq==0 ){ iLower = 0; @@ -1487,7 +1484,7 @@ static int whereEqualScanEst( return SQLITE_OK; } - aff = p->pTable->aCol[p->aiColumn[nEq-1]].affinity; + aff = sqlite3IndexColumnAffinity(pParse->db, p, nEq-1); rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq-1, &bOk); pBuilder->pRec = pRec; if( rc!=SQLITE_OK ) return rc; diff --git a/src/wherecode.c b/src/wherecode.c index eb23d8f1a..e5c0b40b1 100644 --- a/src/wherecode.c +++ b/src/wherecode.c @@ -492,7 +492,7 @@ static int codeAllEqualityTerms( nReg = pLoop->u.btree.nEq + nExtraReg; pParse->nMem += nReg; - zAff = sqlite3DbStrDup(pParse->db, sqlite3IndexAffinityStr(v, pIdx)); + zAff = sqlite3DbStrDup(pParse->db,sqlite3IndexAffinityStr(pParse->db,pIdx)); if( !zAff ){ pParse->db->mallocFailed = 1; } |