将本地数据库存储在共享文件夹中

时间:2015-07-11 22:07:40

标签: javascript sql sqlite

我有一个WebSQL数据库,我想通过网络共享,以便访问与数据库链接的html文件的任何人都将查看/编辑数据库的同一副本。

所以,基本上,有没有办法改变浏览器(Chrome)保存数据库的位置?

我知道WebSQL已被弃用,但我必须将其用于我的项目。

<script>

if (window.openDatabase) {

    var mydb = openDatabase("students2_db", "0.1", "A Database of Students", 1024 * 1024);

   mydb.transaction(function (t) {

         t.executeSql("CREATE TABLE IF NOT EXISTS student (id INTEGER PRIMARY KEY ASC, fname TEXT, lname TEXT, mclass TEXT, aclass TEXT, com TEXT, lates INTEGER DEFAULT 0)");
        t.executeSql("CREATE TABLE IF NOT EXISTS lates (lid INTEGER PRIMARY KEY ASC, flname TEXT, llname TEXT, time TEXT, reason TEXT, date TEXT, nextdet TEXT)");    });

} else {
    alert("WebSQL is not supported by your browser!");
}

function ClearFunction() {
    document.getElementById("morningclass").value = "";
    document.getElementById("afternoonclass").value = "";
}


function addStudent() {

    if (mydb) {

        var fname = document.getElementById("firstname").value;
        fname = fname.replace(/\s/g, '');
        fname = fname.toLowerCase();
        var lname = document.getElementById("lastname").value;
        lname = lname.replace(/\s/g, '');
        lname = lname.toLowerCase();
        var mclass = document.getElementById("morningclass").value;
        var aclass = document.getElementById("afternoonclass").value;
        var com = document.getElementById("comments").value;

        if (fname !== "" && lname !== "" && mclass !== "" && aclass !== "") {
            mydb.transaction(function (t) {
                t.executeSql("INSERT INTO student (fname, lname, mclass, aclass, com) VALUES (?, ?, ?, ?, ?)", [fname, lname, mclass, aclass, com]);
                alert("Entry succesfully added");
                document.getElementById("firstname").value = "";
                document.getElementById("lastname").value = "";
                document.getElementById("morningclass").value = "";
                document.getElementById("afternoonclass").value = "";
                document.getElementById("comments").value = "";
            });
        } else {
            alert("You must fill out all the empty information!");
        }
    } else {
        alert("db not found, your browser does not support web sql!");
    }
}

</script>  

0 个答案:

没有答案