diff --git a/src/ios/SQLitePlugin.m b/src/ios/SQLitePlugin.m index b9cc9622d..dbea000b3 100755 --- a/src/ios/SQLitePlugin.m +++ b/src/ios/SQLitePlugin.m @@ -19,6 +19,10 @@ # define DLog(...) #endif +#if !__has_feature(objc_arc) +# error "Missing objc_arc feature" +#endif + @implementation SQLitePlugin @synthesize openDBs; @@ -31,10 +35,6 @@ -(void)pluginInitialize { openDBs = [PSPDFThreadSafeMutableDictionary dictionaryWithCapacity:0]; appDBPaths = [NSMutableDictionary dictionaryWithCapacity:0]; -#if !__has_feature(objc_arc) - [openDBs retain]; - [appDBPaths retain]; -#endif NSString *docs = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex: 0]; DLog(@"Detected docs path: %@", docs); @@ -268,7 +268,7 @@ -(void) executeSqlBatchNow: (CDVInvokedUrlCommand*)command CDVPluginResult* pluginResult; - @synchronized(self) { + { for (NSMutableDictionary *dict in executes) { CDVPluginResult *result = [self executeSqlWithDict:dict andArgs:dbargs]; if ([result.status intValue] == CDVCommandStatus_ERROR) { @@ -293,23 +293,14 @@ -(void) executeSqlBatchNow: (CDVInvokedUrlCommand*)command [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; } --(void) backgroundExecuteSql: (CDVInvokedUrlCommand*)command -{ - [self.commandDelegate runInBackground:^{ - [self executeSql:command]; - }]; -} - -(void) executeSql: (CDVInvokedUrlCommand*)command { NSMutableDictionary *options = [command.arguments objectAtIndex:0]; NSMutableDictionary *dbargs = [options objectForKey:@"dbargs"]; NSMutableDictionary *ex = [options objectForKey:@"ex"]; - CDVPluginResult* pluginResult; - @synchronized (self) { - pluginResult = [self executeSqlWithDict: ex andArgs: dbargs]; - } + CDVPluginResult * pluginResult = [self executeSqlWithDict: ex andArgs: dbargs]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; } @@ -317,20 +308,20 @@ -(CDVPluginResult*) executeSqlWithDict: (NSMutableDictionary*)options andArgs: ( { NSString *dbFileName = [dbargs objectForKey:@"dbname"]; if (dbFileName == NULL) { - return [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"You must specify database path"]; + return [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"INTERNAL ERROR: You must specify database path"]; } NSMutableArray *params = [options objectForKey:@"params"]; // optional NSValue *dbPointer = [openDBs objectForKey:dbFileName]; if (dbPointer == NULL) { - return [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"No such database, you must open it first"]; + return [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"INTERNAL ERROR: No such database, you must open it first"]; } sqlite3 *db = [dbPointer pointerValue]; NSString *sql = [options objectForKey:@"sql"]; if (sql == NULL) { - return [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"You must specify a sql query to execute"]; + return [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"INTERNAL ERROR: You must specify a sql query to execute"]; } const char *sql_stmt = [sql UTF8String]; @@ -393,9 +384,6 @@ -(CDVPluginResult*) executeSqlWithDict: (NSMutableDictionary*)options andArgs: ( columnValue = [[NSString alloc] initWithBytes:(char *)sqlite3_column_text(statement, i) length:sqlite3_column_bytes(statement, i) encoding:NSUTF8StringEncoding]; -#if !__has_feature(objc_arc) - [columnValue autorelease]; -#endif break; case SQLITE_NULL: // just in case (should not happen): @@ -497,12 +485,6 @@ -(void)dealloc db = [pointer pointerValue]; sqlite3_close (db); } - -#if !__has_feature(objc_arc) - [openDBs release]; - [appDBPaths release]; - [super dealloc]; -#endif } +(NSDictionary *)captureSQLiteErrorFromDb:(struct sqlite3 *)db