8000 Fixing LOAD DATA LOCAL INFILE for SSCursor* types (#473) · codepongo/PyMySQL@30422b2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 30422b2

Browse files
srstricklandmethane
authored andcommitted
Fixing LOAD DATA LOCAL INFILE for SSCursor* types (PyMySQL#473)
1 parent ccc39e0 commit 30422b2

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

pymysql/connections.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,10 @@ def init_unbuffered_query(self):
13191319
self._read_ok_packet(first_packet)
13201320
self.unbuffered_active = False
13211321
self.connection = None
1322+
elif first_packet.is_load_local_packet():
1323+
self._read_load_local_packet(first_packet)
1324+
self.unbuffered_active = False
1325+
self.connection = None
13221326
else:
13231327
self.field_count = first_packet.read_length_encoded_integer()
13241328
self._get_descriptions()

pymysql/tests/test_load_local.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pymysql import OperationalError, Warning
1+
from pymysql import cursors, OperationalError, Warning
22
from pymysql.tests import base
33

44
import os
@@ -42,6 +42,28 @@ def test_load_file(self):
4242
finally:
4343
c.execute("DROP TABLE test_load_local")
4444

45+
def test_unbuffered_load_file(self):
46+
"""Test unbuffered load local infile with a valid file"""
47+
conn = self.connections[0]
48+
c = conn.cursor(cursors.SSCursor)
49+
c.execute("CREATE TABLE test_load_local (a INTEGER, b INTEGER)")
50+
filename = os.path.join(os.path.dirname(os.path.realpath(__file__)),
51+
'data',
52+
'load_local_data.txt')
53+
try:
54+
c.execute(
55+
("LOAD DATA LOCAL INFILE '{0}' INTO TABLE " +
56+
"test_load_local FIELDS TERMINATED BY ','").format(filename)
57+
)
58+
c.execute("SELECT COUNT(*) FROM test_load_local")
59+
self.assertEqual(22749, c.fetchone()[0])
60+
finally:
61+
c.close()
62+
conn.close()
63+
conn.connect()
64+
c = conn.cursor()
65+
c.execute("DROP TABLE test_load_local")
66+
4567
def test_load_warnings(self):
4668
"""Test load local infile produces the appropriate warnings"""
4769
conn = self.connections[0]

0 commit comments

Comments
 (0)
0