App crashes when loading data into Tableview help...

You must Login before you can answer or comment on any questions.

Hello my app keeps crashing when I try to load data from a local SQLite database into it.

I would appreciate any help or guidance

My database code is as follows

function sbaDatabase()
{
    //Create new Database
    this.db = Ti.Database.open('SBA');
    //Create columns of data
    this.db.execute('CREATE TABLE IF NOT EXISTS license(id INTEGER PRIMARY KEY, name TEXT, description TEXT, url TEXT, state TEXT, biz TEXT);');
    //close db conncetion
 
    this.db.close();
    Ti.API.info('creating database')    
}
sbaDatabase.prototype.add = function(data)
{
    Ti.API.info('add is being called');
    //open our database
    this.db = Ti.Database.open('SBA');
    //create our data stream
    for (var i = 0; i < data.length; i++)
    {
        this.db.execute('INSERT INTO license(name, description, url, state, biz) VALUES(?,?,?,?)', data[i].title, data[i].desc, data[i].sba_url, data[i].sba_state, data[i].sba_biz);
        Ti.API.info(data[i].name + ' ' + data[i].sba_url);
    }
    Ti.API.info('for loop finishes');
 
    //close our database
    this.db.close();
 
}
 
sbaDatabase.prototype.get = function()
{
    this.db = Ti.Database.open('SBA');
    var results = [];
    var result = this.db.execute('SELECT * FROM license LIMIT 10');
 
    while (result.isValidRow())
    {
        results.push({
            //add attributes to be called
            title: result.fieldByName('name'),
            desc: result.fieldByName('description'),
            r_url: result.fieldByName('url'),
            r_state: result.fieldByName('state'),
            r_biz: result.fieldByName('biz')
        });
        //Ti.API.info("Your push results " + result.fieldByName('name') + result.fieldByName('address'));
        //Capture all of the data fitting the description
        result.next();
    }
    //close the while loop after all data is loaded
    result.close();
    //close the connection to the database
    this.db.close();
 
    //Ti.API.info('while loop closes');
    //create global variable for the results
    return results;
}
module.exports = sbaDatabase;

and my App code to load data

function JobResource()
{
    var database = require('data/sbaDatabase');
    var createData = new database();
    var results = createData.get();
 
        var win = Ti.UI.createWindow
        ({
            backgroundColor:'transparent',
            barColor: '#4FAB43'
        });
 
        var tableview = Ti.UI.createTableView({data:results});
 
        function populateData()
        {
            var createResult = createData.get();
            tableview.setData(createResult); 
        }; //end function
 
        populateData();
 
        win.add(tableview);
        return win;
};
module.exports = JobResource;

Your Answer

This question has been locked and cannot accept new answers.