pelagos pelagos -4 years ago 138
SQL Question

Titanium mobile - Uncaught Error: no such table

I am having a terrible time trying to figure out why I keep getting this error. I have searched this and other forums and no answer seems to be able to help so I will ask here.

I am trying to create a basic photo catalogue app for Android using Titanium. The catalogue info is strore in an sqlite database.

I can create the database OK - I can access some info from it in one window. When I then go to another window and try to get further info from the table it gives me the error:

Uncaught error: no such table: photos:, while compiling SELECT..........

See code below:

This is the first window that opens from app.js

The table shows up fine here - NO errors

// create var for the currentWindow
var currentWin = Ti.UI.currentWindow;

// set the data from the database to the array
//function setData() {

// create table view
var tableview = Ti.UI.createTableView({

//var db ='catalogue');
var db = Ti.Database.install('catalogue.sqlite','photos');

var rows = db.execute('SELECT * FROM photos GROUP BY title');

// create the array
var dataArray = [];

while(rows.isValidRow()) {

var title = rows.fieldByName('title');
var id = rows.fieldByName('id');

dataArray.push({title:title, id:id, url:'catalogue_detail.js'});;


// add the tableView to the current window

tableview.addEventListener('click', function(e){

if (e.rowData.url)
var win = Ti.UI.createWindow({,


// call the setData function to attach the database results to the array

I then open catalogue_detail.js from the above and I get the error


var win = Titanium.UI.currentWindow;

var id =

var tableview = Titanium.UI.createTableView({

var db ='catalogue.sqlite');//I have chanegd this to 'photos' and I get the same error

var sql = db.execute('SELECT title, location, photographer FROM photos where id="' + id + '"');

var title = sql.fieldByName('title');

var location = sql.fieldByName('location');
var photographer = sql.fieldByName('photographer');

// create the array
var dataArray = [];

while(sql.isValidRow()) {

var title = sql.fieldByName('title');
var location = sql.fieldByName('location');
var photographer = sql.fieldByName('photographer');

dataArray.push({title:title, location:location, photographer:photographer});;



So the table in my database called 'photos' open in one window then I get the error trying to open the same database?

I have uninstalled the app, recreated the database, renamed tables etc but still the same error...

I am sure it is a simple thing I am missing but I am very confused!

Thanks for any assistance.


Answer Source

Try absolute path:'catalogue.sqlite'); and Ti.Database.install('/catalogue.sqlite');.

Also remember about closing connection to database when you retrieve all data from query:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download