Issue Description
Just picked up the latest version of the encrypted DB module from the dashboard (1.1.4) and upgraded our app. However the module is unable to access the DB. We get the error :
(SQLite #26: file is encrypted or is not a database)
Expected behavior
The new version of the module should be able to open the older DB with same secret.
Steps to Replicate:
1. Grab sample code and throw it to app.js
2. Run the app with the DB module version 1.0.0 - Alert is shown - Fetched : 1
3. Change the version of module to 1.1.4 in tiapp.xml
4. Run the app again - Error is seen - The DB cannot be accessed
Test Case
var dbobj = require("appcelerator.encrypteddatabase");
var instance = null;
function init() {
dbobj.setPassword('secret');
Ti.API.info("Opening DB...");
instance = dbobj.open('test.db');
}
function setup() {
instance.execute("CREATE TABLE IF NOT EXISTS testtable(id integer PRIMARY KEY);");
instance.execute("INSERT OR IGNORE INTO testtable(id) VALUES (1);");
}
function fetch() {
var rowValue = null;
var rowHandle = instance.execute("SELECT * FROM testtable;");
if (rowHandle.isValidRow()) {
rowValue = rowHandle.fieldByName('id');
}
alert("Fetched Data: " + rowValue);
}
init();
setup();
fetch();
Logs
-- Start simulator log -------------------------------------------------------
[INFO] Application started
[INFO] AppcDevPushTest/1.0 (4.0.0.9239ff9)
[INFO] Opening DB...
[ERROR] A SQLite database error occurred on database '/Users/egomez/Library/Developer/CoreSimulator/Devices/7144027B-9501-4AD8-B17E-D6797EF0BCE6/data/Containers/Data/Application/0ADB425C-2E78-4247-A1AB-CE977A6450FF/Library/Private Documents/test.db.sql': Error Domain=com.plausiblelabs.EncPLDatabase Code=3 "An error occured parsing the provided SQL statement." UserInfo=0x78e644e0 {com.plausiblelabs.EncPLDatabase.error.vendor.code=26, com.plausiblelabs.EncPLDatabase.error.vendor.string=file is encrypted or is not a database, NSLocalizedDescription=An error occured parsing the provided SQL statement., com.plausiblelabs.EncPLDatabase.error.query.string=CREATE TABLE IF NOT EXISTS testtable(id integer PRIMARY KEY);} (SQLite #26: file is encrypted or is not a database) (query: 'CREATE TABLE IF NOT EXISTS testtable(id integer PRIMARY KEY);')
[ERROR] Script Error {
[ERROR] column = 21;
[ERROR] line = 8;
[ERROR] message = "invalid SQL statement";
[ERROR] nativeLocation = "-[AppceleratorEncrypteddatabaseDBProxy execute:] (AppceleratorEncrypteddatabaseDBProxy.m:128)";
[ERROR] nativeReason = "Error Domain=com.plausiblelabs.EncPLDatabase Code=3 \"An error occured parsing the provided SQL statement.\" UserInfo=0x78e644e0 {com.plausiblelabs.EncPLDatabase.error.vendor.code=26, com.plausiblelabs.EncPLDatabase.error.vendor.string=file is encrypted or is not a database, NSLocalizedDescription=An error occured parsing the provided SQL statement., com.plausiblelabs.EncPLDatabase.error.query.string=CREATE TABLE IF NOT EXISTS testtable(id integer PRIMARY KEY);}";
[ERROR] sourceURL = "file:///Users/egomez/Library/Developer/CoreSimulator/Devices/7144027B-9501-4AD8-B17E-D6797EF0BCE6/data/Containers/Bundle/Application/2B0B25BF-3F5D-45A0-9C77-A9D120F654F1/AppcDevPushTest.app/app.js";
[ERROR] stack = "[native code]\nsetup@file:///Users/egomez/Library/Developer/CoreSimulator/Devices/7144027B-9501-4AD8-B17E-D6797EF0BCE6/data/Containers/Bundle/Application/2B0B25BF-3F5D-45A0-9C77-A9D120F654F1/AppcDevPushTest.app/app.js:8:21\nglobal code@file:///Users/egomez/Library/Developer/CoreSimulator/Devices/7144027B-9501-4AD8-B17E-D6797EF0BCE6/data/Containers/Bundle/Application/2B0B25BF-3F5D-45A0-9C77-A9D120F654F1/AppcDevPushTest.app/app.js:27:6";
[ERROR] }
[~ewieber], That's odd. Mine works fine on 8.4. Also tried using titanium cli and appc cli. Ti SDK 4.1.0.GA and 4.1.1 titanium CLI 4.1.4 Appc CLI 4.2.0-51 [~egomez], yours worked too right? Nevertheless, I replaced the module zip file with a new built. Check it out again?
Latest zip works for me, same setup as [~cng]. Waiting for [~ewieber] to test before merging.
Tried again, using: MacOS 10.11 Studio 4.2.0.201508062204 Ti SDK 4.1.1.v20150816214206 Appc NPM 4.1.0-2 Appc CLI 4.1.3-2 Ti CLI 4.0.1 Alloy 1.6.2 Node v0.10.37 Java 1.7.0_45 preproduction Xcode 6.4 (6E35b) I now get the
Fetched Data: 1
alert with the 1.2.0 module, on iOS 8.4 sims and iOS 8.1 devices.yay. Thanks [~ewieber], merge it now [~hansknoechel].
[~cng] can you please work with [~pkclark] to publish this?
[~cng] just need the file and version info to drop into the manifest and get out on S3. Shoot me the file in an APPTS ticket AYC.
Closing ticket as fixed, if there are any problems, please file a new ticket.