Example #1
0
    def read_text_result(self, sock, count=1):
        """Read MySQL text result

        Reads all or given number of rows from the socket.

        Returns a tuple with 2 elements: a list with all rows and
        the EOF packet.
        """
        rows = []
        eof = None
        rowdata = None
        i = 0
        while True:
            if eof is not None:
                break
            if i == count:
                break
            packet = sock.recv()
            if packet.startswith('\xff\xff\xff'):
                datas = [packet[4:]]
                packet = sock.recv()
                while packet.startswith('\xff\xff\xff'):
                    datas.append(packet[4:])
                    packet = sock.recv()
                if packet[4] == '\xfe':
                    eof = self.parse_eof(packet)
                else:
                    datas.append(packet[4:])
                rowdata = utils.read_lc_string_list(''.join(datas))
            elif packet[4] == '\xfe':
                eof = self.parse_eof(packet)
                rowdata = None
            else:
                eof = None
                rowdata = utils.read_lc_string_list(packet[4:])
            if eof is None and rowdata is not None:
                rows.append(rowdata)
            i += 1
        return (rows, eof)
Example #2
0
    def read_text_result(self, sock, count=1):
        """Read MySQL text result

        Reads all or given number of rows from the socket.

        Returns a tuple with 2 elements: a list with all rows and
        the EOF packet.
        """
        rows = []
        eof = None
        rowdata = None
        i = 0
        while True:
            if eof is not None:
                break
            if i == count:
                break
            packet = sock.recv()
            if packet.startswith(b'\xff\xff\xff'):
                datas = [packet[4:]]
                packet = sock.recv()
                while packet.startswith(b'\xff\xff\xff'):
                    datas.append(packet[4:])
                    packet = sock.recv()
                if packet[4] == 254:
                    eof = self.parse_eof(packet)
                else:
                    datas.append(packet[4:])
                rowdata = utils.read_lc_string_list(''.join(datas))
            elif packet[4] == 254:
                eof = self.parse_eof(packet)
                rowdata = None
            else:
                eof = None
                rowdata = utils.read_lc_string_list(packet[4:])
            if eof is None and rowdata is not None:
                rows.append(rowdata)
            i += 1
        return (rows, eof)
Example #3
0
    def result_get_row(self):
        """Get data for 1 row
        
        Get one row's data. Should be called after getting the field
        descriptions.

        Returns a tuple with 2 elements: a row's data and the
        EOF packet.
        """
#        buf = self.conn.recv()[0]
        buf = (yield self.conn.recv())[0]
        if self.is_eof(buf):
            eof = protocol.EOFPacket(buf)
            rowdata = None
        else:
            eof = None
            rowdata = utils.read_lc_string_list(buf[4:])
#        return (rowdata, eof)
        yield (rowdata, eof)