(0.1ms) begin transaction
/home/ivan/work/temp/packagetest/app/models/material_type.rb:7: warning: multiple values for a block parameter (0 for 1)
from /home/ivan/.rvm/gems/ruby-1.8.7-p371@rails304/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/database_statements.rb:192
(0.4ms) insert into material_types(id,name,code,parent_id,created_at,updated_at) values ('40', '40_name','code', 40, 'Fri Nov 29 11:08:54 +0800 2013', 'Fri Nov 29 11:08:54 +0800 2013')
(317.6ms) commit transaction
(0.1ms) begin transaction
/home/ivan/work/temp/packagetest/app/models/material_type.rb:7: warning: multiple values for a block parameter (0 for 1)
from /home/ivan/.rvm/gems/ruby-1.8.7-p371@rails304/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/database_statements.rb:192
(0.4ms) insert into material_types(id,name,code,parent_id,created_at,updated_at) values ('41', '41_name','code', 41, 'Fri Nov 29 11:08:54 +0800 2013', 'Fri Nov 29 11:08:54 +0800 2013')
(307.8ms) commit transaction
sql="insert into option (release_time, package_type, id, db_name, db_id) ..."@db.executesqlsql="select * from posts where title=? and name=? "@db.execute(sql,'标题','名称')
4 遍历结果集
123
@db.execute(sql,'标题','名称').eachdo|post|#...end
注意:如果没有找到数据会抛出异常,需要自行处理一下。
5 在单个事务中批量操作
12345
@db.transaction100.timesdo|i|@db.execute("insert into post where name = 'name_#{i}' ")end@db.commit
或者
12345
@db.transactiondo100.timesdo|i|@db.execute("insert into post where name = 'name_#{i}' ")endend