瀏覽代碼

Merge pull request #68 from EmbeddedSources/master

Fixed errors handling
August "Gus" Mueller 13 年之前
父節點
當前提交
78784e36c1
共有 1 個文件被更改,包括 18 次插入3 次删除
  1. 18 3
      src/FMDatabase.m

+ 18 - 3
src/FMDatabase.m

@@ -288,8 +288,20 @@ - (int)lastErrorCode {
     return sqlite3_errcode(_db);
 }
 
-- (NSError*)lastError {
-    return [NSError errorWithDomain:@"FMDatabase" code:sqlite3_errcode(_db) userInfo:[NSDictionary dictionaryWithObject:[self lastErrorMessage] forKey:NSLocalizedDescriptionKey]];
+
+-(NSError*)errorWithMessage:( NSString* )message_
+{
+    NSDictionary* errorMessage_ = [ NSDictionary dictionaryWithObject: message_ 
+                                                               forKey: NSLocalizedDescriptionKey];
+    
+    return [NSError errorWithDomain:@"FMDatabase" 
+                               code:sqlite3_errcode(_db)
+                           userInfo:errorMessage_];    
+}
+
+-(NSError*)lastError
+{
+   return [ self errorWithMessage: [ self lastErrorMessage ] ];
 }
 
 - (sqlite_int64)lastInsertRowId {
@@ -725,7 +737,10 @@ - (BOOL)executeUpdate:(NSString*)sql error:(NSError**)outErr withArgumentsInArra
                 sqlite3_finalize(pStmt);
                 
                 if (outErr) {
-                    *outErr = [NSError errorWithDomain:[NSString stringWithUTF8String:sqlite3_errmsg(_db)] code:rc userInfo:nil];
+                    
+                    
+                    
+                    *outErr = [ self errorWithMessage: [NSString stringWithUTF8String:sqlite3_errmsg(_db)] ];
                 }
                 
                 _isExecutingStatement = NO;