diff options
-rw-r--r-- | Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h | 98 | ||||
-rw-r--r-- | Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m | 23 | ||||
-rw-r--r-- | Frameworks/MCPKit/MCPFoundationKit/MCPConnectionDelegate.h | 81 | ||||
-rw-r--r-- | Frameworks/MCPKit/MCPFoundationKit/MCPKit.h | 4 | ||||
-rw-r--r-- | Frameworks/MCPKit/Support files/NSNotificationAdditions.h | 10 | ||||
-rw-r--r-- | Frameworks/MCPKit/Support files/NSNotificationAdditions.m | 50 | ||||
-rw-r--r-- | Source/SPConnectionDelegate.h | 4 | ||||
-rw-r--r-- | Source/SPDatabaseDocument.h | 1 | ||||
-rw-r--r-- | sequel-pro.xcodeproj/project.pbxproj | 16 |
9 files changed, 169 insertions, 118 deletions
diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h index 609830ce..ad30fa07 100644 --- a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h +++ b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h @@ -38,101 +38,21 @@ typedef struct { BOOL *lastPingSuccessPointer; } MCPConnectionPingDetails; -@protocol MCPConnectionProxy; - @class MCPResult, MCPStreamingResult; - -@interface NSObject (MCPConnectionDelegate) - -/** - * - */ -- (void)willQueryString:(NSString *)query connection:(id)connection; - -/** - * - */ -- (void)queryGaveError:(NSString *)error connection:(id)connection; - -/** - * - */ -- (void)showErrorWithTitle:(NSString *)error message:(NSString *)connection; - -/** - * - */ -- (NSString *)keychainPasswordForConnection:(id)connection; - -/** - * - */ -- (NSString *)onReconnectShouldSelectDatabase:(id)connection; - -/** - * - */ -- (void)noConnectionAvailable:(id)connection; - -/** - * - */ -- (MCPConnectionCheck)connectionLost:(id)connection; - -/** - * - */ -- (NSString *)connectionID; - -/** - * - */ -- (NSString *)database; - -/** - * - */ -- (BOOL)navigatorSchemaPathExistsForDatabase:(NSString*)dbname; - -/** - * - */ -- (NSArray*)allDatabaseNames; - -/** - * - */ -- (NSArray*)allSystemDatabaseNames; - -/** - * - */ -- (NSArray*)allTableNames; - -/** - * - */ -- (NSArray*)allViewNames; - -/** - * - */ -- (NSArray*)allSchemaKeys; - -@end +@protocol MCPConnectionProxy, MCPConnectionDelegate; @interface MCPConnection : NSObject { - MYSQL *mConnection; /* The inited MySQL connection. */ - BOOL mConnected; /* Reflect the fact that the connection is already in place or not. */ - NSStringEncoding mEncoding; /* The encoding used by MySQL server, to ISO-1 default. */ - NSTimeZone *mTimeZone; /* The time zone of the session. */ - NSUInteger mConnectionFlags; /* The flags to be used for the connection to the database. */ + MYSQL *mConnection; + BOOL mConnected; + NSStringEncoding mEncoding; + NSTimeZone *mTimeZone; + NSUInteger mConnectionFlags; - id delegate; /* Connection delegate */ + id <MCPConnectionDelegate> delegate; - /* Anything that performs a mysql_net_read is not thread-safe: mysql queries, pings */ - /* Always lock the connection first. Don't use this lock directly, use the lockConnection method! */ + // Anything that performs a mysql_net_read is not thread-safe: mysql queries, pings + // Always lock the connection first. Don't use this lock directly, use the lockConnection method! NSConditionLock *connectionLock; BOOL useKeepAlive; diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m index 15eaae82..f503db55 100644 --- a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m +++ b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m @@ -60,6 +60,25 @@ static BOOL sTruncateLongFieldInLogs = YES; @end +/** + * Note that these aren't actually delegate methods, but are defined because queryDbStructureWithUserInfo needs + * them. We define them here to supress compiler warnings. + * + * TODO: Remove along with queryDbStructureWithUserInfo + */ +@interface MCPConnection (MCPConnectionDelegate) + +- (NSString *)database; +- (NSString *)connectionID; + +- (NSArray *)allDatabaseNames; +- (NSArray *)allSystemDatabaseNames; +- (NSArray *)allTableNames; +- (NSArray *)allViewNames; +- (NSArray *)allSchemaKeys; + +@end + @implementation MCPConnection // Synthesize ivars @@ -2222,6 +2241,8 @@ void pingThreadCleanup(MCPConnectionPingDetails *pingDetails) /** * Updates the dict containing the structure of all available databases (mainly for completion/navigator) * executed on a new connection. + * + * TODO: Split this entire method out of MCPKit if possible */ - (void)queryDbStructureWithUserInfo:(NSDictionary*)userInfo { @@ -2331,7 +2352,7 @@ void pingThreadCleanup(MCPConnectionPingDetails *pingDetails) return; } - // Retrieve the tables and views for this database from SPTablesList (TODO: split out of MCPKit) + // Retrieve the tables and views for this database from SPTablesList NSMutableArray *tablesAndViews = [NSMutableArray array]; for (id aTable in [[[self delegate] valueForKeyPath:@"tablesListInstance"] allTableNames]) { NSDictionary *aTableDict = [NSDictionary dictionaryWithObjectsAndKeys: diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPConnectionDelegate.h b/Frameworks/MCPKit/MCPFoundationKit/MCPConnectionDelegate.h new file mode 100644 index 00000000..3cbba325 --- /dev/null +++ b/Frameworks/MCPKit/MCPFoundationKit/MCPConnectionDelegate.h @@ -0,0 +1,81 @@ +// +// $Id$ +// +// MCPConnectionDelegate.h +// MCPKit +// +// Created by Stuart Connolly (stuconnolly.com) on October 20, 2010. +// Copyright (c) 2010 Stuart Connolly. All rights reserved. +// +// Forked by the Sequel Pro team (sequelpro.com), April 2009 +// +// 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://mysql-cocoa.sourceforge.net/> +// More info at <http://code.google.com/p/sequel-pro/> + +@protocol MCPConnectionDelegate + +/** + * + * @param query + * @param connection + */ +- (void)willQueryString:(NSString *)query connection:(id)connection; + +/** + * + * @param error + * @param connection + */ +- (void)queryGaveError:(NSString *)error connection:(id)connection; + +/** + * + * + * @param error + * @param message + */ +- (void)showErrorWithTitle:(NSString *)error message:(NSString *)message; + +/** + * + * + * @param connection + */ +- (NSString *)keychainPasswordForConnection:(id)connection; + +/** + * + * + * @param connection + */ +- (NSString *)onReconnectShouldSelectDatabase:(id)connection; + +/** + * + * + * @param connection + */ +- (void)noConnectionAvailable:(id)connection; + +/** + * + * + * @param connection + */ +- (MCPConnectionCheck)connectionLost:(id)connection; + +@end diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPKit.h b/Frameworks/MCPKit/MCPFoundationKit/MCPKit.h index b83ebb69..57e6d62d 100644 --- a/Frameworks/MCPKit/MCPFoundationKit/MCPKit.h +++ b/Frameworks/MCPKit/MCPFoundationKit/MCPKit.h @@ -36,7 +36,9 @@ #import <MCPKit/MCPNumber.h> #import <MCPKit/MCPResultPlus.h> #import <MCPKit/MCPFastQueries.h> -#import <MCPKit/MCPConnectionProxy.h> #import <MCPKit/MCPGeometryData.h> +#import <MCPKit/MCPConnectionProxy.h> +#import <MCPKit/MCPConnectionDelegate.h> + #import "mysql.h" diff --git a/Frameworks/MCPKit/Support files/NSNotificationAdditions.h b/Frameworks/MCPKit/Support files/NSNotificationAdditions.h index 33c8ec10..7d0d6f9a 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 *)notification; +- (void)postNotificationOnMainThread:(NSNotification *)notification waitUntilDone:(BOOL)wait; -- (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 *)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; @end diff --git a/Frameworks/MCPKit/Support files/NSNotificationAdditions.m b/Frameworks/MCPKit/Support files/NSNotificationAdditions.m index f27a4d5c..d615231e 100644 --- a/Frameworks/MCPKit/Support files/NSNotificationAdditions.m +++ b/Frameworks/MCPKit/Support files/NSNotificationAdditions.m @@ -24,50 +24,64 @@ // More info at <http://code.google.com/p/sequel-pro/> #import "NSNotificationAdditions.h" -#import <pthread.h> +#import "pthread.h" @implementation NSNotificationCenter (NSNotificationCenterAdditions) -- (void) postNotificationOnMainThread:(NSNotification *) notification { - if( pthread_main_np() ) return [self postNotification:notification]; +- (void)postNotificationOnMainThread:(NSNotification *)notification +{ + if (pthread_main_np()) return [self postNotification:notification]; + [self postNotificationOnMainThread:notification waitUntilDone:NO]; } -- (void) postNotificationOnMainThread:(NSNotification *) notification waitUntilDone:(BOOL) wait { - if( pthread_main_np() ) return [self postNotification:notification]; - [[self class] performSelectorOnMainThread:@selector( _postNotification: ) withObject:notification waitUntilDone:wait]; +- (void)postNotificationOnMainThread:(NSNotification *)notification waitUntilDone:(BOOL)wait +{ + if (pthread_main_np()) return [self postNotification:notification]; + + [[self class] performSelectorOnMainThread:@selector(_postNotification:) withObject:notification waitUntilDone:wait]; } -+ (void) _postNotification:(NSNotification *) notification { ++ (void)_postNotification:(NSNotification *)notification +{ [[self defaultCenter] postNotification:notification]; } -- (void) postNotificationOnMainThreadWithName:(NSString *) name object:(id) object { - if( pthread_main_np() ) return [self postNotificationName:name object:object userInfo:nil]; +- (void)postNotificationOnMainThreadWithName:(NSString *)name object:(id)object +{ + if (pthread_main_np()) return [self postNotificationName:name object:object userInfo:nil]; + [self postNotificationOnMainThreadWithName:name object:object 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]; +- (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 *) name object:(id) object userInfo:(NSDictionary *) userInfo waitUntilDone:(BOOL) wait { - if( pthread_main_np() ) return [self postNotificationName:name object:object userInfo:userInfo]; +- (void)postNotificationOnMainThreadWithName:(NSString *)name object:(id)object userInfo:(NSDictionary *)userInfo waitUntilDone:(BOOL)wait +{ + if (pthread_main_np()) return [self postNotificationName:name object:object userInfo:userInfo]; 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"]; + + 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:wait]; + [[self class] performSelectorOnMainThread:@selector(_postNotificationName:) withObject:info waitUntilDone:wait]; [info release]; } -+ (void) _postNotificationName:(NSDictionary *) info { ++ (void)_postNotificationName:(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]; diff --git a/Source/SPConnectionDelegate.h b/Source/SPConnectionDelegate.h index 614ec7bc..deb28e68 100644 --- a/Source/SPConnectionDelegate.h +++ b/Source/SPConnectionDelegate.h @@ -25,6 +25,8 @@ #import "SPDatabaseDocument.h" -@interface SPDatabaseDocument (SPConnectionDelegate) +#import <MCPKit/MCPConnectionDelegate.h> + +@interface SPDatabaseDocument (SPConnectionDelegate) <MCPConnectionDelegate> @end diff --git a/Source/SPDatabaseDocument.h b/Source/SPDatabaseDocument.h index 36514dd2..5d48aa99 100644 --- a/Source/SPDatabaseDocument.h +++ b/Source/SPDatabaseDocument.h @@ -223,7 +223,6 @@ - (IBAction)openCurrentConnectionInNewWindow:(id)sender; - (NSArray *)allDatabaseNames; - (NSArray *)allSystemDatabaseNames; -- (BOOL)navigatorSchemaPathExistsForDatabase:(NSString*)dbname; - (NSDictionary *)getDbStructure; - (NSArray *)allSchemaKeys; diff --git a/sequel-pro.xcodeproj/project.pbxproj b/sequel-pro.xcodeproj/project.pbxproj index 34e88499..c9a2a49e 100644 --- a/sequel-pro.xcodeproj/project.pbxproj +++ b/sequel-pro.xcodeproj/project.pbxproj @@ -108,6 +108,7 @@ 17CC97F310B4ABE90034CD7A /* SPAboutController.m in Sources */ = {isa = PBXBuildFile; fileRef = 17CC97F210B4ABE90034CD7A /* SPAboutController.m */; }; 17CC97F710B4AC6C0034CD7A /* AboutPanel.xib in Resources */ = {isa = PBXBuildFile; fileRef = 17CC97F510B4AC6C0034CD7A /* AboutPanel.xib */; }; 17CC993B10B4C9C80034CD7A /* License.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 17CC993A10B4C9C80034CD7A /* License.rtf */; }; + 17DC8E75126F4AB600E9AAEC /* MCPConnectionDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 17DC8E74126F4AB600E9AAEC /* MCPConnectionDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; }; 17DCC5C7115C202700F89A00 /* MCPStringAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 17DCC5C5115C202700F89A00 /* MCPStringAdditions.h */; }; 17DD52B7115071D0007D8950 /* SPPrintTemplate.html in Resources */ = {isa = PBXBuildFile; fileRef = 17DD52B6115071D0007D8950 /* SPPrintTemplate.html */; }; 17DD52C3115074B3007D8950 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 17DD52C1115074B3007D8950 /* InfoPlist.strings */; }; @@ -658,6 +659,7 @@ 17CC97F610B4AC6C0034CD7A /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = Interfaces/English.lproj/AboutPanel.xib; sourceTree = "<group>"; }; 17CC993A10B4C9C80034CD7A /* License.rtf */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; path = License.rtf; sourceTree = "<group>"; }; 17DA04EA0FC1A7DA00D66140 /* Unit Tests-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "Unit Tests-Info.plist"; path = "Plists/Unit Tests-Info.plist"; sourceTree = "<group>"; }; + 17DC8E74126F4AB600E9AAEC /* MCPConnectionDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MCPConnectionDelegate.h; sourceTree = "<group>"; }; 17DCC5C5115C202700F89A00 /* MCPStringAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MCPStringAdditions.h; sourceTree = "<group>"; }; 17DD52B6115071D0007D8950 /* SPPrintTemplate.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = SPPrintTemplate.html; path = Templates/SPPrintTemplate.html; sourceTree = "<group>"; }; 17DD52B811507217007D8950 /* English */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; name = English; path = English.lproj/Credits.rtf; sourceTree = "<group>"; }; @@ -1503,12 +1505,12 @@ 17B7B5571016004500F057DE /* MCPFoundationKit */ = { isa = PBXGroup; children = ( + 17B7B5CA101603B200F057DE /* MCPKit.h */, 17B7B5C4101603B200F057DE /* MCPConnection.h */, 17B7B5C5101603B200F057DE /* MCPConnection.m */, 17B7B5C7101603B200F057DE /* MCPConstants.h */, 17B7B5C8101603B200F057DE /* MCPFastQueries.h */, 17B7B5C9101603B200F057DE /* MCPFastQueries.m */, - 17B7B5CA101603B200F057DE /* MCPKit.h */, 17B7B5CB101603B200F057DE /* MCPNull.h */, 17B7B5CC101603B200F057DE /* MCPNull.m */, 17B7B5CD101603B200F057DE /* MCPNumber.h */, @@ -1520,9 +1522,9 @@ 583B779710386B0200B21F7E /* MCPStreamingResult.h */, 583B779810386B0200B21F7E /* MCPStreamingResult.m */, 17DCC5C5115C202700F89A00 /* MCPStringAdditions.h */, - 17B7B5C6101603B200F057DE /* MCPConnectionProxy.h */, BCE97AEC125DC4EC0091ED3C /* MCPGeometryData.h */, BCE97AED125DC4EC0091ED3C /* MCPGeometryData.m */, + 17DC8E73126F4A8000E9AAEC /* Protocols */, ); path = MCPFoundationKit; sourceTree = "<group>"; @@ -1665,6 +1667,15 @@ name = "Category Additions"; sourceTree = "<group>"; }; + 17DC8E73126F4A8000E9AAEC /* Protocols */ = { + isa = PBXGroup; + children = ( + 17B7B5C6101603B200F057DE /* MCPConnectionProxy.h */, + 17DC8E74126F4AB600E9AAEC /* MCPConnectionDelegate.h */, + ); + name = Protocols; + sourceTree = "<group>"; + }; 17DD52D0115075B1007D8950 /* Help */ = { isa = PBXGroup; children = ( @@ -2285,6 +2296,7 @@ 17DCC5C7115C202700F89A00 /* MCPStringAdditions.h in Headers */, 58587B5A11B4437C00D129ED /* NSNotificationAdditions.h in Headers */, BCE97AEE125DC4EC0091ED3C /* MCPGeometryData.h in Headers */, + 17DC8E75126F4AB600E9AAEC /* MCPConnectionDelegate.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; |