Result from ActiveRecord::Base.connection.execute(sql)

How can I find number of records processed by PostgreSQL after executing a SQL statement using ActiveRecord::Base Connection class?

temp_sql = "UPDATE table_a SET column_a ='abc' WHERE column_b = 1"
result = ActiveRecord::Base.establish_connection(@db).connection.execute(temp_sql)

Or can you suggest better way to do this. Please keep in mind that above update statement is a simple one to keep question brief. My real queries are "set based" and involves complex create temp tables, update, insert statements.


Found the answer in PG::Result class. It is cmd_tuples method;

temp_sql = "UPDATE table_a SET column_a ='abc' WHERE column_b = 1"
result = ActiveRecord::Base.establish_connection(@db).connection.execute(temp_sql)
number_of_records = result.cmd_tuples
链接地址: http://www.djcxy.com/p/67958.html

上一篇: 如何用std :: bind做到这一点?

下一篇: 来自ActiveRecord :: Base.connection.execute(sql)的结果