javascript Web SQL DROP/DELETE 表不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7820189/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 01:25:57  来源:igfitidea点击:

Web SQL DROP/DELETE Table not working

javascriptsql

提问by Tyler Buchea

I've tried several different commands for clearing my Web SQL Database and none of them work. Just to show you I've assembled all of them into one overkill function. What am I missing?

我尝试了几种不同的命令来清除我的 Web SQL 数据库,但没有一个起作用。只是为了向您展示我已将所有这些组合成一个矫枉过正的功能。我错过了什么?

/** Drop Table from Database - Fix This **/
function overKill(tablename){

  var query = "DELETE FROM " + tablename;
  db.transaction(function (tx) {
    tx.executeSql(query);
  });

  var query = "DELETE * FROM " + tablename;
  db.transaction(function (tx) {
    tx.executeSql(query);
  });

  var query = "DROP TABLE " + tablename;
  db.transaction(function (tx) {
    tx.executeSql(query);
  });

}

回答by Kal

This worked for me

这对我有用

tx.executeSql("DROP TABLE foo",[], 
    function(tx,results){console.log("Successfully Dropped")},
    function(tx,error){console.log("Could not delete")}
);

回答by anar khalilov

Worked for me:

对我来说有效:

tx.executeSql('DELETE FROM FormRecords');

tx.executeSql('DELETE FROM FormRecords');

Moreover, you cannot deletea Web SQL database.

此外,您不能删除Web SQL 数据库。

回答by Serge P

You last variant is correct. Just for testing you can open your web resourse by Chrome. Then open Resourses -> Web SQL where you can type DROP TABLE TABLENAMEand check if everething is right.

您的最后一个变体是正确的。只是为了测试,您可以通过 Chrome 打开您的网络资源。然后打开 Resourses -> Web SQL,您可以在其中键入DROP TABLE TABLENAME并检查一切是否正确。

回答by heximal

DELETE * FROM...

does not make sense. use DELETE FROM instead

没有意义。改用 DELETE FROM

回答by mmcorrelo

The follow code should works well:

以下代码应该运行良好:

var db = openDatabase(databaseName, "0.1", description, size)

var db.transaction(function (t) {
     t.executeSql("DROP TABLE objectTable",[], 
         function(t,results){
             console.error("Table Dropped")
         },
         function(t,error){
             console.error("Error: " + error.message)
         }
     )
})