diff --git a/SQLitePlugin.coffee.md b/SQLitePlugin.coffee.md index 622cb8b1..3cf6af98 100644 --- a/SQLitePlugin.coffee.md +++ b/SQLitePlugin.coffee.md @@ -607,6 +607,7 @@ 'default' : 'nosync' 'Documents' : 'docs' 'Library' : 'libs' + 'Shared' : 'shared' SQLiteFactory = ### diff --git a/src/ios/SQLitePlugin.m b/src/ios/SQLitePlugin.m index 638efdc8..83abb2ba 100755 --- a/src/ios/SQLitePlugin.m +++ b/src/ios/SQLitePlugin.m @@ -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; } @@ -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): @@ -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); diff --git a/www/SQLitePlugin.js b/www/SQLitePlugin.js index 497c3087..c59f0364 100644 --- a/www/SQLitePlugin.js +++ b/www/SQLitePlugin.js @@ -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) { @@ -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]); }