aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/CMMCPConnection.h3
-rw-r--r--Source/CMMCPConnection.m51
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];