Class: Mysql::Protocol::ResultPacket

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

Overview

Result packet

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ ResultPacket

Returns a new instance of ResultPacket.



726
727
728
729
# File 'lib/mysql/protocol.rb', line 726

def initialize(*args)
  @field_count, @affected_rows, @insert_id, @server_status, @warning_count, @message, @session_track = args
  @session_track ||= {}
end

Instance Attribute Details

#affected_rowsObject (readonly)

Returns the value of attribute affected_rows.



724
725
726
# File 'lib/mysql/protocol.rb', line 724

def affected_rows
  @affected_rows
end

#field_countObject (readonly)

Returns the value of attribute field_count.



724
725
726
# File 'lib/mysql/protocol.rb', line 724

def field_count
  @field_count
end

#insert_idObject (readonly)

Returns the value of attribute insert_id.



724
725
726
# File 'lib/mysql/protocol.rb', line 724

def insert_id
  @insert_id
end

#messageObject (readonly)

Returns the value of attribute message.



724
725
726
# File 'lib/mysql/protocol.rb', line 724

def message
  @message
end

#server_statusObject (readonly)

Returns the value of attribute server_status.



724
725
726
# File 'lib/mysql/protocol.rb', line 724

def server_status
  @server_status
end

#session_trackObject (readonly)

Returns the value of attribute session_track.



724
725
726
# File 'lib/mysql/protocol.rb', line 724

def session_track
  @session_track
end

#warning_countObject (readonly)

Returns the value of attribute warning_count.



724
725
726
# File 'lib/mysql/protocol.rb', line 724

def warning_count
  @warning_count
end

Class Method Details

.parse(pkt) ⇒ Object



678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
# File 'lib/mysql/protocol.rb', line 678

def self.parse(pkt)
  field_count = pkt.lcb
  if field_count == 0
    affected_rows = pkt.lcb
    insert_id = pkt.lcb
    server_status = pkt.ushort
    warning_count = pkt.ushort
    message = pkt.lcs
    session_track = parse_session_track(pkt.lcs) if server_status & SERVER_SESSION_STATE_CHANGED
    message = pkt.lcs unless pkt.to_s.empty?

    return self.new(field_count, affected_rows, insert_id, server_status, warning_count, message, session_track)
  elsif field_count.nil?   # LOAD DATA LOCAL INFILE
    return self.new(nil, nil, nil, nil, nil, pkt.to_s)
  else
    return self.new(field_count)
  end
end

.parse_session_track(data) ⇒ Object



697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
# File 'lib/mysql/protocol.rb', line 697

def self.parse_session_track(data)
  session_track = {}
  pkt = Packet.new(data.to_s)
  until pkt.to_s.empty?
    type = pkt.lcb
    session_track[type] ||= []
    case type
    when SESSION_TRACK_SYSTEM_VARIABLES
      p = Packet.new(pkt.lcs)
      session_track[type].push [p.lcs, p.lcs]
    when SESSION_TRACK_SCHEMA
      pkt.lcb  # skip
      session_track[type].push pkt.lcs
    when SESSION_TRACK_STATE_CHANGE
      session_track[type].push pkt.lcs
    when SESSION_TRACK_GTIDS
      pkt.lcb  # skip
      pkt.lcb  # skip
      session_track[type].push pkt.lcs
    when SESSION_TRACK_TRANSACTION_CHARACTERISTICS, SESSION_TRACK_TRANSACTION_STATE
      pkt.lcb  # skip
      session_track[type].push pkt.lcs
    end
  end
  session_track
end