Titanium Community Questions & Answer Archive

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

How can I test whether a database is open?

How can I tell whether a database "install" is successful? In my code, I have installed a pre-existing database, but when I try to access it, any ResultSet comes back null. I don't know whether this is because the resultset is actually empty, or if I have simply failed to connect to the database. Testing on Android, by the way.

Any clues?

var db = Titanium.Database.install('../data/favorites.db','favorites');
var sql = 'select id from favorites limit 1';
var evt = db.execute(sql);

if ( evt.isValidRow() )  { ... } // Fails here, as "evt" seems to be null
— asked August 30th 2010 by Mike Fahy
  • android
  • database
  • install
0 Comments

3 Answers

  • Accepted Answer

    Mike,

    You can use the adb tool that comes with the Android development kit to manually access the database within the emulator. See my question at:

    http://developer.appcelerator.com/question/55621/database-browser

    At a command prompt, enter:

    adb -s emulator-#### shell

    where #### is the port number associated with your emulator. Run the ddms.bat file to open the Dalvik Debug Monitor to get that. It's listed in the top-left pane.

    Then, at the adb prompt, enter:

    sqlite3 /data/data/com.example.yourapp/databases/favorites.db

    Then, issue SQL commands, such as a SELECT statement to view your database. Make sure to end the commands with semicolons. You can also use adb to browse the emulator's file system to confirm that the database has been created. See

    http://developer.android.com/guide/developing/tools/adb.html

    I hope this helps,
    Tim

    — answered August 31st 2010 by Tim Poulsen
    permalink
    1 Comment
    • Hi i did the same but i am not able to access the database its showing that the database is not found but i have checked from ddms.bat that the database is there. Can u tell the detailed and complete command. Thanx in advance.

      — commented August 22nd 2011 by Amit Mukherjee
  • The Database.Install statement returns the database object on success so I guess you can check for that.

    var db = Titanium.Database.instal(...);
    if (db) {
    }
    

    But since you can already track whether the database install has failed you can also move your logic in there.

    — answered August 31st 2010 by Richard Venneman
    permalink
    1 Comment
    • Thanks. The problem is that db seemed to be defined, no matter what random string I used as a filename in the install statement. Something seemed to be there, but it wasn't exactly what I was expecting.

      — commented September 1st 2010 by Mike Fahy
  • Hi Mike,
    Did you get your problem resolved?
    If you did, how?

    I have a similar issue.

    My query returns en_US instead of the actual data.

    I accessed the database on the emulator and all my records go replaced by a single record en_US.

    — answered July 29th 2011 by Horia Dobre
    permalink
    0 Comments
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.