Class: MysqlPR::StmtRawRecord

Inherits:
Object
  • Object
show all
Defined in:
lib/mysql-pr/protocol.rb

Instance Method Summary collapse

Constructor Details

#initialize(packet, fields, encoding) ⇒ StmtRawRecord

Argument

pkt
Packet
fields
Array of Fields
encoding
Encoding


988
989
990
991
992
# File 'lib/mysql-pr/protocol.rb', line 988

def initialize(packet, fields, encoding)
  @packet = packet
  @fields = fields
  @encoding = encoding
end

Instance Method Details

#parse_record_packetObject Also known as: to_a

Parse statement result packet

Return

Array of Object

one record



997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
# File 'lib/mysql-pr/protocol.rb', line 997

def parse_record_packet
  @packet.utiny # skip first byte
  null_bit_map = @packet.read((@fields.length + 7 + 2) / 8).unpack1("b*")
  @fields.each_with_index.map do |f, i|
    if null_bit_map[i + 2] == "1"
      nil
    else
      unsigned = f.flags & Field::UNSIGNED_FLAG != 0
      v = Protocol.net2value(@packet, f.type, unsigned)
      if v.is_a?(Numeric) || v.is_a?(MysqlPR::Time)
        v
      elsif (f.type == Field::TYPE_BIT) || (f.charsetnr == Charset::BINARY_CHARSET_NUMBER)
        Charset.to_binary(v)
      else
        Charset.convert_encoding(v, @encoding)
      end
    end
  end
end