Skip to content

Commit

Permalink
Make Max Packet Size detection more robust (issue with recent sphinx …
Browse files Browse the repository at this point in the history
…versions) #2653
  • Loading branch information
dmoagx committed Jan 10, 2017
1 parent 95c2949 commit 164af9b
Showing 1 changed file with 11 additions and 10 deletions.
Expand Up @@ -97,13 +97,15 @@ @implementation SPMySQLConnection (Max_Packet_Size_Private_API)
*/ */
- (void)_updateMaxQuerySize - (void)_updateMaxQuerySize
{ {

// Determine which query to run based on server version // Determine which query to run based on server version
NSString *packetQueryString; NSString *packetQueryString;
NSUInteger resultCol;
if ([self serverMajorVersion] == 3) { if ([self serverMajorVersion] == 3) {
packetQueryString = @"SHOW VARIABLES LIKE 'max_allowed_packet'"; packetQueryString = @"SHOW VARIABLES LIKE 'max_allowed_packet'";
resultCol = 1;
} else { } else {
packetQueryString = @"SELECT @@global.max_allowed_packet"; packetQueryString = @"SELECT @@global.max_allowed_packet";
resultCol = 0;
} }


// Make a standard query to the server to retrieve the information // Make a standard query to the server to retrieve the information
Expand All @@ -115,17 +117,16 @@ - (void)_updateMaxQuerySize
[result setReturnDataAsStrings:YES]; [result setReturnDataAsStrings:YES];


// Get the maximum size string // Get the maximum size string
NSString *maxQuerySizeString = nil; NSString *maxQuerySizeString = [[result getRowAsArray] objectAtIndex:resultCol];
if ([self serverMajorVersion] == 3) {
maxQuerySizeString = [[result getRowAsArray] objectAtIndex:1];
} else {
maxQuerySizeString = [[result getRowAsArray] objectAtIndex:0];
}


// If a valid size was returned, update the instance variable NSInteger _maxQuerySize = maxQuerySizeString ? [maxQuerySizeString integerValue] : 0;
if (maxQuerySizeString) { //see #2653
maxQuerySize = (NSUInteger)[maxQuerySizeString integerValue]; if(_maxQuerySize < 34) { // the max_allowed_packet query above has at least 34 bytes and succeeded, so any value less than that would be nonsense
NSLog(@"Query for max_allowed_packet returned invalid or implausible value: %ld (raw value: %@) (on %@)", _maxQuerySize, maxQuerySizeString, [self serverVersionString]);
return;
} }
// If a valid size was returned, update the instance variable
maxQuerySize = (NSUInteger)_maxQuerySize;
} }


/** /**
Expand Down

0 comments on commit 164af9b

Please sign in to comment.