A
Aldric Giacomoni
Is there a way with the DBI gem to figure out how many rows were
touched? I have the following ugly and naive code which, of course,
doesn't give me the number of rows updated (but works like a charm
otherwise):
def run_query query
begin
dbh = DBI.connect( 'DBI:ODBC
ACS' )
statement_handle = dbh.prepare query
statement_handle.execute
rows = statement_handle.rows
statement_handle.finish
dbh.commit
rescue DBI:
atabaseError => e
puts "An error occurred"
puts "Error code: #{e.err}"
puts "Error message: #{e.errstr}"
dbh.rollback
ensure
# disconnect from server
dbh.disconnect if dbh
end
return rows rescue 0
end
def fix_ultrasounds
rows_updated = 0
[UPDATE_QUERY1, UPDATE_QUERY2].each do |q|
rows_updated += run_query q
end
puts "#{rows_updated} rows updated."
end
touched? I have the following ugly and naive code which, of course,
doesn't give me the number of rows updated (but works like a charm
otherwise):
def run_query query
begin
dbh = DBI.connect( 'DBI:ODBC
statement_handle = dbh.prepare query
statement_handle.execute
rows = statement_handle.rows
statement_handle.finish
dbh.commit
rescue DBI:
puts "An error occurred"
puts "Error code: #{e.err}"
puts "Error message: #{e.errstr}"
dbh.rollback
ensure
# disconnect from server
dbh.disconnect if dbh
end
return rows rescue 0
end
def fix_ultrasounds
rows_updated = 0
[UPDATE_QUERY1, UPDATE_QUERY2].each do |q|
rows_updated += run_query q
end
puts "#{rows_updated} rows updated."
end