如何将多维数组传输到 MySQL 表(通过 Zeoslib)?

发布于 2024-12-02 20:51:25 字数 185 浏览 2 评论 0原文

我正在 Delphi 中使用 Zeoslib 库。

我有一个大型多维静态数组,需要将其传输到本地 MySQL 数据库中的空表。我怎样才能有效地做到这一点?

只是迭代一百万个插入语句?

I am using the Zeoslib library in Delphi.

I have a large multidimensional static array that I need to transfer to an empty table in a local MySQL database. How can I do this efficiently?

Just iterate through a million insert statements?

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

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

发布评论

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

评论(3

南薇 2024-12-09 20:51:25
  1. 您可以使用 MySQL 语法:INSERT INTO tab VALUES (v11,..., v1n), ..., (vm1, ..., vmn)。 IOW,您可以将数组行收集成由 M 行组成的块。这将严重提高性能。 (更多)
  2. 您可以将数组卸载到文本文件中,然后使用LOAD DATA INFILE 语句可有效加载文本文件。 (更多)
  3. 您可以考虑使用其他3d方库,例如 AnyDAC。它实现了 Array DML 功能,该功能正是为您的任务而设计的。 (更多
  1. You can use MySQL syntax: INSERT INTO tab VALUES (v11,..., v1n), ..., (vm1, ..., vmn). IOW, you can collect your array rows into chunks consisting of M rows. This will seriously improve performance. (More)
  2. You can offload array into text file, then use LOAD DATA INFILE statement to load text file efficiently. (More)
  3. You can consider to use other 3d party libraries, like AnyDAC. Which implements Array DML feature, which is intended exactly for your task. (More)
故事灯 2024-12-09 20:51:25

多维数组不能很好地转换为 MySQL。

如果您正在处理一个小型数组,您可能会完成任务,但它无法扩展。无论如何,它很快就会变得丑陋。

  • 对于简单的二维数组,您可以考虑为一维创建一列,并为另一维创建行。
    但是,表中的列数不能超过 4096:

http://dev.mysql.com/doc/refman/4.1/en/column-count-limit.html

每个表有 4096 列的硬性限制,但对于给定表,有效最大值可能会更少。确切的限制取决于以下讨论中列出的几个相互作用的因素。

每个表的最大行大小为 65,535 字节。此最大值适用于所有存储引擎,但给定引擎可能具有其他约束,导致有效最大行大小较低。

  • 或者,您可以为每个数组项创建一行,并将每个维度的索引存储为主键。但是当您想要检索值时,您需要创建一个怪物查询。
  • 您需要执行以下操作:
    • 多个联接,但在一个查询中只能执行 61 个联接:

http://dev.mysql.com/doc/refman/5.0/en/joins-limits.html

单个联接中可引用的表的最大数量为 61。这也适用于视图定义中可引用的表的数量。

    • 或者创建一个查询,按行键分组,并通过组合函数和条件的组合有条件地选择正确的值,如下所示:
      sum(if(x=1,y,0))

Multi-dimensional array's don't translate well to MySQL.

If you're dealing with a tiny array you'll probably get things done, but it just doesn't scale. No matter what, it's going to get ugly real soon.

  • For a simple 2-dimensional array, you could consider creating a column for one dimension, and use rows for the other.
    However, you cannot have more than 4096 columns in a table:

http://dev.mysql.com/doc/refman/4.1/en/column-count-limit.html

There is a hard limit of 4096 columns per table, but the effective maximum may be less for a given table. The exact limit depends on several interacting factors, listed in the following discussion.

Every table has a maximum row size of 65,535 bytes. This maximum applies to all storage engines, but a given engine might have additional constraints that result in a lower effective maximum row size.

  • Or, you can create a row per array item, and store the index of each dimension as a primary key.But when you want to retrieve the values, you need to create a monster query.
  • You either need to do:
    • multiple joins, but you can only do 61 joins in a query:

http://dev.mysql.com/doc/refman/5.0/en/joins-limits.html

The maximum number of tables that can be referenced in a single join is 61. This also applies to the number of tables that can be referenced in the definition of a view.

    • Or create a query, group by the row key, and conditionally pick the right value with the combination of a group function and a condition, something like this:
      sum(if(x=1,y,0))
梦里泪两行 2024-12-09 20:51:25

我有同样的问题,只在 php 二维数组中。保存数组的维度(x、y、z 等长度,表示每个级别上的值的数量)。然后将整个数组连接成一个长字符串,用特殊的、唯一的字符(如 |,)分隔,当您获取数据时,您可以根据尺寸数据。

如果您需要它,我可以向您展示我的 php 代码,但我发现您更喜欢 delphi。

编辑:这是您编辑问题之前的答案。现在有点无关紧要了。

I had the same problem, only in php 2D arrays. Save the dimensions of the array (x, y, z etc. length, meaning the number of values on each level). then join the whole array into ane long string, divide with a special, unique character like | or ,, and when you fetch the data you can split the sting based on the dimensions data.

If you need it, I can show you my php code, but I see you prefer delphi.

EDIT: this is an answer for your question before you edited it. Now it's kind of irrelevant.

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