Skip to content

Commit

Permalink
Fixing LOAD DATA LOCAL INFILE for SSCursor* types (#473)
Browse files Browse the repository at this point in the history
  • Loading branch information
srstrickland authored and methane committed Jun 8, 2016
1 parent ccc39e0 commit 30422b2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pymysql/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,10 @@ def init_unbuffered_query(self):
self._read_ok_packet(first_packet)
self.unbuffered_active = False
self.connection = None
elif first_packet.is_load_local_packet():
self._read_load_local_packet(first_packet)
self.unbuffered_active = False
self.connection = None
else:
self.field_count = first_packet.read_length_encoded_integer()
self._get_descriptions()
Expand Down
24 changes: 23 additions & 1 deletion pymysql/tests/test_load_local.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pymysql import OperationalError, Warning
from pymysql import cursors, OperationalError, Warning
from pymysql.tests import base

import os
Expand Down Expand Up @@ -42,6 +42,28 @@ def test_load_file(self):
finally:
c.execute("DROP TABLE test_load_local")

def test_unbuffered_load_file(self):
"""Test unbuffered load local infile with a valid file"""
conn = self.connections[0]
c = conn.cursor(cursors.SSCursor)
c.execute("CREATE TABLE test_load_local (a INTEGER, b INTEGER)")
filename = os.path.join(os.path.dirname(os.path.realpath(__file__)),
'data',
'load_local_data.txt')
try:
c.execute(
("LOAD DATA LOCAL INFILE '{0}' INTO TABLE " +
"test_load_local FIELDS TERMINATED BY ','").format(filename)
)
c.execute("SELECT COUNT(*) FROM test_load_local")
self.assertEqual(22749, c.fetchone()[0])
finally:
c.close()
conn.close()
conn.connect()
c = conn.cursor()
c.execute("DROP TABLE test_load_local")

def test_load_warnings(self):
"""Test load local infile produces the appropriate warnings"""
conn = self.connections[0]
Expand Down

0 comments on commit 30422b2

Please sign in to comment.