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 | ** |
drh | 9647ff8 | 2002-01-14 02:56:24 +0000 | [diff] [blame^] | 15 | ** $Id: update.c,v 1.26 2002/01/14 02:56:25 drh Exp $ |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 16 | */ |
| 17 | #include "sqliteInt.h" |
| 18 | |
| 19 | /* |
| 20 | ** Process an UPDATE statement. |
| 21 | */ |
| 22 | void sqliteUpdate( |
| 23 | Parse *pParse, /* The parser context */ |
| 24 | Token *pTableName, /* The table in which we should change things */ |
| 25 | ExprList *pChanges, /* Things to be changed */ |
| 26 | Expr *pWhere /* The WHERE clause. May be null */ |
| 27 | ){ |
| 28 | int i, j; /* Loop counters */ |
| 29 | Table *pTab; /* The table to be updated */ |
| 30 | IdList *pTabList = 0; /* List containing only pTab */ |
| 31 | int end, addr; /* A couple of addresses in the generated code */ |
| 32 | WhereInfo *pWInfo; /* Information about the WHERE clause */ |
| 33 | Vdbe *v; /* The virtual database engine */ |
| 34 | Index *pIdx; /* For looping over indices */ |
| 35 | int nIdx; /* Number of indices that need updating */ |
drh | 4794b98 | 2000-06-06 13:54:14 +0000 | [diff] [blame] | 36 | int base; /* Index of first available table cursor */ |
drh | ecdc753 | 2001-09-23 02:35:53 +0000 | [diff] [blame] | 37 | sqlite *db; /* The database structure */ |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 38 | Index **apIdx = 0; /* An array of indices that need updating too */ |
| 39 | int *aXRef = 0; /* aXRef[i] is the index in pChanges->a[] of the |
drh | 967e8b7 | 2000-06-21 13:59:10 +0000 | [diff] [blame] | 40 | ** an expression for the i-th column of the table. |
| 41 | ** aXRef[i]==-1 if the i-th column is not changed. */ |
drh | f57b339 | 2001-10-08 13:22:32 +0000 | [diff] [blame] | 42 | int openOp; /* Opcode used to open tables */ |
drh | 4a32431 | 2001-12-21 14:30:42 +0000 | [diff] [blame] | 43 | int chngRecno; /* True if the record number is being changed */ |
| 44 | Expr *pRecnoExpr; /* Expression defining the new record number */ |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 45 | |
drh | daffd0e | 2001-04-11 14:28:42 +0000 | [diff] [blame] | 46 | if( pParse->nErr || sqlite_malloc_failed ) goto update_cleanup; |
drh | ecdc753 | 2001-09-23 02:35:53 +0000 | [diff] [blame] | 47 | db = pParse->db; |
drh | daffd0e | 2001-04-11 14:28:42 +0000 | [diff] [blame] | 48 | |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 49 | /* Locate the table which we want to update. This table has to be |
drh | 1ccde15 | 2000-06-17 13:12:39 +0000 | [diff] [blame] | 50 | ** put in an IdList structure because some of the subroutines we |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 51 | ** will be calling are designed to work with multiple tables and expect |
drh | c839258 | 2001-12-31 02:48:51 +0000 | [diff] [blame] | 52 | ** an IdList* parameter instead of just a Table* parameter. |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 53 | */ |
| 54 | pTabList = sqliteIdListAppend(0, pTableName); |
drh | daffd0e | 2001-04-11 14:28:42 +0000 | [diff] [blame] | 55 | if( pTabList==0 ) goto update_cleanup; |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 56 | for(i=0; i<pTabList->nId; i++){ |
drh | ecdc753 | 2001-09-23 02:35:53 +0000 | [diff] [blame] | 57 | pTabList->a[i].pTab = sqliteFindTable(db, pTabList->a[i].zName); |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 58 | if( pTabList->a[i].pTab==0 ){ |
| 59 | sqliteSetString(&pParse->zErrMsg, "no such table: ", |
| 60 | pTabList->a[i].zName, 0); |
| 61 | pParse->nErr++; |
| 62 | goto update_cleanup; |
| 63 | } |
| 64 | if( pTabList->a[i].pTab->readOnly ){ |
| 65 | sqliteSetString(&pParse->zErrMsg, "table ", pTabList->a[i].zName, |
| 66 | " may not be modified", 0); |
| 67 | pParse->nErr++; |
| 68 | goto update_cleanup; |
| 69 | } |
| 70 | } |
| 71 | pTab = pTabList->a[0].pTab; |
| 72 | aXRef = sqliteMalloc( sizeof(int) * pTab->nCol ); |
| 73 | if( aXRef==0 ) goto update_cleanup; |
| 74 | for(i=0; i<pTab->nCol; i++) aXRef[i] = -1; |
| 75 | |
drh | 967e8b7 | 2000-06-21 13:59:10 +0000 | [diff] [blame] | 76 | /* Resolve the column names in all the expressions in both the |
| 77 | ** WHERE clause and in the new values. Also find the column index |
| 78 | ** for each column to be updated in the pChanges array. |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 79 | */ |
| 80 | if( pWhere ){ |
drh | 4794b98 | 2000-06-06 13:54:14 +0000 | [diff] [blame] | 81 | sqliteExprResolveInSelect(pParse, pWhere); |
| 82 | } |
| 83 | for(i=0; i<pChanges->nExpr; i++){ |
| 84 | sqliteExprResolveInSelect(pParse, pChanges->a[i].pExpr); |
| 85 | } |
| 86 | if( pWhere ){ |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 87 | if( sqliteExprResolveIds(pParse, pTabList, pWhere) ){ |
| 88 | goto update_cleanup; |
| 89 | } |
| 90 | if( sqliteExprCheck(pParse, pWhere, 0, 0) ){ |
| 91 | goto update_cleanup; |
| 92 | } |
| 93 | } |
drh | 4a32431 | 2001-12-21 14:30:42 +0000 | [diff] [blame] | 94 | chngRecno = 0; |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 95 | for(i=0; i<pChanges->nExpr; i++){ |
| 96 | if( sqliteExprResolveIds(pParse, pTabList, pChanges->a[i].pExpr) ){ |
| 97 | goto update_cleanup; |
| 98 | } |
| 99 | if( sqliteExprCheck(pParse, pChanges->a[i].pExpr, 0, 0) ){ |
| 100 | goto update_cleanup; |
| 101 | } |
| 102 | for(j=0; j<pTab->nCol; j++){ |
drh | 6206d50 | 2000-06-19 19:09:08 +0000 | [diff] [blame] | 103 | if( sqliteStrICmp(pTab->aCol[j].zName, pChanges->a[i].zName)==0 ){ |
drh | 9647ff8 | 2002-01-14 02:56:24 +0000 | [diff] [blame^] | 104 | if( j==pTab->iPKey ){ |
drh | 4a32431 | 2001-12-21 14:30:42 +0000 | [diff] [blame] | 105 | chngRecno = 1; |
| 106 | pRecnoExpr = pChanges->a[i].pExpr; |
| 107 | } |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 108 | aXRef[j] = i; |
| 109 | break; |
| 110 | } |
| 111 | } |
| 112 | if( j>=pTab->nCol ){ |
drh | 967e8b7 | 2000-06-21 13:59:10 +0000 | [diff] [blame] | 113 | sqliteSetString(&pParse->zErrMsg, "no such column: ", |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 114 | pChanges->a[i].zName, 0); |
| 115 | pParse->nErr++; |
| 116 | goto update_cleanup; |
| 117 | } |
| 118 | } |
| 119 | |
drh | 5a2c2c2 | 2001-11-21 02:21:11 +0000 | [diff] [blame] | 120 | /* Allocate memory for the array apIdx[] and fill it with pointers to every |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 121 | ** index that needs to be updated. Indices only need updating if their |
drh | c839258 | 2001-12-31 02:48:51 +0000 | [diff] [blame] | 122 | ** key includes one of the columns named in pChanges or if the record |
| 123 | ** number of the original table entry is changing. |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 124 | */ |
| 125 | for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
drh | 4a32431 | 2001-12-21 14:30:42 +0000 | [diff] [blame] | 126 | if( chngRecno ){ |
| 127 | i = 0; |
| 128 | }else { |
| 129 | for(i=0; i<pIdx->nColumn; i++){ |
| 130 | if( aXRef[pIdx->aiColumn[i]]>=0 ) break; |
| 131 | } |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 132 | } |
drh | 967e8b7 | 2000-06-21 13:59:10 +0000 | [diff] [blame] | 133 | if( i<pIdx->nColumn ) nIdx++; |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 134 | } |
drh | b072950 | 2001-03-14 12:35:57 +0000 | [diff] [blame] | 135 | if( nIdx>0 ){ |
| 136 | apIdx = sqliteMalloc( sizeof(Index*) * nIdx ); |
| 137 | if( apIdx==0 ) goto update_cleanup; |
| 138 | } |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 139 | for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
drh | 4a32431 | 2001-12-21 14:30:42 +0000 | [diff] [blame] | 140 | if( chngRecno ){ |
| 141 | i = 0; |
| 142 | }else{ |
| 143 | for(i=0; i<pIdx->nColumn; i++){ |
| 144 | if( aXRef[pIdx->aiColumn[i]]>=0 ) break; |
| 145 | } |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 146 | } |
drh | 967e8b7 | 2000-06-21 13:59:10 +0000 | [diff] [blame] | 147 | if( i<pIdx->nColumn ) apIdx[nIdx++] = pIdx; |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | /* Begin generating code. |
| 151 | */ |
drh | d8bc708 | 2000-06-07 23:51:50 +0000 | [diff] [blame] | 152 | v = sqliteGetVdbe(pParse); |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 153 | if( v==0 ) goto update_cleanup; |
drh | ecdc753 | 2001-09-23 02:35:53 +0000 | [diff] [blame] | 154 | if( (db->flags & SQLITE_InTrans)==0 ){ |
drh | 99fcd71 | 2001-10-13 01:06:47 +0000 | [diff] [blame] | 155 | sqliteVdbeAddOp(v, OP_Transaction, 0, 0); |
| 156 | sqliteVdbeAddOp(v, OP_VerifyCookie, db->schema_cookie, 0); |
drh | ecdc753 | 2001-09-23 02:35:53 +0000 | [diff] [blame] | 157 | pParse->schemaVerified = 1; |
drh | 5e00f6c | 2001-09-13 13:46:56 +0000 | [diff] [blame] | 158 | } |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 159 | |
| 160 | /* Begin the database scan |
| 161 | */ |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 162 | pWInfo = sqliteWhereBegin(pParse, pTabList, pWhere, 1); |
| 163 | if( pWInfo==0 ) goto update_cleanup; |
| 164 | |
| 165 | /* Remember the index of every item to be updated. |
| 166 | */ |
drh | 99fcd71 | 2001-10-13 01:06:47 +0000 | [diff] [blame] | 167 | sqliteVdbeAddOp(v, OP_ListWrite, 0, 0); |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 168 | |
| 169 | /* End the database scan loop. |
| 170 | */ |
| 171 | sqliteWhereEnd(pWInfo); |
| 172 | |
drh | 1bee3d7 | 2001-10-15 00:44:35 +0000 | [diff] [blame] | 173 | /* Initialize the count of updated rows |
| 174 | */ |
| 175 | if( db->flags & SQLITE_CountRows ){ |
| 176 | sqliteVdbeAddOp(v, OP_Integer, 0, 0); |
| 177 | } |
| 178 | |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 179 | /* Rewind the list of records that need to be updated and |
| 180 | ** open every index that needs updating. |
| 181 | */ |
drh | 99fcd71 | 2001-10-13 01:06:47 +0000 | [diff] [blame] | 182 | sqliteVdbeAddOp(v, OP_ListRewind, 0, 0); |
drh | 4794b98 | 2000-06-06 13:54:14 +0000 | [diff] [blame] | 183 | base = pParse->nTab; |
drh | f57b339 | 2001-10-08 13:22:32 +0000 | [diff] [blame] | 184 | openOp = pTab->isTemp ? OP_OpenWrAux : OP_OpenWrite; |
drh | 99fcd71 | 2001-10-13 01:06:47 +0000 | [diff] [blame] | 185 | sqliteVdbeAddOp(v, openOp, base, pTab->tnum); |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 186 | for(i=0; i<nIdx; i++){ |
drh | 99fcd71 | 2001-10-13 01:06:47 +0000 | [diff] [blame] | 187 | sqliteVdbeAddOp(v, openOp, base+i+1, apIdx[i]->tnum); |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | /* Loop over every record that needs updating. We have to load |
drh | 967e8b7 | 2000-06-21 13:59:10 +0000 | [diff] [blame] | 191 | ** the old data for each record to be updated because some columns |
drh | 1ccde15 | 2000-06-17 13:12:39 +0000 | [diff] [blame] | 192 | ** might not change and we will need to copy the old value. |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 193 | ** Also, the old data is needed to delete the old index entires. |
drh | 4a32431 | 2001-12-21 14:30:42 +0000 | [diff] [blame] | 194 | ** So make the cursor point at the old record. |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 195 | */ |
| 196 | end = sqliteVdbeMakeLabel(v); |
drh | 99fcd71 | 2001-10-13 01:06:47 +0000 | [diff] [blame] | 197 | addr = sqliteVdbeAddOp(v, OP_ListRead, 0, end); |
| 198 | sqliteVdbeAddOp(v, OP_Dup, 0, 0); |
| 199 | sqliteVdbeAddOp(v, OP_MoveTo, base, 0); |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 200 | |
| 201 | /* Delete the old indices for the current record. |
| 202 | */ |
| 203 | for(i=0; i<nIdx; i++){ |
drh | 99fcd71 | 2001-10-13 01:06:47 +0000 | [diff] [blame] | 204 | sqliteVdbeAddOp(v, OP_Dup, 0, 0); |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 205 | pIdx = apIdx[i]; |
drh | 967e8b7 | 2000-06-21 13:59:10 +0000 | [diff] [blame] | 206 | for(j=0; j<pIdx->nColumn; j++){ |
drh | c839258 | 2001-12-31 02:48:51 +0000 | [diff] [blame] | 207 | int x = pIdx->aiColumn[j]; |
| 208 | if( x==pTab->iPKey ){ |
| 209 | sqliteVdbeAddOp(v, OP_Dup, j, 0); |
| 210 | }else{ |
| 211 | sqliteVdbeAddOp(v, OP_Column, base, x); |
| 212 | } |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 213 | } |
drh | 99fcd71 | 2001-10-13 01:06:47 +0000 | [diff] [blame] | 214 | sqliteVdbeAddOp(v, OP_MakeIdxKey, pIdx->nColumn, 0); |
drh | 8721ce4 | 2001-11-07 14:22:00 +0000 | [diff] [blame] | 215 | sqliteVdbeAddOp(v, OP_IdxDelete, base+i+1, 0); |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 216 | } |
| 217 | |
drh | 4a32431 | 2001-12-21 14:30:42 +0000 | [diff] [blame] | 218 | /* If changing the record number, remove the old record number |
| 219 | ** from the top of the stack and replace it with the new one. |
| 220 | */ |
| 221 | if( chngRecno ){ |
| 222 | sqliteVdbeAddOp(v, OP_Pop, 1, 0); |
| 223 | sqliteExprCode(pParse, pRecnoExpr); |
drh | 8aff101 | 2001-12-22 14:49:24 +0000 | [diff] [blame] | 224 | sqliteVdbeAddOp(v, OP_MustBeInt, 0, 0); |
drh | 4a32431 | 2001-12-21 14:30:42 +0000 | [diff] [blame] | 225 | } |
| 226 | |
drh | 5a2c2c2 | 2001-11-21 02:21:11 +0000 | [diff] [blame] | 227 | /* Compute new data for this record. |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 228 | */ |
| 229 | for(i=0; i<pTab->nCol; i++){ |
drh | 4a32431 | 2001-12-21 14:30:42 +0000 | [diff] [blame] | 230 | if( i==pTab->iPKey ){ |
| 231 | sqliteVdbeAddOp(v, OP_Dup, i, 0); |
| 232 | continue; |
| 233 | } |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 234 | j = aXRef[i]; |
| 235 | if( j<0 ){ |
drh | 99fcd71 | 2001-10-13 01:06:47 +0000 | [diff] [blame] | 236 | sqliteVdbeAddOp(v, OP_Column, base, i); |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 237 | }else{ |
| 238 | sqliteExprCode(pParse, pChanges->a[j].pExpr); |
| 239 | } |
| 240 | } |
| 241 | |
drh | c839258 | 2001-12-31 02:48:51 +0000 | [diff] [blame] | 242 | /* If changing the record number, delete the old record. |
drh | 4a32431 | 2001-12-21 14:30:42 +0000 | [diff] [blame] | 243 | */ |
| 244 | if( chngRecno ){ |
| 245 | sqliteVdbeAddOp(v, OP_Delete, 0, 0); |
| 246 | } |
| 247 | |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 248 | /* Insert new index entries that correspond to the new data |
| 249 | */ |
| 250 | for(i=0; i<nIdx; i++){ |
drh | 99fcd71 | 2001-10-13 01:06:47 +0000 | [diff] [blame] | 251 | sqliteVdbeAddOp(v, OP_Dup, pTab->nCol, 0); /* The KEY */ |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 252 | pIdx = apIdx[i]; |
drh | 967e8b7 | 2000-06-21 13:59:10 +0000 | [diff] [blame] | 253 | for(j=0; j<pIdx->nColumn; j++){ |
drh | 4a32431 | 2001-12-21 14:30:42 +0000 | [diff] [blame] | 254 | int idx = pIdx->aiColumn[j]; |
| 255 | if( idx==pTab->iPKey ){ |
| 256 | sqliteVdbeAddOp(v, OP_Dup, j, 0); |
| 257 | }else{ |
| 258 | sqliteVdbeAddOp(v, OP_Dup, j+pTab->nCol-idx, 0); |
| 259 | } |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 260 | } |
drh | 99fcd71 | 2001-10-13 01:06:47 +0000 | [diff] [blame] | 261 | sqliteVdbeAddOp(v, OP_MakeIdxKey, pIdx->nColumn, 0); |
drh | 8721ce4 | 2001-11-07 14:22:00 +0000 | [diff] [blame] | 262 | sqliteVdbeAddOp(v, OP_IdxPut, base+i+1, pIdx->isUnique); |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | /* Write the new data back into the database. |
| 266 | */ |
drh | 99fcd71 | 2001-10-13 01:06:47 +0000 | [diff] [blame] | 267 | sqliteVdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0); |
| 268 | sqliteVdbeAddOp(v, OP_Put, base, 0); |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 269 | |
drh | 1bee3d7 | 2001-10-15 00:44:35 +0000 | [diff] [blame] | 270 | /* Increment the count of rows affected by the update |
| 271 | */ |
| 272 | if( db->flags & SQLITE_CountRows ){ |
| 273 | sqliteVdbeAddOp(v, OP_AddImm, 1, 0); |
| 274 | } |
| 275 | |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 276 | /* Repeat the above with the next record to be updated, until |
| 277 | ** all record selected by the WHERE clause have been updated. |
| 278 | */ |
drh | 99fcd71 | 2001-10-13 01:06:47 +0000 | [diff] [blame] | 279 | sqliteVdbeAddOp(v, OP_Goto, 0, addr); |
| 280 | sqliteVdbeResolveLabel(v, end); |
drh | a8b38d2 | 2001-11-01 14:41:34 +0000 | [diff] [blame] | 281 | sqliteVdbeAddOp(v, OP_ListReset, 0, 0); |
drh | ecdc753 | 2001-09-23 02:35:53 +0000 | [diff] [blame] | 282 | if( (db->flags & SQLITE_InTrans)==0 ){ |
drh | 99fcd71 | 2001-10-13 01:06:47 +0000 | [diff] [blame] | 283 | sqliteVdbeAddOp(v, OP_Commit, 0, 0); |
drh | 5e00f6c | 2001-09-13 13:46:56 +0000 | [diff] [blame] | 284 | } |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 285 | |
drh | 1bee3d7 | 2001-10-15 00:44:35 +0000 | [diff] [blame] | 286 | /* |
| 287 | ** Return the number of rows that were changed. |
| 288 | */ |
| 289 | if( db->flags & SQLITE_CountRows ){ |
| 290 | sqliteVdbeAddOp(v, OP_ColumnCount, 1, 0); |
| 291 | sqliteVdbeAddOp(v, OP_ColumnName, 0, 0); |
| 292 | sqliteVdbeChangeP3(v, -1, "rows updated", P3_STATIC); |
| 293 | sqliteVdbeAddOp(v, OP_Callback, 1, 0); |
| 294 | } |
| 295 | |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 296 | update_cleanup: |
| 297 | sqliteFree(apIdx); |
| 298 | sqliteFree(aXRef); |
| 299 | sqliteIdListDelete(pTabList); |
| 300 | sqliteExprListDelete(pChanges); |
| 301 | sqliteExprDelete(pWhere); |
| 302 | return; |
| 303 | } |