hi everybody
i want to execute a sql sentence like “UPDATE employes set status = 1
WHERE sex = 1”
if any know how to do it…
please tell me
thanks
hi everybody
i want to execute a sql sentence like “UPDATE employes set status = 1
WHERE sex = 1”
if any know how to do it…
please tell me
thanks
I believe that .find_by_sql will allow you to do pure sql queries
bypassing the ActiveRecord engine. Downside is you lose the bonuses it
gives you to prevent SQL injection attacks and single/double quoting
issues.
On 12/28/06, j. smith [email protected] wrote:
hi everybody
i want to execute a sql sentence like “UPDATE employes set status = 1
WHERE sex = 1”
Employee.update_all “status=1”, “sex=1”
On 12/28/06, Steve K. [email protected] wrote:
I believe that .find_by_sql will allow you to do pure sql queries
bypassing the ActiveRecord engine. Downside is you lose the bonuses it
gives you to prevent SQL injection attacks and single/double quoting
issues.
If you’re doing updates, it’s better to just do
ActiveRecord::Base.connection.execute “MY SQL HERE”
you can use a model class instead of AR::Base if you want there, it
doesn’t matter. Well actually it does, if your model class is using a
different connection then the default. But it doesn’t matter the vast
majority of the time ![]()
Pat
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs