MCPcopy Index your code
hub / github.com/PyMySQL/PyMySQL / _execute_command

Method _execute_command

pymysql/connections.py:859–900  ·  view source on GitHub ↗

:raise InterfaceError: If the connection is closed. :raise ValueError: If no username was specified.

(self, command, sql)

Source from the content-addressed store, hash-verified

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

Callers 9

_send_autocommit_modeMethod · 0.95
beginMethod · 0.95
commitMethod · 0.95
rollbackMethod · 0.95
show_warningsMethod · 0.95
select_dbMethod · 0.95
queryMethod · 0.95
pingMethod · 0.95
set_character_setMethod · 0.95

Calls 5

next_resultMethod · 0.95
_write_bytesMethod · 0.95
write_packetMethod · 0.95
dump_packetFunction · 0.85

Tested by

no test coverage detected