diff options
author | drh <drh@noemail.net> | 2010-05-14 19:24:02 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2010-05-14 19:24:02 +0000 |
commit | 5c092e8a4ff961530bfaccdbc393ee4ab91a982b (patch) | |
tree | 89188a1a8028865bdb65717f5a7cd05c62a9d4eb /src/expr.c | |
parent | d91c68f6cc006823be486f716f9f722b97fb6562 (diff) | |
download | sqlite-5c092e8a4ff961530bfaccdbc393ee4ab91a982b.tar.gz sqlite-5c092e8a4ff961530bfaccdbc393ee4ab91a982b.zip |
Make sure the value of an INTEGER PRIMARY KEY column supplied to triggers
and especially to FK constraints really contains the ROWID and not the
NULL that is stored in the column itself. Ticket [dd08e5a988d00dec].
FossilOrigin-Name: 636f86095eb1f4bdcfb0c9ed846c4c6b3589c10b
Diffstat (limited to 'src/expr.c')
-rw-r--r-- | src/expr.c | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/src/expr.c b/src/expr.c index f82f6d429..b77697961 100644 --- a/src/expr.c +++ b/src/expr.c @@ -2083,6 +2083,27 @@ static void sqlite3ExprCachePinRegister(Parse *pParse, int iReg){ } /* +** Generate code to extract the value of the iCol-th column of a table. +*/ +void sqlite3ExprCodeGetColumnOfTable( + Vdbe *v, /* The VDBE under construction */ + Table *pTab, /* The table containing the value */ + int iTabCur, /* The cursor for this table */ + int iCol, /* Index of the column to extract */ + int regOut /* Extract the valud into this register */ +){ + if( iCol<0 || iCol==pTab->iPKey ){ + sqlite3VdbeAddOp2(v, OP_Rowid, iTabCur, regOut); + }else{ + int op = IsVirtual(pTab) ? OP_VColumn : OP_Column; + sqlite3VdbeAddOp3(v, op, iTabCur, iCol, regOut); + } + if( iCol>=0 ){ + sqlite3ColumnDefault(v, pTab, iCol, regOut); + } +} + +/* ** Generate code that will extract the iColumn-th column from ** table pTab and store the column value in a register. An effort ** is made to store the column value in register iReg, but this is @@ -2110,13 +2131,7 @@ int sqlite3ExprCodeGetColumn( } } assert( v!=0 ); - if( iColumn<0 ){ - sqlite3VdbeAddOp2(v, OP_Rowid, iTable, iReg); - }else if( ALWAYS(pTab!=0) ){ - int op = IsVirtual(pTab) ? OP_VColumn : OP_Column; - sqlite3VdbeAddOp3(v, op, iTable, iColumn, iReg); - sqlite3ColumnDefault(v, pTab, iColumn, iReg); - } + sqlite3ExprCodeGetColumnOfTable(v, pTab, iTable, iColumn, iReg); sqlite3ExprCacheStore(pParse, iTable, iColumn, iReg); return iReg; } |