示例#1
0
 def _parse(self):
     buf = self.data
     (buf,self.field_count) = utils.read_int(buf,1)
     (buf,self.affected_rows) = utils.read_lc_int(buf)
     (buf,self.insert_id) = utils.read_lc_int(buf)
     (buf,self.server_status) = utils.read_int(buf,2)
     (buf,self.warning_count) = utils.read_int(buf,2)
     if buf:
         (buf,self.info_msg) = utils.read_lc_string(buf)
示例#2
0
 def _pkt_parse_ok(self, buf):
     """Parse a MySQL OK-packet"""
     ok = {}
     (buf,ok['field_count']) = utils.read_int(buf,1)
     (buf,ok['affected_rows']) = utils.read_lc_int(buf)
     (buf,ok['insert_id']) = utils.read_lc_int(buf)
     (buf,ok['server_status']) = utils.read_int(buf,2)
     (buf,ok['warning_count']) = utils.read_int(buf,2)
     if buf:
         (buf,ok['info_msg']) = utils.read_lc_string(buf)
     return ok
 def _pkt_parse_ok(self, buf):
     """Parse a MySQL OK-packet"""
     ok = {}
     (buf,ok['field_count']) = utils.read_int(buf,1)
     (buf,ok['affected_rows']) = utils.read_lc_int(buf)
     (buf,ok['insert_id']) = utils.read_lc_int(buf)
     (buf,ok['server_status']) = utils.read_int(buf,2)
     (buf,ok['warning_count']) = utils.read_int(buf,2)
     if buf:
         (buf,ok['info_msg']) = utils.read_lc_string(buf)
     return ok
示例#4
0
文件: event.py 项目: yelu/mysqlsub
 def __init__(self, packet, table_map, table_subscribed, ctl_conn):
     super(TableMapEvent, self).__init__(packet)
     self._payload = packet[24:]
     self._ctl_conn = ctl_conn
     head = self._payload
     
     head, self.table_id = utils.read_int(head, 6)
     # add or modify table map.
     if self.table_id not in table_map:
         table_map[self.table_id] = {"schema":None, "table":None, "column_schemas":[]}           
     if self.schema in table_subscribed and self.table in table_subscribed[self.schema]:
         table_map[self.table_id]["column_schemas"] = \
            self.__get_table_informations(self.schema, self.table)
            
     head, self.flags = utils.read_int(head, 2)
     head, schema_name_len = utils.read_int(head, 1)
     head, self.schema = utils.read_bytes(head, schema_name_len)
     self.schema = str(self.schema)
     table_map[self.table_id]["schema"] = self.schema
     head, _ = utils.read_bytes(head, 1) #filler
     head, table_name_len = utils.read_int(head, 1)
     head, self.table = utils.read_bytes(head, table_name_len)
     self.table = str(self.table)
     table_map[self.table_id]["table"] = self.table
     head, _ = utils.read_bytes(head, 1) #filler
     head, self.columns_cnt = utils.read_lc_int(head)
     head, column_types = utils.read_bytes(head, self.columns_cnt)
     for i in range(0, self.columns_cnt):
         schema = table_map[self.table_id]["column_schemas"][i]
         t = ord(column_types[i])
         schema["TYPE_ID"] = t
         head, _ = self.__read_metadata(t, schema, head)
示例#5
0
文件: event.py 项目: yelu/mysqlsub
 def __init__(self, packet, table_map, table_subscribed):
     super(RowsEvent, self).__init__(packet)
     self._payload = packet[23:]
     self._table_map = table_map
     self._table_subscribed = table_subscribed
     
     head = self._payload
     # header
     head, self.table_id = utils.read_int(head, 6)
     head, self.flags = utils.read_int(head, 2)
     # with MySQL 5.6.x there will be other data following.
     
     # body
     head, self.number_of_columns = utils.read_lc_int(head)
     columns_present_bitmap_len = (self.number_of_columns + 7) / 8
     head, columns_present_bitmap1 = utils.read_int(head, 
                                     columns_present_bitmap_len)
     if self.header.event_type == EventType.UPDATE_ROWS_EVENT:
         head, columns_present_bitmap2 = utils.read_int(head, 
                                         columns_present_bitmap_len)
     # read rows.
     null_bitmap_len = (self.number_of_columns + 7) / 8;
     head, null_bitmap = utils.read_int(head, null_bitmap_len)
     row = {}
     for i in range(self.number_of_columns):
         is_null = True if ((null_bitmap[i/8] >> (i%8)) & 0x01) else False
