Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-8695] Android: Database Install fails to install from applicationDataDirectory

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionFixed
Resolution Date2020-01-10T18:50:18.000+0000
Affected Version/sRelease 2.0.0
Fix Version/sRelease 8.1.0
ComponentsAndroid
Labelsapi, database, install
ReporterKetan Majmudar
AssigneeJoshua Quick
Created2012-04-11T17:44:36.000+0000
Updated2020-01-10T18:50:21.000+0000

Description

The documentation doesn't state that its impossible to run Ti.Database.install(Ti.Filesystem.applicationDataDirectory, 'mydb'); However not matter what you do, it is impossible, further more its a little frustrating as many a database strategy will involve remote files and source files that can be used for later purposes. I can see no reason why the command has to default to the Resources directory. Could there be some clarification on what you can and can't do. And if currently, you can't install from the appDataDirectory, can i suggest it goes high up on the roadmap. this will cost days of developers time a) figuring out what works and doesn't work, then having to write a very long process in evaluating and inserting data, when its not necessary. At the moment you can write to the DB storage space on iOS, it mainly affects android, but I think the SDK should allow for this behaviour.

Comments

  1. Ketan Majmudar 2013-11-26

    I will throw up a test case for this shortly
  2. Alan Hutton 2020-01-10

    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. 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.
  3. Joshua Quick 2020-01-10

    You can use the following code to test this...
       function dbInsert(dbConnection, key, value) {
       	var sqlStatement = "INSERT OR REPLACE INTO properties(key, value) VALUES (?, ?);";
       	dbConnection.execute(sqlStatement, key, value);
       }
       
       var dbSourceFile = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, "Source.sqlite");
       Ti.API.info("@@@ dbSourceFile: " + dbSourceFile.nativePath);
       var dbConnection = Ti.Database.open(dbSourceFile);
       dbConnection.execute("CREATE TABLE IF NOT EXISTS properties(key TEXT PRIMARY KEY, value TEXT);");
       dbInsert(dbConnection, "Message1", "This is message 1.");
       dbConnection.close();
       
       var dbConnection = Ti.Database.install(dbSourceFile.nativePath, "MyInstalledDatabase");
       dbInsert(dbConnection, "Message2", "This is message 2.");
       var resultSet = dbConnection.execute("SELECT key, value FROM properties");
       Ti.API.info("@@@ Database Table 'properties' row count: " + (resultSet ? resultSet.rowCount : "<null>"));
       if (resultSet) {
       	for (; resultSet.isValidRow(); resultSet.next()) {
       		Ti.API.info("- Key: '" + resultSet.field(0) + "', Value: '" + resultSet.field(1) + "'");
       	}
       }
       dbConnection.close();
       
  4. Joshua Quick 2020-01-10

    This issue was resolved on Android in Titanium 8.1.0. It was solved by: [TIMOB-26878] *Note:* While this now works on Android, it does not work on iOS. See: [TIMOB-15458]

JSON Source