ar-extensions gem を使用して CSV ファイルから Oracle テーブルにレコードをインポートしようとしていますが、シーケンスを介してキー列の値を生成していますが、その値は私のファイルにあり、そのままにしておく必要があります。キーの自動生成を無効にする方法はありますか?
これは、テスト用の初期データをロードする必要のある Cucumber タスク用に準備された私のコードです。
require 'rubygems'
require 'active_record'
require 'CSV'
require 'ar-extensions'
#Logger Objects are handy for finding out why imports crash
logger = Logger.new('import.log')
#Set the Logger level to Info to prevent boring debug messages
logger.level = Logger::INFO
fileName = " "
tableName = " "
validate = true
ActiveRecord::Base::establish_connection(
:adapter=>"oracle_enhanced",
:host=>"192.168.202.123",
:port=>"1521",
:database=>"XE",
:username=>"xxx",
:password=>"xxx")
#Connect Logger to Active Record
ActiveRecord::Base.logger = logger
class Oacm < ActiveRecord::Base
self.table_name = "OACM"
#self.set_primary_key "id_acm"
self.set_sequence_name :id_acm
attr_accessible :id_acm
attr_accessible :descr
attr_accessible :gp_acm_type_fk
attr_accessible :chan_fk
attr_accessible :dt_start
attr_accessible :dt_end
attr_accessible :ext_code_ref
attr_accessible :flg_burn
attr_accessible :layout_code
attr_accessible :max_num
attr_accessible :flg_dpl
attr_accessible :flg_def
attr_accessible :flg_state
attr_accessible :usr_ins
attr_accessible :ts_ins
attr_accessible :usr_del
attr_accessible :ts_del
attr_accessible :usr_upd
attr_accessible :ts_upd
attr_accessible :ver_no
attr_accessible :ord_no
attr_accessible :cpccchk
attr_accessible :ts_dpl
attr_accessible :ts_dpl
end
def cpccchk_before_type_cast
cpccchk
end
Given(/^a file named "(.*?)" containing all "(.*?)" data$/) do |arg1, arg2|
fileName = arg1
tableName = arg2
#puts arg1.to_s << " " << arg2.to_s
end
Then(/^it should be loaded$/) do
preparedRecord = []
CSV.foreach(fileName, :headers => true) do |row|
hashedRow = row.to_hash
puts hashedRow
#Oacm.id_acm = hashedRow["id_acm"]
preparedRecord << Oacm.new(hashedRow)
#puts preparedRecord.to_s
end
#puts preparedRecord.to_s
Oacm.import preparedRecord, :validate => true
end
これは私が得るエラーメッセージです:
OCIError: ORA-02289: sequence does not exist: INSERT INTO "OACM" ("ID_ACM","DESCR","GP_ACM_TYPE_FK","CHAN_FK","DT_START","DT_END","EXT_CODE_REF","FLG_BURN","LAYOUT_CODE","MAX_NUM","FLG_DPL","FLG_DEF","FLG_STATE","USR_INS","TS_INS","USR_DEL","TS_DEL","USR_UPD","TS_UPD","VER_NO","ORD_NO","CPCCCHK","TS_DPL") VALUES(id_acm.nextval,'DESCR','001','001',TO_DATE('01-APR-10','YYYY-MM-DD HH24:MI:SS'),TO_DATE('30-APR-11','YYYY-MM-DD HH24:MI:SS'),'','0','2',0,'3','','0',NULL,NULL,NULL,NULL,3,TO_TIMESTAMP('13-APR-11 18:21:24','YYYY-MM-DD HH24:MI:SS:FF6'),0,NULL,NULL,TO_TIMESTAMP('3','YYYY-MM-DD HH24:MI:SS:FF6')) (ActiveRecord::StatementInvalid)
ありがとうございました