Skip to content
This repository

Added a base class for all FMDatabase errors. #110

Open
wants to merge 1 commit into from

2 participants

Oleksandr Dodatko August "Gus" Mueller
Oleksandr Dodatko

Added an NSError child as a base class for all FMDatabase errors (both existing and upcoming ones). It should be easier for your users to handle them.

Fixed error domain for SQL validation function.

August "Gus" Mueller
Owner

Not sure why this is needed?

Oleksandr Dodatko

I use error polymorphism in my applications to avoid long if statements (by implementing UI related categories within the client code).

P.S. Sorry for long delay in response and missing your reply among other notifications.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jan 10, 2013
Oleksandr Dodatko Added a base class for all FMDatabase errors. Fixed error domain for …
…SQL validation function
797a965
This page is out of date. Refresh to see the latest.
13  FMError.h
... ...
@@ -0,0 +1,13 @@
  1
+//
  2
+//  FMError.h
  3
+//  fmdb
  4
+//
  5
+//  Created by Oleksandr Dodatko on 1/10/13.
  6
+//
  7
+//
  8
+
  9
+#import <Foundation/Foundation.h>
  10
+
  11
+@interface FMError : NSError
  12
+
  13
+@end
13  FMError.m
... ...
@@ -0,0 +1,13 @@
  1
+//
  2
+//  FMError.m
  3
+//  fmdb
  4
+//
  5
+//  Created by Oleksandr Dodatko on 1/10/13.
  6
+//
  7
+//
  8
+
  9
+#import "FMError.h"
  10
+
  11
+@implementation FMError
  12
+
  13
+@end
37  fmdb.xcodeproj/project.pbxproj
@@ -7,6 +7,8 @@
7 7
 	objects = {
8 8
 
9 9
 /* Begin PBXBuildFile section */
  10
+		7E98261F169F252F00013023 /* FMError.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E98261D169F252F00013023 /* FMError.h */; };
  11
+		7E982620169F252F00013023 /* FMError.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E98261E169F252F00013023 /* FMError.m */; };
10 12
 		8DD76F9C0486AA7600D96B5E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 08FB779EFE84155DC02AAC07 /* Foundation.framework */; };
11 13
 		8DD76F9F0486AA7600D96B5E /* fmdb.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = C6859EA3029092ED04C91782 /* fmdb.1 */; };
12 14
 		CC47A00F148581E9002CCDAB /* FMDatabaseQueue.h in Headers */ = {isa = PBXBuildFile; fileRef = CC47A00D148581E9002CCDAB /* FMDatabaseQueue.h */; };
@@ -51,6 +53,8 @@
51 53
 /* Begin PBXFileReference section */
52 54
 		08FB779EFE84155DC02AAC07 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
53 55
 		32A70AAB03705E1F00C91783 /* fmdb_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fmdb_Prefix.pch; sourceTree = "<group>"; };
  56
+		7E98261D169F252F00013023 /* FMError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FMError.h; sourceTree = "<group>"; };
  57
+		7E98261E169F252F00013023 /* FMError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FMError.m; sourceTree = "<group>"; };
54 58
 		8DD76FA10486AA7600D96B5E /* fmdb */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = fmdb; sourceTree = BUILT_PRODUCTS_DIR; };
55 59
 		C6859EA3029092ED04C91782 /* fmdb.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = fmdb.1; sourceTree = "<group>"; };
56 60
 		CC47A00D148581E9002CCDAB /* FMDatabaseQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FMDatabaseQueue.h; path = src/FMDatabaseQueue.h; sourceTree = "<group>"; };
@@ -128,6 +132,8 @@
128 132
 				CC9E4EB813B31188005F9210 /* FMDatabasePool.m */,
129 133
 				32A70AAB03705E1F00C91783 /* fmdb_Prefix.pch */,
130 134
 				CCC24EBE0A13E34D00A6D3E3 /* fmdb.m */,
  135
+				7E98261D169F252F00013023 /* FMError.h */,
  136
+				7E98261E169F252F00013023 /* FMError.m */,
131 137
 			);
132 138
 			name = Source;
133 139
 			sourceTree = "<group>";
@@ -171,15 +177,16 @@
171 177
 				EE42910912B42FD00088BD94 /* FMResultSet.h in Headers */,
172 178
 				CC9E4EBA13B31188005F9210 /* FMDatabasePool.h in Headers */,
173 179
 				CC47A00F148581E9002CCDAB /* FMDatabaseQueue.h in Headers */,
  180
+				7E98261F169F252F00013023 /* FMError.h in Headers */,
174 181
 			);
175 182
 			runOnlyForDeploymentPostprocessing = 0;
176 183
 		};
