Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide AppGroup directory as location for iOS #75

Open
wants to merge 10 commits into
base: cordova-sqlite-ext-2.x
Choose a base branch
from
1 change: 1 addition & 0 deletions SQLitePlugin.coffee.md
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,7 @@
'default' : 'nosync'
'Documents' : 'docs'
'Library' : 'libs'
'Shared' : 'shared'

SQLiteFactory =
###
Expand Down
18 changes: 17 additions & 1 deletion src/ios/SQLitePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,15 @@ -(id) getDBPath:(NSString *)dbFile at:(NSString *)atkey {
}

NSString *dbdir = [appDBPaths objectForKey:atkey];
NSString *dbPath = [dbdir stringByAppendingPathComponent: dbFile];
return [self getDBPath:dbFile inDirectory:dbdir];
}

-(id) getDBPath:(NSString *)dbFile inDirectory:(NSString *)directory {
if (dbFile == NULL || directory == NULL) {
return NULL;
}

NSString *dbPath = [directory stringByAppendingPathComponent: dbFile];
return dbPath;
}

Expand Down Expand Up @@ -120,6 +128,10 @@ -(void)openNow: (CDVInvokedUrlCommand*)command
// DLog(@"using db location: %@", dblocation);

NSString *dbname = [self getDBPath:dbfilename at:dblocation];
NSString *directoryURL = [options objectForKey:@"iosDirectoryURL"];
if (directoryURL != NULL) {
dbname = [self getDBPath:dbfilename inDirectory:directoryURL];
}

if (dbname == NULL) {
// XXX NOT EXPECTED (INTERNAL ERROR - XXX TODO SIGNAL ERROR STATUS):
Expand Down Expand Up @@ -275,6 +287,10 @@ -(void)deleteNow: (CDVInvokedUrlCommand*)command
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"You must specify database path"];
} else {
NSString *dbPath = [self getDBPath:dbFileName at:dblocation];
NSString *directoryURL = [options objectForKey:@"iosDirectoryURL"];
if (directoryURL != NULL) {
dbPath = [self getDBPath:dbFileName inDirectory:directoryURL];
}

if ([[NSFileManager defaultManager]fileExistsAtPath:dbPath]) {
DLog(@"delete full db path: %@", dbPath);
Expand Down
28 changes: 17 additions & 11 deletions www/SQLitePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,15 +569,17 @@
if (!openargs.name) {
throw newSQLError('Database name value is missing in openDatabase call');
}
if (!openargs.iosDatabaseLocation && !openargs.location && openargs.location !== 0) {
throw newSQLError('Database location or iosDatabaseLocation setting is now mandatory in openDatabase call.');
if (!openargs.iosDatabaseLocation && !openargs.location && openargs.location !== 0 && !openargs.iosDirectoryURL) {
throw newSQLError('Database location, iosDatabaseLocation or iosDirectoryURL setting is now mandatory in openDatabase call.');
}
if (!!openargs.location && !!openargs.iosDatabaseLocation) {
throw newSQLError('AMBIGUOUS: both location and iosDatabaseLocation settings are present in openDatabase call. Please use either setting, not both.');
}
dblocation = !!openargs.location && openargs.location === 'default' ? iosLocationMap['default'] : !!openargs.iosDatabaseLocation ? iosLocationMap[openargs.iosDatabaseLocation] : dblocations[openargs.location];
if (!dblocation) {
throw newSQLError('Valid iOS database location could not be determined in openDatabase call');
if (!openargs.iosDirectoryURL) {
dblocation = !!openargs.location && openargs.location === 'default' ? iosLocationMap['default'] : !!openargs.iosDatabaseLocation ? iosLocationMap[openargs.iosDatabaseLocation] : dblocations[openargs.location];
if (!dblocation) {
throw newSQLError('Valid iOS database location could not be determined in openDatabase call');
}
}
openargs.dblocation = dblocation;
if (!!openargs.createFromLocation && openargs.createFromLocation === 1) {
Expand Down Expand Up @@ -614,17 +616,21 @@
}
args.path = dbname;
}
if (!first.iosDatabaseLocation && !first.location && first.location !== 0) {
throw newSQLError('Database location or iosDatabaseLocation setting is now mandatory in deleteDatabase call.');
if (!first.iosDatabaseLocation && !first.location && first.location !== 0 && !first.iosDirectoryURL) {
throw newSQLError('Database location, iosDatabaseLocation and iosDirectoryURL setting is now mandatory in deleteDatabase call.');
}
if (!!first.location && !!first.iosDatabaseLocation) {
throw newSQLError('AMBIGUOUS: both location and iosDatabaseLocation settings are present in deleteDatabase call. Please use either setting value, not both.');
}
dblocation = !!first.location && first.location === 'default' ? iosLocationMap['default'] : !!first.iosDatabaseLocation ? iosLocationMap[first.iosDatabaseLocation] : dblocations[first.location];
if (!dblocation) {
throw newSQLError('Valid iOS database location could not be determined in deleteDatabase call');
if (!first.iosDirectoryURL) {
dblocation = !!first.location && first.location === 'default' ? iosLocationMap['default'] : !!first.iosDatabaseLocation ? iosLocationMap[first.iosDatabaseLocation] : dblocations[first.location];
if (!dblocation) {
throw newSQLError('Valid iOS database location could not be determined in deleteDatabase call');
}
args.dblocation = dblocation;
} else {
args.iosDirectoryURL = first.iosDirectoryURL;
}
args.dblocation = dblocation;
delete SQLitePlugin.prototype.openDBs[args.path];
return cordova.exec(success, error, "SQLitePlugin", "delete", [args]);
}
Expand Down