How to execute an SQL statement in rails?

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. [email protected]
Currently in: Sydney, Australia

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 Peak Obsession
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

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. [email protected] wrote:

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

Bruno M. [email protected]
Currently in: Sydney, Australia