我的 WebSQL 脚本不会将条目保存在数据库中



我写了一个程序来创建一个名为"picture"的数据库并将值保存到其中。但它不起作用,他在数据库中没有保存任何条目。谷歌浏览器浏览器的控制台没有向我显示任何错误。你有想法吗?

    var db = openDatabase("mskindb", '1.0', 'mskindb', 2 * 1024 * 1024);
var textMessage = "";
function initDatabase() {
    db.transaction(function (tx) {
        tx.executeSql('CREATE TABLE IF NOT EXISTS picture (id INTEGER PRIMARY KEY AUTOINCREMENT, docid0 TEXT, docid1 TEXT, doctype TEXT, data TEXT, date TEXT' + 
            'creation_date TEXT, delete_date TEXT, transmit_date TEXT)');
        alert("initDatabase");
    });
}
function dropTables() {
    db.transaction(function (tx) {
        tx.executeSql('DROP TABLE patient');
        tx.executeSql('DROP TABLE picture');
        tx.executeSql('DROP TABLE senderMessage');
        tx.executeSql('DROP TABLE receiverMessage');
        initDatabase();
        alert("dropTables");
    });
}
function dropPicture() {
    db.transaction(function (tx) {
        tx.executeSql('DROP TABLE picture');
        initDatabase();
    });
}
function addPatient(patient) {
    db.transaction(function (tx) {
        tx.executeSql('INSERT INTO patient (lastname, firstname) VALUES (?, ?)', [patient.lastName, patient.firstName]);
    });
}
function addPicture() {
    //textMessage = document.getElementById("patientMessage").value;
    db.transaction(function (tx) {
        tx.executeSql('INSERT INTO picture (docid0, ' + 
            'docid1, doctype, data, date, creation_date, transmit_date, delete_date) VALUES (?, ?, ?, ?, ?, ?, ?, ?)',
            ["0", "0", "mSkinPicture", JSON.stringify(actualPhoto), new Date(), "0", "0", "0"]);
        alert("addPicture() ausgeführt");
        alert(JSON.stringify(actualPhoto))
    });
}
function displayAllPictures() {
    alert("1");
    var psrDisplayArea = document.getElementById("psrDisplayArea");
    db.transaction(function (tx) {
        alert("2");
        tx.executeSql('SELECT * FROM picture', [], function (tx, results) {
            alert("3");
            alert(results.rows.length);
            for (var i = 0; i < results.rows.length; i++) {
                alert("4");
                alert(JSON.parse(results.rows.item(i).data));
            }
        }, null);
    });
}
//
actualPhoto = new photoData("HelloWorld");
function photoData(path) {
    this.path = path;
}
//
initDatabase();
addPicture();
displayAllPictures();

事务方法为您提供了一个回调函数,其中包含一个错误对象,尝试通过以下方式进行调试:

function addPicture() {
  db.transaction(function (tx) {
    tx.executeSql('INSERT INTO picture (docid0, ' + 
        'docid1, doctype, data, date, creation_date, transmit_date, delete_date) VALUES (?, ?, ?, ?, ?, ?, ?, ?)',
        ["0", "0", "mSkinPicture", JSON.stringify(actualPhoto), new Date(), "0", "0", "0"]);
    alert("addPicture() ausgeführt");
    alert(JSON.stringify(actualPhoto))
}, function (error) {
    // Here check what your console says ^^
    console.log(error);
});

}

http://cordova.apache.org/docs/en/6.x/cordova/storage/storage.html#websql

;)取得联系

最新更新