[英]WebSQL database creating, then deleting itself
嘗試創建一個webSQL數據庫。 經過很長一段時間的故障排除,並嘗試了許多不同的方法,但仍未解決。 將其簡化為一個硬編碼功能。 從觀看Chrome中的開發人員工具來看,它似乎最初是在創建數據庫,然后立即將其刪除。
有人知道我要去哪里錯嗎? Java語言非常新,因此可能很小。
謝謝。
<script>
function writeToDatabase(){
var my_array = new Array();
my_array[0] = "23 November 2013";
my_array[1] = "3:00 AM";
my_array[2] = "Go to the doctor for yearly checkup";
my_array[3] = "Doctor visit";
var db = openDatabase('events_db', '1.0', 'DB for storing event details', 2 * 1024 * 1024);
db.transaction(function (tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS EVENTS (id integer primary key autoincrement, date, time, description, title)');
tx.executeSql('INSERT INTO EVENTS (date, time, description, title) VALUES (?, ?, ?, ?)', my_array);
});
window.alert("done");
db.transaction(function (tx) {
tx.executeSql('SELECT * FROM EVENTS', [], function (tx, results) {
var len = results.rows.length, i;
msg = "<p>Found rows: " + len + "</p>";
for (i = 0; i < len; i++){
window.alert(results.rows.item(i).description);
}
}, null);
});
}
</script>
我認為您需要執行CREATE-INSERT-SELECT操作作為每個操作的回調(在db.transaction內部):
tx.executeSql('CREATE TABLE IF NOT EXISTS EVENTS (id integer primary key autoincrement, date, time, description, title)', [], function(tx) {
tx.executeSql('INSERT INTO EVENTS (date, time, description, title) VALUES (?, ?, ?, ?)', my_array, function(tx) {
tx.executeSql('SELECT * FROM EVENTS', [], function (tx, results) {
...
});
});
});
盡管這看起來很糟糕,但這是WebSQL的工作方式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.