Class: PostgresPR::Parse

Inherits:
Message show all
Defined in:
lib/postgres-pr/message.rb

Constant Summary

Constants inherited from Message

Message::MsgTypeMap

Instance Method Summary collapse

Methods inherited from Message

create, dump, fields, read, register_message_type

Constructor Details

#initialize(query, stmt_name = "", parameter_oids = []) ⇒ Parse

Returns a new instance of Parse.


387
388
389
# File 'lib/postgres-pr/message.rb', line 387

def initialize(query, stmt_name="", parameter_oids=[])
  @query, @stmt_name, @parameter_oids = query, stmt_name, parameter_oids
end

Instance Method Details

#dumpObject


391
392
393
394
395
396
397
398
399
# File 'lib/postgres-pr/message.rb', line 391

def dump
  sz = @stmt_name.size + 1 + @query.size + 1 + 2 + (4 * @parameter_oids.size)
  super(sz) do |buffer| 
    buffer.write_cstring(@stmt_name)
    buffer.write_cstring(@query)
    buffer.write_int16_network(@parameter_oids.size)
    @parameter_oids.each {|oid| buffer.write_int32_network(oid) }
  end
end

#parse(buffer) ⇒ Object


401
402
403
404
405
406
407
408
409
410
411
# File 'lib/postgres-pr/message.rb', line 401

def parse(buffer)
  super do 
    @stmt_name = buffer.read_cstring
    @query = buffer.read_cstring
    n_oids = buffer.read_int16_network
    @parameter_oids = (1..n_oids).collect {
      # TODO: zero means unspecified. map to nil?
      buffer.read_int32_network
    }
  end
end