def drop_column(table, col_name)
col_index = table.field_names.index(col_name)
with_write_lock(table.name) do
fptr = open(table.filename, 'r')
new_fptr = open(table.filename+'temp', 'w')
line = fptr.readline.chomp
if line[0..0] == 'Z'
header_rec = unencrypt_str(line[1..-1]).split('|')
header_rec.delete_at(col_index+3)
new_fptr.write('Z' + encrypt_str(header_rec.join('|')) +
"\n")
else
header_rec = line.split('|')
header_rec.delete_at(col_index+3)
new_fptr.write(header_rec.join('|') + "\n")
end
begin
while true
line = fptr.readline.chomp
if table.encrypted?
temp_line = unencrypt_str(line)
else
temp_line = line
end
rec = temp_line.split('|', -1)
rec.delete_at(col_index)
if table.encrypted?
new_fptr.write(encrypt_str(rec.join('|')) + "\n")
else
new_fptr.write(rec.join('|') + "\n")
end
end
rescue EOFError
end
fptr.close
new_fptr.close
File.delete(table.filename)
FileUtils.mv(table.filename+'temp', table.filename)
end
end