2016-09-30 5 views
0

私はIonic 2を使用しており、その後にはthis tutorialと書いてあります。Ionic 2 SQLiteデータベースが開かない

私の問題は、データベースを開くことができないことです。私はそれをKOPLAYERというAndroidエミュレータにデプロイしました。

app.ts

initializeApp() { 
    this.platform.ready().then(() => { 
     StatusBar.styleDefault(); 
     if (window.cordova) { 
     this.createDatabase(); 
     } 
    }); 
    } 

private createDatabase(): void { 
    let db: SQLite = new SQLite(); 
    db.openDatabase({ 
     name: "data.db", 
     location: "default" 
    }).then(() => { 
     db.executeSql("CREATE TABLE IF NOT EXISTS chats (_id TEXT PRIMARY KEY, memberIds TEXT, title TEXT, subTitle TEXT, picture TEXT, lastMessageId TEXT, lastMessageCreatedAt DATE)", {}).then((chatData) => { 
     console.log("chats TABLE CREATED: ", chatData); 
     db.executeSql("CREATE TABLE IF NOT EXISTS messages (_id TEXT PRIMARY KEY, chatId TEXT, senderId TEXT, ownership TEXT, content TEXT, createdAt DATE, changeDate BOOLEAN, readByReceiver BOOLEAN)", {}).then((messageData) => { 
      console.log("messages TABLE CREATED: ", messageData); 
     }, (error) => { 
      console.error("Unable to execute messages sql", error); 
     }); 

     }, (error) => { 
     console.error("Unable to execute chats sql", error); 
     }); 
    }, (error) => { 
     console.error("Unable to open database", error); 
    }); 
    } 

storageService.ts

public database: SQLite; 

constructor() { 
    if (window.cordova) { 
     this.openDatabase(); 
    } 
} 

private openDatabase(): void { 
    console.log('openDatabase'); 
    this.database.openDatabase({ name: "data.db", location: "default" }).then(() => { 
     this.refreshChats(); 
     this.refreshMessages(); 
    }, (error) => { 
     console.log("ERROR: ", error); 
    }); 
} 

openDatabaseはコンソールに出力されますが、this.refreshChats();は呼び出されません。 app.tsのデータベース作成は、コンソールログに応じて正しく表示されます。 Iは、コンソール出力を表示するchrome://inspect/#devicesを使用

OPEN database: data.db SQLitePlugin.js:175 
OPEN database: data.db - OK SQLitePlugin.js:179 
chats TABLE CREATED: Object app.bundle.js:215 
messages TABLE CREATED: Object app.bundle.js:217 

次いで

openDatabase

。エミュレータで実行中のデータベースを表示するために使用できる他のツールはありますか?

助けてください。

答えて

0

私のミス、私はthis.database = new SQLite();

private openDatabase(): void { 
    this.database = new SQLite(); 
    this.database.openDatabase({ name: "data.db", location: "default" }).then(() => { 
     this.refreshChats(); 
     this.refreshMessages(); 
    }, (error) => { 
     console.log("ERROR: ", error); 
    }); 
} 
を忘れてしまいました
関連する問題