From 5923e19578422993013f93b3a6c4ca6a0b95da57 Mon Sep 17 00:00:00 2001 From: Stacey Wrazien Date: Wed, 7 Jan 2015 13:46:42 -0500 Subject: [PATCH] Print warnings from load local --- pymysql/connections.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/pymysql/connections.py b/pymysql/connections.py index 9948a83..776f9f6 100644 --- a/pymysql/connections.py +++ b/pymysql/connections.py @@ -15,6 +15,7 @@ import socket import struct import sys import re +import traceback try: import ssl @@ -1245,11 +1246,22 @@ class LoadLocalFile(object): self.filename = filename self.connection = connection + def _print_warnings(self): + self.connection._execute_command(COMMAND.COM_QUERY, 'SHOW WARNINGS') + self.connection._read_query_result() + warnings = self.connection._result.rows + if warnings: + warning_source = list(traceback.extract_stack())[0] + print("{}:{}: {}".format(warning_source[0], warning_source[1], warning_source[3])) + for warning in warnings: + print(" Warning: {}".format(warning[2])) + def send_data(self): - """Send data packets from the local file""" + """Send data packets from the local file to the server""" if not self.connection.socket: raise InterfaceError("(0, '')") + seq_id = 2 try: with open(self.filename, 'r') as open_file: chunk_size = MAX_PACKET_LEN @@ -1257,7 +1269,6 @@ class LoadLocalFile(object): packet = "" packet_size = 0 # sequence id is 2 as we already sent a query packet - seq_id = 2 for line in open_file: line_length = len(line) @@ -1280,15 +1291,18 @@ class LoadLocalFile(object): prelude = struct.pack(' 0: + self._print_warnings() # g:khuno_ignore='E226,E301,E701'