如何将多维数组传输到 MySQL 表(通过 Zeoslib)?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
INSERT INTO tab VALUES (v11,..., v1n), ..., (vm1, ..., vmn)
。 IOW,您可以将数组行收集成由 M 行组成的块。这将严重提高性能。 (更多)LOAD DATA INFILE
语句可有效加载文本文件。 (更多)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)LOAD DATA INFILE
statement to load text file efficiently. (More)多维数组不能很好地转换为 MySQL。
如果您正在处理一个小型数组,您可能会完成任务,但它无法扩展。无论如何,它很快就会变得丑陋。
但是,表中的列数不能超过 4096:
http://dev.mysql.com/doc/refman/4.1/en/column-count-limit.html
http://dev.mysql.com/doc/refman/5.0/en/joins-limits.html
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.
However, you cannot have more than 4096 columns in a table:
http://dev.mysql.com/doc/refman/4.1/en/column-count-limit.html
http://dev.mysql.com/doc/refman/5.0/en/joins-limits.html
sum(if(x=1,y,0))
我有同样的问题,只在 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.