Titanium Community Questions & Answer Archive

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

Database Install Making Me Sad :(

Hi all, first let me start by saying any help is GREATLY appreciated! I have been struggling for a good while trying to get a demo database connection made in my test app… The app will load with no problems but the minute I try to query the database or write out the variable contents it kills the app and goes back to the home screen. When I run the following code the console will render the code with no problems or errors and the app will load and immediately exit…

var win = Titanium.UI.currentWindow;

var db = Titanium.Database.install('../testdb.db','testdb');

var rows = db.execute('SELECT tip FROM TIPS WHERE rowid=1');

// close database



Also, the console debug code looks like the following note the lines towards the end with "session did end with error (null)", I read a few others having issues with a similar comment but all efforts have failed…

[INFO] Compiling JavaScript...one moment
[INFO] No JavaScript errors detected.
[INFO] One moment, building ...
[INFO] Titanium SDK version:
[INFO] iPhone Device family: iphone
[INFO] iPhone SDK version: 4.1
[DEBUG] executing command: /usr/bin/killall iPhone Simulator
[DEBUG] No matching processes belonging to you were found
[DEBUG] finding old log files
[DEBUG] executing command: mdfind -onlyin /Users/chris/Library/Application Support/iPhone Simulator/4.1 -name a937089a-d853-49ac-be16-5be374402318.log
[DEBUG] /Users/chris/Library/Application Support/iPhone Simulator/4.1/Applications/400617D5-861A-4651-9454-DDA345421E87/Documents/a937089a-d853-49ac-be16-5be374402318.log
[DEBUG] removing old log file: /Users/chris/Library/Application Support/iPhone Simulator/4.1/Applications/400617D5-861A-4651-9454-DDA345421E87/Documents/a937089a-d853-49ac-be16-5be374402318.log
[INFO] Launching application in Simulator
[DEBUG] App Spec: <DTiPhoneSimulatorApplicationSpecifier 0x1003024d0> specified by path /Users/chris/Documents/Appcelerator/testdb/build/iphone/build/Debug-iphonesimulator/testdb.app
[DEBUG] SDK Root: <DTiPhoneSimulatorSystemRoot 0x100301870> path=/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.1.sdk version=4.1 name=Simulator - iOS 4.1
[DEBUG] using device family iphone
[INFO] Launched application in Simulator (1.49 seconds)
[DEBUG] Session started
[DEBUG] executing command: xcodebuild -version
[DEBUG] Session did end with error (null)
[INFO] Application has exited from Simulator
— asked October 20th 2010 by Chris Givens
  • 4
  • crash
  • database
  • error
  • immediately
  • install
  • ios
  • iphone
  • issue
  • mobile
  • null
  • problem

2 Answers

  • Give this a shot…

    var data = (function() {
        // Maintain a database connection we can use
        var conn = Ti.Database.install('../testdb.db','testdb');
        // Accepts a variable number of arguments.
        // The first argument should always be SQL. Every subsequent argument is a
        // param to be replaced within the sql.
        function getResults(){
            var result = null;
            var results = [];
            var resultSet = Function.apply.call(conn.execute, conn, arguments);
            while (resultSet.isValidRow()) {
                result = {};
                var fieldCount = resultSet.fieldCount();
                for (var i=0; i<fieldCount; i++){
                    result[resultSet.fieldName(i)] = resultSet.field(i);
            return results;
        var api = {};
        // Get all items from a specific table.
        api.getTip = function(rowId) {
            return getResults('SELECT tip FROM tips WHERE rowid=?', rowId);
        return api;
    var tip = data.getTip(1);
    // Print to console for debug
    — answered October 20th 2010 by Bart Lewis
    • Bart, thanks for the response I really appreciate the help with this. I can confirm that your code did allow me to connect to the database without it immediately closing and returning the simulator home-screen. It accessed the database and logged the appropriate value from the table in the console window. What I don't really get is why it was crashing out in the first place. Was I not properly connecting to the database or doing an improper call to access the data through the SQL statement. I am just trying to understand for future reference what the real cause of my issue was here… My ultimate goal with the database is to store pointer file locations for some sound files in the resource directory and have the program read that database and access those file pointers to populate a scrollable table… So I will need some way to iterate through the database values in that table and present them… This was my first stab at trying to get a solid understanding of how to work with the database in Titanium… Again any help you can provide is absolutely appreciated…and I really thank you for providing the code above it has helped me to at least verify that everything can work and that the real issue was apparently within something I was doing as I suspected… :)

      — commented October 21st 2010 by Chris Givens
    • Sweet.

      — commented May 25th 2011 by Stan Silver
  • Did you look at this:


    — answered October 20th 2010 by Jeffrey Messick
    1 Comment
    • Thanks for the reply, I did go through that document. I tried to focus on page 18 and 19 as they were the closest to what I was attempting to accomplish but still the console fails with the same results. It should be noted that I am using a pre-existing database that is made up of the testdb.db database that is used in the kitchen sink example. So I am not trying to create a DB on the fly and insert data into it I am just simply trying to install the existing database and read data from it into a variable and utilize that stored value…

      — commented October 20th 2010 by Chris Givens
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.