1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-08 03:22:21 +03:00

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
This commit is contained in:
drh
2010-05-14 19:24:02 +00:00
parent d91c68f6cc
commit 5c092e8a4f
7 changed files with 85 additions and 27 deletions

View File

@@ -2082,6 +2082,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
@@ -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;
}