Class: Mysql::StmtRawRecord

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

Overview

prepared statement raw record

Instance Method Summary collapse

Constructor Details

#initialize(packet, fields, encoding) ⇒ StmtRawRecord

Returns a new instance of StmtRawRecord.

Parameters:

  • pkt (Packet)
  • fields (Array of Fields)
  • encoding (Encoding)


882
883
884
# File 'lib/mysql/protocol.rb', line 882

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

Instance Method Details

#parse_record_packetArray<Object> Also known as: to_a

Parse statement result packet

Returns:

  • (Array<Object>)

    one record



888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
# File 'lib/mysql/protocol.rb', line 888

def parse_record_packet
  @packet.utiny  # skip first byte
  null_bit_map = @packet.read((@fields.length+7+2)/8).unpack1("b*")
  rec = @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.nil? or v.is_a? Numeric or v.is_a? Time or v.is_a? Date
        v
      elsif f.type == Field::TYPE_BIT
        Charset.to_binary(v)
      elsif v.is_a? String
        f.charsetnr == Charset::BINARY_CHARSET_NUMBER ? Charset.to_binary(v) : Charset.convert_encoding(v, @encoding)
      else
        v
      end
    end
  end
  rec
end