Browse Source

Fixed a problem where executeUpdateWithFormat: + %@ as a placeholder and the value was nil would cause a bad value to be inserted. Thanks to rustybox on github for the fix.

ccgus 12 years ago
parent
commit
8c259dbe5d
5 changed files with 22 additions and 4 deletions
  1. 1 0
      CHANGES_AND_TODO_LIST.txt
  2. 1 0
      CONTRIBUTORS.txt
  3. 2 2
      fmdb.xcodeproj/project.pbxproj
  4. 3 1
      src/FMDatabase.m
  5. 15 1
      src/fmdb.m

+ 1 - 0
CHANGES_AND_TODO_LIST.txt

@@ -5,6 +5,7 @@ If you would like to contribute some code- awesome!  I just ask that you make it
 
 2013.05.24
     Merged in Chris Wright's date format additions to FMDatabase.
+    Fixed a problem where executeUpdateWithFormat: + %@ as a placeholder and the value was nil would cause a bad value to be inserted.  Thanks to rustybox on github for the fix.
 
 2013.04.17
     Added two new methods to FMDatabase for setting crypto keys, which take NSData objects.  Thanks to Phillip Kast for the patch! <https://github.com/ccgus/fmdb/pull/135>

+ 1 - 0
CONTRIBUTORS.txt

@@ -38,5 +38,6 @@ Daniel Dickison
 Peter Carr
 Jim Correia
 Phillip Kast
+Chris Wright
 
 Aaaaannnd, Gus Mueller (that's me!)

+ 2 - 2
fmdb.xcodeproj/project.pbxproj

@@ -280,7 +280,7 @@
 				CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES;
 				COPY_PHASE_STRIP = NO;
 				GCC_DYNAMIC_NO_PIC = NO;
-				GCC_OPTIMIZATION_LEVEL = s;
+				GCC_OPTIMIZATION_LEVEL = 0;
 				GCC_PRECOMPILE_PREFIX_HEADER = YES;
 				GCC_PREFIX_HEADER = fmdb_Prefix.pch;
 				GCC_WARN_SHADOW = YES;
@@ -293,7 +293,7 @@
 		1DEB927608733DD40010E9CD /* Release */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
-				ARCHS = "$(ARCHS_STANDARD_64_BIT)";
+				ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
 				CLANG_ENABLE_OBJC_ARC = YES;
 				CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES;
 				CLANG_WARN_OBJCPP_ARC_ABI = YES;

+ 3 - 1
src/FMDatabase.m

@@ -59,7 +59,6 @@ - (void)dealloc {
     FMDBRelease(_dateFormat);
     FMDBRelease(_databasePath);
     FMDBRelease(_openFunctions);
-    FMDBRelease(_dateFormatLock);
     
 #if ! __has_feature(objc_arc)
     [super dealloc];
@@ -550,6 +549,9 @@ - (void)extractSQL:(NSString *)sql argumentsList:(va_list)args intoString:(NSMut
             [cleanedSQL appendString:@"?"];
             [arguments addObject:arg];
         }
+        else if (add == (unichar)'@' && last == (unichar) '%') {
+            [cleanedSQL appendFormat:@"NULL"];
+        }
         else if (add != '\0') {
             [cleanedSQL appendFormat:@"%C", add];
         }

+ 15 - 1
src/fmdb.m

@@ -705,7 +705,21 @@ int main (int argc, const char * argv[]) {
         
     }
     
-    
+    {
+        FMDBQuickCheck([db executeUpdate:@"create table tatwhat (a text)"]);
+        
+        BOOL worked = [db executeUpdateWithFormat:@"insert into tatwhat values(%@)", nil];
+        
+        FMDBQuickCheck(worked);
+        
+        rs = [db executeQueryWithFormat:@"select * from tatwhat"];
+        FMDBQuickCheck((rs != nil));
+        FMDBQuickCheck(([rs next]));
+        FMDBQuickCheck([rs columnIndexIsNull:0]);
+        
+        FMDBQuickCheck((![rs next]));
+        
+    }
     
     
     {