Example #1
0
    def read_result(self, is_prepare=False, read_rows=True, data_types=None):
        self.resetTimeout()
        t = yield self.read_header()
        field_count = yield t.read_lcb()
        ret = {}
        if field_count == util._EOF:
            ret = yield self.read_eof(read_header=False)
        elif field_count == 0:
            if is_prepare:
                ret["stmt_id"], ret["columns"], ret["parameters"], ret["warning_count"] = yield t.unpack("<IHHxH")
                if ret["parameters"]:
                    ret["placeholders"] = yield self.read_fields()
                ret["fields"] = yield self.read_fields()
            elif data_types is not None:
                nulls = yield t.read((len(data_types) + 7) // 8)
                nulls = util.unpack_little_endian(nulls) >> 2
                cols = []
                for type in data_types:
                    if nulls & 1:
                        cols.append(None)
                    elif type in typemap:
                        val = yield t.read(typemap[type])
                        if type == 4:
                            val, = struct.unpack("<f", val)
                        elif type == 5:
                            val, = struct.unpack("<d", val)
                        elif type == 12:
                            val = datetime.datetime(*struct.unpack("<xHBBBBB", val)).strftime("%Y-%m-%d %H:%M:%S")
                        else:
                            val = util.unpack_little_endian(val)
                        cols.append(val)
                    else:
                        cols.append((yield t.read_lcs()))
                    nulls >>= 1
                ret["cols"] = cols
                ret["x"] = yield t.read_rest()
            else:
                ret["affected_rows"] = yield t.read_lcb()
                ret["insert_id"] = yield t.read_lcb()
                ret["server_status"], ret["warning_count"] = yield t.unpack("<HH")
                ret["message"] = yield t.read_rest()
        elif field_count == 0xFF:
            errno, sqlstate = yield t.unpack("<Hx5s")
            message = yield t.read_rest()
            raise error.MySQLError(message, errno, sqlstate, self.debug_query)
        else:
            if t:
                ret["extra"] = yield t.read_lcb()
            ret["fields"] = yield self.read_fields()
            if read_rows:
                ret["rows"] = yield self.read_rows(field_count)
                ret["eof"] = yield self.read_eof(read_header=False)

        defer.returnValue(ret)
Example #2
0
 def read_result(self, is_prepare=False, read_rows=True, data_types=None):
     self.resetTimeout()
     t = yield self.read_header()
     field_count = yield t.read_lcb()
     ret = {}
     if field_count == util._EOF:
         ret = yield self.read_eof(read_header=False)
     elif field_count == 0:
         if is_prepare:
             ret['stmt_id'], ret['columns'], ret['parameters'], ret[
                 'warning_count'] = yield t.unpack('<IHHxH')
             if ret['parameters']:
                 ret['placeholders'] = yield self.read_fields()
             ret['fields'] = yield self.read_fields()
         elif data_types is not None:
             nulls = yield t.read((len(data_types) + 7) // 8)
             nulls = util.unpack_little_endian(nulls) >> 2
             cols = []
             for type in data_types:
                 if nulls & 1:
                     cols.append(None)
                 elif type in typemap:
                     val = yield t.read(typemap[type])
                     if type == 4:
                         val, = struct.unpack('<f', val)
                     elif type == 5:
                         val, = struct.unpack('<d', val)
                     elif type == 12:
                         try:
                             val = datetime.datetime(
                                 *struct.unpack("<xHBBBBB", val)).strftime(
                                     '%Y-%m-%d %H:%M:%S')
                         except Exception, e:
                             print "CRITICAL: Caught exception in txmysql when trying",
                             print "to decode datetime value %r" % (val, ),
                             print "exception follows, returning None to application",
                             print e
                             val = None
                     else:
                         val = util.unpack_little_endian(val)
                     cols.append(val)
                 else:
                     cols.append((yield t.read_lcs()))
                 nulls >>= 1
             ret['cols'] = cols
             ret['x'] = yield t.read_rest()
         else:
             ret['affected_rows'] = yield t.read_lcb()
             ret['insert_id'] = yield t.read_lcb()
             ret['server_status'], ret['warning_count'] = yield t.unpack(
                 '<HH')
             ret['message'] = yield t.read_rest()
Example #3
0
 def read_result(self, is_prepare=False, read_rows=True, data_types=None):
     self.resetTimeout()
     t = yield self.read_header()
     field_count = yield t.read_lcb()
     ret = {}
     if field_count == util._EOF:
         ret = yield self.read_eof(read_header=False)
     elif field_count == 0:
         if is_prepare:
             ret['stmt_id'], ret['columns'], ret['parameters'], ret['warning_count'] = yield t.unpack('<IHHxH')
             if ret['parameters']:
                 ret['placeholders'] = yield self.read_fields()
             ret['fields'] = yield self.read_fields()
         elif data_types is not None:
             nulls = yield t.read((len(data_types) + 9) // 8)
             nulls = util.unpack_little_endian(nulls) >> 2
             cols = []
             for type in data_types:
                 if nulls & 1:
                     cols.append(None)
                 elif type in typemap:
                     val = yield t.read(typemap[type])
                     if type == 4:
                         val, = struct.unpack('<f', val)
                     elif type == 5:
                         val, = struct.unpack('<d', val)
                     elif type == 12:
                         try:
                             val = datetime.datetime(*struct.unpack("<xHBBBBB",val)).strftime('%Y-%m-%d %H:%M:%S')
                         except Exception, e:
                             print "CRITICAL: Caught exception in txmysql when trying",
                             print "to decode datetime value %r" % (val,),
                             print "exception follows, returning None to application",
                             print e
                             val = None
                     else:
                         val = util.unpack_little_endian(val)
                     cols.append(val)
                 else:
                     cols.append((yield t.read_lcs()))
                 nulls >>= 1
             ret['cols'] = cols
             ret['x'] = yield t.read_rest()
         else:
             ret['affected_rows'] = yield t.read_lcb()
             ret['insert_id'] = yield t.read_lcb()
             ret['server_status'], ret['warning_count'] = yield t.unpack('<HH')
             ret['message'] = yield t.read_rest()
Example #4
0
 def _read_header(self, data):
     length, _ = struct.unpack('<3sB', data)
     length = util.unpack_little_endian(length)
     def cb(data):
         log.msg('unhandled packet: %r' % (data,))
         return self._read_header, 4
     return cb, length
Example #5
0
    def _read_header(self, data):
        length, _ = struct.unpack('<3sB', data)
        length = util.unpack_little_endian(length)

        def cb(data):
            log.msg('unhandled packet: %r' % (data, ))
            return self._read_header, 4

        return cb, length
Example #6
0
 def read_header(self):
     length, seq = yield self.unpack('<3sB')
     self.sequence = seq + 1
     length = util.unpack_little_endian(length)
     defer.returnValue(util.LengthTracker(self, length))
Example #7
0
 def read_header(self):
     length, seq = yield self.unpack('<3sB')
     self.sequence = seq + 1
     length = util.unpack_little_endian(length)
     defer.returnValue(util.LengthTracker(self, length))