【问题标题】:How to open an existing database in phonegap如何在phonegap中打开现有数据库
【发布时间】:2015-03-24 20:00:56
【问题描述】:

我想在我的 .js 文件所在的文件夹中打开一个名为 qw.db 的数据库 但是,似乎它创建了一个新文件 qw 而不是打开我自己的 db 文件 这是我的代码

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);

                }
            });
        });
    }

如果需要,这里是一个参考Phonegap Offline Database

【问题讨论】:

标签: javascript database cordova phonegap-plugins


【解决方案1】:

对于现有数据库,您必须将 db 文件复制到文档目录或应用程序目录。您可以使用 cordova-plugin-dbcopy 将 SQLite 数据库从 www 复制到应用程序目录

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-06-07
  • 2011-10-02
  • 1970-01-01
  • 2019-04-07
  • 1970-01-01
  • 2014-11-19
  • 1970-01-01
相关资源
最近更新 更多