drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 1 | /* |
drh | b19a2bc | 2001-09-16 00:13:26 +0000 | [diff] [blame] | 2 | ** 2001 September 15 |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 3 | ** |
drh | b19a2bc | 2001-09-16 00:13:26 +0000 | [diff] [blame] | 4 | ** The author disclaims copyright to this source code. In place of |
| 5 | ** a legal notice, here is a blessing: |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 6 | ** |
drh | b19a2bc | 2001-09-16 00:13:26 +0000 | [diff] [blame] | 7 | ** May you do good and not evil. |
| 8 | ** May you find forgiveness for yourself and forgive others. |
| 9 | ** May you share freely, never taking more than you give. |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 10 | ** |
| 11 | ************************************************************************* |
| 12 | ** This file contains C code routines that are called by the parser |
| 13 | ** to handle UPDATE statements. |
| 14 | ** |
danielk1977 | aee18ef | 2005-03-09 12:26:50 +0000 | [diff] [blame^] | 15 | ** $Id: update.c,v 1.105 2005/03/09 12:26:51 danielk1977 Exp $ |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 16 | */ |
| 17 | #include "sqliteInt.h" |
| 18 | |
| 19 | /* |
danielk1977 | aee18ef | 2005-03-09 12:26:50 +0000 | [diff] [blame^] | 20 | ** The most recently coded instruction was an OP_Column to retrieve column |
| 21 | ** 'i' of table pTab. This routine sets the P3 parameter of the |
| 22 | ** OP_Column to the default value, if any. |
| 23 | ** |
| 24 | ** The default value of a column is specified by a DEFAULT clause in the |
| 25 | ** column definition. This was either supplied by the user when the table |
| 26 | ** was created, or added later to the table definition by an ALTER TABLE |
| 27 | ** command. If the latter, then the row-records in the table btree on disk |
| 28 | ** may not contain a value for the column and the default value, taken |
| 29 | ** from the P3 parameter of the OP_Column instruction, is returned instead. |
| 30 | ** If the former, then all row-records are guaranteed to include a value |
| 31 | ** for the column and the P3 value is not required. |
| 32 | ** |
| 33 | ** Column definitions created by an ALTER TABLE command may only have |
| 34 | ** literal default values specified: a number, null or a string. (If a more |
| 35 | ** complicated default expression value was provided, it is evaluated |
| 36 | ** when the ALTER TABLE is executed and one of the literal values written |
| 37 | ** into the sqlite_master table.) |
| 38 | ** |
| 39 | ** Therefore, the P3 parameter is only required if the default value for |
| 40 | ** the column is a literal number, string or null. The sqlite3ValueFromExpr() |
| 41 | ** function is capable of transforming these types of expressions into |
| 42 | ** sqlite3_value objects. |
| 43 | */ |
| 44 | void sqlite3ColumnDefault(Vdbe *v, Table *pTab, int i){ |
| 45 | if( pTab && !pTab->pSelect ){ |
| 46 | sqlite3_value *pValue; |
| 47 | u8 enc = sqlite3VdbeDb(v)->enc; |
| 48 | Column *pCol = &pTab->aCol[i]; |
| 49 | sqlite3ValueFromExpr(pCol->pDflt, enc, pCol->affinity, &pValue); |
| 50 | sqlite3VdbeChangeP3(v, -1, (const char *)pValue, P3_MEM); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | /* |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 55 | ** Process an UPDATE statement. |
drh | b2fe7d8 | 2003-04-20 17:29:23 +0000 | [diff] [blame] | 56 | ** |
| 57 | ** UPDATE OR IGNORE table_wxyz SET a=b, c=d WHERE e<5 AND f NOT NULL; |
| 58 | ** \_______/ \________/ \______/ \________________/ |
| 59 | * onError pTabList pChanges pWhere |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 60 | */ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 61 | void sqlite3Update( |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 62 | Parse *pParse, /* The parser context */ |
drh | 113088e | 2003-03-20 01:16:58 +0000 | [diff] [blame] | 63 | SrcList *pTabList, /* The table in which we should change things */ |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 64 | ExprList *pChanges, /* Things to be changed */ |
drh | 9cfcf5d | 2002-01-29 18:41:24 +0000 | [diff] [blame] | 65 | Expr *pWhere, /* The WHERE clause. May be null */ |
| 66 | int onError /* How to handle constraint errors */ |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 67 | ){ |
| 68 | int i, j; /* Loop counters */ |
| 69 | Table *pTab; /* The table to be updated */ |
danielk1977 | 742f947 | 2004-06-16 12:02:43 +0000 | [diff] [blame] | 70 | int addr = 0; /* VDBE instruction address of the start of the loop */ |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 71 | WhereInfo *pWInfo; /* Information about the WHERE clause */ |
| 72 | Vdbe *v; /* The virtual database engine */ |
| 73 | Index *pIdx; /* For looping over indices */ |
| 74 | int nIdx; /* Number of indices that need updating */ |
drh | 0ca3e24 | 2002-01-29 23:07:02 +0000 | [diff] [blame] | 75 | int nIdxTotal; /* Total number of indices */ |
drh | 6a3ea0e | 2003-05-02 14:32:12 +0000 | [diff] [blame] | 76 | int iCur; /* VDBE Cursor number of pTab */ |
drh | 9bb575f | 2004-09-06 17:24:11 +0000 | [diff] [blame] | 77 | sqlite3 *db; /* The database structure */ |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 78 | Index **apIdx = 0; /* An array of indices that need updating too */ |
drh | b2fe7d8 | 2003-04-20 17:29:23 +0000 | [diff] [blame] | 79 | char *aIdxUsed = 0; /* aIdxUsed[i]==1 if the i-th index is used */ |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 80 | int *aXRef = 0; /* aXRef[i] is the index in pChanges->a[] of the |
drh | 967e8b7 | 2000-06-21 13:59:10 +0000 | [diff] [blame] | 81 | ** an expression for the i-th column of the table. |
| 82 | ** aXRef[i]==-1 if the i-th column is not changed. */ |
drh | 4a32431 | 2001-12-21 14:30:42 +0000 | [diff] [blame] | 83 | int chngRecno; /* True if the record number is being changed */ |
danielk1977 | 742f947 | 2004-06-16 12:02:43 +0000 | [diff] [blame] | 84 | Expr *pRecnoExpr = 0; /* Expression defining the new record number */ |
| 85 | int openAll = 0; /* True if all indices need to be opened */ |
drh | 85e2096 | 2003-04-25 17:52:11 +0000 | [diff] [blame] | 86 | AuthContext sContext; /* The authorization context */ |
danielk1977 | b3bce66 | 2005-01-29 08:32:43 +0000 | [diff] [blame] | 87 | NameContext sNC; /* The name-context to resolve expressions in */ |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 88 | |
drh | 798da52 | 2004-11-04 04:42:28 +0000 | [diff] [blame] | 89 | #ifndef SQLITE_OMIT_TRIGGER |
| 90 | int isView; /* Trying to update a view */ |
drh | dca7684 | 2004-12-07 14:06:13 +0000 | [diff] [blame] | 91 | int triggers_exist = 0; /* True if any row triggers exist */ |
drh | 798da52 | 2004-11-04 04:42:28 +0000 | [diff] [blame] | 92 | #endif |
danielk1977 | c3f9bad | 2002-05-15 08:30:12 +0000 | [diff] [blame] | 93 | |
| 94 | int newIdx = -1; /* index of trigger "new" temp table */ |
| 95 | int oldIdx = -1; /* index of trigger "old" temp table */ |
| 96 | |
drh | 85e2096 | 2003-04-25 17:52:11 +0000 | [diff] [blame] | 97 | sContext.pParse = 0; |
danielk1977 | 6f8a503 | 2004-05-10 10:34:51 +0000 | [diff] [blame] | 98 | if( pParse->nErr || sqlite3_malloc_failed ) goto update_cleanup; |
drh | ecdc753 | 2001-09-23 02:35:53 +0000 | [diff] [blame] | 99 | db = pParse->db; |
drh | 113088e | 2003-03-20 01:16:58 +0000 | [diff] [blame] | 100 | assert( pTabList->nSrc==1 ); |
drh | daffd0e | 2001-04-11 14:28:42 +0000 | [diff] [blame] | 101 | |
drh | b2fe7d8 | 2003-04-20 17:29:23 +0000 | [diff] [blame] | 102 | /* Locate the table which we want to update. |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 103 | */ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 104 | pTab = sqlite3SrcListLookup(pParse, pTabList); |
drh | a69d916 | 2003-04-17 22:57:53 +0000 | [diff] [blame] | 105 | if( pTab==0 ) goto update_cleanup; |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 106 | |
| 107 | /* Figure out if we have any triggers and if the table being |
| 108 | ** updated is a view |
| 109 | */ |
| 110 | #ifndef SQLITE_OMIT_TRIGGER |
drh | dca7684 | 2004-12-07 14:06:13 +0000 | [diff] [blame] | 111 | triggers_exist = sqlite3TriggersExist(pParse, pTab, TK_UPDATE, pChanges); |
drh | 5cf590c | 2003-04-24 01:45:04 +0000 | [diff] [blame] | 112 | isView = pTab->pSelect!=0; |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 113 | #else |
drh | dca7684 | 2004-12-07 14:06:13 +0000 | [diff] [blame] | 114 | # define triggers_exist 0 |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 115 | # define isView 0 |
| 116 | #endif |
| 117 | #ifdef SQLITE_OMIT_VIEW |
| 118 | # undef isView |
| 119 | # define isView 0 |
| 120 | #endif |
| 121 | |
drh | dca7684 | 2004-12-07 14:06:13 +0000 | [diff] [blame] | 122 | if( sqlite3IsReadOnly(pParse, pTab, triggers_exist) ){ |
drh | 5cf590c | 2003-04-24 01:45:04 +0000 | [diff] [blame] | 123 | goto update_cleanup; |
drh | a69d916 | 2003-04-17 22:57:53 +0000 | [diff] [blame] | 124 | } |
drh | 85e2096 | 2003-04-25 17:52:11 +0000 | [diff] [blame] | 125 | if( isView ){ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 126 | if( sqlite3ViewGetColumnNames(pParse, pTab) ){ |
drh | 85e2096 | 2003-04-25 17:52:11 +0000 | [diff] [blame] | 127 | goto update_cleanup; |
| 128 | } |
drh | 5cf590c | 2003-04-24 01:45:04 +0000 | [diff] [blame] | 129 | } |
drh | eafe05b | 2004-06-13 00:54:01 +0000 | [diff] [blame] | 130 | aXRef = sqliteMallocRaw( sizeof(int) * pTab->nCol ); |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 131 | if( aXRef==0 ) goto update_cleanup; |
| 132 | for(i=0; i<pTab->nCol; i++) aXRef[i] = -1; |
| 133 | |
drh | b2fe7d8 | 2003-04-20 17:29:23 +0000 | [diff] [blame] | 134 | /* If there are FOR EACH ROW triggers, allocate cursors for the |
| 135 | ** special OLD and NEW tables |
| 136 | */ |
drh | dca7684 | 2004-12-07 14:06:13 +0000 | [diff] [blame] | 137 | if( triggers_exist ){ |
danielk1977 | c3f9bad | 2002-05-15 08:30:12 +0000 | [diff] [blame] | 138 | newIdx = pParse->nTab++; |
| 139 | oldIdx = pParse->nTab++; |
| 140 | } |
| 141 | |
drh | 53e3fc7 | 2002-07-16 17:22:50 +0000 | [diff] [blame] | 142 | /* Allocate a cursors for the main database table and for all indices. |
| 143 | ** The index cursors might not be used, but if they are used they |
| 144 | ** need to occur right after the database cursor. So go ahead and |
| 145 | ** allocate enough space, just in case. |
| 146 | */ |
drh | 6a3ea0e | 2003-05-02 14:32:12 +0000 | [diff] [blame] | 147 | pTabList->a[0].iCursor = iCur = pParse->nTab++; |
drh | 53e3fc7 | 2002-07-16 17:22:50 +0000 | [diff] [blame] | 148 | for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 149 | pParse->nTab++; |
| 150 | } |
| 151 | |
danielk1977 | b3bce66 | 2005-01-29 08:32:43 +0000 | [diff] [blame] | 152 | /* Initialize the name-context */ |
| 153 | memset(&sNC, 0, sizeof(sNC)); |
| 154 | sNC.pParse = pParse; |
| 155 | sNC.pSrcList = pTabList; |
| 156 | |
drh | 85e2096 | 2003-04-25 17:52:11 +0000 | [diff] [blame] | 157 | /* Resolve the column names in all the expressions of the |
| 158 | ** of the UPDATE statement. Also find the column index |
drh | ed6c867 | 2003-01-12 18:02:16 +0000 | [diff] [blame] | 159 | ** for each column to be updated in the pChanges array. For each |
| 160 | ** column to be updated, make sure we have authorization to change |
| 161 | ** that column. |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 162 | */ |
drh | 4a32431 | 2001-12-21 14:30:42 +0000 | [diff] [blame] | 163 | chngRecno = 0; |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 164 | for(i=0; i<pChanges->nExpr; i++){ |
danielk1977 | b3bce66 | 2005-01-29 08:32:43 +0000 | [diff] [blame] | 165 | if( sqlite3ExprResolveNames(&sNC, pChanges->a[i].pExpr) ){ |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 166 | goto update_cleanup; |
| 167 | } |
| 168 | for(j=0; j<pTab->nCol; j++){ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 169 | if( sqlite3StrICmp(pTab->aCol[j].zName, pChanges->a[i].zName)==0 ){ |
drh | 9647ff8 | 2002-01-14 02:56:24 +0000 | [diff] [blame] | 170 | if( j==pTab->iPKey ){ |
drh | 4a32431 | 2001-12-21 14:30:42 +0000 | [diff] [blame] | 171 | chngRecno = 1; |
| 172 | pRecnoExpr = pChanges->a[i].pExpr; |
| 173 | } |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 174 | aXRef[j] = i; |
| 175 | break; |
| 176 | } |
| 177 | } |
| 178 | if( j>=pTab->nCol ){ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 179 | if( sqlite3IsRowid(pChanges->a[i].zName) ){ |
drh | a0217ba | 2003-06-01 01:10:33 +0000 | [diff] [blame] | 180 | chngRecno = 1; |
| 181 | pRecnoExpr = pChanges->a[i].pExpr; |
| 182 | }else{ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 183 | sqlite3ErrorMsg(pParse, "no such column: %s", pChanges->a[i].zName); |
drh | a0217ba | 2003-06-01 01:10:33 +0000 | [diff] [blame] | 184 | goto update_cleanup; |
| 185 | } |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 186 | } |
drh | ed6c867 | 2003-01-12 18:02:16 +0000 | [diff] [blame] | 187 | #ifndef SQLITE_OMIT_AUTHORIZATION |
drh | e5f9c64 | 2003-01-13 23:27:31 +0000 | [diff] [blame] | 188 | { |
| 189 | int rc; |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 190 | rc = sqlite3AuthCheck(pParse, SQLITE_UPDATE, pTab->zName, |
drh | e22a334 | 2003-04-22 20:30:37 +0000 | [diff] [blame] | 191 | pTab->aCol[j].zName, db->aDb[pTab->iDb].zName); |
drh | e5f9c64 | 2003-01-13 23:27:31 +0000 | [diff] [blame] | 192 | if( rc==SQLITE_DENY ){ |
| 193 | goto update_cleanup; |
| 194 | }else if( rc==SQLITE_IGNORE ){ |
| 195 | aXRef[j] = -1; |
| 196 | } |
drh | ed6c867 | 2003-01-12 18:02:16 +0000 | [diff] [blame] | 197 | } |
| 198 | #endif |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 199 | } |
| 200 | |
drh | 5a2c2c2 | 2001-11-21 02:21:11 +0000 | [diff] [blame] | 201 | /* Allocate memory for the array apIdx[] and fill it with pointers to every |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 202 | ** index that needs to be updated. Indices only need updating if their |
drh | c839258 | 2001-12-31 02:48:51 +0000 | [diff] [blame] | 203 | ** key includes one of the columns named in pChanges or if the record |
| 204 | ** number of the original table entry is changing. |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 205 | */ |
drh | 0ca3e24 | 2002-01-29 23:07:02 +0000 | [diff] [blame] | 206 | for(nIdx=nIdxTotal=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdxTotal++){ |
drh | 4a32431 | 2001-12-21 14:30:42 +0000 | [diff] [blame] | 207 | if( chngRecno ){ |
| 208 | i = 0; |
| 209 | }else { |
| 210 | for(i=0; i<pIdx->nColumn; i++){ |
| 211 | if( aXRef[pIdx->aiColumn[i]]>=0 ) break; |
| 212 | } |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 213 | } |
drh | 967e8b7 | 2000-06-21 13:59:10 +0000 | [diff] [blame] | 214 | if( i<pIdx->nColumn ) nIdx++; |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 215 | } |
drh | 0ca3e24 | 2002-01-29 23:07:02 +0000 | [diff] [blame] | 216 | if( nIdxTotal>0 ){ |
drh | eafe05b | 2004-06-13 00:54:01 +0000 | [diff] [blame] | 217 | apIdx = sqliteMallocRaw( sizeof(Index*) * nIdx + nIdxTotal ); |
drh | b072950 | 2001-03-14 12:35:57 +0000 | [diff] [blame] | 218 | if( apIdx==0 ) goto update_cleanup; |
drh | 0ca3e24 | 2002-01-29 23:07:02 +0000 | [diff] [blame] | 219 | aIdxUsed = (char*)&apIdx[nIdx]; |
drh | b072950 | 2001-03-14 12:35:57 +0000 | [diff] [blame] | 220 | } |
drh | 0ca3e24 | 2002-01-29 23:07:02 +0000 | [diff] [blame] | 221 | for(nIdx=j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){ |
drh | 4a32431 | 2001-12-21 14:30:42 +0000 | [diff] [blame] | 222 | if( chngRecno ){ |
| 223 | i = 0; |
| 224 | }else{ |
| 225 | for(i=0; i<pIdx->nColumn; i++){ |
| 226 | if( aXRef[pIdx->aiColumn[i]]>=0 ) break; |
| 227 | } |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 228 | } |
drh | 0ca3e24 | 2002-01-29 23:07:02 +0000 | [diff] [blame] | 229 | if( i<pIdx->nColumn ){ |
danielk1977 | 7cedc8d | 2004-06-10 10:50:08 +0000 | [diff] [blame] | 230 | if( sqlite3CheckIndexCollSeq(pParse, pIdx) ) goto update_cleanup; |
drh | 0ca3e24 | 2002-01-29 23:07:02 +0000 | [diff] [blame] | 231 | apIdx[nIdx++] = pIdx; |
| 232 | aIdxUsed[j] = 1; |
| 233 | }else{ |
| 234 | aIdxUsed[j] = 0; |
| 235 | } |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 236 | } |
| 237 | |
drh | 85e2096 | 2003-04-25 17:52:11 +0000 | [diff] [blame] | 238 | /* Resolve the column names in all the expressions in the |
| 239 | ** WHERE clause. |
| 240 | */ |
danielk1977 | b3bce66 | 2005-01-29 08:32:43 +0000 | [diff] [blame] | 241 | if( sqlite3ExprResolveNames(&sNC, pWhere) ){ |
drh | 290c194 | 2004-08-21 17:54:45 +0000 | [diff] [blame] | 242 | goto update_cleanup; |
drh | 85e2096 | 2003-04-25 17:52:11 +0000 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | /* Start the view context |
| 246 | */ |
| 247 | if( isView ){ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 248 | sqlite3AuthContextPush(pParse, &sContext, pTab->zName); |
drh | 85e2096 | 2003-04-25 17:52:11 +0000 | [diff] [blame] | 249 | } |
| 250 | |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 251 | /* Begin generating code. |
| 252 | */ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 253 | v = sqlite3GetVdbe(pParse); |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 254 | if( v==0 ) goto update_cleanup; |
drh | 4794f73 | 2004-11-05 17:17:50 +0000 | [diff] [blame] | 255 | if( pParse->nested==0 ) sqlite3VdbeCountChanges(v); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 256 | sqlite3BeginWriteOperation(pParse, 1, pTab->iDb); |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 257 | |
drh | 5cf590c | 2003-04-24 01:45:04 +0000 | [diff] [blame] | 258 | /* If we are trying to update a view, construct that view into |
| 259 | ** a temporary table. |
| 260 | */ |
| 261 | if( isView ){ |
drh | 85e2096 | 2003-04-25 17:52:11 +0000 | [diff] [blame] | 262 | Select *pView; |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 263 | pView = sqlite3SelectDup(pTab->pSelect); |
danielk1977 | b3bce66 | 2005-01-29 08:32:43 +0000 | [diff] [blame] | 264 | sqlite3Select(pParse, pView, SRT_TempTable, iCur, 0, 0, 0, 0); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 265 | sqlite3SelectDelete(pView); |
drh | 5cf590c | 2003-04-24 01:45:04 +0000 | [diff] [blame] | 266 | } |
| 267 | |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 268 | /* Begin the database scan |
| 269 | */ |
drh | e6f85e7 | 2004-12-25 01:03:13 +0000 | [diff] [blame] | 270 | pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0); |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 271 | if( pWInfo==0 ) goto update_cleanup; |
| 272 | |
| 273 | /* Remember the index of every item to be updated. |
| 274 | */ |
drh | e6f85e7 | 2004-12-25 01:03:13 +0000 | [diff] [blame] | 275 | sqlite3VdbeAddOp(v, OP_Recno, iCur, 0); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 276 | sqlite3VdbeAddOp(v, OP_ListWrite, 0, 0); |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 277 | |
| 278 | /* End the database scan loop. |
| 279 | */ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 280 | sqlite3WhereEnd(pWInfo); |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 281 | |
drh | 1bee3d7 | 2001-10-15 00:44:35 +0000 | [diff] [blame] | 282 | /* Initialize the count of updated rows |
| 283 | */ |
danielk1977 | c3f9bad | 2002-05-15 08:30:12 +0000 | [diff] [blame] | 284 | if( db->flags & SQLITE_CountRows && !pParse->trigStack ){ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 285 | sqlite3VdbeAddOp(v, OP_Integer, 0, 0); |
drh | 1bee3d7 | 2001-10-15 00:44:35 +0000 | [diff] [blame] | 286 | } |
| 287 | |
drh | dca7684 | 2004-12-07 14:06:13 +0000 | [diff] [blame] | 288 | if( triggers_exist ){ |
drh | 70ce3f0 | 2003-04-15 19:22:22 +0000 | [diff] [blame] | 289 | /* Create pseudo-tables for NEW and OLD |
| 290 | */ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 291 | sqlite3VdbeAddOp(v, OP_OpenPseudo, oldIdx, 0); |
danielk1977 | 84ac9d0 | 2004-05-18 09:58:06 +0000 | [diff] [blame] | 292 | sqlite3VdbeAddOp(v, OP_SetNumColumns, oldIdx, pTab->nCol); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 293 | sqlite3VdbeAddOp(v, OP_OpenPseudo, newIdx, 0); |
danielk1977 | 84ac9d0 | 2004-05-18 09:58:06 +0000 | [diff] [blame] | 294 | sqlite3VdbeAddOp(v, OP_SetNumColumns, newIdx, pTab->nCol); |
danielk1977 | c3f9bad | 2002-05-15 08:30:12 +0000 | [diff] [blame] | 295 | |
drh | 70ce3f0 | 2003-04-15 19:22:22 +0000 | [diff] [blame] | 296 | /* The top of the update loop for when there are triggers. |
| 297 | */ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 298 | sqlite3VdbeAddOp(v, OP_ListRewind, 0, 0); |
| 299 | addr = sqlite3VdbeAddOp(v, OP_ListRead, 0, 0); |
| 300 | sqlite3VdbeAddOp(v, OP_Dup, 0, 0); |
danielk1977 | c3f9bad | 2002-05-15 08:30:12 +0000 | [diff] [blame] | 301 | |
drh | 70ce3f0 | 2003-04-15 19:22:22 +0000 | [diff] [blame] | 302 | /* Open a cursor and make it point to the record that is |
| 303 | ** being updated. |
| 304 | */ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 305 | sqlite3VdbeAddOp(v, OP_Dup, 0, 0); |
drh | 5cf590c | 2003-04-24 01:45:04 +0000 | [diff] [blame] | 306 | if( !isView ){ |
drh | ad6d946 | 2004-09-19 02:15:24 +0000 | [diff] [blame] | 307 | sqlite3OpenTableForReading(v, iCur, pTab); |
drh | 5cf590c | 2003-04-24 01:45:04 +0000 | [diff] [blame] | 308 | } |
drh | 7cf6e4d | 2004-05-19 14:56:55 +0000 | [diff] [blame] | 309 | sqlite3VdbeAddOp(v, OP_MoveGe, iCur, 0); |
danielk1977 | c3f9bad | 2002-05-15 08:30:12 +0000 | [diff] [blame] | 310 | |
drh | 70ce3f0 | 2003-04-15 19:22:22 +0000 | [diff] [blame] | 311 | /* Generate the OLD table |
| 312 | */ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 313 | sqlite3VdbeAddOp(v, OP_Recno, iCur, 0); |
| 314 | sqlite3VdbeAddOp(v, OP_RowData, iCur, 0); |
| 315 | sqlite3VdbeAddOp(v, OP_PutIntKey, oldIdx, 0); |
danielk1977 | c3f9bad | 2002-05-15 08:30:12 +0000 | [diff] [blame] | 316 | |
drh | 70ce3f0 | 2003-04-15 19:22:22 +0000 | [diff] [blame] | 317 | /* Generate the NEW table |
| 318 | */ |
| 319 | if( chngRecno ){ |
drh | 2530378 | 2004-12-07 15:41:48 +0000 | [diff] [blame] | 320 | sqlite3ExprCodeAndCache(pParse, pRecnoExpr); |
drh | 70ce3f0 | 2003-04-15 19:22:22 +0000 | [diff] [blame] | 321 | }else{ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 322 | sqlite3VdbeAddOp(v, OP_Recno, iCur, 0); |
drh | 70ce3f0 | 2003-04-15 19:22:22 +0000 | [diff] [blame] | 323 | } |
drh | 2530378 | 2004-12-07 15:41:48 +0000 | [diff] [blame] | 324 | for(i=0; i<pTab->nCol; i++){ |
drh | 70ce3f0 | 2003-04-15 19:22:22 +0000 | [diff] [blame] | 325 | if( i==pTab->iPKey ){ |
danielk1977 | 0f69c1e | 2004-05-29 11:24:50 +0000 | [diff] [blame] | 326 | sqlite3VdbeAddOp(v, OP_String8, 0, 0); |
drh | 70ce3f0 | 2003-04-15 19:22:22 +0000 | [diff] [blame] | 327 | continue; |
| 328 | } |
| 329 | j = aXRef[i]; |
| 330 | if( j<0 ){ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 331 | sqlite3VdbeAddOp(v, OP_Column, iCur, i); |
danielk1977 | aee18ef | 2005-03-09 12:26:50 +0000 | [diff] [blame^] | 332 | sqlite3ColumnDefault(v, pTab, i); |
danielk1977 | c3f9bad | 2002-05-15 08:30:12 +0000 | [diff] [blame] | 333 | }else{ |
drh | 2530378 | 2004-12-07 15:41:48 +0000 | [diff] [blame] | 334 | sqlite3ExprCodeAndCache(pParse, pChanges->a[j].pExpr); |
danielk1977 | c3f9bad | 2002-05-15 08:30:12 +0000 | [diff] [blame] | 335 | } |
| 336 | } |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 337 | sqlite3VdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0); |
danielk1977 | a37cdde | 2004-05-16 11:15:36 +0000 | [diff] [blame] | 338 | if( !isView ){ |
| 339 | sqlite3TableAffinityStr(v, pTab); |
| 340 | } |
| 341 | if( pParse->nErr ) goto update_cleanup; |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 342 | sqlite3VdbeAddOp(v, OP_PutIntKey, newIdx, 0); |
drh | 5cf590c | 2003-04-24 01:45:04 +0000 | [diff] [blame] | 343 | if( !isView ){ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 344 | sqlite3VdbeAddOp(v, OP_Close, iCur, 0); |
drh | 5cf590c | 2003-04-24 01:45:04 +0000 | [diff] [blame] | 345 | } |
danielk1977 | c3f9bad | 2002-05-15 08:30:12 +0000 | [diff] [blame] | 346 | |
drh | 5cf590c | 2003-04-24 01:45:04 +0000 | [diff] [blame] | 347 | /* Fire the BEFORE and INSTEAD OF triggers |
drh | 70ce3f0 | 2003-04-15 19:22:22 +0000 | [diff] [blame] | 348 | */ |
drh | dca7684 | 2004-12-07 14:06:13 +0000 | [diff] [blame] | 349 | if( sqlite3CodeRowTrigger(pParse, TK_UPDATE, pChanges, TRIGGER_BEFORE, pTab, |
danielk1977 | 6f34903 | 2002-06-11 02:25:40 +0000 | [diff] [blame] | 350 | newIdx, oldIdx, onError, addr) ){ |
danielk1977 | f29ce55 | 2002-05-19 23:43:12 +0000 | [diff] [blame] | 351 | goto update_cleanup; |
| 352 | } |
danielk1977 | c3f9bad | 2002-05-15 08:30:12 +0000 | [diff] [blame] | 353 | } |
| 354 | |
drh | 5cf590c | 2003-04-24 01:45:04 +0000 | [diff] [blame] | 355 | if( !isView ){ |
| 356 | /* |
| 357 | ** Open every index that needs updating. Note that if any |
| 358 | ** index could potentially invoke a REPLACE conflict resolution |
| 359 | ** action, then we need to open all indices because we might need |
| 360 | ** to be deleting some records. |
| 361 | */ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 362 | sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0); |
| 363 | sqlite3VdbeAddOp(v, OP_OpenWrite, iCur, pTab->tnum); |
danielk1977 | b4964b7 | 2004-05-18 01:23:38 +0000 | [diff] [blame] | 364 | sqlite3VdbeAddOp(v, OP_SetNumColumns, iCur, pTab->nCol); |
drh | 5cf590c | 2003-04-24 01:45:04 +0000 | [diff] [blame] | 365 | if( onError==OE_Replace ){ |
| 366 | openAll = 1; |
| 367 | }else{ |
| 368 | openAll = 0; |
| 369 | for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 370 | if( pIdx->onError==OE_Replace ){ |
| 371 | openAll = 1; |
| 372 | break; |
| 373 | } |
drh | 0ca3e24 | 2002-01-29 23:07:02 +0000 | [diff] [blame] | 374 | } |
| 375 | } |
drh | 5cf590c | 2003-04-24 01:45:04 +0000 | [diff] [blame] | 376 | for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){ |
| 377 | if( openAll || aIdxUsed[i] ){ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 378 | sqlite3VdbeAddOp(v, OP_Integer, pIdx->iDb, 0); |
drh | d3d39e9 | 2004-05-20 22:16:29 +0000 | [diff] [blame] | 379 | sqlite3VdbeOp3(v, OP_OpenWrite, iCur+i+1, pIdx->tnum, |
| 380 | (char*)&pIdx->keyInfo, P3_KEYINFO); |
drh | 6a3ea0e | 2003-05-02 14:32:12 +0000 | [diff] [blame] | 381 | assert( pParse->nTab>iCur+i+1 ); |
drh | 5cf590c | 2003-04-24 01:45:04 +0000 | [diff] [blame] | 382 | } |
drh | 0ca3e24 | 2002-01-29 23:07:02 +0000 | [diff] [blame] | 383 | } |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 384 | |
drh | 5cf590c | 2003-04-24 01:45:04 +0000 | [diff] [blame] | 385 | /* Loop over every record that needs updating. We have to load |
| 386 | ** the old data for each record to be updated because some columns |
| 387 | ** might not change and we will need to copy the old value. |
| 388 | ** Also, the old data is needed to delete the old index entires. |
| 389 | ** So make the cursor point at the old record. |
| 390 | */ |
drh | dca7684 | 2004-12-07 14:06:13 +0000 | [diff] [blame] | 391 | if( !triggers_exist ){ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 392 | sqlite3VdbeAddOp(v, OP_ListRewind, 0, 0); |
| 393 | addr = sqlite3VdbeAddOp(v, OP_ListRead, 0, 0); |
| 394 | sqlite3VdbeAddOp(v, OP_Dup, 0, 0); |
drh | 4a32431 | 2001-12-21 14:30:42 +0000 | [diff] [blame] | 395 | } |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 396 | sqlite3VdbeAddOp(v, OP_NotExists, iCur, addr); |
drh | 5cf590c | 2003-04-24 01:45:04 +0000 | [diff] [blame] | 397 | |
| 398 | /* If the record number will change, push the record number as it |
| 399 | ** will be after the update. (The old record number is currently |
| 400 | ** on top of the stack.) |
| 401 | */ |
| 402 | if( chngRecno ){ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 403 | sqlite3ExprCode(pParse, pRecnoExpr); |
| 404 | sqlite3VdbeAddOp(v, OP_MustBeInt, 0, 0); |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 405 | } |
drh | 5cf590c | 2003-04-24 01:45:04 +0000 | [diff] [blame] | 406 | |
| 407 | /* Compute new data for this record. |
| 408 | */ |
| 409 | for(i=0; i<pTab->nCol; i++){ |
| 410 | if( i==pTab->iPKey ){ |
danielk1977 | 0f69c1e | 2004-05-29 11:24:50 +0000 | [diff] [blame] | 411 | sqlite3VdbeAddOp(v, OP_String8, 0, 0); |
drh | 5cf590c | 2003-04-24 01:45:04 +0000 | [diff] [blame] | 412 | continue; |
| 413 | } |
| 414 | j = aXRef[i]; |
| 415 | if( j<0 ){ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 416 | sqlite3VdbeAddOp(v, OP_Column, iCur, i); |
danielk1977 | aee18ef | 2005-03-09 12:26:50 +0000 | [diff] [blame^] | 417 | sqlite3ColumnDefault(v, pTab, i); |
drh | 5cf590c | 2003-04-24 01:45:04 +0000 | [diff] [blame] | 418 | }else{ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 419 | sqlite3ExprCode(pParse, pChanges->a[j].pExpr); |
drh | 5cf590c | 2003-04-24 01:45:04 +0000 | [diff] [blame] | 420 | } |
| 421 | } |
| 422 | |
| 423 | /* Do constraint checks |
| 424 | */ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 425 | sqlite3GenerateConstraintChecks(pParse, pTab, iCur, aIdxUsed, chngRecno, 1, |
drh | 5cf590c | 2003-04-24 01:45:04 +0000 | [diff] [blame] | 426 | onError, addr); |
| 427 | |
| 428 | /* Delete the old indices for the current record. |
| 429 | */ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 430 | sqlite3GenerateRowIndexDelete(db, v, pTab, iCur, aIdxUsed); |
drh | 5cf590c | 2003-04-24 01:45:04 +0000 | [diff] [blame] | 431 | |
| 432 | /* If changing the record number, delete the old record. |
| 433 | */ |
| 434 | if( chngRecno ){ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 435 | sqlite3VdbeAddOp(v, OP_Delete, iCur, 0); |
drh | 5cf590c | 2003-04-24 01:45:04 +0000 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | /* Create the new index entries and the new record. |
| 439 | */ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 440 | sqlite3CompleteInsertion(pParse, pTab, iCur, aIdxUsed, chngRecno, 1, -1); |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 441 | } |
| 442 | |
drh | 0ca3e24 | 2002-01-29 23:07:02 +0000 | [diff] [blame] | 443 | /* Increment the row counter |
drh | 1bee3d7 | 2001-10-15 00:44:35 +0000 | [diff] [blame] | 444 | */ |
danielk1977 | c3f9bad | 2002-05-15 08:30:12 +0000 | [diff] [blame] | 445 | if( db->flags & SQLITE_CountRows && !pParse->trigStack){ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 446 | sqlite3VdbeAddOp(v, OP_AddImm, 1, 0); |
drh | 1bee3d7 | 2001-10-15 00:44:35 +0000 | [diff] [blame] | 447 | } |
| 448 | |
drh | 5cf590c | 2003-04-24 01:45:04 +0000 | [diff] [blame] | 449 | /* If there are triggers, close all the cursors after each iteration |
| 450 | ** through the loop. The fire the after triggers. |
| 451 | */ |
drh | dca7684 | 2004-12-07 14:06:13 +0000 | [diff] [blame] | 452 | if( triggers_exist ){ |
drh | 5cf590c | 2003-04-24 01:45:04 +0000 | [diff] [blame] | 453 | if( !isView ){ |
| 454 | for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){ |
| 455 | if( openAll || aIdxUsed[i] ) |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 456 | sqlite3VdbeAddOp(v, OP_Close, iCur+i+1, 0); |
drh | 5cf590c | 2003-04-24 01:45:04 +0000 | [diff] [blame] | 457 | } |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 458 | sqlite3VdbeAddOp(v, OP_Close, iCur, 0); |
danielk1977 | c3f9bad | 2002-05-15 08:30:12 +0000 | [diff] [blame] | 459 | } |
drh | dca7684 | 2004-12-07 14:06:13 +0000 | [diff] [blame] | 460 | if( sqlite3CodeRowTrigger(pParse, TK_UPDATE, pChanges, TRIGGER_AFTER, pTab, |
danielk1977 | 6f34903 | 2002-06-11 02:25:40 +0000 | [diff] [blame] | 461 | newIdx, oldIdx, onError, addr) ){ |
danielk1977 | f29ce55 | 2002-05-19 23:43:12 +0000 | [diff] [blame] | 462 | goto update_cleanup; |
| 463 | } |
danielk1977 | c3f9bad | 2002-05-15 08:30:12 +0000 | [diff] [blame] | 464 | } |
| 465 | |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 466 | /* Repeat the above with the next record to be updated, until |
| 467 | ** all record selected by the WHERE clause have been updated. |
| 468 | */ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 469 | sqlite3VdbeAddOp(v, OP_Goto, 0, addr); |
| 470 | sqlite3VdbeChangeP2(v, addr, sqlite3VdbeCurrentAddr(v)); |
| 471 | sqlite3VdbeAddOp(v, OP_ListReset, 0, 0); |
danielk1977 | c3f9bad | 2002-05-15 08:30:12 +0000 | [diff] [blame] | 472 | |
| 473 | /* Close all tables if there were no FOR EACH ROW triggers */ |
drh | dca7684 | 2004-12-07 14:06:13 +0000 | [diff] [blame] | 474 | if( !triggers_exist ){ |
danielk1977 | c3f9bad | 2002-05-15 08:30:12 +0000 | [diff] [blame] | 475 | for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){ |
| 476 | if( openAll || aIdxUsed[i] ){ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 477 | sqlite3VdbeAddOp(v, OP_Close, iCur+i+1, 0); |
danielk1977 | c3f9bad | 2002-05-15 08:30:12 +0000 | [diff] [blame] | 478 | } |
| 479 | } |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 480 | sqlite3VdbeAddOp(v, OP_Close, iCur, 0); |
danielk1977 | f29ce55 | 2002-05-19 23:43:12 +0000 | [diff] [blame] | 481 | }else{ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 482 | sqlite3VdbeAddOp(v, OP_Close, newIdx, 0); |
| 483 | sqlite3VdbeAddOp(v, OP_Close, oldIdx, 0); |
danielk1977 | c3f9bad | 2002-05-15 08:30:12 +0000 | [diff] [blame] | 484 | } |
| 485 | |
drh | 1bee3d7 | 2001-10-15 00:44:35 +0000 | [diff] [blame] | 486 | /* |
danielk1977 | e7de6f2 | 2004-11-05 06:02:06 +0000 | [diff] [blame] | 487 | ** Return the number of rows that were changed. If this routine is |
| 488 | ** generating code because of a call to sqlite3NestedParse(), do not |
| 489 | ** invoke the callback function. |
drh | 1bee3d7 | 2001-10-15 00:44:35 +0000 | [diff] [blame] | 490 | */ |
danielk1977 | e7de6f2 | 2004-11-05 06:02:06 +0000 | [diff] [blame] | 491 | if( db->flags & SQLITE_CountRows && !pParse->trigStack && pParse->nested==0 ){ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 492 | sqlite3VdbeAddOp(v, OP_Callback, 1, 0); |
danielk1977 | 22322fd | 2004-05-25 23:35:17 +0000 | [diff] [blame] | 493 | sqlite3VdbeSetNumCols(v, 1); |
danielk1977 | 3cf8606 | 2004-05-26 10:11:05 +0000 | [diff] [blame] | 494 | sqlite3VdbeSetColName(v, 0, "rows updated", P3_STATIC); |
drh | 1bee3d7 | 2001-10-15 00:44:35 +0000 | [diff] [blame] | 495 | } |
| 496 | |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 497 | update_cleanup: |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 498 | sqlite3AuthContextPop(&sContext); |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 499 | sqliteFree(apIdx); |
| 500 | sqliteFree(aXRef); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 501 | sqlite3SrcListDelete(pTabList); |
| 502 | sqlite3ExprListDelete(pChanges); |
| 503 | sqlite3ExprDelete(pWhere); |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 504 | return; |
| 505 | } |