示例#6
0
    def parse_ok(self, packet):
        """Parse a MySQL OK-packet"""
        if not packet[4] == '\x00':
            raise errors.InterfaceError("Failed parsing OK packet.")

        ok = {}
        try:
            (packet, ok['field_count']) = utils.read_int(packet[4:], 1)
            (packet, ok['affected_rows']) = utils.read_lc_int(packet)
            (packet, ok['insert_id']) = utils.read_lc_int(packet)
            (packet, ok['server_status']) = utils.read_int(packet, 2)
            (packet, ok['warning_count']) = utils.read_int(packet, 2)
            if packet:
                (packet, ok['info_msg']) = utils.read_lc_string(packet)
        except ValueError:
            raise errors.InterfaceError("Failed parsing OK packet.")
        return ok
示例#7
0
    def parse_ok(self, packet):
        """Parse a MySQL OK-packet"""
        if not packet[4] == '\x00':
            raise errors.InterfaceError("Failed parsing OK packet.")

        ok = {}
        try:
            (packet, ok['field_count']) = utils.read_int(packet[4:], 1)
            (packet, ok['affected_rows']) = utils.read_lc_int(packet)
            (packet, ok['insert_id']) = utils.read_lc_int(packet)
            (packet, ok['server_status']) = utils.read_int(packet, 2)
            (packet, ok['warning_count']) = utils.read_int(packet, 2)
            if packet:
                (packet, ok['info_msg']) = utils.read_lc_string(packet)
        except ValueError:
            raise errors.InterfaceError("Failed parsing OK packet.")
        return ok
示例#8
0
 def _handle_resultset(self, buf):
     (buf,nrflds) = utils.read_lc_int(buf)
     if nrflds == 0:
         raise errors.InterfaceError('Empty result set.')
         
     fields = []
     for i in xrange(0,nrflds):
         buf = self._recv_packet()
         fields.append(self._pkt_parse_field(buf))
     
     buf = self._recv_packet()
     eof = self._handle_eof(buf)
     return (nrflds, fields, eof)
 def _handle_resultset(self, buf):
     (buf,nrflds) = utils.read_lc_int(buf)
     if nrflds == 0:
         raise errors.InterfaceError('Empty result set.')
         
     fields = []
     for i in xrange(0,nrflds):
         buf = self.conn.recv()
         fields.append(self._pkt_parse_field(buf))
     
     buf = self.conn.recv()
     eof = self._handle_eof(buf)
     return (nrflds, fields, eof)
示例#10
0
    def _handle_resultset(self, pkt):
        """Processes a resultset getting fields information.
        
        The argument pkt must be a protocol.Packet with length 1, a byte
        which contains the number of fields.
        """
        if not isinstance(pkt, PacketIn):
            raise ValueError("%s is not a protocol.PacketIn" % pkt)
        
        if len(pkt) == 1:
            (buf,nrflds) = utils.read_lc_int(pkt.data)
            
            # Get the fields
            fields = self._handle_fields(nrflds)

            buf = self.conn().recv()[0]
            eof = EOFPacket(buf)

            return (nrflds, fields, eof)
        else:
            raise errors.InterfaceError('Something wrong reading result after query.')
示例#11
0
 def parse_column_count(self, packet):
     """Parse a MySQL packet with the number of columns in result set"""
     return utils.read_lc_int(packet[4:])[1]
示例#12
0
 def parse_column_count(self, packet):
     """Parse a MySQL packet with the number of columns in result set"""
     return utils.read_lc_int(packet[4:])[1]