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