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
Developer
Posts: 166
Registered: ‎02-15-2012
My Device: Playbook 16GB
My Carrier: Bags are useful

Rendering Data from Database

      var finance = {};
      finance.master = {};
      finance.master.db = null;
      
      finance.master.open = function() {
        var dbSize = 5 * 1024 * 1024; // 5MB
        finance.master.db = openDatabase("Accounts", "1.0", "List of Accounts", dbSize);
      }
      
      finance.master.createTable = function() {
        var db = finance.master.db;
        db.transaction(function(tx) {
          tx.executeSql("CREATE TABLE IF NOT EXISTS accounts(ID INTEGER PRIMARY KEY ASC, name TEXT, balance INTEGER)", []);
        });
      }
      
      finance.master.addinfo = function(name,balance)  {
        var db = finance.master.db;
        db.transaction(function(tx){
          tx.executeSql("INSERT INTO accounts(name,balance) VALUES (?,?)",
              [name,balance],
              finance.master.onSuccess,
              finance.master.onError);
         });
      }  
      
      finance.master.onError = function(tx, e) {
        alert("There has been an error: " + e.message);
      }
      
      finance.master.onSuccess = function(tx, r) {
        // re-render the data.
        finance.master.getAllAccounts(loadAccountItems);
      }
      
      
      finance.master.getAllAccounts = function(renderFunc) {
        var db = finance.master.db;
        db.transaction(function(tx) {
          tx.executeSql("SELECT * FROM accounts", [], renderFunc,
              finance.master.onError);
        });
      }
      
      finance.master.deleteAccount = function(id) {
        var db = finance.master.db;
        db.transaction(function(tx){
          tx.executeSql("DELETE FROM accounts WHERE ID=?", [id],
              finance.master.onSuccess,
              finance.master.onError);
          });
      }
      
      function loadAccountItems(tx, rs) {
        var rowOutput = "";
        var AccountList = document.getElementById("AccountList");
        for (var i=0; i < rs.rows.length; i++) {
          rowOutput += renderList(rs.rows.item(i));
        }
      
        AccountList.innerHTML = rowOutput;
      }
      
      function renderList(row) {
        return "<div data-bb-type= 'item' data-bb-title='Title'> "+ row.name + "</div>";
      }
      
	  
      function init() {
        finance.master.open();
        finance.master.createTable();
        finance.master.getAllAccounts(loadAccountItems);
      }
      
      function addinfo() {
        var balance = document.getElementById("balance");
		var name = document.getElementById("name");
        finance.master.addinfo(name.value,balance.value);
        balance.value = "";
        name.value = "";
      }

 

Hi guys,

 

I have a problem in which I cannot see the data stored in the database, most likely because of rendering issues.

 

The code above is in a file called addAccount.js

 

My form is on a page called addAccount.html

 

I want the data to be shown on a page called accounts.html:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<script src="js/addAccount.js"></script>
<div data-bb-type="screen">
<div data-bb-type="title" data-bb-caption="Accounts"></div>   
<body onLoad="init();">
<div id="AccountList" data-bb-type="image-list" data-bb-style="removebuttons"></div> 
</body>
 </div>

 Any help is greatly appreciated.

If any post helps you please click the Like Button below the post(s) that helped you.
2. Please resolve your thread by marking the post "Solution?" which solved it for you!

New Developer
Posts: 105
Registered: ‎06-11-2013
My Device: DEVELOPER
My Carrier: vodafone

Re: Rendering Data from Database

How reliable is xml Data storage and how is the retrieval process?

******Blackberry Developer*******---Built for the Kill-----
#######Developer of @Sudoku#########