aboutsummaryrefslogtreecommitdiff
path: root/src/vdbeblob.c
diff options
context:
space:
mode:
authordan <dan@noemail.net>2009-09-19 17:00:31 +0000
committerdan <dan@noemail.net>2009-09-19 17:00:31 +0000
commit1da40a381fcf28953cd914aa1cff2d4d2f30ffb0 (patch)
tree499fd358c9173002d540833d9a7a77c3421119d4 /src/vdbeblob.c
parent3991bb0deec345af79e0346bc0b29a0f8a594a3a (diff)
downloadsqlite-1da40a381fcf28953cd914aa1cff2d4d2f30ffb0.tar.gz
sqlite-1da40a381fcf28953cd914aa1cff2d4d2f30ffb0.zip
Check in implementation of foreign key constraints.
FossilOrigin-Name: d5d399811876391642937edeb9e8434dd9e356f5
Diffstat (limited to 'src/vdbeblob.c')
-rw-r--r--src/vdbeblob.c36
1 files changed, 26 insertions, 10 deletions
diff --git a/src/vdbeblob.c b/src/vdbeblob.c
index 009234f4e..394335a92 100644
--- a/src/vdbeblob.c
+++ b/src/vdbeblob.c
@@ -144,25 +144,41 @@ int sqlite3_blob_open(
}
/* If the value is being opened for writing, check that the
- ** column is not indexed. It is against the rules to open an
- ** indexed column for writing.
- */
+ ** column is not indexed, and that it is not part of a foreign key.
+ ** It is against the rules to open a column to which either of these
+ ** descriptions applies for writing. */
if( flags ){
+ const char *zFault = 0;
Index *pIdx;
+#ifndef SQLITE_OMIT_FOREIGN_KEY
+ if( db->flags&SQLITE_ForeignKeys ){
+ FKey *pFKey;
+ for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){
+ int j;
+ for(j=0; j<pFKey->nCol; j++){
+ if( pFKey->aCol[j].iFrom==iCol ){
+ zFault = "foreign key";
+ }
+ }
+ }
+ }
+#endif
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
int j;
for(j=0; j<pIdx->nColumn; j++){
if( pIdx->aiColumn[j]==iCol ){
- sqlite3DbFree(db, zErr);
- zErr = sqlite3MPrintf(db,
- "cannot open indexed column for writing");
- rc = SQLITE_ERROR;
- (void)sqlite3SafetyOff(db);
- sqlite3BtreeLeaveAll(db);
- goto blob_open_out;
+ zFault = "indexed";
}
}
}
+ if( zFault ){
+ sqlite3DbFree(db, zErr);
+ zErr = sqlite3MPrintf(db, "cannot open %s column for writing", zFault);
+ rc = SQLITE_ERROR;
+ (void)sqlite3SafetyOff(db);
+ sqlite3BtreeLeaveAll(db);
+ goto blob_open_out;
+ }
}
v = sqlite3VdbeCreate(db);