diff options
author | ccgus <gus@flyingmeat.com> | 2013-11-07 01:25:42 +0400 |
---|---|---|
committer | ccgus <gus@flyingmeat.com> | 2013-11-07 01:25:42 +0400 |
commit | cc933296482098c7689b17c9ce97022fffdf65b2 (patch) | |
tree | daca5b443d704815ec1bfea35f924684cdd7b05d | |
parent | 1af6d471826e2f2344dcff027f4245c33b755f65 (diff) |
Just a little refactoring for the busy timeout stuff.
-rw-r--r-- | src/FMDatabase.h | 2 | ||||
-rw-r--r-- | src/FMDatabase.m | 8 | ||||
-rw-r--r-- | src/FMDatabaseAdditions.m | 2 | ||||
-rw-r--r-- | src/FMResultSet.m | 2 | ||||
-rw-r--r-- | src/fmdb.m | 4 |
5 files changed, 12 insertions, 6 deletions
diff --git a/src/FMDatabase.h b/src/FMDatabase.h index 25fb8d3..db743b5 100644 --- a/src/FMDatabase.h +++ b/src/FMDatabase.h @@ -49,6 +49,8 @@ #define instancetype id #endif +#define FMDatabaseSQLiteBusyMicrosecondsTimeout 20 + /** A SQLite ([http://sqlite.org/](http://sqlite.org/)) Objective-C wrapper. ### Usage diff --git a/src/FMDatabase.m b/src/FMDatabase.m index 7e25e47..e3a6db3 100644 --- a/src/FMDatabase.m +++ b/src/FMDatabase.m @@ -134,7 +134,7 @@ if (SQLITE_BUSY == rc || SQLITE_LOCKED == rc) { retry = YES; - usleep(20); + usleep(FMDatabaseSQLiteBusyMicrosecondsTimeout); if (_busyRetryTimeout && (numberOfRetries++ > _busyRetryTimeout)) { NSLog(@"%s:%d", __FUNCTION__, __LINE__); @@ -615,7 +615,7 @@ if (SQLITE_BUSY == rc || SQLITE_LOCKED == rc) { retry = YES; - usleep(20); + usleep(FMDatabaseSQLiteBusyMicrosecondsTimeout); if (_busyRetryTimeout && (numberOfRetries++ > _busyRetryTimeout)) { NSLog(@"%s:%d Database busy (%@)", __FUNCTION__, __LINE__, [self databasePath]); @@ -807,7 +807,7 @@ rc = sqlite3_prepare_v2(_db, [sql UTF8String], -1, &pStmt, 0); if (SQLITE_BUSY == rc || SQLITE_LOCKED == rc) { retry = YES; - usleep(20); + usleep(FMDatabaseSQLiteBusyMicrosecondsTimeout); if (_busyRetryTimeout && (numberOfRetries++ > _busyRetryTimeout)) { NSLog(@"%s:%d Database busy (%@)", __FUNCTION__, __LINE__, [self databasePath]); @@ -930,7 +930,7 @@ NSLog(@"Unexpected result from sqlite3_reset (%d) eu", rc); } } - usleep(20); + usleep(FMDatabaseSQLiteBusyMicrosecondsTimeout); if (_busyRetryTimeout && (numberOfRetries++ > _busyRetryTimeout)) { NSLog(@"%s:%d Database busy (%@)", __FUNCTION__, __LINE__, [self databasePath]); diff --git a/src/FMDatabaseAdditions.m b/src/FMDatabaseAdditions.m index ab47c90..bee79ed 100644 --- a/src/FMDatabaseAdditions.m +++ b/src/FMDatabaseAdditions.m @@ -191,7 +191,7 @@ return ret; int rc = sqlite3_prepare_v2(_db, [sql UTF8String], -1, &pStmt, 0); if (rc == SQLITE_BUSY || rc == SQLITE_LOCKED) { keepTrying = YES; - usleep(20); + usleep(FMDatabaseSQLiteBusyMicrosecondsTimeout); if (_busyRetryTimeout && (numberOfRetries++ > _busyRetryTimeout)) { NSLog(@"%s:%d Database busy (%@)", __FUNCTION__, __LINE__, [self databasePath]); diff --git a/src/FMResultSet.m b/src/FMResultSet.m index 1aa4df9..beab640 100644 --- a/src/FMResultSet.m +++ b/src/FMResultSet.m @@ -167,7 +167,7 @@ NSLog(@"Unexpected result from sqlite3_reset (%d) rs", rc); } } - usleep(20); + usleep(FMDatabaseSQLiteBusyMicrosecondsTimeout); if ([_parentDB busyRetryTimeout] && (numberOfRetries++ > [_parentDB busyRetryTimeout])) { @@ -353,6 +353,8 @@ int main (int argc, const char * argv[]) { NSLog(@"Testing the busy timeout"); + NSTimeInterval startTime = [NSDate timeIntervalSinceReferenceDate]; + BOOL success = [db executeUpdate:@"insert into t1 values (5)"]; if (success) { @@ -375,7 +377,9 @@ int main (int argc, const char * argv[]) { NSLog(@"Hurray, we can insert again!"); } + NSTimeInterval end = [NSDate timeIntervalSinceReferenceDate] - startTime; + NSLog(@"Took %f seconds for the timeout.", end); // test some nullness. [db executeUpdate:@"create table t2 (a integer, b integer)"]; |