177 184
 /* End PBXHeadersBuildPhase section */
178 185
 
179 186
 /* Begin PBXNativeTarget section */
180  
-		8DD76F960486AA7600D96B5E /* fmdb */ = {
  187
+		8DD76F960486AA7600D96B5E /* fmdb-demo */ = {
181 188
 			isa = PBXNativeTarget;
182  
-			buildConfigurationList = 1DEB927408733DD40010E9CD /* Build configuration list for PBXNativeTarget "fmdb" */;
  189
+			buildConfigurationList = 1DEB927408733DD40010E9CD /* Build configuration list for PBXNativeTarget "fmdb-demo" */;
183 190
 			buildPhases = (
184 191
 				8DD76F990486AA7600D96B5E /* Sources */,
185 192
 				8DD76F9B0486AA7600D96B5E /* Frameworks */,
@@ -189,7 +196,7 @@
189 196
 			);
190 197
 			dependencies = (
191 198
 			);
192  
-			name = fmdb;
  199
+			name = "fmdb-demo";
193 200
 			productInstallPath = "$(HOME)/bin";
194 201
 			productName = fmdb;
195 202
 			productReference = 8DD76FA10486AA7600D96B5E /* fmdb */;
@@ -234,7 +241,7 @@
234 241
 			projectDirPath = "";
235 242
 			projectRoot = "";
236 243
 			targets = (
237  
-				8DD76F960486AA7600D96B5E /* fmdb */,
  244
+				8DD76F960486AA7600D96B5E /* fmdb-demo */,
238 245
 				EE4290EE12B42F870088BD94 /* FMDB */,
239 246
 			);
240 247
 		};
@@ -263,6 +270,7 @@
263 270
 				EE42910A12B42FD20088BD94 /* FMResultSet.m in Sources */,
264 271
 				CC9E4EBB13B31188005F9210 /* FMDatabasePool.m in Sources */,
265 272
 				CC47A011148581E9002CCDAB /* FMDatabaseQueue.m in Sources */,
  273
+				7E982620169F252F00013023 /* FMError.m in Sources */,
266 274
 			);
267 275
 			runOnlyForDeploymentPostprocessing = 0;
268 276
 		};
@@ -282,9 +290,7 @@
282 290
 				GCC_PREFIX_HEADER = fmdb_Prefix.pch;
283 291
 				INSTALL_PATH = "$(HOME)/bin";
284 292
 				LIBRARY_SEARCH_PATHS = "$(LIBRARY_SEARCH_PATHS)";
285  
-				MACOSX_DEPLOYMENT_TARGET = 10.7;
286 293
 				PRODUCT_NAME = fmdb;
287  
-				SDKROOT = macosx;
288 294
 			};
289 295
 			name = Debug;
290 296
 		};
@@ -300,9 +306,7 @@
300 306
 				GCC_PREFIX_HEADER = fmdb_Prefix.pch;
301 307
 				INSTALL_PATH = "$(HOME)/bin";
302 308
 				LIBRARY_SEARCH_PATHS = "$(LIBRARY_SEARCH_PATHS)";
303  
-				MACOSX_DEPLOYMENT_TARGET = 10.7;
304 309
 				PRODUCT_NAME = fmdb;
305  
-				SDKROOT = macosx;
306 310
 			};
307 311
 			name = Release;
308 312
 		};
@@ -310,26 +314,22 @@
310 314
 			isa = XCBuildConfiguration;
311 315
 			buildSettings = {
312 316
 				ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
313  
-				GCC_C_LANGUAGE_STANDARD = c99;
314  
-				GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
  317
+				CLANG_CXX_LANGUAGE_STANDARD = "c++0x";
315 318
 				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
316 319
 				GCC_WARN_ABOUT_RETURN_TYPE = YES;
317 320
 				GCC_WARN_MISSING_PARENTHESES = YES;
318 321
 				GCC_WARN_PEDANTIC = YES;
319 322
 				GCC_WARN_SIGN_COMPARE = YES;
320 323
 				GCC_WARN_UNUSED_VARIABLE = YES;
321  
-				MACOSX_DEPLOYMENT_TARGET = 10.7;
322 324
 			};
323 325
 			name = Debug;
324 326
 		};
325 327
 		1DEB927A08733DD40010E9CD /* Release */ = {
326 328
 			isa = XCBuildConfiguration;
327 329
 			buildSettings = {
328  
-				GCC_C_LANGUAGE_STANDARD = c99;
329  
-				GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
  330
+				CLANG_CXX_LANGUAGE_STANDARD = "c++0x";
330 331
 				GCC_WARN_ABOUT_RETURN_TYPE = YES;
331 332
 				GCC_WARN_UNUSED_VARIABLE = YES;
332  
-				MACOSX_DEPLOYMENT_TARGET = 10.7;
333 333
 			};
334 334
 			name = Release;
335 335
 		};
