def set(recs, data)
update_rec = convert_input_data(data) unless data.is_a?(Proc)
updated_recs = []
recs.each do |rec|
temp_rec = rec.dup
if data.is_a?(Proc)
begin
data.call(temp_rec)
rescue NoMethodError
raise 'Invalid field name in code block: %s' % $!
end
else
@field_names.each { |fn| temp_rec[fn] = update_rec.fetch(fn,
temp_rec.send(fn)) }
end
raise 'Cannot update recno field!' unless \
rec.recno == temp_rec.recno
raise 'Cannot update internal fpos field!' unless \
rec.fpos == temp_rec.fpos
raise 'Cannot update internal line_length field!' unless \
rec.line_length == temp_rec.line_length
validate_input(temp_rec)
check_required_fields(temp_rec)
check_against_input_for_specials(temp_rec)
updated_recs << { :rec => @field_names.zip(@field_types
).collect { |fn, ft| convert_to_encoded_string(ft,
temp_rec.send(fn)) }, :fpos => rec.fpos,
:line_length => rec.line_length }
temp_rec.each { |r| r.write_to_file if r.is_a?(KBMemo) } if \
@field_types.include?(:Memo)
temp_rec.each { |r| r.write_to_file if r.is_a?(KBBlob) } if \
@field_types.include?(:Blob)
end
@db.engine.update_records(self, updated_recs)
return recs.size
end