mercredi 8 avril 2015

How to use the load command with MySQL in Ruby/Rails?

In MySQL, I can run:



LOAD DATA LOCAL INFILE "/home/pt/test/bal.csv" INTO TABLE bal FIELDS
TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '"' IGNORE 1
LINES;


However, in my Ruby program:



str="LOAD DATA LOCAL INFILE "/home/pt/test/bal.csv" INTO TABLE bal
FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '"'
IGNORE 1 LINES;"

puts str

dbh.query(str)


The output is:



LOAD DATA LOCAL INFILE "/home/pt/test/bal.csv" INTO TABLE bal FIELDS
TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '"' IGNORE 1
LINES;

/home/pt/test/ptb.rb:34:in `query': Field separator argument is not what
is expected; check the manual (Mysql::Error)
from /home/pt/test/ptb.rb:34:in `<main>'


What's wrong with this code?


Aucun commentaire:

Enregistrer un commentaire