diff options
author | Bibiko <bibiko@eva.mpg.de> | 2009-06-11 12:33:13 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2009-06-11 12:33:13 +0000 |
commit | a4911754d0fba5909c5bb35157aff8032c47bc2b (patch) | |
tree | 9b5800d294ec69e1c13842aae28cbb4a28ffe445 | |
parent | c281b67fc313c54839b106b7910daa3c21ca297e (diff) | |
download | sequelpro-a4911754d0fba5909c5bb35157aff8032c47bc2b.tar.gz sequelpro-a4911754d0fba5909c5bb35157aff8032c47bc2b.tar.bz2 sequelpro-a4911754d0fba5909c5bb35157aff8032c47bc2b.zip |
• introduced these methods to CMMCPConnection
- (int) getMaxAllowedPacket;
- (BOOL) isMaxAllowedPacketEditable;
- (int) setMaxAllowedPacketTo:(int)newSize;
-rw-r--r-- | Source/CMMCPConnection.h | 3 | ||||
-rw-r--r-- | Source/CMMCPConnection.m | 51 |
2 files changed, 54 insertions, 0 deletions
diff --git a/Source/CMMCPConnection.h b/Source/CMMCPConnection.h index 962e315a..4b0330ec 100644 --- a/Source/CMMCPConnection.h +++ b/Source/CMMCPConnection.h @@ -96,6 +96,9 @@ - (void) keepAlive:(NSTimer *)theTimer; - (void) threadedKeepAlive; - (const char *) cStringFromString:(NSString *) theString usingEncoding:(NSStringEncoding) encoding; +- (int) getMaxAllowedPacket; +- (BOOL) isMaxAllowedPacketEditable; +- (int) setMaxAllowedPacketTo:(int)newSize; /* return server major version number or -1 on fail */ - (int)serverMajorVersion; diff --git a/Source/CMMCPConnection.m b/Source/CMMCPConnection.m index 1c54427a..540cfa8c 100644 --- a/Source/CMMCPConnection.m +++ b/Source/CMMCPConnection.m @@ -1042,6 +1042,57 @@ static void forcePingTimeout(int signalNumber) return (const char *)[theData bytes]; } +/* + * Retrieves max_allowed_packet size set as global variable. + * It returns -1 if it fails. + */ +- (int) getMaxAllowedPacket +{ + CMMCPResult * r; + r = [self queryString:@"SELECT @@global.max_allowed_packet" usingEncoding:mEncoding]; + if (![[self getLastErrorMessage] isEqualToString:@""]) { + if ([self isConnected]) + NSRunAlertPanel(@"Error", [NSString stringWithFormat:@"An error occured while retrieving max_allowed_packet size:\n\n%@", [self getLastErrorMessage]], @"OK", nil, nil); + return -1; + } + NSArray *a = [r fetchRowAsArray]; + if([a count]) + return [[a objectAtIndex:0] intValue]; + + return -1; +} + +/* + * It sets max_allowed_packet size to newSize and it returns + * max_allowed_packet after setting it to newSize for cross-checking + * if the maximal size was reached (e.g. set it to 4GB it'll return 1GB up to now). + * If something failed it return -1; + */ +- (int) setMaxAllowedPacketTo:(int)newSize +{ + + if(![self isMaxAllowedPacketEditable]) return [self getMaxAllowedPacket]; + + [self queryString:[NSString stringWithFormat:@"SET GLOBAL max_allowed_packet = %d", newSize] usingEncoding:mEncoding]; + if (![[self getLastErrorMessage] isEqualToString:@""]) { + if ([self isConnected]) + NSRunAlertPanel(@"Error", [NSString stringWithFormat:@"An error occured while setting max_allowed_packet size:\n\n%@", [self getLastErrorMessage]], @"OK", nil, nil); + } + + return [self getMaxAllowedPacket]; +} + + +/* + * It returns whether max_allowed_packet is setable for the user. + */ +- (BOOL) isMaxAllowedPacketEditable +{ + [self queryString:[NSString stringWithFormat:@"SET GLOBAL max_allowed_packet = %d", [self getMaxAllowedPacket]] usingEncoding:mEncoding]; + return ([[self getLastErrorMessage] isEqualToString:@""]); +} + + - (void) dealloc { [super dealloc]; |