Forum: Ruby on Rails How to execute an SQL statement in rails?

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.
D25d7166e80639478ef1811788b8e61e?d=identicon&s=25 Bruno Mattarollo (Guest)
on 2006-01-11 08:00
(Received via mailing list)
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 Mattarollo <bruno.mattarollo@gmail.com>
Currently in: Sydney, Australia
82476266af9d460415d8f1fc16bb54ed?d=identicon&s=25 Jarkko Laine (jarkko)
on 2006-01-11 08:24
(Received via mailing list)
Hi Bruno,

On 11.1.2006, at 8.59, Bruno Mattarollo 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
D25d7166e80639478ef1811788b8e61e?d=identicon&s=25 Bruno Mattarollo (Guest)
on 2006-01-11 08:27
(Received via mailing list)
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 Laine <jarkko@jlaine.net> wrote:
> > to do this?
> SomeModel.connection.select_all("your select statement")
--
Bruno Mattarollo <bruno.mattarollo@gmail.com>
Currently in: Sydney, Australia
This topic is locked and can not be replied to.