示例#1
0
 def _close_stmt(self, stmt_id):
     """
     Destroy a prepared statement. The statement handle becomes invalid.
     """
     with util.DataPacker(self) as p:
         p.pack('<BI', 0x19, stmt_id)
     yield defer.succeed(True)
示例#2
0
    def _prepare(self, query):
        with util.DataPacker(self) as p:
            p.write('\x16')
            p.write(query)

        result = yield self.read_result(is_prepare=True)
        defer.returnValue(result)
示例#3
0
    def _ping(self):
        with util.DataPacker(self) as p:
            p.write('\x0e')

        result = yield self.read_result()
        import pprint
        pprint.pprint(result)
示例#4
0
    def do_handshake(self):
        self.resetTimeout()
        t = yield self.read_header()
        protocol_version, = yield t.unpack('<B')
        yield t.read_cstring()  # server_version
        thread_id, scramble_buf = yield t.unpack('<I8sx')
        capabilities, language, status = yield t.unpack('<HBH')
        #print hex(capabilities)
        capabilities ^= capabilities & 32
        capabilities |= 0x30000
        if self.database:
            capabilities |= 1 << 3  # CLIENT_CONNECT_WITH_DB
        yield t.read(13)
        scramble_buf += yield t.read(12)  # The last byte is a NUL
        yield t.read(1)

        scramble_response = _xor(
            sha1(scramble_buf +
                 sha1(sha1(self.password).digest()).digest()).digest(),
            sha1(self.password).digest())

        with util.DataPacker(self) as p:
            p.pack('<IIB23x', capabilities, 2**23, language)
            p.write_cstring(self.username)
            p.write_lcs(scramble_response)
            if self.database:
                p.write_cstring(self.database)

        result = yield self.read_result()
        defer.returnValue(result)
示例#5
0
    def query(self, query, read_result=False):
        "A query with no response data"
        self.debug_query = query
        with util.DataPacker(self) as p:
            p.write('\x03')
            p.write(query)

        ret = yield self.read_result()
        defer.returnValue(ret)
示例#6
0
    def _fetch(self, stmt_id, rows, types):
        with util.DataPacker(self) as p:
            p.pack('<BII', 0x1c, stmt_id, rows)

        rows = []
        while True:
            result = yield self.read_result(data_types=types)
            # TODO: We should check whether this result indicates that there
            # are no rows for us to fetch; then rather than hanging forever we
            # should immediately return to the application code.  Perhaps one
            # of read_result's cases will already cover this eventuality and we
            # can just inspect it here.
            if result.get('is_eof'):
                more_rows = not result['flags'] & 128
                break
            rows.append(result)

        defer.returnValue((rows, more_rows))
示例#7
0
    def select_db(self, database):
        with util.DataPacker(self) as p:
            p.write('\x02')
            p.write(database)

        yield self.read_result()
示例#8
0
 def _execute(self, stmt_id):
     with util.DataPacker(self) as p:
         p.pack('<BIBIB', 0x17, stmt_id, 1, 1, 1)
     result = yield self.read_result(read_rows=False)
     defer.returnValue([d['type'] for d in result['fields']])