select_all, or connection.delete statement, so as you can guess, you can
directly use any of these as you need.
CHAPTER 7 ?– WORKING WITH LEGACY SCHEMA 177
The following example shows each of these low-level operations in use (in a real-world
situation, you would want to include exception handling, because you are opening yourself up
to a large number of potential errors when you work with low-level operations):
# Code snippet showing use of low level connection statements
ins = ActiveRecord::Base.connection.insert("insert into
members(members_name, members_username, members_password)
values('Kevin', 'Falicon', 'CAKNTOBA')")
puts ins #=> should return the id of the record that was inserted
upd = ActiveRecord::Base.connection.update("update members set
members_password = 'CAKNTOBA1' where members_id = #{ins}")
puts upd #=> returns 0 regardless of if the update really ran or not!
sel = ActiveRecord::Base.connection.select_all("select * from members
where members_id = #{ins}")
sel.each do |rec|
puts "Name: #{rec["Members_Name"]} Username: #{rec["Members_Username"]"
end
del = ActiveRecord::Base.
Pages:
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404