** Implementation of .ar "Remove" command. */
| 27421 | ** Implementation of .ar "Remove" command. |
| 27422 | */ |
| 27423 | static int arRemoveCommand(ArCommand *pAr){ |
| 27424 | int rc = 0; |
| 27425 | char *zSql = 0; |
| 27426 | char *zWhere = 0; |
| 27427 | |
| 27428 | if( pAr->nArg ){ |
| 27429 | /* Verify that args actually exist within the archive before proceeding. |
| 27430 | ** And formulate a WHERE clause to match them. */ |
| 27431 | rc = arCheckEntries(pAr); |
| 27432 | arWhereClause(&rc, pAr, &zWhere); |
| 27433 | } |
| 27434 | if( rc==SQLITE_OK ){ |
| 27435 | zSql = sqlite3_mprintf("DELETE FROM %s WHERE %s;", |
| 27436 | pAr->zSrcTable, zWhere); |
| 27437 | if( pAr->bDryRun ){ |
| 27438 | sqlite3_fprintf(pAr->out, "%s\n", zSql); |
| 27439 | }else{ |
| 27440 | char *zErr = 0; |
| 27441 | rc = sqlite3_exec(pAr->db, "SAVEPOINT ar;", 0, 0, 0); |
| 27442 | if( rc==SQLITE_OK ){ |
| 27443 | rc = sqlite3_exec(pAr->db, zSql, 0, 0, &zErr); |
| 27444 | if( rc!=SQLITE_OK ){ |
| 27445 | sqlite3_exec(pAr->db, "ROLLBACK TO ar; RELEASE ar;", 0, 0, 0); |
| 27446 | }else{ |
| 27447 | rc = sqlite3_exec(pAr->db, "RELEASE ar;", 0, 0, 0); |
| 27448 | } |
| 27449 | } |
| 27450 | if( zErr ){ |
| 27451 | sqlite3_fprintf(stdout, "ERROR: %s\n", zErr); /* stdout? */ |
| 27452 | sqlite3_free(zErr); |
| 27453 | } |
| 27454 | } |
| 27455 | } |
| 27456 | sqlite3_free(zWhere); |
| 27457 | sqlite3_free(zSql); |
| 27458 | return rc; |
| 27459 | } |
| 27460 | |
| 27461 | /* |
| 27462 | ** Implementation of .ar "eXtract" command. |
no test coverage detected