0

I want to open a database named qw.db in the same folder as my .js file however, seems like it creates a new file qw rather than open my own db file here is my code

function onDeviceReady() {

        var shortName = 'qw';
        var version = '1.0';
        var displayName = 'qwq';
        var maxSize = 65535;
        if (!window.openDatabase) {
            alert('!! Databases are not supported in this Device !! \n\n We are sorry for the inconvenience and are currently working on a version that will work on your phone');
        }
        db = openDatabase(shortName, version, displayName, maxSize);
        createAllTables(db);


    }


    function createAllTables(db){
        db.transaction(function (transaction) {
            transaction.executeSql("CREATE TABLE IF NOT EXISTS model(ModelId INTEGER PRIMARY KEY AUTOINCREMENT,ModelNumber varchr(50))");
        });
        db.transaction(function(transaction){
            var rowCount = 'SELECT * FROM model';
            transaction.executeSql(rowCount,[],function(transaction,result){
                if(result.rows.length == 0){
                    var sqlString = 'INSERT INTO model (ModelId,ModelNumber) VALUES("200","Female")';
                    transaction.executeSql(sqlString);

                }
            });
        });
    }

here is a reference if needed Phonegap Offline Database

Community
  • 1
  • 1
Ting
  • 23
  • 7
  • See this link: http://stackoverflow.com/questions/27187826/websql-for-phonegap-application/27189861#27189861 – Ved Mar 25 '15 at 04:46
  • @Ved seems like it's specifically for android. i want my app works for android, ios and windows devices. – Ting Mar 25 '15 at 13:27
  • Ok .. see my another post :http://stackoverflow.com/questions/26629244/phonegap3-4-0-android-app-with-sqlite-its-working-fine-in-emulator-but-not-in?noredirect=1#comment41867305_26629244 – Ved Mar 25 '15 at 13:55

1 Answers1

0

for the existing database, you have to copy the db file into document directory or application directory.You can use this cordova-plugin-dbcopy which does copy SQLite Database from www to App Directory

Banik
  • 911
  • 6
  • 10
  • I am using Visual Studio cordova plugin, there is no www folder there – Ting Mar 25 '15 at 18:00
  • you can try this http://smile-sa.github.io/cordova-plugin-websqldatabase-initializer/ and let me knw... – Banik Mar 25 '15 at 19:04