Hi all, first let me start by saying any help is GREATLY appreciated! I have been struggling for a good while trying to get a demo database connection made in my test app... The app will load with no problems but the minute I try to query the database or write out the variable contents it kills the app and goes back to the home screen. When I run the following code the console will render the code with no problems or errors and the app will load and immediately exit...
var win = Titanium.UI.currentWindow; var db = Titanium.Database.install('../testdb.db','testdb'); var rows = db.execute('SELECT tip FROM TIPS WHERE rowid=1'); // close database rows.close(); win.add(rows); Ti.UI.currentWindow.addEventListener('click',function(e){Titanium.UI.currentWindow.close();});Also, the console debug code looks like the following note the lines towards the end with "session did end with error (null)", I read a few others having issues with a similar comment but all efforts have failed...
[INFO] Compiling JavaScript...one moment [INFO] No JavaScript errors detected. [INFO] One moment, building ... [INFO] Titanium SDK version: 1.4.1.1 [INFO] iPhone Device family: iphone [INFO] iPhone SDK version: 4.1 [DEBUG] executing command: /usr/bin/killall iPhone Simulator [DEBUG] No matching processes belonging to you were found [DEBUG] finding old log files [DEBUG] executing command: mdfind -onlyin /Users/chris/Library/Application Support/iPhone Simulator/4.1 -name a937089a-d853-49ac-be16-5be374402318.log [DEBUG] /Users/chris/Library/Application Support/iPhone Simulator/4.1/Applications/400617D5-861A-4651-9454-DDA345421E87/Documents/a937089a-d853-49ac-be16-5be374402318.log [DEBUG] removing old log file: /Users/chris/Library/Application Support/iPhone Simulator/4.1/Applications/400617D5-861A-4651-9454-DDA345421E87/Documents/a937089a-d853-49ac-be16-5be374402318.log [INFO] Launching application in Simulator [DEBUG] App Spec: <DTiPhoneSimulatorApplicationSpecifier 0x1003024d0> specified by path /Users/chris/Documents/Appcelerator/testdb/build/iphone/build/Debug-iphonesimulator/testdb.app [DEBUG] SDK Root: <DTiPhoneSimulatorSystemRoot 0x100301870> path=/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.1.sdk version=4.1 name=Simulator - iOS 4.1 [DEBUG] using device family iphone [INFO] Launched application in Simulator (1.49 seconds) [DEBUG] Session started [DEBUG] executing command: xcodebuild -version [DEBUG] Session did end with error (null) [INFO] Application has exited from Simulator
2 Answers
Give this a shot...
var data = (function() { // Maintain a database connection we can use var conn = Ti.Database.install('../testdb.db','testdb'); // Accepts a variable number of arguments. // The first argument should always be SQL. Every subsequent argument is a // param to be replaced within the sql. function getResults(){ var result = null; var results = []; var resultSet = Function.apply.call(conn.execute, conn, arguments); while (resultSet.isValidRow()) { result = {}; var fieldCount = resultSet.fieldCount(); for (var i=0; i<fieldCount; i++){ result[resultSet.fieldName(i)] = resultSet.field(i); } results.push(result); resultSet.next(); } resultSet.close(); return results; } var api = {}; // Get all items from a specific table. api.getTip = function(rowId) { return getResults('SELECT tip FROM tips WHERE rowid=?', rowId); }; return api; }()); var tip = data.getTip(1); // Print to console for debug Ti.API.info(tip);
Did you look at this:
http://assets.appcelerator.com.s3.amazonaws.com/docs/API_DatabaseClass.pdf
Your Answer
Think you can help? Login to answer this question!