MCPcopy Create free account
hub / github.com/PyMySQL/PyMySQL / _execute_command

Method _execute_command

pymysql/connections.py:879–920  ·  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

877 return 0
878
879 def _execute_command(self, command, sql):
880 """
881 :raise InterfaceError: If the connection is closed.
882 :raise ValueError: If no username was specified.
883 """
884 if not self._sock:
885 raise err.InterfaceError(0, "")
886
887 # If the last query was unbuffered, make sure it finishes before
888 # sending new commands
889 if self._result is not None:
890 if self._result.unbuffered_active:
891 warnings.warn("Previous unbuffered result was left incomplete")
892 self._result._finish_unbuffered_query()
893 while self._result.has_next:
894 self.next_result()
895 self._result = None
896
897 if isinstance(sql, str):
898 sql = sql.encode(self.encoding)
899
900 packet_size = min(MAX_PACKET_LEN, len(sql) + 1) # +1 is for command
901
902 # tiny optimization: build first packet manually instead of
903 # calling self..write_packet()
904 prelude = struct.pack("<iB", packet_size, command)
905 packet = prelude + sql[: packet_size - 1]
906 self._write_bytes(packet)
907 if DEBUG:
908 dump_packet(packet)
909 self._next_seq_id = 1
910
911 if packet_size < MAX_PACKET_LEN:
912 return
913
914 sql = sql[packet_size - 1 :]
915 while True:
916 packet_size = min(MAX_PACKET_LEN, len(sql))
917 self.write_packet(sql[:packet_size])
918 sql = sql[packet_size:]
919 if not sql and packet_size < MAX_PACKET_LEN:
920 break
921
922 def _request_authentication(self):
923 # 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