Parsing a SQL file directly into activerecord::execute metho

Hello folks,

I’m trying to do something like:

  1. db = ActiveRecord::Base.establish_connection(:adapter => “mysql”,
    :database => “app_development”, :username => “root”)
  2. Cmd =‘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 parser.

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


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

Brian C.

Try this:


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?


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs