lib/btrieve/btrieve_table.rb in beezwax-0.1.3 vs lib/btrieve/btrieve_table.rb in beezwax-0.1.4
- old
+ new
@@ -92,14 +92,24 @@
indices = @schema[:indices]
indices.each_index(){ |index| return index if(indices[index].include_all?(keys)) }
raise Exception.new("No matching index for #{keys}")
end
+ INTEGER_TYPES=['TINYINT','SMALLINT','INTEGER','BIT','UTINYINT','USMALLINT','UINTEGER','UBIGINT']
+ FLOAT_TYPES=['REAL','DOUBLE']
def finder(match, index_number = nil, &block)
index_number ||= find_matching_index(match)
index = @schema[:indices][index_number]
columns = @schema[:columns]
- key_components = index.inject([]) { |vals, key| vals << match[key]; vals}
+ key_components = index.inject([]) do |vals, key|
+ datatype = BtrieveSchema.lookup(columns[key][:datatype], columns[key][:size])[:name]
+ puts "#{key}=>#{datatype}"
+ value = match[key]
+ value = value.to_f if FLOAT_TYPES.include?(datatype)
+ value = value.to_i if INTEGER_TYPES.include?(datatype)
+ vals << value
+ vals
+ end
key_packer = index.inject("") do |packer, key|
datatype = BtrieveSchema.lookup(columns[key][:datatype], columns[key][:size])
if(match[key] != nil)
packer += "#{datatype[:unpacker]}#{datatype[:name].match('CHAR') ? columns[key][:size] : ''}"
else