Post Reply

[Q] PhoneGap Storage Problem

OP markvistavision

24th April 2014, 04:49 PM   |  #1  
OP Junior Member
Thanks Meter: 0
 
1 posts
Join Date:Joined: Apr 2014
Hi all,

I'm stuck with my first Android App and I really hope you can help me out. I've build a simple app with a SQL database, based on the documentation on docs.phonegap.

I've created this script:

HTML Code:
<script type="text/javascript" charset="utf-8">

    // Wait for device API libraries to load
    //
    document.addEventListener("deviceready", onDeviceReady, false);

    // Populate the database
    //
    function populateDB(tx) {
        tx.executeSql('DROP TABLE IF EXISTS DEMO');
        tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, date, naam, description, image)');
        tx.executeSql('INSERT INTO DEMO (id, date, naam, description, image) VALUES (1, "2014-04-23", "Jacques Villeneuve", "Canadees autocoureur","test.jpg")');
        tx.executeSql('INSERT INTO DEMO (id, date, naam, description, image) VALUES (2, "1954-09-04","Dennis Quaid", "Amerikaans acteur","test.JPEG")');
        tx.executeSql('INSERT INTO DEMO (id, date, naam, description, image) VALUES (3, "1933-09-04","Jean-Paul Belmondo", "Frans acteur","test.jpg")');
    }

    // Query the database
    //
    function queryDB(tx) {
   
// Datum van vandaag
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
today = yyyy+'-'+mm+'-'+dd;
alert (today);


        tx.executeSql('SELECT * FROM DEMO WHERE date = "2014-04-23" ORDER BY DATE ', [], querySuccess, errorCB);
    }

    // Query the success callback
    //
    function querySuccess(tx, results) {
        var len = results.rows.length;
        console.log("DEMO table: " + len + " rows found.");
        for (var i=0; i<len; i++){
                console.log("Row = " + i + " ID = " + results.rows.item(i).id + " Data =  " + results.rows.item(i).date + " Naam: " + results.rows.item(i).naam);
        }
    }

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

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

    // device APIs are available
    //
    function onDeviceReady() {
        var db = window.openDatabase("Database", "1.0", "Cordova Demo", 200000);
        db.transaction(populateDB, errorCB, successCB);
    }

    </script>
And I get the information in a div:

HTML Code:
    <script>
    function querySuccess(tx, results) {
        var len = results.rows.length;
        console.log("DEMO table: " + len + " rows found.");
       
        for (var i=0; i<len; i++){
       
       
    var div = document.getElementById("textDiv");
    div.innerHTML = div.innerHTML
    + "<div>"
    +" " + results.rows.item(i).date +" "
    +"<h1>" + results.rows.item(i).naam +"</h1>"
    +" " + results.rows.item(i).description +" "
    +"<img src=\"" + results.rows.item(i).image + "\">"
    + "</div>";
       


        }
    }
</script>
When I test it in Chrome Ripple, I see the information from the database perfectly! Only when I check it in Dreamweaver, I don't see the information. Also when I build the app with Dreamweaver Phonegap build and emulate it, it doesn't work either. This is probably a beginner question but I really need some help right now!!!

Thank so much for your help!

Kind regards,
Mark
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes