Skip to content

Commit

Permalink
Reapplied [cbc4188] (Added interrupt method to cancel/interrupt pendi…
Browse files Browse the repository at this point in the history
…ng database operation - Marek Serafin <[email protected]>) which was (presumably accidentally) removed in [59f8d63].
  • Loading branch information
Evan D. Schoenberg, M.D committed Jun 8, 2016
1 parent 1cd3279 commit 2309720
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/fmdb/FMDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,15 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary

- (void)setShouldCacheStatements:(BOOL)value;

/** Interupt pending database operation
This method causes any pending database operation to abort and return at its earliest opportunity
@return `YES` on success; `NO` on failure. If failed, you can call `<lastError>`, `<lastErrorCode>`, or `<lastErrorMessage>` for diagnostic information regarding the failure.
*/

- (BOOL)interrupt;

///-------------------------
/// @name Encryption methods
Expand Down
15 changes: 15 additions & 0 deletions src/fmdb/FMDatabase.m
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,12 @@ - (BOOL)executeUpdate:(NSString*)sql error:(NSError**)outErr withArgumentsInArra
if (SQLITE_DONE == rc) {
// all is well, let's return.
}
else if (SQLITE_INTERRUPT == rc) {
if (_logsErrors) {
NSLog(@"Error calling sqlite3_step. Query was interrupted (%d: %s) SQLITE_INTERRUPT", rc, sqlite3_errmsg(_db));
NSLog(@"DB Query: %@", sql);
}
}
else if (rc == SQLITE_ROW) {
NSString *message = [NSString stringWithFormat:@"A executeUpdate is being called with a query string '%@'", sql];
if (_logsErrors) {
Expand Down Expand Up @@ -1301,6 +1307,15 @@ - (BOOL)inTransaction {
return _inTransaction;
}

- (BOOL)interrupt
{
if (_db) {
sqlite3_interrupt([self sqliteHandle]);
return YES;
}
return NO;
}

static NSString *FMDBEscapeSavePointName(NSString *savepointName) {
return [savepointName stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
}
Expand Down
4 changes: 4 additions & 0 deletions src/fmdb/FMDatabaseQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@

- (void)close;

/** Interupt pending database operation. */

- (void)interrupt;

///-----------------------------------------------
/// @name Dispatching database operations to queue
///-----------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions src/fmdb/FMDatabaseQueue.m
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ - (void)close {
FMDBRelease(self);
}

- (void)interrupt
{
[[self database] interrupt];
}

- (FMDatabase*)database {
if (!_db) {
_db = FMDBReturnRetained([[[self class] databaseClass] databaseWithPath:_path]);
Expand Down

0 comments on commit 2309720

Please sign in to comment.