Google Chrome でHTML5SQL.jsを使用していますが、次のエラーしか表示されません。
Uncaught TypeError: Cannot read property 'sql' of undefined
私が使用しているこのスクリプトを見てください: http://jsfiddle.net/mporras/Cx3x5/
Google Chrome でHTML5SQL.jsを使用していますが、次のエラーしか表示されません。
Uncaught TypeError: Cannot read property 'sql' of undefined
私が使用しているこのスクリプトを見てください: http://jsfiddle.net/mporras/Cx3x5/
htm5sql.comのガイドにあるように、html5sql.js SQL ステートメントを指定する方法はいくつかあり、エラーはいくつかの異なる方法が混在しているために発生します。
彼の回答で言及されている xdazz のように、html5sql.process の最初の引数は、1 つ以上の SQL ステートメントを含む文字列にすることができます。SQL ステートメント文字列または SQL ステートメント オブジェクトの配列を渡すこともできます。SQL ステートメント オブジェクトを使用する利点は、データ配列を定義し、個々の成功コールバックを指定できることです。
したがって、基本的にこれを行うことができます:
$(function() {
html5sql.openDatabase("demo", "Demo Database", 5 * 1024 * 1024);
html5sql.process(
[
"DROP TABLE IF EXISTS speedtest;",
"CREATE TABLE speedtest (id INTEGER PRIMARY KEY, label TEXT);",
{
sql: "INSERT INTO speedtest VALUES (?, ?);",
data: [1,'1'],
success: function(transaction, results) {
console.info('Success Inserting First Record');
}
},
{
sql: "INSERT INTO speedtest VALUES (?, ?);",
data: [2,'2'],
success: function(transaction, results) {
console.info('Success Inserting Second Record');
}
}
],
function() {
console.log("Final Sucess Callback");
},
function(error, failingQuery) {
console.error("Error: " + error.message);
}
);
});
これのデモは、このjsfiddleにあります
関数のhtml5sql.process
シグネチャはhtml5sql.process(SQL, finalSuccessCallback, errorCallback)
ですので、以下の方法を試してみてください。
$(function() {
html5sql.openDatabase("demo", "Demo Database", 5 * 1024 * 1024);
var st = "DROP TABLE IF EXISTS speedtest; CREATE TABLE speedtest (id INTEGER PRIMARY KEY, label TEXT); INSERT INTO speedtest VALUES (1, '1');INSERT INTO speedtest VALUES (2, '2');";
html5sql.process(
st,
function(transaction, results) {
console.info('Success');
},
function(error, failingQuery) {
console.error("Error: " + error.message);
});
});