Usman.din-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Amir
2006-Nov-11 21:10 UTC
MySQL and INFILE on Ruby...
Hey Folks, New here and to Ruby. Need some help trying to get a MySQL infile command to work in Ruby: dbh = Mysql.real_connect("localhost", "user", "pass", "db_test") dbh.query("LOAD DATA LOCAL INFILE ''C:\\test.csv'' INTO TABLE db_test.tbl_testing FIELDS TERMINATED BY '','' ENCLOSED BY ''"'' LINES TERMINATED BY ''\r\n''(data1,data2) ") printf "%d rows were inserted\n", dbh.affected_rows However when I run the program it returns an error: .......LINES TERMINATED BY ''\r\n''.... ^ testcsv.rb:3: unterminated string meets end of file Any ideas as to how to get around this issue... I''m assuming it has to do with the \r\n ... i''ve tried to use \\r\\n to no avail... Thanks! Amir... -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Usman.din-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Amir wrote:> Hey Folks, > > New here and to Ruby. Need some help trying to get a MySQL infile > command to work in Ruby: > > dbh = Mysql.real_connect("localhost", "user", "pass", "db_test") > dbh.query("LOAD DATA LOCAL INFILE ''C:\\test.csv'' INTO TABLE > db_test.tbl_testing FIELDS TERMINATED BY '','' ENCLOSED BY ''"'' LINES > TERMINATED BY ''\r\n''(data1,data2) > ") > printf "%d rows were inserted\n", dbh.affected_rows > > However when I run the program it returns an error: > .......LINES TERMINATED BY ''\r\n''.... > ^ > testcsv.rb:3: unterminated string meets end of file > > Any ideas as to how to get around this issue... I''m assuming it has to > do with the \r\n ... i''ve tried to use \\r\\n to no avail... > > Thanks! > > Amir... >You do need to escape the \r\n but you also need to escape the " you have in the string so... "LOAD DATA LOCAL INFILE ''C:\\test.csv'' INTO TABLE db_test.tbl_testing FIELDS TERMINATED BY '','' ENCLOSED BY ''\"'' LINES TERMINATED BY ''\\r\\n''(data1,data2)" (Note that would all be on one line, my email wraps it) Should work, I use the same thing in my migrations with no problems. -- Jim Morris, http://blog.wolfman.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---