Skip to content

Commit

Permalink
Merge upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
p2 committed Feb 3, 2011
2 parents 6809d43 + 06bccb3 commit 2b4540f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 15 deletions.
7 changes: 7 additions & 0 deletions CHANGES_AND_TODO_LIST.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ Zip, nada, zilch. Got any ideas?

If you would like to contribute some code- awesome! I just ask that you make it conform to the coding conventions already set in here, and to add a couple of tests for your new code to fmdb.m. And of course, the code should be of general use to more than just a couple of folks. Send your patches to [email protected].

2011.01.13
Happy New Year!
Now checking for SQLITE_LOCKED along with SQLITE_BUSY when trying to perform a query. Patch from Jeff Meininger!

2010.12.28
Fixed some compiler warnings (thanks to Casey Fleser!)

2010.11.30
Added and updated some new methods to take NSError** params.
Only execute the assertion macros if NS_BLOCK_ASSERTIONS is not set. Patch from David E. Wheeler!
Expand Down
4 changes: 3 additions & 1 deletion CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@ Jens Alfke
Pascal Pfiffner
Augie Fackler
David E. Wheeler
Casey Fleser
Jeff Meininger

Aaaaannnd, Gus Mueller (that's me!)
Aaaaannnd, Gus Mueller (that's me!)
9 changes: 5 additions & 4 deletions fmdb.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,7 @@
1DEB927608733DD40010E9CD /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = (
ppc,
i386,
);
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
GCC_MODEL_TUNING = G5;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
Expand All @@ -279,7 +276,11 @@
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_MISSING_PARENTHESES = YES;
GCC_WARN_PEDANTIC = YES;
GCC_WARN_SIGN_COMPARE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
PREBINDING = NO;
};
Expand Down
20 changes: 13 additions & 7 deletions src/FMDatabase.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ - (BOOL)close {
do {
retry = NO;
rc = sqlite3_close(db);
if (SQLITE_BUSY == rc) {
if (SQLITE_BUSY == rc || SQLITE_LOCKED == rc) {
retry = YES;
usleep(20);
if (busyRetryTimeout && (numberOfRetries++ > busyRetryTimeout)) {
Expand Down Expand Up @@ -178,7 +178,7 @@ - (BOOL)goodConnection {
- (void)compainAboutInUse {
NSLog(@"The FMDatabase %@ is currently in use.", self);

#if !NS_BLOCK_ASSERTIONS
#ifndef NS_BLOCK_ASSERTIONS
if (crashOnErrors) {
NSAssert1(false, @"The FMDatabase %@ is currently in use.", self);
}
Expand Down Expand Up @@ -301,7 +301,7 @@ - (FMResultSet *)executeQuery:(NSString *)sql withArgumentsInArray:(NSArray*)arr
retry = NO;
rc = sqlite3_prepare_v2(db, [sql UTF8String], -1, &pStmt, 0);

if (SQLITE_BUSY == rc) {
if (SQLITE_BUSY == rc || SQLITE_LOCKED == rc) {
retry = YES;
usleep(20);

Expand All @@ -319,7 +319,7 @@ - (FMResultSet *)executeQuery:(NSString *)sql withArgumentsInArray:(NSArray*)arr
if (logsErrors) {
NSLog(@"DB Error: %d \"%@\"", [self lastErrorCode], [self lastErrorMessage]);
NSLog(@"DB Query: %@", sql);
#if !NS_BLOCK_ASSERTIONS
#ifndef NS_BLOCK_ASSERTIONS
if (crashOnErrors) {
NSAssert2(false, @"DB Error: %d \"%@\"", [self lastErrorCode], [self lastErrorMessage]);
}
Expand Down Expand Up @@ -432,7 +432,7 @@ - (BOOL)executeUpdate:(NSString*)sql error:(NSError**)outErr withArgumentsInArra
do {
retry = NO;
rc = sqlite3_prepare_v2(db, [sql UTF8String], -1, &pStmt, 0);
if (SQLITE_BUSY == rc) {
if (SQLITE_BUSY == rc || SQLITE_LOCKED == rc) {
retry = YES;
usleep(20);

Expand All @@ -450,7 +450,7 @@ - (BOOL)executeUpdate:(NSString*)sql error:(NSError**)outErr withArgumentsInArra
if (logsErrors) {
NSLog(@"DB Error: %d \"%@\"", [self lastErrorCode], [self lastErrorMessage]);
NSLog(@"DB Query: %@", sql);
#if !NS_BLOCK_ASSERTIONS
#ifndef NS_BLOCK_ASSERTIONS
if (crashOnErrors) {
NSAssert2(false, @"DB Error: %d \"%@\"", [self lastErrorCode], [self lastErrorMessage]);
}
Expand Down Expand Up @@ -509,10 +509,16 @@ - (BOOL)executeUpdate:(NSString*)sql error:(NSError**)outErr withArgumentsInArra
rc = sqlite3_step(pStmt);
retry = NO;

if (SQLITE_BUSY == rc) {
if (SQLITE_BUSY == rc || SQLITE_LOCKED == rc) {
// this will happen if the db is locked, like if we are doing an update or insert.
// in that case, retry the step... and maybe wait just 10 milliseconds.
retry = YES;
if (SQLITE_LOCKED == rc) {
rc = sqlite3_reset(pStmt);
if (rc != SQLITE_LOCKED) {
NSLog(@"Unexpected result from sqlite3_reset (%d) eu", rc);
}
}
usleep(20);

if (busyRetryTimeout && (numberOfRetries++ > busyRetryTimeout)) {
Expand Down
12 changes: 9 additions & 3 deletions src/FMResultSet.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ - (void)kvcMagic:(id)object {

- (NSDictionary *)resultDict {

NSInteger num_cols = sqlite3_data_count(statement.statement);
int num_cols = sqlite3_data_count(statement.statement);

if (num_cols > 0) {
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:num_cols];

NSUInteger i;
int i;
for (i = 0; i < num_cols; i++) {

const char *col_name = sqlite3_column_name(statement.statement, i);
Expand Down Expand Up @@ -138,10 +138,16 @@ - (BOOL)next {

rc = sqlite3_step(statement.statement);

if (SQLITE_BUSY == rc) {
if (SQLITE_BUSY == rc || SQLITE_LOCKED == rc) {
// this will happen if the db is locked, like if we are doing an update or insert.
// in that case, retry the step... and maybe wait just 10 milliseconds.
retry = YES;
if (SQLITE_LOCKED == rc) {
rc = sqlite3_reset(statement.statement);
if (rc != SQLITE_LOCKED) {
NSLog(@"Unexpected result from sqlite3_reset (%d) rs", rc);
}
}
usleep(20);

if ([parentDB busyRetryTimeout] && (numberOfRetries++ > [parentDB busyRetryTimeout])) {
Expand Down

0 comments on commit 2b4540f

Please sign in to comment.