diff options
author | drh <> | 2021-08-18 19:22:27 +0000 |
---|---|---|
committer | drh <> | 2021-08-18 19:22:27 +0000 |
commit | 72532f52bce548348cff66b6113776e11d6d7f3f (patch) | |
tree | e8f60a3acdb016bc9085aaa9a2ba39e8d5caa56f /src/insert.c | |
parent | 44183f83d0fbbc1e092b990afd2ede033759574f (diff) | |
download | sqlite-72532f52bce548348cff66b6113776e11d6d7f3f.tar.gz sqlite-72532f52bce548348cff66b6113776e11d6d7f3f.zip |
Trying to insert an incorrect datatype into a STRICT table raises an
SQLITE_CONSTRAINT_DATATYPE error. Seems to work, though lots more testing
is needed.
FossilOrigin-Name: a19305e5cfedf5c472200d6e05c1396443e348f052a40a0979f860f2ff06851d
Diffstat (limited to 'src/insert.c')
-rw-r--r-- | src/insert.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/insert.c b/src/insert.c index 0692198b1..1148257ad 100644 --- a/src/insert.c +++ b/src/insert.c @@ -131,7 +131,25 @@ const char *sqlite3IndexAffinityStr(sqlite3 *db, Index *pIdx){ */ void sqlite3TableAffinity(Vdbe *v, Table *pTab, int iReg){ int i, j; - char *zColAff = pTab->zColAff; + char *zColAff; + if( pTab->tabFlags & TF_Strict ){ + if( iReg==0 ){ + /* Move the previous opcode (which should be OP_MakeRecord) forward + ** by one slot and insert a new OP_TypeCheck where the current + ** OP_MakeRecord is found */ + VdbeOp *pPrev; + sqlite3VdbeAppendP4(v, pTab, P4_TABLE); + pPrev = sqlite3VdbeGetOp(v, -1); + pPrev->opcode = OP_TypeCheck; + sqlite3VdbeAddOp3(v, OP_MakeRecord, pPrev->p1, pPrev->p2, pPrev->p3); + }else{ + /* Insert an isolated OP_Typecheck */ + sqlite3VdbeAddOp2(v, OP_TypeCheck, iReg, pTab->nNVCol); + sqlite3VdbeAppendP4(v, pTab, P4_TABLE); + } + return; + } + zColAff = pTab->zColAff; if( zColAff==0 ){ sqlite3 *db = sqlite3VdbeDb(v); zColAff = (char *)sqlite3DbMallocRaw(0, pTab->nCol+1); |