【发布时间】:2012-11-02 22:15:08
【问题描述】:
我正在使用 html5sql.com 来做 html5 DB 的东西 :o) - 真是一个很棒的模块...
但是,我卡住了!
在我的 index.html/index.js 中,我在其中创建了我的数据库和表。
try {
html5sql.openDatabase("com.dynamicvenues.fairkeyMobile.db","Questionnaire",3*1024*1024);
html5sql.process(
[
"CREATE TABLE IF NOT EXISTS Questionnaire (uid INTEGER, json TEXT, hash TEXT);",
"CREATE TABLE IF NOT EXISTS Answers (id INTEGER PRIMARY KEY, visitor_id TEXT, json TEXT);"
],
function(){
console.log("Success Creating Tables");
},
function(error, statement){
console.error("Error: " + error.message + " when processing " + statement);
}
)
} catch(error) {
alert("Database create failed: "+error.message);
}
在同一页面中,我用数据填充了一个表:
jQuery.get(serverHttp+"json.php?exhibitorID="+exhibitorID, function(data){
var html = $(data).map(function() {
return $(this).html();
});
var jsonStr = html[0];
var exhibitorID = html[1];
var hashStr = html[2];
var SQL = "INSERT INTO Questionnaire (uid, json, hash) VALUES ("+exhibitorID+",'"+jsonStr+"','"+hashStr+"')";
try {
html5sql.process(SQL,
function(){
console.log('Inserted 1 row!');
},
function(){
console.error("Error: " + error.message + " when processing " + statement);
}
)
} catch(error) {
alert("Query failed: "+error);
}
现在,在另一个名为 questions.html/questionnaire.js 的页面中,我尝试检索存储在问卷调查表中的数据。
html5sql.process(
["SELECT * FROM Questionnaire;"],
function(transaction, results, rowsArray){
for(var i = 0; i < rowsArray.length; i++){
var uid = rowsArray[i].uid;
var json = rowsArray[i].json;
var hash = rowsArray[i].hash;
console.log("Retrieved rows: "+uid+" - "+json+" "+hash);
}
console.log("Done selecting data");
},
function(error, statement){
console.error(error.message+" Occured while processing: "+statement);
}
);
我做错了什么???
问候, 丹尼尔
【问题讨论】:
-
您使用哪个浏览器进行测试?请注意,只有特定浏览器在取消之前实现了该功能。 html5sql.com 似乎在使用 Web SQL 数据库,这是一个不再由 W3C 维护的本地 SQL 数据库:"Beware. This specification is no longer in active maintenance and the Web Applications Working Group does not intend to maintain it further."
-
解决了!插入:html5sql.openDatabase("com.dynamicvenues.fairkeyMobile.db","Questionnaire",3*1024*1024);在问卷调查表的 html5sql.process() 之前...顺便说一句。这是针对我正在使用 Phonegap/Cordova 构建的 Android 应用程序
-
然后post that as answer instead of a comment 并接受它。 “明确地说,不仅可以提出和回答自己的问题,而且明确鼓励这样做。”
-
由于我是新来的,在接下来的 8 小时内我无法回答自己的问题 :( 抱歉
-
那里,你现在应该可以发布你的答案了:)
标签: javascript jquery html sqlite web-storage