From a4911754d0fba5909c5bb35157aff8032c47bc2b Mon Sep 17 00:00:00 2001 From: Bibiko Date: Thu, 11 Jun 2009 12:33:13 +0000 Subject: =?UTF-8?q?=E2=80=A2=20introduced=20these=20methods=20to=20CMMCPCo?= =?UTF-8?q?nnection=20-=20(int)=20getMaxAllowedPacket;=20-=20(BOOL)=20isMa?= =?UTF-8?q?xAllowedPacketEditable;=20-=20(int)=20setMaxAllowedPacketTo:(in?= =?UTF-8?q?t)newSize;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/CMMCPConnection.h | 3 +++ Source/CMMCPConnection.m | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) (limited to 'Source') 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]; -- cgit v1.2.3