How to execute an SQL statement in rails?


#1

Hello,

This is probably a silly question but looking at
api.rubyonrails.org”, I can’t seem to figure out which method I
should be using … I want to execute an sql statement, like “truncate
table BLAH” from within one of my rails app … What’s the “right” way
to do this?

Thanks,

/B


Bruno M. removed_email_address@domain.invalid
Currently in: Sydney, Australia


#2

Hi Bruno,

On 11.1.2006, at 8.59, Bruno M. wrote:

Hello,

This is probably a silly question but looking at
api.rubyonrails.org”, I can’t seem to figure out which method I
should be using … I want to execute an sql statement, like “truncate
table BLAH” from within one of my rails app … What’s the “right” way
to do this?

See http://api.rubyonrails.com/classes/ActiveRecord/
ConnectionAdapters/DatabaseStatements.html

You’ll want to use the raw db connection, like:

SomeModel.connection.execute(“your statement”)

or, if you’re still wanting something in return,

SomeModel.connection.select_all(“your select statement”)

//jarkko


#3

Thanks Jarkko,

I gave that a try and it works fine! Just in time. You always have
helpful answers mate.

BTW how are you doing? It’s been a while since we met in Copenhagen
for that OpenACS/.LRN gathering …

Cheers

/B

On 1/11/06, Jarkko L. removed_email_address@domain.invalid wrote:

to do this?
SomeModel.connection.select_all(“your select statement”)

Bruno M. removed_email_address@domain.invalid
Currently in: Sydney, Australia