Print warnings from load local

This commit is contained in:
Stacey Wrazien
2015-01-07 13:46:42 -05:00
parent 0ea120e29a
commit 5923e19578

View File

@@ -15,6 +15,7 @@ import socket
import struct import struct
import sys import sys
import re import re
import traceback
try: try:
import ssl import ssl
@@ -1245,11 +1246,22 @@ class LoadLocalFile(object):
self.filename = filename self.filename = filename
self.connection = connection 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): 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: if not self.connection.socket:
raise InterfaceError("(0, '')") raise InterfaceError("(0, '')")
seq_id = 2
try: try:
with open(self.filename, 'r') as open_file: with open(self.filename, 'r') as open_file:
chunk_size = MAX_PACKET_LEN chunk_size = MAX_PACKET_LEN
@@ -1257,7 +1269,6 @@ class LoadLocalFile(object):
packet = "" packet = ""
packet_size = 0 packet_size = 0
# sequence id is 2 as we already sent a query packet # sequence id is 2 as we already sent a query packet
seq_id = 2
for line in open_file: for line in open_file:
line_length = len(line) line_length = len(line)
@@ -1280,15 +1291,18 @@ class LoadLocalFile(object):
prelude = struct.pack('<i', packet_size)[:3] + int2byte(seq_id) prelude = struct.pack('<i', packet_size)[:3] + int2byte(seq_id)
packet = prelude + packet packet = prelude + packet
self.connection._write_bytes(packet) self.connection._write_bytes(packet)
# send the empty packet to signify we are done sending data
seq_id += 1 seq_id += 1
packet = struct.pack('<i', 0)[:3] + int2byte(seq_id)
self.connection._write_bytes(packet)
self.connection._read_ok_packet()
except IOError: except IOError:
raise OperationalError(1017, "Can't find file '{}'".format(self.filename)) raise OperationalError(1017, "Can't find file '{}'".format(self.filename))
finally:
# send the empty packet to signify we are done sending data
packet = struct.pack('<i', 0)[:3] + int2byte(seq_id)
self.connection._write_bytes(packet)
result = MySQLResult(self.connection)
result.read()
if result.warning_count > 0:
self._print_warnings()
# g:khuno_ignore='E226,E301,E701' # g:khuno_ignore='E226,E301,E701'