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: 67
Registered: ‎09-23-2010
My Device: Curve
My Carrier: T-Mobile
Accepted Solution

SQLite and HTML

Does anyone have any sample code to show how to use a SQL result set to construct HTML using DOM manipulation, as in, using innerHTML?

 

 

Thanks

Developer
Posts: 37
Registered: ‎01-18-2011
My Device: Huron 8800
My Carrier: IM3

Re: SQLite and HTML

[ Edited ]

Here's the example, i've used this one on my recent project

 

 

kemasD.getCustomerById = function(id) {
    var db = kemasD.webdb.db;
    
    db.transaction(function(tx){
        tx.executeSql("SELECT * FROM CUSTOMER WHERE ID = ? ORDER BY ID",  
            [id],
            function(tx, results) {
                var buffer = "";
                
                // results = SQLite result set
                if (results.rows && results.rows.length) {
                    for ( var i = 0; i < results.rows.length; i++) {
                        var current = results.rows.item(i);
                        
                        // This part where you want to process the result and wrap it with HTML tag
                        buffer += '<div>';
                        buffer += '<p>Customer name: ' + current.NAME + '</p>';
                        buffer += '<p>Customer address: ' + current.ADDRESS + '</p>';
                        buffer += '<p>Customer phone: ' + current.PHONE + '</p>';
                        buffer += '</div>';
                        
                        // Modify the DOM using jQuery (this is the easiest way, AFAIK)
                        // This syntax will insert the 'buffer' inside the <div class="customer-detail-box"> block
                        // in your page
                        $("div.customer-detail-box").prepend(buffer);
                        
                        buffer = "";
                    }
                }
            },
            onErrorHandler);
    });
};

Hope this example will help you out : )

Highlighted
Developer
Posts: 37
Registered: ‎01-18-2011
My Device: Huron 8800
My Carrier: IM3

Re: SQLite and HTML

Please note that using StringBuffer is recommended, instead of the aString += otherString