@@ -569,6 +569,7 @@ def __init__(self, host=None, user=None, password="",
569
569
autocommit: Autocommit mode. None means use server default. (default: False)
570
570
local_infile: Boolean to enable the use of LOAD DATA LOCAL command. (default: False)
571
571
max_allowed_packet: Max size of packet sent to server in bytes. (default: 16MB)
572
+ Only used to limit size of "LOAD LOCAL INFILE" data packet smaller than default (16KB).
572
573
defer_connect: Don't explicitly connect on contruction - wait for connect call.
573
574
(default: False)
574
575
auth_plugin_map: A dict of plugin names to a class that processes that plugin.
@@ -676,7 +677,7 @@ def _config(key, arg):
676
677
self .socket = None
677
678
else :
678
679
self .connect ()
679
-
680
+
680
681
def _create_ssl_ctx (self , sslp ):
681
682
if isinstance (sslp , ssl .SSLContext ):
682
683
return sslp
@@ -1027,26 +1028,25 @@ def _execute_command(self, command, sql):
1027
1028
if isinstance (sql , text_type ):
1028
1029
sql = sql .encode (self .encoding )
1029
1030
1030
- # +1 is for command
1031
- chunk_size = min (self .max_allowed_packet , len (sql ) + 1 )
1031
+ packet_size = min (MAX_PACKET_LEN , len (sql ) + 1 ) # +1 is for command
1032
1032
1033
1033
# tiny optimization: build first packet manually instead of
1034
1034
# calling self..write_packet()
1035
- prelude = struct .pack ('<iB' , chunk_size , command )
1036
- packet = prelude + sql [:chunk_size - 1 ]
1035
+ prelude = struct .pack ('<iB' , packet_size , command )
1036
+ packet = prelude + sql [:packet_size - 1 ]
1037
1037
self ._write_bytes (packet )
1038
1038
if DEBUG : dump_packet (packet )
1039
1039
self ._next_seq_id = 1
1040
1040
1041
- if chunk_size < self . max_allowed_packet :
1041
+ if packet_size < MAX_PACKET_LEN :
1042
1042
return
1043
1043
1044
- sql = sql [chunk_size - 1 :]
1044
+ sql = sql [packet_size - 1 :]
1045
1045
while True :
1046
- chunk_size = min (self . max_allowed_packet , len (sql ))
1047
- self .write_packet (sql [:chunk_size ])
1048
- sql = sql [chunk_size :]
1049
- if not sql and chunk_size < self . max_allowed_packet :
1046
+ packet_size = min (MAX_PACKET_LEN , len (sql ))
1047
+ self .write_packet (sql [:packet_size ])
1048
+ sql = sql [packet_size :]
1049
+ if not sql and packet_size < MAX_PACKET_LEN :
1050
1050
break
1051
1051
1052
1052
def _request_authentication (self ):
@@ -1447,11 +1447,9 @@ def send_data(self):
1447
1447
1448
1448
try :
1449
1449
with open (self .filename , 'rb' ) as open_file :
1450
- chunk_size = conn .max_allowed_packet
1451
- packet = b""
1452
-
1450
+ packet_size = min (conn .max_allowed_packet , 16 * 1024 ) # 16KB is efficient enough
1453
1451
while True :
1454
- chunk = open_file .read (chunk_size )
1452
+ chunk = open_file .read (packet_size )
1455
1453
if not chunk :
1456
1454
break
1457
1455
conn .write_packet (chunk )
0 commit comments