FasterCSV 错误 /Library/Ruby/Gems/1.8/gems/fastercsv-1.5.4/lib/faster_csv.rb:1641: 在 `shift'
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我怀疑这与 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.