本文整理匯總了TypeScript中ionic-native.SQLite類的典型用法代碼示例。如果您正苦於以下問題:TypeScript SQLite類的具體用法?TypeScript SQLite怎麽用?TypeScript SQLite使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了SQLite類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: constructor
constructor(private navController: NavController, private platform: Platform) {
this.database = new SQLite();
this.database.openDatabase({name: "data.db", location: "default"}).then(() => {
//this.refresh();
}, (error) => {
console.log("ERROR: ", error);
});
}
示例2: tests
}).then(() => {
this.db.executeSql('CREATE TABLE IF NOT EXISTS tests (id INTEGER PRIMARY KEY AUTOINCREMENT, name Text, user_id Text, date TIMESTAMP)', {}).then((data) =>{
console.log("TESTS TABLE CREATED", JSON.stringify(data.res));
}, (error) => {
console.log("Error creating tests table", JSON.stringify(error.err));
});
this.db.executeSql('CREATE TABLE IF NOT EXISTS test_sections (id INTEGER PRIMARY KEY AUTOINCREMENT, section INTEGER, question TEXT, score TEXT, question_id INTEGER, test_id INTEGER, CONSTRAINT composite_id UNIQUE (section, question_id, test_id))', {}).then((data) =>{
console.log("TEST SECTIONS TABLE CREATED", JSON.stringify(data.res));
}, (error) => {
console.log("Error creating tests table", JSON.stringify(error.err));
});
}, (err) => {
示例3: add
public add() {
this.database.executeSql("INSERT INTO user (firstname, lastname) VALUES (?, ?)", ['Alejandro', 'Romero']).then((data) => {
console.log("INSERTED: " + JSON.stringify(data));
}, (error) => {
console.log("ERROR: " + JSON.stringify(error));
});
}
示例4: createTable
createTable(){
let sql = 'CREATE TABLE IF NOT EXISTS product(' +
'id INTEGER PRIMARY KEY AUTOINCREMENT, ' +
'type TEXT, ' +
'quantity INTEGER, ' +
'price TEXT, ' +
'name TEXT)';
return this.db.executeSql(sql, []);
}
示例5: getAll
getAll(){
let query = 'SELECT * FROM product';
return this.db.executeSql(query, [])
.then(response => {
let products = [];
for (let index = 0; index < response.rows.length; index++) {
products.push(response.rows.item(index));
}
return Promise.resolve(products);
})
}
示例6: refresh
public refresh() {
this.database.executeSql("SELECT * FROM user", {}).then((data) => {
this.user = [];
if(data.rows.length > 0) {
for(var i = 0; i < data.rows.length; i++) {
this.user.push({firstname: data.rows.item(i).firstname, lastname: data.rows.item(i).lastname});
}
}
}, (error) => {
console.log("ERROR: " + JSON.stringify(error));
});
}
示例7: deleteTestByUser
public deleteTestByUser(user_id: number) {
let sql = 'DELETE FROM tests WHERE user_id = ?';
return this.db.executeSql(sql, [user_id]);
}
示例8: update
// Update an existing note with a given ID
public update(test: Test) {
let sql = 'UPDATE test_sections SET score = ? WHERE section = ? AND question_id = ? AND test_id = ?';
return this.db.executeSql(sql, [test.score, test.section, test.question_id, test.test_id]);
}
示例9: deleteAnswers
public deleteAnswers(id: number){
let sql = 'DELETE FROM test_sections WHERE test_id = ?';
return this.db.executeSql(sql, [id]);
}