Note that there are some explanatory texts on larger screens.

plurals
  1. PODisable key autogeneration whil importing with Ruby Activerecord Extensions
    text
    copied!<p>I'm trying to use ar-extensions gem to import records from a CSV file into an Oracle table and it is generating the value for the key column via sequence but that value is in my file and I need it to stay like that, is there any way of disabling key auto generation?</p> <p>This is my code, prepared for a Cucumber task that had to load initial data for a test:</p> <pre><code> 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=&gt;"oracle_enhanced", :host=&gt;"192.168.202.123", :port=&gt;"1521", :database=&gt;"XE", :username=&gt;"xxx", :password=&gt;"xxx") #Connect Logger to Active Record ActiveRecord::Base.logger = logger class Oacm &lt; 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 &lt;&lt; " " &lt;&lt; arg2.to_s end Then(/^it should be loaded$/) do preparedRecord = [] CSV.foreach(fileName, :headers =&gt; true) do |row| hashedRow = row.to_hash puts hashedRow #Oacm.id_acm = hashedRow["id_acm"] preparedRecord &lt;&lt; Oacm.new(hashedRow) #puts preparedRecord.to_s end #puts preparedRecord.to_s Oacm.import preparedRecord, :validate =&gt; true end </code></pre> <p>This is the error message I get: <code>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)</code></p> <p>Thank you </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload