:raise InterfaceError: If the connection is closed. :raise ValueError: If no username was specified.
(self, command, sql)
| 857 | return 0 |
| 858 | |
| 859 | def _execute_command(self, command, sql): |
| 860 | """ |
| 861 | :raise InterfaceError: If the connection is closed. |
| 862 | :raise ValueError: If no username was specified. |
| 863 | """ |
| 864 | if not self._sock: |
| 865 | raise err.InterfaceError(0, "") |
| 866 | |
| 867 | # If the last query was unbuffered, make sure it finishes before |
| 868 | # sending new commands |
| 869 | if self._result is not None: |
| 870 | if self._result.unbuffered_active: |
| 871 | warnings.warn("Previous unbuffered result was left incomplete") |
| 872 | self._result._finish_unbuffered_query() |
| 873 | while self._result.has_next: |
| 874 | self.next_result() |
| 875 | self._result = None |
| 876 | |
| 877 | if isinstance(sql, str): |
| 878 | sql = sql.encode(self.encoding) |
| 879 | |
| 880 | packet_size = min(MAX_PACKET_LEN, len(sql) + 1) # +1 is for command |
| 881 | |
| 882 | # tiny optimization: build first packet manually instead of |
| 883 | # calling self..write_packet() |
| 884 | prelude = struct.pack("<iB", packet_size, command) |
| 885 | packet = prelude + sql[: packet_size - 1] |
| 886 | self._write_bytes(packet) |
| 887 | if DEBUG: |
| 888 | dump_packet(packet) |
| 889 | self._next_seq_id = 1 |
| 890 | |
| 891 | if packet_size < MAX_PACKET_LEN: |
| 892 | return |
| 893 | |
| 894 | sql = sql[packet_size - 1 :] |
| 895 | while True: |
| 896 | packet_size = min(MAX_PACKET_LEN, len(sql)) |
| 897 | self.write_packet(sql[:packet_size]) |
| 898 | sql = sql[packet_size:] |
| 899 | if not sql and packet_size < MAX_PACKET_LEN: |
| 900 | break |
| 901 | |
| 902 | def _request_authentication(self): |
| 903 | # https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::HandshakeResponse |
no test coverage detected