App crashes when SQLite database is instantiated
Hi guys,
I am facing a problem when I try to use SQLite in my app.
With this code I try to open the file (placed inside Resources and another copy under the root app's directory - I don't know where this database is loaded from).
var db = Titanium.Database.install('../love_calc.db', 'love_calc');
var myResultSet = db.execute('SELECT * FROM resultset_values');
The SQL statement is correct, but I get this error and the simulator crashes inexplicably.
Terminating app due to uncaught exception 'org.lovecalculator.TiDatabaseProxy',
reason: 'invalid SQL statement. Error Domain=com.plausiblelabs.pldatabase Code=3
"An error occured parsing the provided SQL statement." UserInfo=0x6e36e30
{com.plausiblelabs.pldatabase.error.vendor.code=26, NSLocalizedDescription=An
error occured parsing the provided SQL statement.,
com.plausiblelabs.pldatabase.error.query.string=SELECT * FROM resultset_values,
com.plausiblelabs.pldatabase.error.vendor.string=file is encrypted or is not a
database} in -[TiDatabaseProxy execute:] (TiDatabaseProxy.m:136)'
Do you have any ideas why I am getting this error? I am using the module ti.admob to monetize my app. Could it be the reason why I got this error?
Thanks!!!
4 Answers
-
Problem Solved !
To generate the database I was using Firefox SQLite Manager and this addon was creating a Sqlite2 instead Sqlite3.I had to create it by the command line (sqlite3 command).
Now the App works flawless.
Thanks everybody -
I already changed the path many times :(
But I still get this error, it looks like the app says the query is malformed.
Any ideas ?Thanks guys :)
-
The db path is relative to the main application Resources folder at build time, so if it is under Resources directory, then try changing it to:
var db = Titanium.Database.install('love_calc.db', 'love_calc'); -
You don't mention what OS you are targeting, or for that matter even if it is a desktop or mobile project. Nor do you mention the SDK.
If using a mobile project at 1.7.0 or higher, be sure you understand the changes to the filesystem as discussed in this blog.
However, the error messages seem to suggest it is finding a file but is unable to open it as a database compatible with SQLite.
What are you using to create the file love_calc.db? Can you open and examine it successfully in a tool like Firefox SQLite Manager?