Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Highlighted
Contributor
Posts: 21
Registered: ‎04-23-2011
My Device: 9700
My Carrier: xl

webwork smartphone database

[ Edited ]

i create application with database.. in simulator running smootly when simulate change sd card but not work in device.... i cannot update.. data...

I ready search but don't know what the problem...

here my code:

	var db = null;

	function startdb(){
	    alert("loaddb0");  
		// create/open database
		db = window.openDatabase("databaseinquotes", '1.0', 'inquotes', 5*1024*1024);
		db.changeVersion('', '1.0');    
                    if (db){
                        alert("loaddb1"); 
                        db.transaction(function (tx) {
						// If table not exsist create it
                        tx.executeSql("CREATE TABLE IF NOT EXISTS appconfig (key int unique, ipsocket text, port text)");
                        alert("Table is created");
                        // Get values from table
                        tx.executeSql("SELECT ipsocket,port FROM appconfig WHERE key = ?", [1], function (ax, results) {
                            alert("results.rows.length ::"+results.rows.length);
							//Check record. If zero application will not work
                           if(results.rows.length == 0){
                            // If zero create defauld config
                               tx.executeSql("INSERT INTO appconfig (key, ipsocket, port) VALUES (?, ?, ?)", [1,$.configuration.serverSocketIp, $.configuration.serverSocketPort]);
                               alert("Server and conection empty. you need configure it in configuration"); 
                           }
                            
                        });
						});
                         alert("database start");
						}
	}
	function updateConfig(ip,port) {
             db.transaction(function(bx){
					//put values into database
					//bx.executeSql("UPDATE appconfig SET ipsocket = ? WHERE key = ? ", [ip, 1]);
					bx.executeSql("UPDATE appconfig SET ipsocket = ?, port = ? WHERE key = ? ", [ip, port, 1],onExecuteSuccess,onExecuteFail);
					  
					
					});
    }
function onExecuteFail(){
    alert("Fail update configuration"); 
}	
function onExecuteSuccess(){
    alert("database uptodate, please restart application");
}
	function loadConfigDB() {
	     db.transaction(function (tx) {
            tx.executeSql("CREATE TABLE IF NOT EXISTS appconfig (key int unique, ipsocket text, port text)");
            tx.executeSql("SELECT ipsocket,port FROM appconfig WHERE key = 1", [], function (ax, results) {
               
                   if (results.rows.length == 1) {
                       $.configuration.serverSocketIp = results.rows.item(0).ipsocket;
                       $.configuration.serverSocketPort = results.rows.item(0).port;
                       alert("ip:"+results.rows.item(0).ipsocket+"-- port:"+results.rows.item(0).port);
                   }else {
                       alert("Please insert configuration");    
                   }
            });
		});	
	}
	//init for config.html pages
    function initConfigPages(){
        loadConfigDB();
        alert('loadConfigDB');
        document.getElementById("serverip").value = $.configuration.serverSocketIp;
        document.getElementById("port").value = $.configuration.serverSocketPort;
    }