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
Developer
Posts: 777
Registered: ‎07-21-2012
My Device: 9810
My Carrier: 0

Store data in data base using HTML 5.

Hi

 

i want to creat database to store list .i used local storage , but it not working fine . iwant to use ceate data base function , then crate table , in table insert list , then retrive list from data base .

 

 

can you please suggest.

 

Developer
Developer
Posts: 607
Registered: ‎04-29-2011
My Device: PlayBook 16GB, BB10 LE Z10 (red)
My Carrier: none

Re: Store data in data base using HTML 5.

All you need to do is mainly in your post, create DB, insert table(s) data and and retrieve it from DB.

 

For getting started have a closer look to the BlackBerry HTML5 openDatabase API and tutorials around the web like this one.


"Like" if you liked the post.
"Accept as Solution" if the post solves your question.
Developer
Posts: 214
Registered: ‎01-07-2011
My Device: Bold 9900
My Carrier: Rogers

Re: Store data in data base using HTML 5.

Easiest way is to use the HTML5 Database built in (uses WebSQL):

https://developer.blackberry.com/html5/apis/database.html

--
Rory (@roryboy)
Click "Accept as Solution" if post solved your original issue. Give like/thumbs up if you feel post is helpful
Developer
Posts: 777
Registered: ‎07-21-2012
My Device: 9810
My Carrier: 0

Re: Store data in data base using HTML 5.

<script type="text/javascript" src="script/soapclient.js"></script>
	<script type="text/javascript" src="script/cordova-1.9.0.js"></script>
	<script type="text/javascript">
   		
		//Wait for Cordova to load
	   document.addEventListener("deviceready", onDeviceReady, false);

	    //Cordova is loaded and it is now safe to make calls Cordova methods
	    
	    function onDeviceReady() 
	    {
		   
	        checkConnection();
	    }
	
	    function checkConnection() 
	    {
	        var networkState = navigator.network.connection.type;
	
	        var states = {};
	        states[Connection.UNKNOWN]  = 'Unknown connection';
	        states[Connection.ETHERNET] = 'Ethernet connection';
	        states[Connection.WIFI]     = 'WiFi connection';
	        states[Connection.CELL_2G]  = 'Cell 2G connection';
	        states[Connection.CELL_3G]  = 'Cell 3G connection';
	        states[Connection.CELL_4G]  = 'Cell 4G connection';
	        states[Connection.NONE]     = 'No network connection';
	       	//alert('Connection type: ' + states[networkState]);
			if(states[networkState]=="No network connection")
			{
	  			alert("No Connection Available ");
				navigator.app.exitApp();
			}	
		}
		var stationList = new Array;	
	     
   		function GetStationCodes()
  		{    
	  		document.getElementById('loadingImg').style.visibility = "visible"; 
	  		
		     var pl = new SOAPClientParameters();
		     var parameter1 = "";
		     var parameter2 = "";
		     pl.add("parameter1", parameter1);
		     pl.add("parameter2", parameter2);
		     SOAPClient.invoke(WSDLURL, "stationSearch", pl, true, GetStationCodes_callBack);
		}
  		function GetStationCodes_callBack(r)
 		{ 
	 		document.getElementById('loadingImg').style.visibility = "hidden";
	 		document.getElementById('submitBtn1').removeAttribute('disabled');
			document.getElementById('submitBtn2').removeAttribute('disabled');
			document.getElementById('getStationDesc').removeAttribute('disabled');
			for (var i = 0; i < r.length-1; i++)
          	{
	          	stationList[i] = r[i].stationCode + " - " + r[i].stationName;// i download complete
          	}
          	var db = window.openDatabase("Database", "1.0", "Cordova Demo", 200000);// create data base*********
            db.transaction(populateDB, errorCB, successCB);*****call function
		}	
		function SetAction(flag)
		{
			if(flag==1)
			{
				 document.frmIndex.action="arrival.html";
			}
			else
			{
				 document.frmIndex.action="departure.html";
			}
		}
		
		
		function populateDB(tx) {
         tx.executeSql('DROP TABLE IF EXISTS DEMO');
         tx.executeSql('CREATE TABLE IF NOT EXISTS STATIONLIST (id unique, data)');
       for (var i = 0; i <stationList.length-1 ; i++){
         tx.executeSql('INSERT INTO DEMO (id, data) VALUES (i,stationList[i] )');// is it correct..?
         
       }
    }

    // Transaction error callback
    //
    function errorCB(tx, err) {
        alert("Error processing SQL: "+err);
    }

    // Transaction success callback
    //
    function successCB() {
        alert("success!");
    }

	</script>
</head>
<body onload="GetStationCodes()"> ********Here i download list******

 Hi 

 

i am begineer can you tell me is it correct way to create database.

 

Thanks

Developer
Posts: 777
Registered: ‎07-21-2012
My Device: 9810
My Carrier: 0

Re: Store data in data base using HTML 5.

 tx.executeSql('DROP TABLE IF EXISTS STATIONLIST');
Developer
Posts: 777
Registered: ‎07-21-2012
My Device: 9810
My Carrier: 0

Re: Store data in data base using HTML 5.

'INSERT INTO STATIONLIST (id, data) VALUES (i,stationList[i] )'

Developer
Developer
Posts: 607
Registered: ‎04-29-2011
My Device: PlayBook 16GB, BB10 LE Z10 (red)
My Carrier: none

Re: Store data in data base using HTML 5.

If you aren't familiar with HTML5 database try to create a minimal sample project to work with examples provided in the tutorial I linked to, or search for other tutorials to set up your use case in the sample project to make sure it is working for you.

 

IMHO, since nobody exactly knows what data you want to store and also not in which relationship the data needs to be in your database it is really hard to answer.


"Like" if you liked the post.
"Accept as Solution" if the post solves your question.