Using the latest titanium and BB NDK i have been getting to grips with mobile development accross iOS, Android and Blackberry. I have been going through the Ti bounty hunter labs after the video tutorials and have got stuck after working with local data. The issue is, i have implemented the database as shown below, this works fine in iOS and Andoroid but crashes the app on the Blackberry Simulator, I can't run on a device as I get a syntax error in the token...
database.js
var db = Ti.Database.open('BountyHunter'); db.execute('Create TABLE IF NOT EXISTS fugitives(id INTEGER PRIMARY KEY, name TEXT, captured INTEGER)'); db.close (); function List(captured){ var data = []; var db = Ti.Database.open('BountyHunter'); var bountyData = db.execute('Select * from fugitives where captured = ? ORDER BY NAME ASC',captured); while (bountyData.isValidRow()) { data.push({ID: bountyData.fieldByName('id'), Name: bountyData.fieldByName('name'), hasChild:true, color: '#fff', captured: (Number(bountyData.fieldByName('captured')) == 1), title:bountyData.fieldByName('name') }); bountyData.next(); } bountyData.close(); db.close(); return data; } exports.list = List; function Add(name,captured){ var db = Ti.Database.open('BountyHunter'); db.execute('INSERT INTO fugitives(name,captured) values (?,?)',name,captured); db.close(); Ti.App.fireEvent('fugitivesUpdated'); } exports.Add = Add; function Delete(ID){ var db = Ti.Database.open('BountyHunter'); db.execute('DELETE from fugitives where id = ?',ID); db.close(); Ti.App.fireEvent('fugitivesUpdated'); } exports.Delete = Delete; function Bust(ID){ var db = Ti.Database.open('BountyHunter'); db.execute('Update fugitives set captured = 1 where id = ?',ID); db.close(); Ti.App.fireEvent('fugitivesUpdated'); } exports.Bust = Bust;fugitives.js (loads on start up) called form tab group
function FugitiveWindow() { var self = Ti.UI.createWindow({ title:'fugitives', backgroundColor:'#6d0a0c' }); var BountyTable = require('ui/common/BountyTable'); var bountyTable = new BountyTable(0); self.enableDatabase(true); bountyTable.addEventListener('click', function(_e) { var DetailWindow = require('ui/common/DetailWindow'); self.containingTab.open(new DetailWindow(_e.rowData, self.containingTab)); }); self.add(bountyTable); if(Ti.Platform.osname =='iphone' || Ti.Platform.osname =='blackberry') { var button = Ti.UI.createButton({title:L('Add')}); button.addEventListener('click', function(e) { var addwindow = require('ui/common/AddFugitive'); self.containingTab.open(new addwindow()); }); self.setRightNavButton(button); } return self; }; module.exports = FugitiveWindow;bountytable.js
var BountytableView = function (captured){ // Create a TableView. var aTableView = Ti.UI.createTableView({ backgroundColor:'transparent' }); // Populate the TableView data. function populatedata(){ var database = require('lib/database'); var data = database.list(captured); aTableView.setData(data); } populatedata(); // Add to the parent view. Ti.App.addEventListener('fugitivesUpdated',function(e) { populatedata(); }); return aTableView; }; module.exports = BountytableView;in database.js if I comment out the database code as below it runs
function List(captured){ var data = []; // var db = Ti.Database.open('BountyHunter'); // var bountyData = db.execute('Select * from fugitives where captured = ? ORDER BY NAME ASC',captured); // while (bountyData.isValidRow()) // { // data.push({ID: bountyData.fieldByName('id'), // Name: bountyData.fieldByName('name'), // hasChild:true, // color: '#fff', // captured: (Number(bountyData.fieldByName('captured')) == 1), // title:bountyData.fieldByName('name') // }); // bountyData.next(); // } // bountyData.close(); // db.close(); return data; } exports.list = List;but if i just un comment this line
var db = Ti.Database.open('BountyHunter');
It crashes on BB again.
Any help appreciated