无法访问预先填充的数据库

时间:2017-04-25 04:27:00

标签: typescript sqlite ionic3

根据我对互联网的研究,我读过在Ionic 2应用程序中允许预先填充的SQLite数据库;您只需将其添加到/ www目录即可。

我多次尝试过这种情况并且没有取得任何成功。当我从其中一个预先填充的表中选择时,我得到一个错误,表示该表不存在。

我的package.json设置:

"dependencies": {
"@angular/common": "4.0.0",
"@angular/compiler": "4.0.0",
"@angular/compiler-cli": "4.0.0",
"@angular/core": "4.0.0",
"@angular/forms": "4.0.0",
"@angular/http": "4.0.0",
"@angular/platform-browser": "4.0.0",
"@angular/platform-browser-dynamic": "4.0.0",
"@ionic-native/core": "3.4.2",
"@ionic-native/splash-screen": "3.4.2",
"@ionic-native/sqlite": "^3.4.4",
"@ionic-native/status-bar": "3.4.2",
"@ionic/storage": "2.0.1",
"@types/cordova": "0.0.34",
"ionic-angular": "3.0.1",
"ionicons": "3.0.0",
"rxjs": "5.1.1",
"sw-toolbox": "3.4.0",
"zone.js": "^0.8.4"
},
"devDependencies": {
"@ionic/app-scripts": "1.3.0",
"typescript": "~2.2.1"
},
"cordovaPlugins": [
"cordova-plugin-whitelist",
"cordova-plugin-console",
"cordova-plugin-statusbar",
"cordova-plugin-device",
"ionic-plugin-keyboard",
"cordova-plugin-splashscreen"
],
"cordovaPlatforms": [],
"description": "eqm: Equipment Manager"

访问我的数据库的代码(以及其中一个表至少:) :)是:

public getPeople() {

    return new Promise((resolve, reject) => 
    this.sql.create({
        name: "eqm.db",
        location: "default"
    }).then((db2: SQLiteObject) => {
            let players = new Array<PlayerModel>();
            db2.executeSql("SELECT * FROM players", []).then((data) => {
                if(data.rows.length > 0) {
                    for(let i = 0; i < data.rows.length; i++) {
                        var model = new PlayerModel(data.rows.item(i).playerName,  data.rows.item(i).playerBarcode);
                        players.push(model);
                    }
                }
                resolve(players);

            }, (error) => {
                reject(error);

            });
    }));
}

在我的插件目录中,我注意到:     科尔多瓦-sqlite的-EXT     科尔多瓦-源码存储

我相信当我添加我的android平台时,第一个被安装到这个目录。我尝试过小型测试项目并且只添加了cordova-sqlite-storage,但我对预先填充的数据库的测试没有成功。

我哪里错了?

0 个答案:

没有答案