aboutsummaryrefslogtreecommitdiffstats
path: root/Source/CMMCPConnection.m
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2009-06-11 12:33:13 +0000
committerBibiko <bibiko@eva.mpg.de>2009-06-11 12:33:13 +0000
commita4911754d0fba5909c5bb35157aff8032c47bc2b (patch)
tree9b5800d294ec69e1c13842aae28cbb4a28ffe445 /Source/CMMCPConnection.m
parentc281b67fc313c54839b106b7910daa3c21ca297e (diff)
downloadsequelpro-a4911754d0fba5909c5bb35157aff8032c47bc2b.tar.gz
sequelpro-a4911754d0fba5909c5bb35157aff8032c47bc2b.tar.bz2
sequelpro-a4911754d0fba5909c5bb35157aff8032c47bc2b.zip
• introduced these methods to CMMCPConnection
- (int) getMaxAllowedPacket; - (BOOL) isMaxAllowedPacketEditable; - (int) setMaxAllowedPacketTo:(int)newSize;
Diffstat (limited to 'Source/CMMCPConnection.m')
-rw-r--r--Source/CMMCPConnection.m51
1 files changed, 51 insertions, 0 deletions
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];