FasterCSV 错误 /Library/Ruby/Gems/1.8/gems/fastercsv-1.5.4/lib/faster_csv.rb:1641: 在 `shift'

发布于 2024-12-11 11:28:04 字数 866 浏览 6 评论 0原文

ruby 新手,这是我使用 FasterCSV Gem 的第一个项目,并且非常喜欢它的速度。

我发现一个问题,当字段太长时,会抛出以下错误:

/Library/Ruby/Gems/1.8/gems/fastercsv-1.5.4/lib/faster_csv.rb:1641:in `shift': FasterCSV ::MalformedCSVError (FasterCSV::MalformedCSVError)

错误位于第二行 第一行读取正确:-)

"1013197145","PSION HU6020 手带","1","1","10"

"1013197542","HP ProBook NA920EA_KT931AT 39.6 cm (15.6") 笔记本电脑 - Intel Core 2 Duo T6570 2.10 GHz - 1366 x 768 WXGA展示 - 2 GB RAM - 250 GB HDD - DVD 刻录机 LightScribe - Intel GMA 4500MHD 显卡 - 蓝牙 - 网络摄像头 - 正版 Windows Vista Business - 5 小时电池 - HDMI","1","1","10"

这是我的代码:

FasterCSV.foreach(file_path, {:col_sep=> colsep, :quote_char => char}) do |row|

   my.query("INSERT INTO product_prices (partno,costpriceexvat,sku, supplierid) VALUES ('#{row[7]}', '#{row[8]}', '#{row[3]}','1')")

end

任何帮助将不胜感激。

Newbie to ruby this is my first project I am using the FasterCSV Gem and absolutely love the speed.

I have found one problem that when a field is too long it throws up an error below:

/Library/Ruby/Gems/1.8/gems/fastercsv-1.5.4/lib/faster_csv.rb:1641:in `shift': FasterCSV::MalformedCSVError (FasterCSV::MalformedCSVError)

The error is on the second line first line is read correctly :-)

"1013197145","PSION HU6020 Hand Strap","1","1","10"

"1013197542","HP ProBook NA920EA_KT931AT 39.6 cm (15.6") Notebook - Intel Core 2 Duo T6570 2.10 GHz - 1366 x 768 WXGA Display - 2 GB RAM - 250 GB HDD - DVD-Writer LightScribe - Intel GMA 4500MHD Graphics Card - Bluetooth - Webcam - Genuine Windows Vista Business - 5 Hour Battery - HDMI","1","1","10"

here is my code:

FasterCSV.foreach(file_path, {:col_sep=> colsep, :quote_char => char}) do |row|

   my.query("INSERT INTO product_prices (partno,costpriceexvat,sku, supplierid) VALUES ('#{row[7]}', '#{row[8]}', '#{row[3]}','1')")

end

any help would be much appreciated.

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

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

发布评论

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

评论(1

淡墨 2024-12-18 11:28:04

我怀疑这与 FasterCSV 阻塞长字符串以及项目描述的“(15.6”)”部分中带有英寸字符的所有内容无关 - 因为它与引用相同,它终止了 CSV 值,从而使得对于格式错误的 CSV 行,FasterCSV 设计得对这种类型很严格。的事情。

I suspect this has nothing to do whatsoever with FasterCSV choking on long strings and everything with the inch character in the “(15.6")” part of your item description – as it is identical to the quote, it terminates the CSV value, thus making for a malformed CSV line. FasterCSV is designed to be strict about this kind of things.

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