diff --git a/lib/mysql/connector/connection.py b/lib/mysql/connector/connection.py index 2fb72401..c40ff8ef 100644 --- a/lib/mysql/connector/connection.py +++ b/lib/mysql/connector/connection.py @@ -1,4 +1,5 @@ -# Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2009, 2018, 2019 Oracle and/or its affiliates. +# All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License, version 2.0, as @@ -399,6 +400,8 @@ def _handle_load_data_infile(self, filename): """Handle a LOAD DATA INFILE LOCAL request""" try: data_file = open(filename, 'rb') + return self._handle_ok(self._send_data(data_file, + send_empty_packet=True)) except IOError: # Send a empty packet to cancel the operation try: @@ -408,9 +411,13 @@ def _handle_load_data_infile(self, filename): "MySQL Connection not available.") raise errors.InterfaceError( "File '{0}' could not be read".format(filename)) + finally: + try: + data_file.close() + except IOError, NameError: + # don't worry if the file was never opened + pass - return self._handle_ok(self._send_data(data_file, - send_empty_packet=True)) def _handle_result(self, packet): """Handle a MySQL Result