1
Ionic & Cordovaを使用してモバイルアプリケーションを構築しています。私はSQLiteを使用しているので、ローカルデータベースのテーブルにデータを格納する必要があります。私app.jsでSQLiteを使用してionic1で複数のテーブルを作成できません
私はこれがあります。
var db = null;
var weatherApp = angular.module('weather', ['ionic', 'ngCordova']);
weatherApp.run(function($ionicPlatform, $cordovaSQLite, Cities) {
$ionicPlatform.ready(function() {
if(window.cordova) {
db = $cordovaSQLite.openDB({name: 'weather.db', location: 'default'});
create table for storing favourites
$cordovaSQLite.execute(db, 'CREATE TABLE IF NOT EXISTS favourites (id integer primary key, name text, openWeatherId integer)');
create table for storing the current location of the device
$cordovaSQLite.execute(db, 'CREATE TABLE IF NOT EXISTS location (id integer primary key, openWeatherId integer');
//also tried
// db.transaction(function (tx) {
// //create table for storing favourites
// tx.executeSql(db, 'CREATE TABLE IF NOT EXISTS favourites (id integer primary key, name text, openWeatherId integer)');
// });
// db.transaction(function (tx) {
// //create table for storing the current location of the device
// tx.executeSql(db, 'CREATE TABLE IF NOT EXISTS location (id integer primary key, openWeatherId integer');
// });
$cordovaSQLite.execute(db, 'SELECT tbl_name FROM sqlite_master WHERE type = "table"').then(function (res) {
var tables = [];
if (res.rows.length > 0) {
for (var i = 0; i < res.rows.length; i++) {
if (res.rows.item(i).tbl_name !== "android_metadata"){
tables.push(res.rows.item(i).tbl_name);
}
}
console.log(tables);
// gives:
// Array(1)
// 0 : "favourites"
} else {
console.log('no tables in db!');
}
}, function (error) {
console.log(error);
});
}
});
});
を私は物理のAndroidデバイス上でこの(コルドバの実行アンドロイド)を実行すると、1つのだけテーブルが作成され、お気に入り、他の場所はありません。
なぜでしょうか?ありがとう!
はわずか2つの作成する文と不気味、まだだけのお気に入りの順番を切り替えてみました創造された。ワット!? –
2番目のSQLクエリの最後にエラーがありますか?あなたは括弧を閉じる必要があります:openWeatherId整数 '); - > openWeatherId整数) '); –
ありがとうございましたGustavo - 今はダムエラーでした!回答として提出してください。私はそれを正しくマークします:) –