Skip to content

Fixed load data infile file handle bug. #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions lib/mysql/connector/connection.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down