From e1af7c62ee26b33be9ced00561bda8873ada8fc6 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Wed, 17 Jun 2009 21:59:45 +0000 Subject: =?UTF-8?q?=E2=80=A2=20some=20improvement=20to=20speed=20up=20quer?= =?UTF-8?q?yString:=20-=20caching=20of=20delegate=20&&=20respondsToSelecto?= =?UTF-8?q?r=20-=20use=20clock()=20to=20calculate=20query's=20execution=20?= =?UTF-8?q?time=20=E2=80=A2=20converting=20to=20cString:=20if=20utf8=20enc?= =?UTF-8?q?oding=20make=20usage=20of=20UTF8String=20=E2=80=A2=20added=20to?= =?UTF-8?q?=20StringAddition=20to=20display=20=C2=B5s=20for=20a=20timeInte?= =?UTF-8?q?rvall?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/CMMCPConnection.m | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'Source/CMMCPConnection.m') diff --git a/Source/CMMCPConnection.m b/Source/CMMCPConnection.m index 5d5cf52e..7dc8804f 100644 --- a/Source/CMMCPConnection.m +++ b/Source/CMMCPConnection.m @@ -261,6 +261,7 @@ static void forcePingTimeout(int signalNumber); [self timeZone]; // Getting the timezone used by the server. isMaxAllowedPacketEditable = [self isMaxAllowedPacketEditable]; + if (![self fetchMaxAllowedPacket]) { [self setLastErrorMessage:nil]; if (connectionTunnel) { @@ -699,7 +700,7 @@ static void forcePingTimeout(int signalNumber); - (CMMCPResult *)queryString:(NSString *) query usingEncoding:(NSStringEncoding) encoding { CMMCPResult *theResult = nil; - NSDate *queryStartDate; + float queryStartTime; const char *theCQuery; unsigned long theCQueryLength; int queryResultCode; @@ -722,9 +723,11 @@ static void forcePingTimeout(int signalNumber); } [self stopKeepAliveTimer]; + + queryStartTime = clock(); // Inform the delegate about the query - if (delegate && [delegate respondsToSelector:@selector(willQueryString:)]) { + if (delegateResponseToWillQueryString) { [delegate willQueryString:query]; } @@ -736,11 +739,11 @@ static void forcePingTimeout(int signalNumber); // Check query length against max_allowed_packet; if it is larger, the // query would error, so if max_allowed_packet is editable for the user // increase it for the current session and reconnect. - if([self getMaxAllowedPacket] < theCQueryLength) { + if(maxAllowedPacketSize < theCQueryLength) { if(isMaxAllowedPacketEditable) { - currentMaxAllowedPacket = [self getMaxAllowedPacket]; + currentMaxAllowedPacket = maxAllowedPacketSize; [self setMaxAllowedPacketTo:strlen(theCQuery)+1024 resetSize:NO]; [self reconnect]; @@ -748,7 +751,7 @@ static void forcePingTimeout(int signalNumber); NSString *errorMessage = [NSString stringWithFormat:NSLocalizedString(@"The query length of %d bytes is larger than max_allowed_packet size (%d).", @"error message if max_allowed_packet < query size"), - theCQueryLength, [self getMaxAllowedPacket]]; + theCQueryLength, maxAllowedPacketSize]; // Write a log entry and update the connection error messages for those uses that check it if ([delegate respondsToSelector:@selector(queryGaveError:)]) [delegate queryGaveError:errorMessage]; @@ -779,9 +782,8 @@ static void forcePingTimeout(int signalNumber); // Run (or re-run) the query, timing the execution time of the query - note // that this time will include network lag. - queryStartDate = [NSDate date]; queryResultCode = mysql_real_query(mConnection, theCQuery, theCQueryLength); - lastQueryExecutionTime = [[NSDate date] timeIntervalSinceDate:queryStartDate]; + lastQueryExecutionTime = (clock() - queryStartTime)/CLOCKS_PER_SEC; // On success, capture the results if (0 == queryResultCode) { @@ -929,6 +931,7 @@ static void forcePingTimeout(int signalNumber); - (void)setDelegate:(id)object { delegate = object; + delegateResponseToWillQueryString = (delegate && [delegate respondsToSelector:@selector(willQueryString:)]); } /* Getting the currently used time zone (in communication with the DB server). */ @@ -1130,7 +1133,11 @@ static void forcePingTimeout(int signalNumber) */ - (const char *) cStringFromString:(NSString *) theString usingEncoding:(NSStringEncoding) encoding { - NSMutableData *theData; + + if(encoding == NSUTF8StringEncoding) + return [theString UTF8String]; + + NSMutableData *theData; if (! theString) { return (const char *)NULL; @@ -1226,7 +1233,7 @@ static void forcePingTimeout(int signalNumber) */ - (int) setMaxAllowedPacketTo:(int)newSize resetSize:(BOOL)reset { - if(![self isMaxAllowedPacketEditable] || newSize < 1024) return [self getMaxAllowedPacket]; + if(![self isMaxAllowedPacketEditable] || newSize < 1024) return maxAllowedPacketSize; mysql_query(mConnection, [[NSString stringWithFormat:@"SET GLOBAL max_allowed_packet = %d", newSize] UTF8String]); // Inform the user via a log entry about that change according to reset value @@ -1236,7 +1243,7 @@ static void forcePingTimeout(int signalNumber) else [delegate queryGaveError:[NSString stringWithFormat:@"Query too large; max_allowed_packet temporarily set to %d for the current session to allow query to succeed", newSize]]; - return [self getMaxAllowedPacket]; + return maxAllowedPacketSize; } -- cgit v1.2.3