Skip to content
This repository was archived by the owner on Dec 22, 2020. It is now read-only.

Query order execution fix #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions src/ios/SQLitePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ @implementation SQLitePlugin

@synthesize openDBs;
@synthesize appDBPaths;
@synthesize commandCache;
@synthesize processingCache;

-(void)pluginInitialize
{
Expand All @@ -30,6 +32,8 @@ -(void)pluginInitialize
{
openDBs = [NSMutableDictionary dictionaryWithCapacity:0];
appDBPaths = [NSMutableDictionary dictionaryWithCapacity:0];
commandCache = [NSMutableArray arrayWithCapacity:0];
processingCache = NO;
#if !__has_feature(objc_arc)
[openDBs retain];
[appDBPaths retain];
Expand Down Expand Up @@ -242,13 +246,33 @@ -(void)deleteNow: (CDVInvokedUrlCommand*)command
}


-(void) backgroundExecuteSqlBatch: (CDVInvokedUrlCommand*)command
-(void) processCache
{
processingCache = YES;
[self.commandDelegate runInBackground:^{
[self executeSqlBatchNow: command];
@synchronized (self) {
if (commandCache.count) {
CDVInvokedUrlCommand* cachedCmd = [commandCache objectAtIndex:0];
[commandCache removeObjectAtIndex:0];
[self executeSqlBatchNow: cachedCmd];
}
else {
processingCache = NO;
}
}
}];
}


-(void) backgroundExecuteSqlBatch: (CDVInvokedUrlCommand*)command
{
@synchronized (self) {
[commandCache addObject:command];
if (!processingCache)
[self processCache];
}
}

-(void) executeSqlBatchNow: (CDVInvokedUrlCommand*)command
{
NSMutableDictionary *options = [command.arguments objectAtIndex:0];
Expand Down Expand Up @@ -283,6 +307,7 @@ -(void) executeSqlBatchNow: (CDVInvokedUrlCommand*)command
}

[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
[self processCache];
}

-(void) backgroundExecuteSql: (CDVInvokedUrlCommand*)command
Expand Down