如何处理客户端数据库删除表事务?

发布于 2024-10-04 17:56:49 字数 323 浏览 1 评论 0原文

我的客户端数据库上有以下功能:

      dropTable = function (a, tbl) {
        a.executeSql('Drop Table If Exists ' + tbl + ';', [], 
          function(a, b){
            console.log('Table "' + tbl + '" dropped.');
          }
        , errorHandler);
      };

我需要做什么才能仅在删除表时显示控制台消息?目前它显示在每个函数调用上。

I've got the following function on my client-side db:

      dropTable = function (a, tbl) {
        a.executeSql('Drop Table If Exists ' + tbl + ';', [], 
          function(a, b){
            console.log('Table "' + tbl + '" dropped.');
          }
        , errorHandler);
      };

What do I have to do to show the console message only when a table is dropped? It currently shows on every function call.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

被翻牌 2024-10-11 17:56:49

看起来你的查询是“成功的”,无论它是否存在(因为你保护不存在的情况)。如果你想硬失败:

     dropTable = function (a, tbl) {
        a.executeSql('Drop Table ' + tbl + ';', [], 
          function(a, b){
            console.log('Table "' + tbl + '" dropped.');
          }
        , errorHandler);
      };

如果 errorHandler 不存在,应该调用它。干杯!

Looks like your query is "successful" whether it exists or not (since you guard for the case of nonexistence). If you want to fail hard:

     dropTable = function (a, tbl) {
        a.executeSql('Drop Table ' + tbl + ';', [], 
          function(a, b){
            console.log('Table "' + tbl + '" dropped.');
          }
        , errorHandler);
      };

This should call the errorHandler if it doesn't exist. Cheers!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文