@@ -337,10 +337,14 @@
337 337
 			isa = XCBuildConfiguration;
338 338
 			buildSettings = {
339 339
 				ALWAYS_SEARCH_USER_PATHS = NO;
  340
+				ARCHS = "$(ARCHS_STANDARD_32_BIT)";
  341
+				CLANG_ENABLE_OBJC_ARC = YES;
340 342
 				COPY_PHASE_STRIP = NO;
341 343
 				GCC_DYNAMIC_NO_PIC = NO;
342 344
 				GCC_OPTIMIZATION_LEVEL = 0;
  345
+				IPHONEOS_DEPLOYMENT_TARGET = 5.0;
343 346
 				PRODUCT_NAME = FMDB;
  347
+				SDKROOT = iphoneos;
344 348
 			};
345 349
 			name = Debug;
346 350
 		};
@@ -348,9 +352,12 @@
348 352
 			isa = XCBuildConfiguration;
349 353
 			buildSettings = {
350 354
 				ALWAYS_SEARCH_USER_PATHS = NO;
  355
+				CLANG_ENABLE_OBJC_ARC = YES;
351 356
 				COPY_PHASE_STRIP = YES;
352 357
 				DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
  358
+				IPHONEOS_DEPLOYMENT_TARGET = 5.0;
353 359
 				PRODUCT_NAME = FMDB;
  360
+				SDKROOT = iphoneos;
354 361
 				ZERO_LINK = NO;
355 362
 			};
356 363
 			name = Release;
@@ -358,7 +365,7 @@
358 365
 /* End XCBuildConfiguration section */
359 366
 
360 367
 /* Begin XCConfigurationList section */
361  
-		1DEB927408733DD40010E9CD /* Build configuration list for PBXNativeTarget "fmdb" */ = {
  368
+		1DEB927408733DD40010E9CD /* Build configuration list for PBXNativeTarget "fmdb-demo" */ = {
362 369
 			isa = XCConfigurationList;
363 370
 			buildConfigurations = (
364 371
 				1DEB927508733DD40010E9CD /* Debug */,
8  src/FMDatabase.m
@@ -2,6 +2,8 @@
2 2
 #import "unistd.h"
3 3
 #import <objc/runtime.h>
4 4
 
  5
+#import "FMError.h"
  6
+
5 7
 @interface FMDatabase ()
6 8
 
7 9
 - (FMResultSet *)executeQuery:(NSString *)sql withArgumentsInArray:(NSArray*)arrayArgs orDictionary:(NSDictionary *)dictionaryArgs orVAList:(va_list)args;
@@ -294,9 +296,9 @@ -(NSError*)errorWithMessage:( NSString* )message_
294 296
     NSDictionary* errorMessage_ = [ NSDictionary dictionaryWithObject: message_ 
295 297
                                                                forKey: NSLocalizedDescriptionKey];
296 298
     
297  
-    return [NSError errorWithDomain:@"FMDatabase" 
298  
-                               code:sqlite3_errcode(_db)
299  
-                           userInfo:errorMessage_];    
  299
+    return [ FMError errorWithDomain:@"FMDatabase"
  300
+                                code:sqlite3_errcode(_db)
  301
+                            userInfo:errorMessage_];
300 302
 }
301 303
 
302 304
 -(NSError*)lastError
3  src/FMDatabaseAdditions.m
@@ -8,6 +8,7 @@
8 8
 
9 9
 #import "FMDatabase.h"
10 10
 #import "FMDatabaseAdditions.h"
  11
+#import "FMError.h"
11 12
 
12 13
 @interface FMDatabase (PrivateStuff)
13 14
 - (FMResultSet *)executeQuery:(NSString *)sql withArgumentsInArray:(NSArray*)arrayArgs orDictionary:(NSDictionary *)dictionaryArgs orVAList:(va_list)args;
@@ -139,7 +140,7 @@ - (BOOL)validateSQL:(NSString*)sql error:(NSError**)error {
139 140
         else if (rc != SQLITE_OK) {
140 141
             validationSucceeded = NO;
141 142
             if (error) {
142  
-                *error = [NSError errorWithDomain:NSCocoaErrorDomain 
  143
+                *error = [FMError errorWithDomain: @"FMDatabase"
143 144
                                              code:[self lastErrorCode]
144 145
                                          userInfo:[NSDictionary dictionaryWithObject:[self lastErrorMessage] 
145 146
                                                                               forKey:NSLocalizedDescriptionKey]];
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.