diff options
Diffstat (limited to 'Frameworks/MCPKit')
-rw-r--r-- | Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m | 25 | ||||
-rw-r--r-- | Frameworks/MCPKit/MCPFoundationKit/MCPStringAdditions.h | 3 | ||||
-rw-r--r-- | Frameworks/MCPKit/MCPFoundationKit/MCPStringAdditions.m | 50 | ||||
-rw-r--r-- | Frameworks/MCPKit/MySQL/include/mysql.h | 3 | ||||
-rw-r--r-- | Frameworks/MCPKit/MySQL/include/mysql_com.h | 2 | ||||
-rw-r--r-- | Frameworks/MCPKit/MySQL/include/mysql_embed.h | 1 | ||||
-rw-r--r-- | Frameworks/MCPKit/MySQL/include/mysql_version.h | 4 | ||||
-rw-r--r-- | Frameworks/MCPKit/MySQL/lib/libmysqlclient.a | bin | 4561036 -> 4560292 bytes | |||
-rw-r--r-- | Frameworks/MCPKit/MySQL/lib/libmysqlclient_r.a | bin | 4595172 -> 4594252 bytes | |||
-rw-r--r-- | Frameworks/MCPKit/Support files/NSNotificationAdditions.h | 10 | ||||
-rw-r--r-- | Frameworks/MCPKit/Support files/NSNotificationAdditions.m | 78 |
11 files changed, 113 insertions, 63 deletions
diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m index 7efe4499..cf66a102 100644 --- a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m +++ b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m @@ -34,15 +34,14 @@ #import "MCPConnectionProxy.h" #import "MCPConnectionDelegate.h" #import "MCPStringAdditions.h" -#import "SPStringAdditions.h" -#import "RegexKitLite.h" +#import "RegexKitLite.h" // TODO: Remove along with queryDbStructureWithUserInfo #import "NSNotificationAdditions.h" #include <unistd.h> #include <mach/mach_time.h> #include <SystemConfiguration/SystemConfiguration.h> -const NSUInteger kMCPConnectionDefaultOption = CLIENT_COMPRESS | CLIENT_REMEMBER_OPTIONS | CLIENT_MULTI_RESULTS; +const NSUInteger kMCPConnectionDefaultOption = CLIENT_COMPRESS | CLIENT_REMEMBER_OPTIONS | CLIENT_MULTI_RESULTS | CLIENT_INTERACTIVE; const char *kMCPConnectionDefaultSocket = MYSQL_UNIX_ADDR; const char *kMCPSSLCipherList = "DHE-RSA-AES256-SHA:AES256-SHA:DHE-RSA-AES128-SHA:AES128-SHA:AES256-RMD:AES128-RMD:DES-CBC3-RMD:DHE-RSA-AES256-RMD:DHE-RSA-AES128-RMD:DHE-RSA-DES-CBC3-RMD:RC4-SHA:RC4-MD5:DES-CBC3-SHA:DES-CBC-SHA:EDH-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC-SHA"; const NSUInteger kMCPConnection_Not_Inited = 1000; @@ -166,7 +165,8 @@ static BOOL sTruncateLongFieldInLogs = YES; lastQueryErrorId = 0; lastQueryErrorMessage = nil; lastQueryAffectedRows = 0; - lastPingSuccess = NO; + lastPingSuccess = NO; + delegate = nil; delegateSupportsConnectionLostDecisions = NO; delegateResponseToWillQueryString = NO; @@ -525,7 +525,9 @@ static BOOL sTruncateLongFieldInLogs = YES; } while (![self tryLockConnection]); [self unlockConnection]; - if (mConnection->net.vio && mConnection->net.buff) mysql_close(mConnection); + // Only close the connection if it appears to still be active, and not reading or + // writing. This may result in a leak, but minimises crashes. + if (!mConnection->net.reading_or_writing && mConnection->net.vio && mConnection->net.buff) mysql_close(mConnection); mConnection = NULL; } @@ -580,6 +582,7 @@ static BOOL sTruncateLongFieldInLogs = YES; // Close the connection if it exists. if (mConnected) { + mConnected = NO; // Allow any pings or query cleanups to complete - within a time limit. uint64_t startTime_t, currentTime_t; @@ -594,11 +597,12 @@ static BOOL sTruncateLongFieldInLogs = YES; } while (![self tryLockConnection]); [self unlockConnection]; - if (mConnection->net.vio && mConnection->net.buff) mysql_close(mConnection); + // Only close the connection if it's not reading or writing - this may result + // in leaks, but minimises crashes. + if (!mConnection->net.reading_or_writing) mysql_close(mConnection); mConnection = NULL; } - mConnected = NO; isDisconnecting = NO; [self lockConnection]; @@ -2014,6 +2018,13 @@ void pingThreadCleanup(void *pingDetails) NSLog(@"Task cancelletion MySQL init failed."); } + // As the attempt may have taken up to the connection timeout, check lock status + // again, returning if nothing is required. + if ([self tryLockConnection]) { + [self unlockConnection]; + return; + } + // Reset the connection [self unlockConnection]; if (!isDisconnecting) [self reconnect]; diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPStringAdditions.h b/Frameworks/MCPKit/MCPFoundationKit/MCPStringAdditions.h index 36693703..bf57b789 100644 --- a/Frameworks/MCPKit/MCPFoundationKit/MCPStringAdditions.h +++ b/Frameworks/MCPKit/MCPFoundationKit/MCPStringAdditions.h @@ -40,4 +40,7 @@ static inline NSData *NSStringDataUsingLossyEncoding(NSString *self, NSInteger e @interface NSString (MCPStringAdditions) +- (NSString *)backtickQuotedString; +- (NSString *)tickQuotedString; + @end diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPStringAdditions.m b/Frameworks/MCPKit/MCPFoundationKit/MCPStringAdditions.m new file mode 100644 index 00000000..bd5b06cd --- /dev/null +++ b/Frameworks/MCPKit/MCPFoundationKit/MCPStringAdditions.m @@ -0,0 +1,50 @@ +// +// $Id$ +// +// MCPStringAdditions.m +// sequel-pro +// +// Created by Stuart Connolly (stuconnolly.com) on March 25, 2010 +// Copyright (c) 2010 Stuart Connolly. All rights reserved. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// More info at <http://code.google.com/p/sequel-pro/> + + + +@implementation NSString (MCPStringAdditions) + +/** + * Returns the string quoted with backticks as required for MySQL identifiers + * eg.: tablename => `tablename` + * my`table => `my``table` + */ +- (NSString *)backtickQuotedString +{ + return [NSString stringWithFormat: @"`%@`", [self stringByReplacingOccurrencesOfString:@"`" withString:@"``"]]; +} + +/** + * Returns the string quoted with ticks as required for MySQL identifiers + * eg.: tablename => 'tablename' + * my'table => 'my''table' + */ +- (NSString *)tickQuotedString +{ + return [NSString stringWithFormat: @"'%@'", [self stringByReplacingOccurrencesOfString:@"'" withString:@"''"]]; +} + +@end diff --git a/Frameworks/MCPKit/MySQL/include/mysql.h b/Frameworks/MCPKit/MySQL/include/mysql.h index dcf3e167..699bd1f1 100644 --- a/Frameworks/MCPKit/MySQL/include/mysql.h +++ b/Frameworks/MCPKit/MySQL/include/mysql.h @@ -224,7 +224,8 @@ struct st_mysql_options { enum mysql_status { - MYSQL_STATUS_READY,MYSQL_STATUS_GET_RESULT,MYSQL_STATUS_USE_RESULT + MYSQL_STATUS_READY, MYSQL_STATUS_GET_RESULT, MYSQL_STATUS_USE_RESULT, + MYSQL_STATUS_STATEMENT_GET_RESULT }; enum mysql_protocol_type diff --git a/Frameworks/MCPKit/MySQL/include/mysql_com.h b/Frameworks/MCPKit/MySQL/include/mysql_com.h index 7d3dd3d4..357519d5 100644 --- a/Frameworks/MCPKit/MySQL/include/mysql_com.h +++ b/Frameworks/MCPKit/MySQL/include/mysql_com.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2000 MySQL AB +/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/Frameworks/MCPKit/MySQL/include/mysql_embed.h b/Frameworks/MCPKit/MySQL/include/mysql_embed.h index 4a7fd3ef..a7d6e610 100644 --- a/Frameworks/MCPKit/MySQL/include/mysql_embed.h +++ b/Frameworks/MCPKit/MySQL/include/mysql_embed.h @@ -20,7 +20,6 @@ /* Things we don't need in the embedded version of MySQL */ /* TODO HF add #undef HAVE_VIO if we don't want client in embedded library */ -#undef HAVE_PSTACK /* No stacktrace */ #undef HAVE_OPENSSL #undef HAVE_SMEM /* No shared memory */ #undef HAVE_NDBCLUSTER_DB /* No NDB cluster */ diff --git a/Frameworks/MCPKit/MySQL/include/mysql_version.h b/Frameworks/MCPKit/MySQL/include/mysql_version.h index 736c2021..1eba2ede 100644 --- a/Frameworks/MCPKit/MySQL/include/mysql_version.h +++ b/Frameworks/MCPKit/MySQL/include/mysql_version.h @@ -9,11 +9,11 @@ #include <custom_conf.h> #else #define PROTOCOL_VERSION 10 -#define MYSQL_SERVER_VERSION "5.1.50" +#define MYSQL_SERVER_VERSION "5.1.57" #define MYSQL_BASE_VERSION "mysqld-5.1" #define MYSQL_SERVER_SUFFIX_DEF "" #define FRM_VER 6 -#define MYSQL_VERSION_ID 50150 +#define MYSQL_VERSION_ID 50157 #define MYSQL_PORT 3306 #define MYSQL_PORT_DEFAULT 0 #define MYSQL_UNIX_ADDR "/tmp/mysql.sock" diff --git a/Frameworks/MCPKit/MySQL/lib/libmysqlclient.a b/Frameworks/MCPKit/MySQL/lib/libmysqlclient.a Binary files differindex ab6939c1..969697fb 100644 --- a/Frameworks/MCPKit/MySQL/lib/libmysqlclient.a +++ b/Frameworks/MCPKit/MySQL/lib/libmysqlclient.a diff --git a/Frameworks/MCPKit/MySQL/lib/libmysqlclient_r.a b/Frameworks/MCPKit/MySQL/lib/libmysqlclient_r.a Binary files differindex b04f6c35..3c8d05fd 100644 --- a/Frameworks/MCPKit/MySQL/lib/libmysqlclient_r.a +++ b/Frameworks/MCPKit/MySQL/lib/libmysqlclient_r.a diff --git a/Frameworks/MCPKit/Support files/NSNotificationAdditions.h b/Frameworks/MCPKit/Support files/NSNotificationAdditions.h index 7d0d6f9a..82777ebb 100644 --- a/Frameworks/MCPKit/Support files/NSNotificationAdditions.h +++ b/Frameworks/MCPKit/Support files/NSNotificationAdditions.h @@ -25,11 +25,11 @@ @interface NSNotificationCenter (NSNotificationCenterAdditions) -- (void)postNotificationOnMainThread:(NSNotification *)notification; -- (void)postNotificationOnMainThread:(NSNotification *)notification waitUntilDone:(BOOL)wait; +- (void)postNotificationOnMainThread:(NSNotification *)aNotification; +- (void)postNotificationOnMainThread:(NSNotification *)aNotification waitUntilDone:(BOOL)shouldWaitUntilDone; -- (void)postNotificationOnMainThreadWithName:(NSString *)name object:(id)object; -- (void)postNotificationOnMainThreadWithName:(NSString *)name object:(id)object userInfo:(NSDictionary *)userInfo; -- (void)postNotificationOnMainThreadWithName:(NSString *)name object:(id)object userInfo:(NSDictionary *)userInfo waitUntilDone:(BOOL)wait; +- (void)postNotificationOnMainThreadWithName:(NSString *)aName object:(id)anObject; +- (void)postNotificationOnMainThreadWithName:(NSString *)aName object:(id)anObject userInfo:(NSDictionary *)aUserInfo; +- (void)postNotificationOnMainThreadWithName:(NSString *)aName object:(id)anObject userInfo:(NSDictionary *)aUserInfo waitUntilDone:(BOOL)shouldWaitUntilDone; @end diff --git a/Frameworks/MCPKit/Support files/NSNotificationAdditions.m b/Frameworks/MCPKit/Support files/NSNotificationAdditions.m index 9991c999..91b8134d 100644 --- a/Frameworks/MCPKit/Support files/NSNotificationAdditions.m +++ b/Frameworks/MCPKit/Support files/NSNotificationAdditions.m @@ -27,85 +27,71 @@ #import "pthread.h" @interface NSNotificationCenter (NSNotificationCenterAdditions_PrivateAPI) -+ (void)_postNotification:(NSNotification *)notification; -+ (void)_postNotificationName:(NSDictionary *)info; -+ (void)_postNotificationForwarder:(NSDictionary *)info; ++ (void)_postNotification:(NSNotification *)aNotification; ++ (void)_postNotificationWithDetails:(NSDictionary *)anInfoDictionary; @end @implementation NSNotificationCenter (NSNotificationCenterAdditions) -- (void)postNotificationOnMainThread:(NSNotification *)notification +- (void)postNotificationOnMainThread:(NSNotification *)aNotification { - if (pthread_main_np()) return [self postNotification:notification]; - - [self postNotificationOnMainThread:notification waitUntilDone:NO]; + if (pthread_main_np()) return [self postNotification:aNotification]; + + [self performSelectorOnMainThread:@selector(_postNotification:) withObject:aNotification waitUntilDone:NO]; } -- (void)postNotificationOnMainThread:(NSNotification *)notification waitUntilDone:(BOOL)shouldWaitUntilDone +- (void)postNotificationOnMainThread:(NSNotification *)aNotification waitUntilDone:(BOOL)shouldWaitUntilDone { - if (pthread_main_np()) return [self postNotification:notification]; - - [self performSelectorOnMainThread:@selector(_postNotification:) withObject:notification waitUntilDone:shouldWaitUntilDone]; + if (pthread_main_np()) return [self postNotification:aNotification]; + + [self performSelectorOnMainThread:@selector(_postNotification:) withObject:aNotification waitUntilDone:shouldWaitUntilDone]; } -- (void)postNotificationOnMainThreadWithName:(NSString *)name object:(id)object +- (void)postNotificationOnMainThreadWithName:(NSString *)aName object:(id)anObject { - if (pthread_main_np()) return [self postNotificationName:name object:object userInfo:nil]; - - [self postNotificationOnMainThreadWithName:name object:object userInfo:nil waitUntilDone:NO]; + if (pthread_main_np()) return [self postNotificationName:aName object:anObject userInfo:nil]; + + [self postNotificationOnMainThreadWithName:aName object:anObject userInfo:nil waitUntilDone:NO]; } -- (void)postNotificationOnMainThreadWithName:(NSString *)name object:(id)object userInfo:(NSDictionary *)userInfo -{ - if(pthread_main_np()) return [self postNotificationName:name object:object userInfo:userInfo]; - - [self postNotificationOnMainThreadWithName:name object:object userInfo:userInfo waitUntilDone:NO]; +- (void)postNotificationOnMainThreadWithName:(NSString *)aName object:(id)anObject userInfo:(NSDictionary *)aUserInfo +{ + if(pthread_main_np()) return [self postNotificationName:aName object:anObject userInfo:aUserInfo]; + + [self postNotificationOnMainThreadWithName:aName object:anObject userInfo:aUserInfo waitUntilDone:NO]; } -- (void)postNotificationOnMainThreadWithName:(NSString *)name object:(id)object userInfo:(NSDictionary *)userInfo waitUntilDone:(BOOL)shouldWaitUntilDone +- (void)postNotificationOnMainThreadWithName:(NSString *)aName object:(id)anObject userInfo:(NSDictionary *)aUserInfo waitUntilDone:(BOOL)shouldWaitUntilDone { - if (pthread_main_np()) return [self postNotificationName:name object:object userInfo:userInfo]; + if (pthread_main_np()) return [self postNotificationName:aName object:anObject userInfo:aUserInfo]; NSMutableDictionary *info = [[NSMutableDictionary allocWithZone:nil] initWithCapacity:3]; - - if (name) [info setObject:name forKey:@"name"]; - if (object) [info setObject:object forKey:@"object"]; - if (userInfo) [info setObject:userInfo forKey:@"userInfo"]; - [[self class] performSelectorOnMainThread:@selector(_postNotificationName:) withObject:info waitUntilDone:shouldWaitUntilDone]; + if (aName) [info setObject:aName forKey:@"name"]; + if (anObject) [info setObject:anObject forKey:@"object"]; + if (aUserInfo) [info setObject:aUserInfo forKey:@"userInfo"]; - [info release]; + [[self class] performSelectorOnMainThread:@selector(_postNotificationWithDetails:) withObject:info waitUntilDone:shouldWaitUntilDone]; } @end @implementation NSNotificationCenter (NSNotificationCenterAdditions_PrivateAPI) -+ (void)_postNotification:(NSNotification *)notification ++ (void)_postNotification:(NSNotification *)aNotification { - [[self defaultCenter] postNotification:notification]; + [[self defaultCenter] postNotification:aNotification]; } -+ (void)_postNotificationName:(NSDictionary *)info ++ (void)_postNotificationWithDetails:(NSDictionary *)anInfoDictionary { - NSString *name = [info objectForKey:@"name"]; - - id object = [info objectForKey:@"object"]; - - NSDictionary *userInfo = [info objectForKey:@"userInfo"]; + NSString *name = [anInfoDictionary objectForKey:@"name"]; + id object = [anInfoDictionary objectForKey:@"object"]; + NSDictionary *userInfo = [anInfoDictionary objectForKey:@"userInfo"]; [[self defaultCenter] postNotificationName:name object:object userInfo:userInfo]; -} - -+ (void)_postNotificationForwarder:(NSDictionary *)info -{ - NSString *name = [info objectForKey:@"name"]; - - id object = [info objectForKey:@"object"]; - - NSDictionary *userInfo = [info objectForKey:@"userInfo"]; - [[self defaultCenter] postNotificationName:name object:object userInfo:userInfo]; + [anInfoDictionary release]; } @end |