2013-05-21 65 views
0

我需要做多次插入在database.It顯示我的錯誤所有的時間Ruby on Rails的:多插入的SQLite3 ::的SQLException:近「」:語法錯誤:

單一插入完美的作品:

CONN = ActiveRecord::Base.connection 

irb(main):271:0> inserts.push'(1,2,3,4,5,6)' 
=> ["(1,2,3,4,5,6)"] 

sql="INSERT INTO signals_rmas (groupsnorm_id, arraydb_id, probeset_id,signal,updated_at,created_at) VALUES #{inserts.join(", ")}" 

irb(main):276:0> CONN.execute sql 
    (32.3ms) INSERT INTO signals_rmas (groupsnorm_id, arraydb_id, probeset_id,signal,updated_at,created_at) VALUES (1,2,3,4,5,6) 
=> [] 

多個插入並不在所有的工作:

irb(main):272:0> inserts.push'(7,8,9,10,11,12)' 
=> ["(1,2,3,4,5,6)", "(7,8,9,10,11,12)"] 

irb(main):278:0>sql="INSERT INTO signals_rmas (groupsnorm_id, arraydb_id, probeset_id,signal,updated_at,created_at) VALUES #{inserts.join(", ")}" 
=> "INSERT INTO signals_rmas (groupsnorm_id, arraydb_id, probeset_id,signal,updated_at,created_at) VALUES (1,2,3,4,5,6), (7,8,9,10,11,12)" 

irb(main):279:0> CONN.execute sql 
    (0.4ms) INSERT INTO signals_rmas (groupsnorm_id, arraydb_id, probeset_id,signal,updated_at,created_at) VALUES (1,2,3,4,5,6), (7,8,9,10,11,12) 
ActiveRecord::StatementInvalid: SQLite3::SQLException: near ",": syntax error: INSERT INTO signals_rmas (groupsnorm_id, arraydb_id, probeset_id,signal,updated_at,created_at) VALUES (1,2,3,4,5,6), (7,8,9,10,11,12) 

問題是什麼?如何在SQL中插入多個記錄(創建記錄) 在此先感謝

回答

相關問題