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