Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rubygems'
- require 'fastercsv'
- require 'active_record'
- # connect to the database (sqlite in this case)
- ActiveRecord::Base.establish_connection({
- :adapter => "oracle",
- :username => "my_uname",
- :password => "my_pass",
- :database => "10.0.0.1"
- })
- class PcoPhonebook < ActiveRecord::Base
- set_table_name "PCO_PHONEBOOK"
- set_primary_key "serviceid"
- end
- cnt = 0
- increment_cnt = 0
- FasterCSV.foreach("phonebook.csv") do |row|
- phonebook_entry = PcoPhonebook.find(:first, :conditions => [ "serviceid = ? AND phone = ?", row[0], row[1] ])
- if phonebook_entry != nil
- phonebook_entry.description = row[3]
- phonebook_entry.save
- else
- new_phonebook_entry = PcoPhonebook.new
- new_phonebook_entry.phone = row[1]
- new_phonebook_entry.type = row[2]
- new_phonebook_entry.description = row[3]
- new_phonebook_entry.save
- end
- cnt += 1
- increment_cnt += 1
- if increment_cnt == 100
- puts 'Records processed: ' + cnt.to_s
- increment_cnt = 0
- end
- end
Add Comment
Please, Sign In to add comment