[TIMOB-15458] iOS: Can not install database file using temporary directory
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Low |
Status | Closed |
Resolution | Duplicate |
Resolution Date | 2020-01-15T16:54:53.000+0000 |
Affected Version/s | Release 3.1.1, Release 3.1.2, Release 3.1.3, Release 3.2.1 |
Fix Version/s | n/a |
Components | iOS |
Labels | supportTeam |
Reporter | Ashish Nigam |
Assignee | Unknown |
Created | 2013-10-11T11:42:58.000+0000 |
Updated | 2020-01-15T16:54:53.000+0000 |
Description
Using a temporary file to install existing database, does not copy the content rather creates a blank instance.
*sample code*
// This block will succeed when installing the database from the resourcesDirectory
var sourceDbFile = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, 'testDB');
var sourceDb = Ti.Database.install(sourceDbFile.nativePath, 'test');
var sourceRs = sourceDb.execute('SELECT count(*) AS c FROM test');
if (sourceRs.isValidRow()) {
Ti.API.info('Test record count: ' + sourceRs.fieldByName('c') + ' (should be 3)');
}
// This block will succeed when copying the database file to the applicationDataDirectory before installing
var otherDbFile = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'dbCopy');
otherDbFile.write(sourceDbFile.read());
var otherDb = Ti.Database.install(otherDbFile.nativePath, 'otherTest');
var otherRs = otherDb.execute('SELECT count(*) AS c FROM test');
if (otherRs.isValidRow()) {
Ti.API.info('Other record count: ' + otherRs.fieldByName('c') + ' (should be 3)');
}
// This block will fail if attempting to install the same database from a temp file/directory
var tempDbFile = Ti.Filesystem.createTempFile();
Ti.API.info(tempDbFile.nativePath);
tempDbFile.write(sourceDbFile.read()); // Copy
var tempDb = Ti.Database.install(tempDbFile.nativePath, 'tempTest');
var tempRs = tempDb.execute('SELECT count(*) AS c FROM test');
if (tempRs.isValidRow()) {
Ti.API.info('Temp record count: ' + tempRs.fieldByName('c') + ' (should be 3)');
}
Steps to reproduce:
1: Use the above code and paste it in Alloy.js file.
2: Execute the project and check the console.
3: Third execution to install DB using temporary file is failed, as no test table is found.
No comments