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

— asked September 22nd 2010 by C Lee
  • database
  • error
  • install
  • leopard
  • mac
  • mobile
  • navicat
  • null
  • runtime
  • snow
  • sqlite
  • sqlite3
  • type
0 Comments

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.

    — answered September 22nd 2010 by Kevin Ripka
    permalink
    2 Comments
    • I followed your advice and change the extension to mp3 and now it works! :) Thanks so much. I still don't understand why it would need to be an mp3 extension. That really makes no sense to give a database an mp3 extension, but hey if it works . . . thanks again.

      By the way Navicat Premium is awesome! Just my opinion. :-)

      — commented September 22nd 2010 by C Lee
    • This works surprisingly well. Thanks

      — commented July 26th 2011 by Xiao Jin
  • 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);

    — answered September 22nd 2010 by Varun Atluri
    permalink
    2 Comments
    • Ok I did what you said with the Titanium.API.info(db) and it gave me back this response:

      [574,710] ti.modules.titanium.database.TiDatabaseProxy@43ebd918

      I then tried the Titanium.Database.openFile(dbpath) and I got this error:

      TypeError: Cannot call property openFile in object ti.modules.titanium.database.DatabaseModule@43eb6090. It is not a function, it is "object".

      — commented September 22nd 2010 by C Lee
    • oh by the way, I did try the with double quotes also. No success.

      — commented September 22nd 2010 by C Lee
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.