Forum: Ruby on Rails Parsing a SQL file directly into activerecord::execute metho

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Brian C. (Guest)
on 2006-04-04 20:43
(Received via mailing list)
Hello folks,

I'm trying to do something like:

1. db = ActiveRecord::Base.establish_connection(:adapter => "mysql",
:database => "app_development", :username => "root")
2. Cmd = File.read('commands.sql')  <---  Command.sql contains multiple
valid SQL statement.  I've tested this directly by piping it into MySQL
from the command line
3. ActiveRecord::Base.connection.execute(cmd)

This seems to not work as I would expect.  My guess is that there is
some problem with the File.read parser.

Any ideas?  The SQL file is pretty large.  I bet the parser is doing
something to some of the input characters.

Best,
B

PS: Before anyone starts beating on the, do it the Rails way drum, the
file is big.  Processes relatively large (up to several hundred million
records) tables, and works much faster when doing it in SQL directly.  I
promise.


---------------------------
Brian C.
---------------------------
Nick S. (Guest)
on 2006-04-04 23:29
(Received via mailing list)
Try this:

ActiveRecord::Base.connection.execute(IO.read("#{RAILS_ROOT}/command.sql"))

Should do it for ya. If not, make sure your connection is working
proberly (can type in a command and executes). Let us know!

Also, where are you executing this from? The console? And migration?
And where is the SQL file in relation to your app directory?

-Nick
This topic is locked and can not be replied to.