diff options
author | drh <drh@noemail.net> | 2019-01-17 04:40:04 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2019-01-17 04:40:04 +0000 |
commit | 04fcef00eed718bcaea0ef6c9172500a27a1052e (patch) | |
tree | 30c65d1992cce054bc494e2b13023944c6158156 /src/insert.c | |
parent | 30fdb45da018bb37d4a97a1b68e5b6d99b427332 (diff) | |
download | sqlite-04fcef00eed718bcaea0ef6c9172500a27a1052e.tar.gz sqlite-04fcef00eed718bcaea0ef6c9172500a27a1052e.zip |
Fix a corner-case for the logic that cause an insert of a NULL into an
INTEGER PRIMARY KEY column to be converted into a valid integer key,
when the NULL results from a CASE expression that lacks an ELSE clause.
FossilOrigin-Name: 9a425051e7ba59e797636f5cf32b5f6efafdb21c8d5300e099b8008b829c1439
Diffstat (limited to 'src/insert.c')
-rw-r--r-- | src/insert.c | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/src/insert.c b/src/insert.c index 4f7b19b56..7301d87a1 100644 --- a/src/insert.c +++ b/src/insert.c @@ -953,16 +953,12 @@ void sqlite3Insert( }else if( pSelect ){ sqlite3VdbeAddOp2(v, OP_Copy, regFromSelect+ipkColumn, regRowid); }else{ - VdbeOp *pOp; - sqlite3ExprCode(pParse, pList->a[ipkColumn].pExpr, regRowid); - pOp = sqlite3VdbeGetOp(v, -1); - assert( pOp!=0 ); - if( pOp->opcode==OP_Null && !IsVirtual(pTab) ){ + Expr *pIpk = pList->a[ipkColumn].pExpr; + if( pIpk->op==TK_NULL && !IsVirtual(pTab) ){ + sqlite3VdbeAddOp3(v, OP_NewRowid, iDataCur, regRowid, regAutoinc); appendFlag = 1; - pOp->opcode = OP_NewRowid; - pOp->p1 = iDataCur; - pOp->p2 = regRowid; - pOp->p3 = regAutoinc; + }else{ + sqlite3ExprCode(pParse, pList->a[ipkColumn].pExpr, regRowid); } } /* If the PRIMARY KEY expression is NULL, then use OP_NewRowid |