Safari 中的 HTML5 存储可以进行交易吗

发布于 2024-08-12 15:46:48 字数 777 浏览 3 评论 0原文

Safari 客户端存储是否可以简单地将数据包装在“BEGIN TRANSACTION”/“COMMIT TRANSACTION”中并传递,而不是在包含 SQL 语句列表的 JSON 文件上执行每个循环并一次传递一个。一次调用数据库系统?循环 1,000 多个语句需要太多时间。

当前一次迭代一项事务:

$j.getJSON("update1.json",
  function(data){
    $j.each(data, function(i,item){
            testDB.transaction(
                function (transaction) {
                    transaction.executeSql(data[i], [], nullDataHandler, errorHandler);
                }
            );
   });
});

试图找出如何只进行一次调用:

$j.getJSON("update1.json",
  function(data){
            testDB.transaction(
                function (transaction) {
                    transaction.executeSql(data, [], nullDataHandler, errorHandler);
                }
            );
});

有人尝试过并成功了吗?

Instead of doing an each loop on a JSON file containing a list of SQL statments and passing them one at a time, is it possible with Safari client side storage to simply wrap the data in "BEGIN TRANSACTION" / "COMMIT TRANSACTION" and pass that to the database system in a single call? Looping 1,000+ statements takes too much time.

Currently iterating one transaction at a time:

$j.getJSON("update1.json",
  function(data){
    $j.each(data, function(i,item){
            testDB.transaction(
                function (transaction) {
                    transaction.executeSql(data[i], [], nullDataHandler, errorHandler);
                }
            );
   });
});

Trying to figure out how to make just one call:

$j.getJSON("update1.json",
  function(data){
            testDB.transaction(
                function (transaction) {
                    transaction.executeSql(data, [], nullDataHandler, errorHandler);
                }
            );
});

Has anybody tried this yet and succeeded?

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

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

发布评论

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

评论(3

鹿港巷口少年归 2024-08-19 15:46:48

我在文档中找到的每个示例似乎都只显示每个 executeSql 命令一个 SQL 语句。我只是建议显示一个“ajax spinner”加载图形并在循环中执行 SQL。您可以将其全部保留在事务中,但循环仍然需要存在:

$j.getJSON("update1.json",
    function(data){
       testDB.transaction(
           function (transaction) {
               for(var i = 0; i < data.length; i++){
                   transaction.executeSql(data[i], [], nullDataHandler, errorHandler);
               }
           }
       );
    }
);

将循环移至事务内并使用 for i = 应该有助于提高循环的速度。 $.each 适合少于 1000 次迭代,之后本机 for(var = i... 可能会更快。

注意 使用我的代码,如果任何 SQL 语句抛出错误,则整个事务将失败,如果这不是您的意图,则需要将循环保留在事务之外。

Every example I could find in the documentation seems to show only one SQL statement per executeSql command. I would just suggest showing an "ajax spinner" loading graphic and execute your SQL in a loop. You can keep it all within the transaction, but the loop would still need to be there:

$j.getJSON("update1.json",
    function(data){
       testDB.transaction(
           function (transaction) {
               for(var i = 0; i < data.length; i++){
                   transaction.executeSql(data[i], [], nullDataHandler, errorHandler);
               }
           }
       );
    }
);

Moving the loop inside the transaction and using the for i = should help get a little more speed out of your loop. $.each is good for less than a 1000 iterations, after that the native for(var = i... will probably be faster.

Note Using my code, if any of your SQL statements throw errors, the entire transaction will fail. If that is not your intention, you will need to keep the loop outside the transaction.

烟雨凡馨 2024-08-19 15:46:48

我从来没有搞乱过 HTML5 数据库存储(尽管有 local/sessionStorage),并且我认为可以运行一大串语句。使用 data.join(separator here) 获取 data 数组。

I haven't ever messed with HTML5 database storage (have with local/sessionStorage though) and I would assume that it's possible to run one huge string of statements. Use data.join(separator here) to get the string representation of the data array.

挖个坑埋了你 2024-08-19 15:46:48

是的,可以使用 webSQL 在单个事务中处理整组语句。实际上,您甚至不需要使用 BEGIN 或 COMMIT,只要您从同一事务中进行所有的executeSql 调用,就会自动为您处理。只要您这样做,每个语句都会包含在事务中。

这使得该过程更快,并且当其中一个语句出现错误时,它会回滚整个事务。

Yes, it is possible to process a whole group of statements within a single transaction with webSQL. You actually don't even need to use BEGIN or COMMIT, this is taken care of for you automatically as long as you make all your executeSql calls from the same transaction. As long as you do this every statement gets included within the transaction.

This makes the process much faster and also makes it so that when one of your statements has an error it rolls back the entire transaction.

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