you need to load the .sql file into ruby,
and then call .execute on it.
sql = File.open("some.sql").read
sql.split(';').each do |sql_statement|
ActiveRecord::Base.connection.execute(sql_statement)
end
We split it by ";" because a .sql file may contain multiple
statgements,
and you'll need to execute those seperately.
But that should work fine.
Yours,
MatthewRudy
http://workingwithrails.com/person/12394-matthew-rudy-jacobs
On Oct 16, 8:36 pm, Joe Peck <[EMAIL PROTECTED]> wrote:
> Frederick Cheung wrote:
> > ActiveRecord::Base.connection.execute(...)
>
> > Fred
>
> That seems to work if actual sql code is put in the parenthesis, but how
> can I run SQL out of a sql file in the rake task?
>
> Doing this in the rake task:
> ActiveRecord::Base.connection.execute("#{RAILS_ROOT}/db/html_template.sql")
>
> gives me this error:
> rake aborted!
> Mysql::Error: You have an error in your SQL syntax; check the manual
> that corresponds to your MySQL server version for the right syntax to
> use near '/projects/trieste2/db/html_template.sql' at line 1:
> /projects/trieste2/db/html_template.sql
>
> How can I run the sql that is in the sql file?
> --
> Posted viahttp://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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---