Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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!!!

— asked August 24th 2011 by Joseandro Luiz
  • crash
  • database
  • invalid
  • sqlite
  • sqlite3
0 Comments

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

    — answered August 26th 2011 by Joseandro Luiz
    permalink
    1 Comment
    • Once you have found your solution, if an answer led you to the resolution it is helpful if you mark an answer as best/correct. That impacts the Q&A search rankings, which can help future users searching for answers.

      — commented August 26th 2011 by Doug Handy
  • 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 :)

    — answered August 25th 2011 by Joseandro Luiz
    permalink
    4 Comments
    • Look at this error 'file is encrypted or is not a
      database'. Please post your db table structure as a pastie. You can do this with any sqlite management tool, just export to sql script. The table contents aren't needed, so you can omit the inserts if you want.

      Also, please use 'Add Comment' to comment on previous questions, and only post answers when it is an actual answer to the question. Helps keep the Q&A clean. Thanks

      — commented August 25th 2011 by Adam Paxton
    • Hi Adam, the db consists of only one table, here is its structure:

      CREATE TABLE resultset_values (
          id int(10) NOT NULL, 
          resultsets_id int(5) NOT NULL,  
          points int(10) NOT NULL, 
          description text NOT NULL, 
          created datetime NOT NULL, 
          createdby varchar(45) NOT NULL,  
          updated datetime default NULL, 
          updatedby varchar(45) default NULL,
          PRIMARY KEY  (id) 
      );
      

      For me this is correct, I really don't know where the problem is :(

      Thanks for helping

      — commented August 26th 2011 by Joseandro Luiz
    • I just checked the file:

      /Users/me/Library/Application Support/iPhone Simulator/4.3/Applications/40ECEC5A-941F-4090-87ED-ECDC6A386EB4/Library/Application Support/database/love_calc.sql

      And the first line contains this comment:

      ` This file contains an SQLite 2.1 database

      — commented August 26th 2011 by Joseandro Luiz
    • Completing:

      ** This file contains an SQLite 2.1 database **

      I don't know why this file has this comment, this is a SQLite3 database.

      — commented August 26th 2011 by Joseandro Luiz
  • 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');
    

    Wiki guide and arguments reference.

    — answered August 24th 2011 by Adam Paxton
    permalink
    0 Comments
  • 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?

    — answered August 25th 2011 by Doug Handy
    permalink
    1 Comment
    • Hi Doug,

      I am sorry for not mentioning those specifications.

      I am using the latest version of Titanium Studio, running on MAC OS and I am targeting the latest iOS/iPhone platforms.

      The command to load the database is working (At least it doesn't show any error), but when I execute a query I get that.

      The database was created using Firefox SQLite Manager, so I can open it without any problems. Even setting the permissions to 777 the error persists.

      Any ideas?

      — commented August 26th 2011 by Joseandro Luiz
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.