Database install existing . . . nothing but errors. Please help!
Here is the error I keep getting:
[TRACE] E/KrollContext( 589): (kroll$1) [331,962] ECMA Error evaluating source: TypeError: Cannot call method "execute" of null
[TRACE] E/KrollContext( 589): org.mozilla.javascript.EcmaError: TypeError: Cannot call method "execute" of null
I'm using a pre-existing database that is 27.4MB.
System: Mac OS X, Version 10.6.4
Titanium: 1.4.1.1
App Type: Mobile
Emulator: Both (Iphone (SDK: 4.1)/Android (SDK: APIs 2.2) )
I've followed the documentation to the 't' and I can't seem to get a database to work.
My database is in SQLite3 format. Using Navicat Premium for export and transformation of mysql database to sqlite3.
Database is stored in the "Resources" folder.
I've tried with a smaller database, same issue.
Here is my code (Just the sample code with a db added to it):
inline code
// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');
// create tab group
var tabGroup = Titanium.UI.createTabGroup();
//
// create base UI tab and root window
//
var win1 = Titanium.UI.createWindow({
title:'Tab 1',
backgroundColor:'#fff'
});
var tab1 = Titanium.UI.createTab({
icon:'KS_nav_views.png',
title:'Tab 1',
window:win1
});
var db = Titanium.Database.install('testdb.sqlite','main');
var result = db.execute('SELECT * FROM test_tbl WHERE id=1');
if(result.isValidRow()) { Titanium.API.info('OK'); }
var label1 = Titanium.UI.createLabel({
color:'#999',
text:''+result+'',
font:{fontSize:20,fontFamily:'Helvetica Neue'},
textAlign:'center',
width:'auto'
});
win1.add(label1);
//
// create controls tab and root window
//
var win2 = Titanium.UI.createWindow({
title:'Tab 2',
backgroundColor:'#fff'
});
var tab2 = Titanium.UI.createTab({
icon:'KS_nav_ui.png',
title:'Tab 2',
window:win2
});
var label2 = Titanium.UI.createLabel({
color:'#999',
text:'I am Window 2',
font:{fontSize:20,fontFamily:'Helvetica Neue'},
textAlign:'center',
width:'auto'
});
win2.add(label2);
//
// add tabs
//
tabGroup.addTab(tab1);
tabGroup.addTab(tab2);
// open tab group
tabGroup.open();inline code
I'm obviously not doing something right. Please give me some guidance. I've been at this for days with no luck. Searched Google and all over the net. Can't seem to find my answer.
Thanks in advance.
2 Answers
-
Accepted Answer
And for android I was told you have to save a database over 3mb with an mp3 extension rather than sqlite or sql extensions.
I had originally made a database is some free program and it was exporting a bad database. But once I switched over to SQLite Manager extenstion of Firefox I had no problems. So that could be a problem for you.
-
var db = Titanium.Database.install('testdb.sqlite','main');
// check weather its giving correct path to database
Titanium.API.info(db);//use double quotes sometimes it restricts
var result = db.execute("SELECT * FROM test_tbl WHERE id=1");if still raising errors use
var db = Titanium.Database.openFile(dbpath);