使用参数时,WebSQL不会执行

时间:2014-01-26 11:59:58

标签: javascript web-sql

这是我的代码:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Web SQL Test</title>

    <script type="text/javascript">
    var db = openDatabase('test', '1.0', 'Test', 1024*1024);

    db.transaction(function (tx) {
        tx.executeSql('CREATE TABLE IF NOT EXISTS ?(?, ?, ?)', ['test', 'id unique', 'name', 'age'], function (tx, results) {
            console.log('create table: everything is fine');

            addEntry();
        }, function (tx, error) {
            console.log(error);

            // try same thing without placeholders
            tx.executeSql('CREATE TABLE IF NOT EXISTS test(id unique, name, age)', null, function (tx, results) {
                // weird
                console.log('create table: no placeholders works');

                addEntry();
            }, function (tx, error) {
                console.log('create table: there is obviously something wrong in your query');
            });
        });
    });

    function addEntry() {
        db.transaction(function (tx) {
            tx.executeSql('INSERT INTO ?(?, ?) VALUES(?, ?)', ['test', 'name', 'age', 'George', 24], function (tx, results) {
                console.log('insert into: entry insertion was successfull');
            }, function (tx, error) {
                console.log(error);

                // try same thins without placeholders
                tx.executeSql('INSERT INTO test(name, age) VALUES("George", 24)', null, function (tx, results) {
                    // weird
                    console.log('insert into: no placeholders works');
                }, function (tx, error) {
                    console.log(error);
                    console.log('insert into: there is obviously something wrong in your query');
                });
            });
        });
    }
    </script>
</head>
<body>

</body>
</html>

带参数的初始“CREATE TABLE”查询失败,错误代码为5:无法准备语句(1“接近”?“:语法错误)

然后在没有“?”的情况下将其作为查询提交参数运行顺利。

“INSERT INTO”查询也会发生同样的事情。

在使用参数的情况下,知道我做错了吗?

0 个答案:

没有答案