How to implement database in PhoneGap App ?

前端 未结 3 1290
野性不改
野性不改 2021-02-02 18:04

I\'m new to this, and I am trying to build an app to be deployed with PhoneGap, to both Android and iOS. I am wondering how to link to a database which will store timetable dat

相关标签:
3条回答
  • 2021-02-02 18:22

    Careful because maxSize of database in Android Gingerbread 2.3.3 emulator must be 65535.

    With this OS 200000 maxSize it could give an error.

    200000 maxSize works for newer OS.

    0 讨论(0)
  • 2021-02-02 18:36

    PhoneGap has a storage api that you should use instead of using HTML5 local storage directly. On both Android and iOS, it will use the native implementation.

    see http://docs.phonegap.com/en/2.7.0/cordova_storage_storage.md.html#Storage

    0 讨论(0)
  • 2021-02-02 18:42

    Please refer below link for simple operation with Sq-lite.and also you can get basic idea of Storage API from above link.

    Simple operation with Sq-lite : http://www.raymondcamden.com/index.cfm/2011/10/20/Example-of-PhoneGaps-Database-Support

    Edited on 8th MAY 2013 and fixed 19th January 2016

    Basic operation with DB :

    <script type="text/javascript" charset="utf-8" src="cordova-x.x.x.js"></script>
    <script type="text/javascript" charset="utf-8">
    // Wait for Cordova to load
    document.addEventListener("deviceready", onDeviceReady, false);
    
    // Cordova is ready
    function onDeviceReady() {
        var db = window.openDatabase("Database", "1.0", "Cordova Demo", 200000);
        db.transaction(populateDB, errorCB, successCB);
    }
    
    // Populate the database 
    function populateDB(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")');
    }
    
    // Transaction error callback
    function errorCB(err) {
        alert("Error processing SQL: " + err);
    }
    
    // Transaction success callback
    function successCB() {
        alert("success!");
    }
    </script>
    

    refrence

    You can check Data base in File explorer

    In ADT bundle Window>>show view>> File Explorer

    0 讨论(0)
提交回复
热议问题