Skip to content Skip to sidebar Skip to footer

How To Read The Data From Sqlite3 In Javascript In Phonegap Application For Iphone

I am working on an application in phonegap for iphone, where i have a database in sqlite3 which contains values of latitudes and longitudes and corresponding there area names. I ha

Solution 1:

@PiTheNumber try that code

var arr = newArray(); 
        // Wait for PhoneGap to load//document.addEventListener("deviceready", onDeviceReady, false);

        // Populate the database //functionpopulateDB(tx) {
            tx.executeSql('DROP TABLE IF EXISTS DEMO');
            tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)');
            tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")');
            tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")');
            tx.executeSql('INSERT INTO DEMO (id, data) VALUES (3, "First row")');
            tx.executeSql('INSERT INTO DEMO (id, data) VALUES (4, "Second row")');
            tx.executeSql('INSERT INTO DEMO (id, data) VALUES (5, "First row")');
            tx.executeSql('INSERT INTO DEMO (id, data) VALUES (6, "Second row")');
            tx.executeSql('INSERT INTO DEMO (id, data) VALUES (7, "First row")');
            tx.executeSql('INSERT INTO DEMO (id, data) VALUES (8, "Second row")');
            tx.executeSql('INSERT INTO DEMO (id, data) VALUES (9, "First row")');
            tx.executeSql('INSERT INTO DEMO (id, data) VALUES (10, "Second row")');
            tx.executeSql('INSERT INTO DEMO (id, data) VALUES (11, "First row")');
            tx.executeSql('INSERT INTO DEMO (id, data) VALUES (12, "Second row")');
            tx.executeSql('INSERT INTO DEMO (id, data) VALUES (13, "First row")');
            tx.executeSql('INSERT INTO DEMO (id, data) VALUES (14, "Second row")');
            tx.executeSql('INSERT INTO DEMO (id, data) VALUES (15, "First row")');
            tx.executeSql('INSERT INTO DEMO (id, data) VALUES (16, "Second row")');
        }



        // Query the database//functionqueryDB(tx) {
            tx.executeSql('SELECT * FROM DEMO', [], querySuccess, errorCB);
        }

        // Query the success callback//functionquerySuccess(tx, results) {
            var len = results.rows.length;
            console.log("DEMO table: " + len + " rows found.");
            for (var i=0; i<len; i++){
            $('#home').append('<li><a href="#artists">'+results.rows.item(i).data+'</a></li>');



            }
            console.log("aaa"+arr+"aaa"); 

        }

        // Transaction error callback//functionerrorCB(err) {
            console.log("Error processing SQL: "+err.code);
        }

        // Transaction success callback//functionsuccessCB() {
            var db = window.openDatabase("Database", "1.0", "PhoneGap Demo", 200000);
            db.transaction(queryDB, errorCB);
        }

        // PhoneGap is ready//functiononDeviceReady() {
            var db = window.openDatabase("Database", "1.0", "PhoneGap Demo", 200000);
            db.transaction(populateDB, errorCB, successCB);
        }

Solution 2:

@shasha replace the refrence of phonegap.js" file with phonegap-1.4.1.js

(if u are using 1.4.1 version of phone gap) it will work.

@InderKumarRathore dude i just figured it out this was my table view or ur can say list view

<body><divclass="toolbar"><h1id="pageTitle"></h1><aid="backButton"class="button"href="#"></a><aclass="button"href="#searchForm">Search</a></div><ulid="home"title="Music"selected="true"><li><ahref="#artists">Artists</a></li><li><ahref="#settings">Settings</a></li><li><ahref="stats.gtpl">Stats</a></li><li><ahref="#themes">Theme Switcher</a></li><li><ahref="#iui-cache-panel">HTML5 WebApp Cache</a></li><li><ahref="http://code.google.com/p/iui/"target="_self">About</a></li><li>Nothing</li></ul></body>

and in Java script use this code

$('#home').append('<li>'+data+'</li>');

data will the the variable u want to use

hope it worked it does for me... !!!!

Cheers

Post a Comment for "How To Read The Data From Sqlite3 In Javascript In Phonegap Application For Iphone"