Permalink
Browse files

Merge upstream

  • Loading branch information...
2 parents 6809d43 + 06bccb3 commit 2b4540f8aa6f9affe2706fda736cecb990168955 @p2 p2 committed Feb 3, 2011
Showing with 37 additions and 15 deletions.
  1. +7 −0 CHANGES_AND_TODO_LIST.txt
  2. +3 −1 CONTRIBUTORS.txt
  3. +5 −4 fmdb.xcodeproj/project.pbxproj
  4. +13 −7 src/FMDatabase.m
  5. +9 −3 src/FMResultSet.m
@@ -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 gus@flyingmeat.com.
+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!
View
@@ -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!)
@@ -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;
@@ -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;
};
View
@@ -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)) {
@@ -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);
}
@@ -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);
@@ -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]);
}
@@ -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);
@@ -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]);
}
@@ -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)) {
View
@@ -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);
@@ -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])) {

0 comments on commit 2b4540f

Please sign in to comment.