lib/btrieve/btrieve_table.rb in beezwax-0.6.0 vs lib/btrieve/btrieve_table.rb in beezwax-0.6.1

- old
+ new

@@ -45,10 +45,12 @@ end # Finds an array of records in this table, using the specified index number, a key and a range of values. # If a block is passed in, the entries of this set are passed into this block one by one. Otherwise, # the set is returned to the caller. + # WARNING - NO UNIT TEST EXIST! + # TODO - Add a unit test for this method. def find_in_range(index_num, key, range, &block) index = @schema[:indices][index_num] columns = @schema[:columns] index_values = index.inject([]){|vals,akey|vals << (akey == key ? range.first : nil); vals} key_packer = index.inject("") do |packer, akey| @@ -78,10 +80,11 @@ end # Closes this btrieve table to conclude a sequence of BTR operation(s). def close btr_op(CLOSE, @pos_buffer, NULL_BUFFER, NULL_BUFFER, NULL_KEY) + @pos_buffer=Btrieve.create_string_buffer(POS_BLOCK_SIZE) end # Loops over the records of this BTR table and passes each record to the block passed in. def each_record(mode=NORMAL_MODE, &block) batch(mode) do @@ -149,12 +152,15 @@ end def find_in_unique_index(match, index_number=nil) finder(match, index_number) do |key_buffer, index| btr_record = BtrieveRecord.new(self) - batch(){ btr_op(GET_EQUAL, @pos_buffer, btr_record.data_buffer, key_buffer, index, [KEY_NOT_FOUND, OK, EOF]) } - btr_record.nil? ? nil : btr_record + open + btr_op(GET_EQUAL, @pos_buffer, btr_record.data_buffer, key_buffer, index, [KEY_NOT_FOUND, OK, EOF]) + btr_record = btr_record.nil? ? nil : btr_record.set_physical_position + close + btr_record end end def find_in_index(match, index_number=nil) finder(match, index_number) do |org_key_buffer, index| @@ -168,11 +174,11 @@ while(ops_result == OK) btr_record = BtrieveRecord.new(self) ops_result = btr_op(ops, @pos_buffer, btr_record.data_buffer, key_buffer, index, [OK, EOF]) break if(key_buffer!=org_key_buffer) ops=GET_NEXT - result << btr_record if(ops_result == OK) + result << btr_record.set_physical_position if(ops_result == OK) end end result end end @@ -180,8 +186,8 @@ def session s=BtrieveSession.get_session raise "Cannot manipulate a BtrieveTable when no BtrieveSession exists." if s.nil? s end - + end