Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-4543] Ti.Database API filesystem discrepancies between iOS and Android

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionWon't Do
Resolution Date2020-01-09T19:16:14.000+0000
Affected Version/sRelease 1.7.1
Fix Version/sn/a
ComponentsAndroid
Labelsparity, rock_solid
ReporterPaul Dowsett
AssigneeIngo Muschenetz
Created2011-07-02T15:35:52.000+0000
Updated2020-01-09T19:16:14.000+0000

Description

When a database is created at the default locations using Ti.Database.open() or Ti.Database.install(), the resulting files are at different filesystem locations and with different filenames. The code below demonstrates how the user must access them directly using filesystem commands, on the respective platforms. Issues: * on Android, there is no way to access the default database directory (using applicationDataDirectory/../database is not allowed by design, for example) other than to specify the full filesystem path. On iOS, however, applicationSupportDirectory may be used. * Android does not automatically add a file extension whereas a .sql extension is added to the file name on iOS Just for incidental information, note that on Android: * Ti.Filesystem.applicationSupportDirectory is undefined. See TIMOB-3041 and TIMOB-4215 * Ti.Filesystem.applicationDataDirectory is located at /data/data/appID/app_appdata * var db = Ti.Database.open(dbName); database created at /data/data/appID/databases/${dbName} by default
var dbName = 'myDB';
var db = Ti.Database.open(dbName);
db.close();
var dbPath;
var dbFile;
var dbPlatform = Ti.Platform.osname;
Ti.API.info("dbName: " + dbName);

if(dbPlatform === 'android'){
  dbPath = 'file:///data/data/' + Ti.App.getID() + '/databases';
  Ti.API.info("dbPath: " + dbPath);
  dbFile = Ti.Filesystem.getFile(dbPath, dbName);
  Ti.API.info("dbFile.nativePath: " + dbFile.nativePath);
} else {
  dbPath = Ti.Filesystem.applicationSupportDirectory + '/database';
  Ti.API.info("dbPath: " + dbPath);
  dbFile = Ti.Filesystem.getFile(dbPath, dbName + '.sql');
  Ti.API.info("dbFile.nativePath: " + dbFile.nativePath);
}

if(dbFile.exists()){
  Ti.API.info('On the platform ' + dbPlatform + ', the database file was created at ' + dbFile.nativePath);
} else {
  Ti.API.info('On the platform ' + dbPlatform + ', the database file was NOT created at ' + dbFile.nativePath);
}
See Doug's comments at: [http://developer.appcelerator.com/question/121945/update-database-from-remote-source] [http://developer.appcelerator.com/question/96771/location-of-titanium-sql-database-on-android]

Comments

  1. Alan Hutton 2020-01-09

    It has been decided that this issue should be closed as “Won’t do.” This issue is out of date with our current supported SDK release (7.5.2.GA as of the date of closure), and out of date with mobile OS versions. Updating, or creating code may not reproduce the issue reported, or be a valid test case. If community members feel that the issue is still valid, please create a new ticket. Please reference this closed ticket number, include SDK used, comments, and code that demonstrates/reproduces the issue.

JSON Source