Class: BtrieveSearchBuffer
- Inherits:
-
Object
- Object
- BtrieveSearchBuffer
- Includes:
- Btrieve
- Defined in:
- lib/btrieve/btrieve_extended.rb
Constant Summary collapse
- COMPARISON =
{:equal=>1,:greater_than=>2,:less_than=>3, :not_equal=>4, :greater_than_or_equal=>5, :less_than_or_equal=>6}
- BOOLEAN =
{:and=>1, :or=>2}
Constants included from BtrCodes
BtrCodes::ABORT_TRANSACTION, BtrCodes::ACCELERATED_MODE, BtrCodes::BEGIN_TRANSACTION, BtrCodes::CLOSE, BtrCodes::DELETE, BtrCodes::END_TRANSACTION, BtrCodes::EOF, BtrCodes::EXCEPTION_MESSAGES, BtrCodes::EXCLUSIVE_MODE, BtrCodes::GET_DIRECT, BtrCodes::GET_EQUAL, BtrCodes::GET_EQUAL_KEY, BtrCodes::GET_FIRST, BtrCodes::GET_GREATER_THAN_OR_EQUAL, BtrCodes::GET_LESS_THAN_OR_EQUAL, BtrCodes::GET_NEXT, BtrCodes::GET_NEXT_EXTENDED, BtrCodes::GET_NEXT_KEY, BtrCodes::GET_POSITION, BtrCodes::GET_PREVIOUS, BtrCodes::INSERT, BtrCodes::KEY_NOT_FOUND, BtrCodes::LOCAL_ACCELERATED_MODE, BtrCodes::LOCAL_EXCLUSIVE_MODE, BtrCodes::LOCAL_NORMAL_MODE, BtrCodes::LOCAL_READ_ONLY_MODE, BtrCodes::MAX_DATATYPE, BtrCodes::NORMAL_MODE, BtrCodes::NO_CURRENCY_CHANGE, BtrCodes::NO_LOGICAL_CURRENCY_KEY, BtrCodes::NULL_BUFFER, BtrCodes::NULL_KEY, BtrCodes::OK, BtrCodes::OPEN, BtrCodes::POS_BLOCK_SIZE, BtrCodes::READ_ONLY_MODE, BtrCodes::RECORD_POSITION_SIZE, BtrCodes::REMOTE_ACCELERATED_MODE, BtrCodes::REMOTE_EXCLUSIVE_MODE, BtrCodes::REMOTE_NORMAL_MODE, BtrCodes::REMOTE_READ_ONLY_MODE, BtrCodes::RESET, BtrCodes::STEP_NEXT, BtrCodes::STEP_NEXT_EXTENDED, BtrCodes::STOP, BtrCodes::SYSTEM_LOG_KEY, BtrCodes::UPDATE, BtrCodes::VERIFY_MODE
Instance Method Summary collapse
- #get_encoded_buffer ⇒ Object
-
#initialize(table, filter, fields_to_return, records_to_fetch = 10, start_point = :next_record, max_reject_count = 0) ⇒ BtrieveSearchBuffer
constructor
A new instance of BtrieveSearchBuffer.
Methods included from Btrieve
Constructor Details
#initialize(table, filter, fields_to_return, records_to_fetch = 10, start_point = :next_record, max_reject_count = 0) ⇒ BtrieveSearchBuffer
Returns a new instance of BtrieveSearchBuffer.
6 7 8 9 10 11 12 13 |
# File 'lib/btrieve/btrieve_extended.rb', line 6 def initialize(table, filter, fields_to_return, records_to_fetch=10, start_point=:next_record, max_reject_count=0) @table=table @filter=filter @records_to_fetch=records_to_fetch @fields_to_return=fields_to_return @start_point = start_point == :current_record ? 'UC' : 'EG' @max_reject_count=max_reject_count end |
Instance Method Details
#get_encoded_buffer ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/btrieve/btrieve_extended.rb', line 15 def get_encoded_buffer filter_buff = [] @filter.each_with_index() do |token, i| is_expr = (i%2 == 0) if(is_expr) column = @table.schema[:columns][token[0]] comparison = COMPARISON[token[1]] right_operand = nil if(is_symbol?(token[2])) # We're comparing against a value stored in another field in this record comparison += 64 right_operand=[@table.schema[:columns][token[2]][:offset]].pack('S') else # We're comparing against a constant in the exact same format as the column itself right_operand=@table.pack_value(column, token[2]) right_operand=right_operand.gsub("\x00",' ') if [0,11,12,21].include?(column[:datatype]) end filter_item = [column[:datatype], column[:size], column[:offset], comparison, 0].pack('CSSCC') filter_item << right_operand filter_buff << filter_item else boolean = BOOLEAN[token] filter_buff.last[6..6]=[boolean].pack('C') end end num_logical_expressions = filter_buff.size result_descriptor=[@records_to_fetch, @fields_to_return.size].pack('SS') @fields_to_return.inject(result_descriptor) do |desc, field| column = @table.schema[:columns][field] desc << [column[:size], column[:offset]].pack('SS') desc end buffer_size=8+result_descriptor.size+filter_buff.join('').size search_buffer=[buffer_size, @start_point, @max_reject_count, num_logical_expressions].pack('Sa2SS') search_buffer << filter_buff.join('') << result_descriptor search_buffer end |