aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2009-07-21 16:47:11 +0000
committerstuconnolly <stuart02@gmail.com>2009-07-21 16:47:11 +0000
commit8b8f3e6cea540b17262aadf6d97a8ad28fe41c03 (patch)
treead6bb7f53b03924aa24d0cf5822a27b3bd453592 /Source
parent383863f98dfc488db0181e01d39da1bb025d421b (diff)
downloadsequelpro-8b8f3e6cea540b17262aadf6d97a8ad28fe41c03.tar.gz
sequelpro-8b8f3e6cea540b17262aadf6d97a8ad28fe41c03.tar.bz2
sequelpro-8b8f3e6cea540b17262aadf6d97a8ad28fe41c03.zip
Merge framework integration branch back to trunk. Summary of changes:
- Includes all custom code from subclasses CMMCPConnection and CMMCPResult, meaning they have subsequently been removed from the project. - All previous Sequel Pro specific code in the above subclasses has been removed in favour of the delegate (currently set to TableDocumet) informing the framework of such information. - All references to CMMCPConnection and CMMCPResult have subsequently been changed to MCPConnection and MCPResult. - Framework includes MySQL 5.1.36 client libraries and source headers. - Framework is now built as a 4-way (32/64 bit, i386/PPC arch) binary. - All import references to <MCPKit_bundled/MCPKit_bundled.h> have been changed to <MCPKit/MCPKit.h>. - New script 'build-mysql-client.sh' can be used to build the MySQL client libraries from the MySQL source. See the script's header for a list of available options or run it with no arguments to display it's usage. Note that there are still a few changes to be made to the framework with regard to removing Sequel Pro specific calls to the delegate. These however can be made later on as they have no effect on functionality and are merely design changes. Also, note that any future development done on the framework should be made to be as 'generic' as possible, with no Sequel Pro specific references. This should allow the framework to be integrated into another project without the need for SP specific code.
Diffstat (limited to 'Source')
-rw-r--r--Source/CMCopyTable.h2
-rw-r--r--Source/CMCopyTable.m3
-rw-r--r--Source/CMMCPConnection.h137
-rw-r--r--Source/CMMCPConnection.m1364
-rw-r--r--Source/CMMCPResult.h54
-rw-r--r--Source/CMMCPResult.m640
-rw-r--r--Source/CMTextView.h9
-rw-r--r--Source/CMTextView.m4
-rw-r--r--Source/CustomQuery.h15
-rw-r--r--Source/CustomQuery.m15
-rw-r--r--Source/KeyChain.m5
-rw-r--r--Source/SPArrayAdditions.h1
-rw-r--r--Source/SPConnectionController.h20
-rw-r--r--Source/SPConnectionController.m38
-rw-r--r--Source/SPDataAdditions.h1
-rw-r--r--Source/SPDataCellFormatter.h3
-rw-r--r--Source/SPDatabaseData.h7
-rw-r--r--Source/SPDatabaseData.m14
-rw-r--r--Source/SPEditSheetTextView.h5
-rw-r--r--Source/SPEditSheetTextView.m1
-rw-r--r--Source/SPExportController.h11
-rw-r--r--Source/SPExportController.m6
-rw-r--r--Source/SPExtendedTableInfo.h7
-rw-r--r--Source/SPExtendedTableInfo.m1
-rw-r--r--Source/SPFieldEditorController.h5
-rw-r--r--Source/SPFieldEditorController.m1
-rw-r--r--Source/SPNarrowDownCompletion.h4
-rw-r--r--Source/SPNarrowDownCompletion.m4
-rw-r--r--Source/SPPrintAccessory.h26
-rw-r--r--Source/SPPrintAccessory.m28
-rw-r--r--Source/SPSSHTunnel.h36
-rw-r--r--Source/SPSSHTunnel.m40
-rw-r--r--Source/SPStringAdditions.h12
-rw-r--r--Source/SPStringAdditions.m1
-rw-r--r--Source/SPTableData.h4
-rw-r--r--Source/SPTableData.m14
-rw-r--r--Source/SPTableInfo.m6
-rw-r--r--Source/SPTableRelations.h8
-rw-r--r--Source/SPTableRelations.m4
-rw-r--r--Source/SPTableView.h2
-rw-r--r--Source/SPTableView.m1
-rw-r--r--Source/TableContent.h10
-rw-r--r--Source/TableContent.m33
-rw-r--r--Source/TableDocument.h38
-rw-r--r--Source/TableDocument.m110
-rw-r--r--Source/TableDump.h17
-rw-r--r--Source/TableDump.m28
-rw-r--r--Source/TableSource.h14
-rw-r--r--Source/TableSource.m7
-rw-r--r--Source/TablesList.h15
-rw-r--r--Source/TablesList.m16
51 files changed, 373 insertions, 2474 deletions
diff --git a/Source/CMCopyTable.h b/Source/CMCopyTable.h
index 4bedac2c..eefc0608 100644
--- a/Source/CMCopyTable.h
+++ b/Source/CMCopyTable.h
@@ -110,4 +110,4 @@
@end
extern int MENU_EDIT_COPY_WITH_COLUMN;
-extern int MENU_EDIT_COPY_AS_SQL; \ No newline at end of file
+extern int MENU_EDIT_COPY_AS_SQL;
diff --git a/Source/CMCopyTable.m b/Source/CMCopyTable.m
index e3717c89..a6189d13 100644
--- a/Source/CMCopyTable.m
+++ b/Source/CMCopyTable.m
@@ -22,10 +22,11 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#import <MCPKit/MCPKit.h>
+
#import "CMCopyTable.h"
#import "SPArrayAdditions.h"
#import "SPStringAdditions.h"
-#import "CMMCPConnection.h"
#import "TableContent.h"
#import "CustomQuery.h"
diff --git a/Source/CMMCPConnection.h b/Source/CMMCPConnection.h
deleted file mode 100644
index 2c505dd5..00000000
--- a/Source/CMMCPConnection.h
+++ /dev/null
@@ -1,137 +0,0 @@
-//
-// $Id$
-//
-// CMMCPConnection.h
-// sequel-pro
-//
-// Created by lorenz textor (lorenz@textor.ch) on Wed Sept 21 2005.
-// Copyright (c) 2002-2003 Lorenz Textor. 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/>
-
-#import <Cocoa/Cocoa.h>
-#import <MCPKit_bundled/MCPKit_bundled.h>
-#import "CMMCPResult.h"
-#import "KeyChain.h"
-#import "SPSSHTunnel.h"
-
-@interface NSObject (CMMCPConnectionDelegate)
-
-- (void)willQueryString:(NSString *)query;
-- (void)queryGaveError:(NSString *)error;
-- (void)setStatusIconToImageWithName:(NSString *)imagePath;
-- (void)setTitlebarStatus:(NSString *)status;
-- (BOOL)connectionEncodingViaLatin1;
-
-@end
-
-@interface CMMCPConnection : MCPConnection {
- IBOutlet NSWindow *connectionErrorDialog;
- NSWindow *parentWindow;
- id delegate;
-
- BOOL nibLoaded;
- SPSSHTunnel *connectionTunnel;
- NSString *connectionLogin;
- NSString *connectionKeychainName;
- NSString *connectionKeychainAccount;
- NSString *connectionPassword;
- NSString *connectionHost;
- int connectionPort;
- NSString *connectionSocket;
- int maxAllowedPacketSize;
- unsigned long connectionThreadId;
- int connectionTimeout;
- int currentSSHTunnelState;
- BOOL useKeepAlive;
- float keepAliveInterval;
-
- double lastQueryExecutionTime;
- NSString *lastQueryErrorMessage;
- unsigned int lastQueryErrorId;
- my_ulonglong lastQueryAffectedRows;
-
- BOOL isMaxAllowedPacketEditable;
-
- NSString *serverVersionString;
-
- NSTimer *keepAliveTimer;
- NSDate *lastKeepAliveSuccess;
-
- BOOL retryAllowed;
-
- BOOL delegateResponseToWillQueryString;
- BOOL consoleLoggingEnabled;
-
- IMP cStringPtr;
- IMP willQueryStringPtr;
- IMP stopKeepAliveTimerPtr;
- IMP startKeepAliveTimerResettingStatePtr;
-
- SEL cStringSEL;
- SEL willQueryStringSEL;
- SEL stopKeepAliveTimerSEL;
- SEL startKeepAliveTimerResettingStateSEL;
-}
-
-- (id) init;
-- (id) initToHost:(NSString *) host withLogin:(NSString *) login usingPort:(int) port;
-- (id) initToSocket:(NSString *) socket withLogin:(NSString *) login;
-- (void) initSPExtensions;
-- (BOOL) setPort:(int) thePort;
-- (BOOL) setPassword:(NSString *)thePassword;
-- (BOOL) setPasswordKeychainName:(NSString *)theName account:(NSString *)theAccount;
-- (BOOL) setSSHTunnel:(SPSSHTunnel *)theTunnel;
-- (BOOL) connect;
-- (void) disconnect;
-- (BOOL) reconnect;
-- (void) setParentWindow:(NSWindow *)theWindow;
-- (IBAction) closeSheet:(id)sender;
-+ (BOOL) isErrorNumberConnectionError:(int)theErrorNumber;
-+ (NSStringEncoding) encodingForMySQLEncoding:(const char *) mysqlEncoding;
-- (BOOL) selectDB:(NSString *) dbName;
-- (CMMCPResult *) queryString:(NSString *) query;
-- (CMMCPResult *) queryString:(NSString *) query usingEncoding:(NSStringEncoding) encoding;
-- (double) lastQueryExecutionTime;
-- (MCPResult *) listDBsLike:(NSString *) dbsName;
-- (BOOL) checkConnection;
-- (void) restoreConnectionDetails;
-- (void) setDelegate:(id)object;
-- (NSTimeZone *) timeZone;
-- (BOOL) pingConnection;
-- (void) startKeepAliveTimerResettingState:(BOOL)resetState;
-- (void) stopKeepAliveTimer;
-- (void) keepAlive:(NSTimer *)theTimer;
-- (void) threadedKeepAlive;
-- (const char *) cStringFromString:(NSString *) theString usingEncoding:(NSStringEncoding) encoding;
-- (void) setLastErrorMessage:(NSString *)theErrorMessage;
-- (BOOL) fetchMaxAllowedPacket;
-- (int) getMaxAllowedPacket;
-- (BOOL) isMaxAllowedPacketEditable;
-- (int) setMaxAllowedPacketTo:(int)newSize resetSize:(BOOL)reset;
-- (NSString *)findSocketPath;
-
-- (void)willPerformQuery:(NSNotification *)notification;
-
-/* return server major version number or -1 on fail */
-- (int)serverMajorVersion;
-/* return server minor version number or -1 on fail */
-- (int)serverMinorVersion;
-/* return server release version number or -1 on fail */
-- (int)serverReleaseVersion;
-
-@end
diff --git a/Source/CMMCPConnection.m b/Source/CMMCPConnection.m
deleted file mode 100644
index 9848101e..00000000
--- a/Source/CMMCPConnection.m
+++ /dev/null
@@ -1,1364 +0,0 @@
-//
-// $Id$
-//
-// CMMCPConnection.m
-// sequel-pro
-//
-// Created by lorenz textor (lorenz@textor.ch) on Wed Sept 21 2005.
-// Copyright (c) 2002-2003 Lorenz Textor. 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/>
-
-#import "CMMCPConnection.h"
-#import "SPStringAdditions.h"
-#include <unistd.h>
-#include <setjmp.h>
-#include <mach/mach_time.h>
-
-static jmp_buf pingTimeoutJumpLocation;
-static void forcePingTimeout(int signalNumber);
-
-@interface CMMCPConnection(hidden)
-- (void)getServerVersionString;
-@end
-
-@implementation CMMCPConnection(hidden)
-- (void)getServerVersionString
-{
- if( mConnected ) {
- CMMCPResult *theResult;
- theResult = [self queryString:@"SHOW VARIABLES LIKE 'version'"];
- if ([theResult numOfRows]) {
- [theResult dataSeek:0];
- serverVersionString = [[NSString stringWithString:[[theResult fetchRowAsArray] objectAtIndex:1]] retain];
- }
- }
-}
-@end
-
-
-@implementation CMMCPConnection
-
-/*
- * Override the normal init methods, extending them to also init additional details,
- * and to store details of the initialised connection to allow reconnection as method.
- * Note this also behaves differently from the standard MCPKit connection methods -
- * passwords are passed separately, and connections are not automatically made on init.
- */
-- (id) init
-{
- [self initSPExtensions];
- self = [super init];
- serverVersionString = nil;
- return self;
-}
-- (id) initToHost:(NSString *) host withLogin:(NSString *) login usingPort:(int) port
-{
- [self initSPExtensions];
-
- self = [super init];
- mEncoding = NSISOLatin1StringEncoding;
- mConnection = mysql_init(mConnection);
- mConnected = NO;
- if (mConnection == NULL) {
- [self autorelease];
- return nil;
- }
-
- mConnectionFlags = kMCPConnectionDefaultOption;
-
- if (!host) host = @"";
- if (!login) login = @"";
-
- connectionHost = [[NSString alloc] initWithString:host];
- connectionLogin = [[NSString alloc] initWithString:login];
- connectionPort = port;
- connectionSocket = nil;
-
- return self;
-}
-- (id) initToSocket:(NSString *) socket withLogin:(NSString *) login
-{
- [self initSPExtensions];
- self = [super init];
- mEncoding = NSISOLatin1StringEncoding;
- mConnection = mysql_init(mConnection);
- mConnected = NO;
- if (mConnection == NULL) {
- [self autorelease];
- return nil;
- }
-
- mConnectionFlags = kMCPConnectionDefaultOption;
-
- if (!socket || ![socket length]) {
- socket = [self findSocketPath];
- if (!socket) socket = @"";
- }
- if (!login) login = @"";
-
- connectionHost = nil;
- connectionLogin = [[NSString alloc] initWithString:login];
- connectionSocket = [[NSString alloc] initWithString:socket];
- connectionPort = 0;
-
- return self;
-}
-
-
-/*
- * Instantiate extra variables and load the connection error dialog for potential use.
- */
-- (void) initSPExtensions
-{
- parentWindow = nil;
- connectionHost = nil;
- connectionLogin = nil;
- connectionSocket = nil;
- connectionPassword = nil;
- connectionKeychainName = nil;
- connectionKeychainAccount = nil;
- keepAliveTimer = nil;
- connectionTunnel = nil;
- connectionTimeout = [[[NSUserDefaults standardUserDefaults] objectForKey:@"ConnectionTimeout"] intValue];
- if (!connectionTimeout) connectionTimeout = 10;
- useKeepAlive = [[[NSUserDefaults standardUserDefaults] objectForKey:@"UseKeepAlive"] doubleValue];
- keepAliveInterval = [[[NSUserDefaults standardUserDefaults] objectForKey:@"KeepAliveInterval"] doubleValue];
- if (!keepAliveInterval) keepAliveInterval = 0;
- lastKeepAliveSuccess = nil;
- connectionThreadId = 0;
- maxAllowedPacketSize = -1;
- lastQueryExecutionTime = 0;
- lastQueryErrorId = 0;
- lastQueryErrorMessage = nil;
- lastQueryAffectedRows = 0;
- if (![NSBundle loadNibNamed:@"ConnectionErrorDialog" owner:self]) {
- NSLog(@"Connection error dialog could not be loaded; connection failure handling will not function correctly.");
- }
-
- willQueryStringSEL = @selector(willQueryString:);
- stopKeepAliveTimerSEL = @selector(stopKeepAliveTimer);
- startKeepAliveTimerResettingStateSEL = @selector(startKeepAliveTimerResettingState:);
- cStringSEL = @selector(cStringFromString:);
-
- cStringPtr = [self methodForSelector:cStringSEL];
- stopKeepAliveTimerPtr = [self methodForSelector:stopKeepAliveTimerSEL];
- startKeepAliveTimerResettingStatePtr = [self methodForSelector:startKeepAliveTimerResettingStateSEL];
-
-}
-
-/*
- * Sets the password to be stored locally.
- * Providing a keychain name is much more secure.
- */
-- (BOOL) setPassword:(NSString *)thePassword
-{
- if (connectionPassword) [connectionPassword release], connectionPassword = nil;
- if (connectionKeychainName) [connectionKeychainName release], connectionKeychainName = nil;
- if (connectionKeychainAccount) [connectionKeychainAccount release], connectionKeychainAccount = nil;
-
- if (!thePassword) thePassword = @"";
-
- connectionPassword = [[NSString alloc] initWithString:thePassword];
-
- return YES;
-}
-
-/*
- * Sets the keychain name to use to retrieve the password. This is the recommended and
- * secure way of supplying a password to the SSH tunnel.
- */
-- (BOOL) setPasswordKeychainName:(NSString *)theName account:(NSString *)theAccount
-{
- if (connectionPassword) [connectionPassword release], connectionPassword = nil;
- if (connectionKeychainName) [connectionKeychainName release], connectionKeychainName = nil;
- if (connectionKeychainAccount) [connectionKeychainAccount release], connectionKeychainAccount = nil;
-
- connectionKeychainName = [[NSString alloc] initWithString:theName];
- connectionKeychainAccount = [[NSString alloc] initWithString:theAccount];
-
- return YES;
-}
-
-/*
- * Sets or updates the connection port - for use with tunnels.
- */
-- (BOOL) setPort:(int) thePort
-{
- connectionPort = thePort;
-
- return YES;
-}
-
-/*
- * Set a SSH tunnel object to connect through. This object will be retained locally,
- * and will be automatically connected/connection checked/reconnected/disconnected
- * together with the main connection.
- */
-- (BOOL) setSSHTunnel:(SPSSHTunnel *)theTunnel
-{
- connectionTunnel = theTunnel;
- [connectionTunnel retain];
-
- currentSSHTunnelState = [connectionTunnel state];
- [connectionTunnel setConnectionStateChangeSelector:@selector(sshTunnelStateChange:) delegate:self];
-
- return YES;
-}
-
-/*
- * Add a new connection method, intended for use with the init methods above.
- * Uses the stored details to instantiate a connection to the specified server,
- * including custom timeouts - used for pings, not for long-running commands.
- */
-- (BOOL) connect
-{
- const char *theLogin = [self cStringFromString:connectionLogin];
- const char *theHost;
- const char *thePass;
- const char *theSocket;
- void *theRet;
-
- // Ensure that a password method has been provided
- if (connectionKeychainName == nil && connectionPassword == nil) return NO;
-
- // Disconnect if a connection is already active
- if (mConnected) {
- [self disconnect];
- mConnection = mysql_init(NULL);
- if (mConnection == NULL) return NO;
- }
-
- // Ensure the custom timeout option is set
- if (mConnection != NULL) {
- mysql_options(mConnection, MYSQL_OPT_CONNECT_TIMEOUT, (const void *)&connectionTimeout);
- }
-
- // Set the host as appropriate
- if (!connectionHost || ![connectionHost length]) {
- theHost = NULL;
- } else {
- theHost = [self cStringFromString:connectionHost];
- }
-
- // Use the default socket if none is set, or set appropriately
- if (connectionSocket == nil || ![connectionSocket length]) {
- theSocket = kMCPConnectionDefaultSocket;
- } else {
- theSocket = [self cStringFromString:connectionSocket];
- }
-
- // Select the password from the provided method
- if (connectionKeychainName) {
- KeyChain *keychain;
- keychain = [[KeyChain alloc] init];
- thePass = [self cStringFromString:[keychain getPasswordForName:connectionKeychainName account:connectionKeychainAccount]];
- [keychain release];
- } else {
- thePass = [self cStringFromString:connectionPassword];
- }
-
- // Connect
- theRet = mysql_real_connect(mConnection, theHost, theLogin, thePass, NULL, connectionPort, theSocket, mConnectionFlags);
- thePass = NULL;
- if (theRet != mConnection) {
- [self setLastErrorMessage:nil];
- lastQueryErrorId = mysql_errno(mConnection);
- return mConnected = NO;
- }
-
- mConnected = YES;
- mEncoding = [MCPConnection encodingForMySQLEncoding:mysql_character_set_name(mConnection)];
- connectionThreadId = mConnection->thread_id;
- [self timeZone]; // Getting the timezone used by the server.
-
- isMaxAllowedPacketEditable = [self isMaxAllowedPacketEditable];
-
- if (![self fetchMaxAllowedPacket]) {
- [self setLastErrorMessage:nil];
- lastQueryErrorId = mysql_errno(mConnection);
- return mConnected = NO;
- }
-
- // Register notification if a query was sent to the MySQL connection
- // to be able to identify the sender of that query
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willPerformQuery:)
- name:@"SMySQLQueryWillBePerformed" object:nil];
-
- [[NSUserDefaults standardUserDefaults] addObserver:self forKeyPath:@"ConsoleEnableLogging" options:NSKeyValueObservingOptionNew context:NULL];
-
- // Init 'consoleLoggingEnabled'
- consoleLoggingEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:@"ConsoleEnableLogging"];
-
- // Start the keepalive timer
- [self startKeepAliveTimerResettingState:YES];
-
- return mConnected;
-}
-
-
-/*
- * Override the stored disconnection method to ensure that disconnecting clears stored timers.
- */
-- (void) disconnect
-{
- [super disconnect];
-
- if (connectionTunnel) {
- [connectionTunnel disconnect];
- if (delegate) [delegate setTitlebarStatus:@"SSH Disconnected"];
- //[delegate setStatusIconToImageWithName:@"ssh-disconnected"];
- }
-
- if( serverVersionString != nil ) {
- [serverVersionString release];
- serverVersionString = nil;
- }
-
- [self stopKeepAliveTimer];
-}
-
-/*
- * return the server major version or -1 on fail
- */
-- (int)serverMajorVersion
-{
-
- if( mConnected ) {
- if( serverVersionString == nil ) {
- [self getServerVersionString];
- }
- if( serverVersionString != nil ) {
- return [[[serverVersionString componentsSeparatedByString:@"."] objectAtIndex:0] intValue];
- }
- }
- return -1;
-}
-
-/*
- * return the server minor version or -1 on fail
- */
-- (int)serverMinorVersion
-{
-
- if( mConnected ) {
- if( serverVersionString == nil ) {
- [self getServerVersionString];
- }
- if( serverVersionString != nil ) {
- return [[[serverVersionString componentsSeparatedByString:@"."] objectAtIndex:1] intValue];
- }
- }
- return -1;
-}
-
-/*
- * return the server release version or -1 on fail
- */
-- (int)serverReleaseVersion
-{
- if( mConnected ) {
- if( serverVersionString == nil ) {
- [self getServerVersionString];
- }
- if( serverVersionString != nil ) {
- NSString *s = [[serverVersionString componentsSeparatedByString:@"."] objectAtIndex:2];
- return [[[s componentsSeparatedByString:@"-"] objectAtIndex:0] intValue];
- }
- }
- return -1;
-}
-
-
-/*
- * Reconnect to the currently "active" - but possibly disconnected - connection, using the
- * stored details.
- * Error checks extensively - if this method fails, it will ask how to proceed and loop depending
- * on the status, not returning control until either a connection has been established or
- * the connection and document have been closed.
- */
-- (BOOL) reconnect
-{
- NSString *currentEncoding = nil;
- BOOL currentEncodingUsesLatin1Transport = NO;
- NSString *currentDatabase = nil;
-
- // Store the current database and encoding so they can be re-set if reconnection was successful
- if (delegate && [delegate valueForKey:@"selectedDatabase"]) {
- currentDatabase = [NSString stringWithString:[delegate valueForKey:@"selectedDatabase"]];
- }
- if (delegate && [delegate valueForKey:@"_encoding"]) {
- currentEncoding = [NSString stringWithString:[delegate valueForKey:@"_encoding"]];
- }
- if (delegate && [delegate respondsToSelector:@selector(connectionEncodingViaLatin1)]) {
- currentEncodingUsesLatin1Transport = [delegate connectionEncodingViaLatin1];
- }
-
- // Close the connection if it exists.
- if (mConnected) {
- mysql_close(mConnection);
- mConnection = NULL;
- }
- mConnected = NO;
-
- // If there is a tunnel, ensure it's disconnected and attempt to reconnect it in blocking fashion
- if (connectionTunnel) {
- [connectionTunnel setConnectionStateChangeSelector:nil delegate:nil];
- if ([connectionTunnel state] != SPSSH_STATE_IDLE) [connectionTunnel disconnect];
- [connectionTunnel connect];
-
- if (delegate) [delegate setTitlebarStatus:@"SSH Connecting…"];
- //[delegate setStatusIconToImageWithName:@"ssh-connecting"];
-
- NSDate *tunnelStartDate = [NSDate date], *interfaceInteractionTimer;
-
- // Allow the tunnel to attempt to connect in a loop
- while (1) {
- if ([connectionTunnel state] == SPSSH_STATE_CONNECTED) {
- if (delegate) [delegate setTitlebarStatus:@"SSH Connected"];
- //[delegate setStatusIconToImageWithName:@"ssh-connected"];
- connectionPort = [connectionTunnel localPort];
- break;
- }
- if ([[NSDate date] timeIntervalSinceDate:tunnelStartDate] > (connectionTimeout + 1)) {
- [connectionTunnel disconnect];
- if (delegate) [delegate setTitlebarStatus:@"SSH Disconnected"];
- //[delegate setStatusIconToImageWithName:@"ssh-disconnected"];
- break;
- }
-
- // Process events for a short time, allowing dialogs to be shown but waiting for the tunnel
- interfaceInteractionTimer = [NSDate date];
- [[NSRunLoop currentRunLoop] runMode:NSModalPanelRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.25]];
- tunnelStartDate = [tunnelStartDate addTimeInterval:([[NSDate date] timeIntervalSinceDate:interfaceInteractionTimer] - 0.25)];
- }
- currentSSHTunnelState = [connectionTunnel state];
- [connectionTunnel setConnectionStateChangeSelector:@selector(sshTunnelStateChange:) delegate:self];
- }
-
- if (!connectionTunnel || [connectionTunnel state] == SPSSH_STATE_CONNECTED) {
-
- // Attempt to reinitialise the connection - if this fails, it will still be set to NULL.
- if (mConnection == NULL) {
- mConnection = mysql_init(NULL);
- }
-
- if (mConnection != NULL) {
-
- // Set a connection timeout for the new connection
- mysql_options(mConnection, MYSQL_OPT_CONNECT_TIMEOUT, (const void *)&connectionTimeout);
-
- // Attempt to reestablish the connection
- [self connect];
- }
- }
-
- // If the connection was successfully established, reselect the old database and encoding if appropriate.
- if (mConnected) {
- if (currentDatabase) {
- [self selectDB:currentDatabase];
- }
- if (currentEncoding) {
- [self queryString:[NSString stringWithFormat:@"/*!40101 SET NAMES '%@' */", currentEncoding]];
- [self setEncoding:[CMMCPConnection encodingForMySQLEncoding:[currentEncoding UTF8String]]];
- if (currentEncodingUsesLatin1Transport) {
- [self queryString:@"/*!40101 SET CHARACTER_SET_RESULTS=latin1 */"];
- }
- }
- } else if (parentWindow) {
- if (connectionTunnel && [connectionTunnel state] != SPSSH_STATE_CONNECTED) {
- [self setLastErrorMessage:@"(Could not connect because the Sequel Pro SSH Tunnel could not be reestablished)"];
- } else {
- [self setLastErrorMessage:nil];
- }
-
- // If the connection was not successfully established, ask how to proceed.
- [NSApp beginSheet:connectionErrorDialog modalForWindow:parentWindow modalDelegate:self didEndSelector:nil contextInfo:nil];
- int connectionErrorCode = [NSApp runModalForWindow:connectionErrorDialog];
- [NSApp endSheet:connectionErrorDialog];
- [connectionErrorDialog orderOut:nil];
-
- switch (connectionErrorCode) {
-
- // Should disconnect
- case 2:
- [parentWindow close];
- return NO;
-
- // Should retry
- default:
- return [self reconnect];
- }
- }
-
- return mConnected;
-}
-
-
-/*
- * Set the parent window of the connection for use with dialogs.
- */
-- (void)setParentWindow:(NSWindow *)theWindow
-{
- parentWindow = theWindow;
-}
-
-/*
- * Handle any state changes in the associated SSH Tunnel
- */
-- (void)sshTunnelStateChange:(SPSSHTunnel *)theTunnel
-{
- int newState = [theTunnel state];
-
- if (delegate && [delegate respondsToSelector:@selector(setStatusIconToImageWithName:)]) {
- if (newState == SPSSH_STATE_IDLE) [delegate setTitlebarStatus:@"SSH Disconnected"];
- else if (newState == SPSSH_STATE_CONNECTED) [delegate setTitlebarStatus:@"SSH Connected"];
- else [delegate setTitlebarStatus:@"SSH Connecting…"];
-
-
-// if (newState == SPSSH_STATE_IDLE) [delegate setStatusIconToImageWithName:@"ssh-disconnected"];
-// else if (newState == SPSSH_STATE_CONNECTED) [delegate setStatusIconToImageWithName:@"ssh-connected"];
-// else [delegate setStatusIconToImageWithName:@"ssh-connecting"];
- }
-
- // Restart the tunnel if it dies
- if (mConnected && newState == SPSSH_STATE_IDLE && currentSSHTunnelState == SPSSH_STATE_CONNECTED) {
- currentSSHTunnelState = newState;
- [connectionTunnel setConnectionStateChangeSelector:nil delegate:nil];
- [self reconnect];
- return;
- }
-
- currentSSHTunnelState = newState;
-}
-
-
-/*
- * Ends an existing modal session
- */
-- (IBAction) closeSheet:(id)sender
-{
- [NSApp stopModalWithCode:[sender tag]];
-}
-
-/*
- * Determines whether a supplied error number can be classed as a connection
- * error.
- */
-+ (BOOL) isErrorNumberConnectionError:(int)theErrorNumber
-{
-
- switch (theErrorNumber) {
- case 2001: // CR_SOCKET_CREATE_ERROR
- case 2002: // CR_CONNECTION_ERROR
- case 2003: // CR_CONN_HOST_ERROR
- case 2004: // CR_IPSOCK_ERROR
- case 2005: // CR_UNKNOWN_HOST
- case 2006: // CR_SERVER_GONE_ERROR
- case 2007: // CR_VERSION_ERROR
- case 2009: // CR_WRONG_HOST_INFO
- case 2012: // CR_SERVER_HANDSHAKE_ERR
- case 2013: // CR_SERVER_LOST
- case 2027: // CR_MALFORMED_PACKET
- case 2032: // CR_DATA_TRUNCATED
- case 2047: // CR_CONN_UNKNOW_PROTOCOL
- case 2048: // CR_INVALID_CONN_HANDLE
- case 2050: // CR_FETCH_CANCELED
- case 2055: // CR_SERVER_LOST_EXTENDED
- return YES;
- }
-
- return NO;
-}
-
-/*
- * Gets a proper NSStringEncoding according to the given MySQL charset.
- *
- * MySQL 4.0 offers this charsets:
- * big5 cp1251 cp1257 croat czech danish dec8 dos estonia euc_kr gb2312 gbk german1
- * greek hebrew hp8 hungarian koi8_ru koi8_ukr latin1 latin1_de latin2 latin5 sjis
- * swe7 tis620 ujis usa7 win1250 win1251ukr
- *
- * WARNING : incomplete implementation. Please, send your fixes.
- */
-+ (NSStringEncoding) encodingForMySQLEncoding:(const char *) mysqlEncoding
-{
- // Unicode encodings:
- if (!strncmp(mysqlEncoding, "utf8", 4)) {
- return NSUTF8StringEncoding;
- }
- if (!strncmp(mysqlEncoding, "ucs2", 4)) {
- return NSUnicodeStringEncoding;
- }
-
- // Roman alphabet encodings:
- if (!strncmp(mysqlEncoding, "ascii", 5)) {
- return NSASCIIStringEncoding;
- }
- if (!strncmp(mysqlEncoding, "latin1", 6)) {
- return NSISOLatin1StringEncoding;
- }
- if (!strncmp(mysqlEncoding, "macroman", 8)) {
- return NSMacOSRomanStringEncoding;
- }
-
- // Roman alphabet with central/east european additions:
- if (!strncmp(mysqlEncoding, "latin2", 6)) {
- return NSISOLatin2StringEncoding;
- }
- if (!strncmp(mysqlEncoding, "cp1250", 6)) {
- return NSWindowsCP1250StringEncoding;
- }
- if (!strncmp(mysqlEncoding, "win1250", 7)) {
- return NSWindowsCP1250StringEncoding;
- }
- if (!strncmp(mysqlEncoding, "cp1257", 6)) {
- return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingWindowsBalticRim);
- }
-
- // Additions for Turkish:
- if (!strncmp(mysqlEncoding, "latin5", 6)) {
- return NSWindowsCP1254StringEncoding;
- }
-
- // Greek:
- if (!strncmp(mysqlEncoding, "greek", 5)) {
- return NSWindowsCP1253StringEncoding;
- }
-
- // Cyrillic:
- if (!strncmp(mysqlEncoding, "win1251ukr", 6)) {
- return NSWindowsCP1251StringEncoding;
- }
- if (!strncmp(mysqlEncoding, "cp1251", 6)) {
- return NSWindowsCP1251StringEncoding;
- }
- if (!strncmp(mysqlEncoding, "koi8_ru", 6)) {
- return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingKOI8_R);
- }
- if (!strncmp(mysqlEncoding, "koi8_ukr", 6)) {
- return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingKOI8_R);
- }
-
- // Arabic:
- if (!strncmp(mysqlEncoding, "cp1256", 6)) {
- return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingWindowsArabic);
- }
-
- // Hebrew:
- if (!strncmp(mysqlEncoding, "hebrew", 6)) {
- CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingISOLatinHebrew);
- }
-
- // Asian:
- if (!strncmp(mysqlEncoding, "ujis", 4)) {
- return NSJapaneseEUCStringEncoding;
- }
- if (!strncmp(mysqlEncoding, "sjis", 4)) {
- return NSShiftJISStringEncoding;
- }
- if (!strncmp(mysqlEncoding, "big5", 4)) {
- return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingBig5);
- }
- if (!strncmp(mysqlEncoding, "euc_kr", 6)) {
- return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingEUC_KR);
- }
- if (!strncmp(mysqlEncoding, "euckr", 5)) {
- return CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingEUC_KR);
- }
-
- // Default to iso latin 1, even if it is not exact (throw an exception?)
- NSLog(@"WARNING : unknown name for MySQL encoding '%s'!\n\t\tFalling back to iso-latin1.", mysqlEncoding);
- return NSISOLatin1StringEncoding;
-}
-
-
-/*
- * Modified version of selectDB to be used in Sequel Pro.
- * Checks the connection exists, and handles keepalive, otherwise calling the parent implementation.
- */
-- (BOOL) selectDB:(NSString *) dbName
-{
- if (!mConnected) return NO;
- [self stopKeepAliveTimer];
- if (![self checkConnection]) return NO;
- if ([super selectDB:dbName]) {
- [self startKeepAliveTimerResettingState:YES];
- return YES;
- }
- [self setLastErrorMessage:nil];
- lastQueryErrorId = mysql_errno(mConnection);
- if (connectionTunnel) {
- [connectionTunnel disconnect];
- if (delegate) [delegate setTitlebarStatus:@"SSH Disconnected"];
- //[delegate setStatusIconToImageWithName:@"ssh-disconnected"];
- }
- return NO;
-}
-
-
-/*
- * Via that method the current mySQLConnection will be informed
- * which object sent the current query.
- */
-- (void)willPerformQuery:(NSNotification *)notification
-{
-
- // If the sender was CustomQuery disable the retry of queries.
- // TODO: maybe there's a better way
- if( [[[[notification object] class] description] isEqualToString:@"CustomQuery"] ) {
- retryAllowed = NO;
- } else {
- retryAllowed = YES;
- }
-
-}
-
-/**
- * This method is called as part of Key Value Observing which is used to watch for prefernce changes which effect the interface.
- */
-- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
-{
- if ([keyPath isEqualToString:@"ConsoleEnableLogging"]) {
- consoleLoggingEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:@"ConsoleEnableLogging"];
- }
-}
-
-/*
- * Override the standard queryString: method to default to the connection encoding, as before,
- * before pssing on to queryString: usingEncoding:.
- */
-- (CMMCPResult *)queryString:(NSString *) query
-{
- return [self queryString:query usingEncoding:mEncoding];
-}
-
-
-/*
- * Modified version of queryString to be used in Sequel Pro.
- * Error checks connection extensively - if this method fails due to a connection error, it will ask how to
- * proceed and loop depending on the status, not returning control until either the query has been executed
- * and the result can be returned or the connection and document have been closed.
- */
-- (CMMCPResult *)queryString:(NSString *) query usingEncoding:(NSStringEncoding) encoding
-{
- CMMCPResult *theResult = nil;
- uint64_t queryStartTime, queryExecutionTime_t;
- Nanoseconds queryExecutionTime;
- const char *theCQuery;
- unsigned long theCQueryLength;
- int queryResultCode;
- int queryErrorId = 0;
- my_ulonglong queryAffectedRows = 0;
- int currentMaxAllowedPacket = -1;
- BOOL isQueryRetry = NO;
- NSString *queryErrorMessage = nil;
-
- // If no connection is present, return nil.
- if (!mConnected) {
- // Write a log entry
- if ([delegate respondsToSelector:@selector(queryGaveError:)]) [delegate queryGaveError:@"No connection available!"];
- // Notify that the query has been performed
- [[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryHasBeenPerformed" object:self];
- // Show an error alert while resetting
- NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), @"No connection available!",
- nil, nil, [delegate valueForKeyPath:@"tableWindow"], self, nil, nil, nil, @"No connection available!");
- return nil;
- }
-
- (void)(*stopKeepAliveTimerPtr)(self, stopKeepAliveTimerSEL);
-
- // queryStartTime = clock();
-
- // Inform the delegate about the query if logging is enabled and
- // delegate responds to willQueryString:
- if (consoleLoggingEnabled && delegateResponseToWillQueryString)
- (void)(NSString*)(*willQueryStringPtr)(delegate, willQueryStringSEL, query);
-
- // Derive the query string in the correct encoding
- NSData *d = NSStringDataUsingLossyEncoding(query, encoding, 1);
- theCQuery = [d bytes];
- // Set the length of the current query
- theCQueryLength = [d length];
-
- // 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(maxAllowedPacketSize < theCQueryLength) {
-
- if(isMaxAllowedPacketEditable) {
-
- currentMaxAllowedPacket = maxAllowedPacketSize;
- [self setMaxAllowedPacketTo:strlen(theCQuery)+1024 resetSize:NO];
- [self reconnect];
-
- } else {
-
- 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, 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];
- [self setLastErrorMessage:errorMessage];
-
- // Notify that the query has been performed
- [[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryHasBeenPerformed" object:self];
- // Show an error alert while resetting
- NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"),
- nil, nil, [delegate valueForKeyPath:@"tableWindow"], self, nil, nil, nil, errorMessage);
-
- return nil;
- }
- }
-
- // In a loop to allow one reattempt, perform the query.
- while (1) {
-
- // If this query has failed once already, check the connection
- if (isQueryRetry) {
- if (![self checkConnection]) {
-
- // Notify that the query has been performed
- [[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryHasBeenPerformed" object:self];
- return nil;
- }
- }
-
- // Run (or re-run) the query, timing the execution time of the query - note
- // that this time will include network lag.
- queryStartTime = mach_absolute_time();
- queryResultCode = mysql_real_query(mConnection, theCQuery, theCQueryLength);
- queryExecutionTime_t = mach_absolute_time() - queryStartTime;
- queryExecutionTime = AbsoluteToNanoseconds( *(AbsoluteTime *) &(queryExecutionTime_t) );
-
- // On success, capture the results
- if (0 == queryResultCode) {
-
- if (mysql_field_count(mConnection) != 0) {
- theResult = [[CMMCPResult alloc] initWithMySQLPtr:mConnection encoding:mEncoding timeZone:mTimeZone];
-
- // Ensure no problem occurred during the result fetch
- if (mysql_errno(mConnection) != 0) {
- queryErrorMessage = [[NSString alloc] initWithString:[self stringWithCString:mysql_error(mConnection)]];
- queryErrorId = mysql_errno(mConnection);
- break;
- }
- }
-
- queryErrorMessage = [[NSString alloc] initWithString:@""];
- queryErrorId = 0;
- queryAffectedRows = mysql_affected_rows(mConnection);
-
- // On failure, set the error messages and IDs
- } else {
-
- queryErrorMessage = [[NSString alloc] initWithString:[self stringWithCString:mysql_error(mConnection)]];
- queryErrorId = mysql_errno(mConnection);
-
- // If the error was a connection error, retry once
- if (!isQueryRetry && retryAllowed && [CMMCPConnection isErrorNumberConnectionError:queryErrorId]) {
- isQueryRetry = YES;
- continue;
- }
- }
-
- break;
- }
-
- // If the mysql thread id has changed as a result of a connection error,
- // ensure connection details are still correct
- if (connectionThreadId != mConnection->thread_id) [self restoreConnectionDetails];
-
- // If max_allowed_packet was changed, reset it to default
- if(currentMaxAllowedPacket > -1)
- [self setMaxAllowedPacketTo:currentMaxAllowedPacket resetSize:YES];
-
- // Update error strings and IDs
- lastQueryErrorId = queryErrorId;
- [self setLastErrorMessage:queryErrorMessage?queryErrorMessage:@""];
- if (queryErrorMessage) [queryErrorMessage release];
- lastQueryAffectedRows = queryAffectedRows;
- lastQueryExecutionTime = ((double) UnsignedWideToUInt64( queryExecutionTime )) * 1e-9;
-
- // If an error occurred, inform the delegate
- if (queryResultCode & delegateResponseToWillQueryString)
- [delegate queryGaveError:lastQueryErrorMessage];
-
- (void)(int)(*startKeepAliveTimerResettingStatePtr)(self, startKeepAliveTimerResettingStateSEL, YES);
-
- if (!theResult) return nil;
- return [theResult autorelease];
-}
-
-
-/*
- * Return the time taken to execute the last query. This should be close to the time it took
- * the server to run the query, but will include network lag and some client library overhead.
- */
-- (double) lastQueryExecutionTime
-{
- return lastQueryExecutionTime;
-}
-
-
-/*
- * Modified version of selectDB to be used in Sequel Pro.
- * Checks the connection exists, and handles keepalive, otherwise calling the parent implementation.
- */
-- (MCPResult *) listDBsLike:(NSString *) dbsName
-{
- if (!mConnected) return NO;
- [self stopKeepAliveTimer];
- if (![self checkConnection]) return [[[MCPResult alloc] init] autorelease];
- [self startKeepAliveTimerResettingState:YES];
- return [super listDBsLike:dbsName];
-}
-
-
-/*
- * Checks whether the connection to the server is still active. If not, prompts for what approach to take,
- * offering to retry, reconnect or disconnect the connection.
- */
-- (BOOL)checkConnection
-{
- if (!mConnected) return NO;
-
- BOOL connectionVerified = FALSE;
-
- // Check whether the connection is still operational via a wrapped version of MySQL ping.
- connectionVerified = [self pingConnection];
-
- // If the connection doesn't appear to be responding, show a dialog asking how to proceed
- if (!connectionVerified) {
- [NSApp beginSheet:connectionErrorDialog modalForWindow:parentWindow modalDelegate:self didEndSelector:nil contextInfo:nil];
- int responseCode = [NSApp runModalForWindow:connectionErrorDialog];
- [NSApp endSheet:connectionErrorDialog];
- [connectionErrorDialog orderOut:nil];
-
- switch (responseCode) {
-
- // "Reconnect" has been selected. Request a reconnect, and retry.
- case 1:
- [self reconnect];
- return [self checkConnection];
-
- // "Disconnect" has been selected. Close the parent window, which will handle disconnections, and return false.
- case 2:
- [parentWindow close];
- return FALSE;
-
- // "Retry" has been selected - return a recursive call.
- default:
- return [self checkConnection];
- }
-
- // If a connection exists, check whether the thread id differs; if so, the connection has
- // probably been reestablished and we need to reset the connection encoding
- } else if (connectionThreadId != mConnection->thread_id) [self restoreConnectionDetails];
-
- return connectionVerified;
-}
-
-/**
- * Restore the connection encoding details as necessary based on the delegate-provided
- * details.
- */
-- (void) restoreConnectionDetails
-{
- connectionThreadId = mConnection->thread_id;
- [self fetchMaxAllowedPacket];
- if (delegate && [delegate valueForKey:@"_encoding"]) {
- [self queryString:[NSString stringWithFormat:@"/*!40101 SET NAMES '%@' */", [NSString stringWithString:[delegate valueForKey:@"_encoding"]]]];
- if (delegate && [delegate respondsToSelector:@selector(connectionEncodingViaLatin1)]) {
- if ([delegate connectionEncodingViaLatin1]) [self queryString:@"/*!40101 SET CHARACTER_SET_RESULTS=latin1 */"];
- }
- }
-}
-
-- (void)setDelegate:(id)object
-{
- delegate = object;
-
- delegateResponseToWillQueryString = (delegate && [delegate respondsToSelector:willQueryStringSEL]);
-
- willQueryStringPtr = [delegate methodForSelector:willQueryStringSEL];
-
-}
-
-/* Getting the currently used time zone (in communication with the DB server). */
-/* fixes mysql 4.1.14 problem, can be deleted as soon as fixed in the framework */
-- (NSTimeZone *)timeZone
-{
- if ([self checkConnection]) {
- MCPResult *theSessionTZ = [self queryString:@"SHOW VARIABLES LIKE '%time_zone'"];
- NSArray *theRow;
- id theTZName;
- NSTimeZone *theTZ;
-
- [theSessionTZ dataSeek:1ULL];
- theRow = [theSessionTZ fetchRowAsArray];
- theTZName = [theRow objectAtIndex:1];
-
- if ( [theTZName isKindOfClass:[NSData class]] ) {
- // MySQL 4.1.14 returns the mysql variables as NSData
- theTZName = [self stringWithText:theTZName];
- }
-
- if ([theTZName isEqualToString:@"SYSTEM"]) {
- [theSessionTZ dataSeek:0ULL];
- theRow = [theSessionTZ fetchRowAsArray];
- theTZName = [theRow objectAtIndex:1];
-
- if ( [theTZName isKindOfClass:[NSData class]] ) {
- // MySQL 4.1.14 returns the mysql variables as NSData
- theTZName = [self stringWithText:theTZName];
- }
- }
-
- if (theTZName) { // Old versions of the server does not support there own time zone ?
- theTZ = [NSTimeZone timeZoneWithName:theTZName];
- } else {
- // By default set the time zone to the local one..
- // Try to get the name using the previously available variable:
- theSessionTZ = [self queryString:@"SHOW VARIABLES LIKE 'timezone'"];
- [theSessionTZ dataSeek:0ULL];
- theRow = [theSessionTZ fetchRowAsArray];
- theTZName = [theRow objectAtIndex:1];
- if (theTZName) {
- // Finally we found one ...
- theTZ = [NSTimeZone timeZoneWithName:theTZName];
- } else {
- theTZ = [NSTimeZone defaultTimeZone];
- //theTZ = [NSTimeZone systemTimeZone];
- NSLog(@"The time zone is not defined on the server, set it to the default one : %@", theTZ);
- }
- }
-
- if (theTZ != mTimeZone) {
- [mTimeZone release];
- mTimeZone = [theTZ retain];
- }
- }
- return mTimeZone;
-}
-
-
-/*
- * The current versions of MCPKit (and up to and including 3.0.1) use MySQL 4.1.12; this has an issue with
- * mysql_ping where a connection which is terminated will cause mysql_ping never to respond, even when
- * connection timeouts are set. Full details of this issue are available at http://bugs.mysql.com/bug.php?id=9678 ;
- * this bug was fixed in 4.1.22 and later versions.
- * This issue can be replicated by connecting to a remote host, and then configuring a firewall on that host
- * to drop all packets on the connected port - mysql_ping and so Sequel Pro will hang.
- * Until the client libraries are updated, this provides a drop-in wrapper for mysql_ping, which calls mysql_ping
- * while running a SIGALRM to enforce the specified connection time. This is low-level but effective.
- * Unlike mysql_ping, this function returns FALSE on failure and TRUE on success.
- */
-- (BOOL) pingConnection
-{
- struct sigaction timeoutAction;
- NSDate *startDate = [[NSDate alloc] initWithTimeIntervalSinceNow:0];
- BOOL pingSuccess = FALSE;
-
- // Construct the SIGALRM to fire after the connection timeout if it isn't cleared, calling the forcePingTimeout function.
- timeoutAction.sa_handler = forcePingTimeout;
- sigemptyset(&timeoutAction.sa_mask);
- timeoutAction.sa_flags = 0;
- sigaction(SIGALRM, &timeoutAction, NULL);
- alarm(connectionTimeout+1);
-
- // Set up a "restore point", returning 0; if longjmp is used later with this reference, execution
- // jumps back to this point and returns a nonzero value, so this function evaluates to false when initially
- // set and true if it's called again.
- if (setjmp(pingTimeoutJumpLocation)) {
-
- // The connection timed out - we want to return false.
- pingSuccess = FALSE;
-
- // On direct execution:
- } else {
-
- // Run mysql_ping, which returns 0 on success, and otherwise an error.
- pingSuccess = (BOOL)(! mysql_ping(mConnection));
-
- // If the ping failed within a second, try another one; this is because a terminated-but-then
- // restored connection is at times restored or functional after a ping, but the ping still returns
- // an error. This additional check ensures the returned status is correct with minimal other effect.
- if (!pingSuccess && ([startDate timeIntervalSinceNow] > -1)) {
- pingSuccess = (BOOL)(! mysql_ping(mConnection));
- }
- }
-
- // Reset and clear the SIGALRM used to check connection timeouts.
- alarm(0);
- timeoutAction.sa_handler = SIG_IGN;
- sigemptyset(&timeoutAction.sa_mask);
- timeoutAction.sa_flags = 0;
- sigaction(SIGALRM, &timeoutAction, NULL);
-
- [startDate release];
-
- return pingSuccess;
-}
-
-/*
- * This function is paired with pingConnection, and provides a method of enforcing the connection
- * timeout when mysql_ping does not respect the specified limits.
- */
-static void forcePingTimeout(int signalNumber)
-{
- longjmp(pingTimeoutJumpLocation, 1);
-}
-
-/*
- * Restarts a keepalive to fire in the future.
- */
-- (void) startKeepAliveTimerResettingState:(BOOL)resetState
-{
- if (keepAliveTimer) [self stopKeepAliveTimer];
- if (!mConnected) return;
-
- if (resetState && lastKeepAliveSuccess) {
- [lastKeepAliveSuccess release];
- lastKeepAliveSuccess = nil;
- }
-
- if (useKeepAlive && keepAliveInterval) {
- keepAliveTimer = [NSTimer
- scheduledTimerWithTimeInterval:keepAliveInterval
- target:self
- selector:@selector(keepAlive:)
- userInfo:nil
- repeats:NO];
- [keepAliveTimer retain];
- }
-}
-
-/*
- * Stops a keepalive if one is set for the future.
- */
-- (void) stopKeepAliveTimer
-{
- if (!keepAliveTimer) return;
- [keepAliveTimer invalidate];
- [keepAliveTimer release];
- keepAliveTimer = nil;
-}
-
-/*
- * Keeps a connection alive by running a ping.
- */
-- (void) keepAlive:(NSTimer *)theTimer
-{
- if (!mConnected) return;
-
- // If there a successful keepalive record exists, and it was more than 5*keepaliveinterval ago,
- // abort. This prevents endless spawning of threads in a state where the connection has been
- // cut but mysql doesn't pick up on the fact - see comment for pingConnection above. The same
- // forced-timeout approach cannot be used here on a background thread.
- // When the connection is disconnected in code, these 5 "hanging" threads are automatically cleaned.
- if (lastKeepAliveSuccess && [lastKeepAliveSuccess timeIntervalSinceNow] < -5 * keepAliveInterval) return;
-
- [NSThread detachNewThreadSelector:@selector(threadedKeepAlive) toTarget:self withObject:nil];
- [self startKeepAliveTimerResettingState:NO];
-}
-
-/*
- * A threaded keepalive to avoid blocking the interface
- */
-- (void) threadedKeepAlive
-{
- if (!mConnected) return;
- mysql_ping(mConnection);
- if (lastKeepAliveSuccess) {
- [lastKeepAliveSuccess release];
- lastKeepAliveSuccess = nil;
- }
- lastKeepAliveSuccess = [[NSDate alloc] initWithTimeIntervalSinceNow:0];
-}
-
-/*
- * Modified version of the original to support a supplied encoding.
- * For internal use only. Transforms a NSString to a C type string (ending with \0).
- * Lossy conversions are enabled.
- */
-- (const char *) cStringFromString:(NSString *) theString usingEncoding:(NSStringEncoding) encoding
-{
-
- NSMutableData *theData;
-
- if (! theString) {
- return (const char *)NULL;
- }
-
- theData = [NSMutableData dataWithData:[theString dataUsingEncoding:encoding allowLossyConversion:YES]];
- [theData increaseLengthBy:1];
- return (const char *)[theData bytes];
-}
-
-/*
- * Returns a string for the last MySQL error message on the connection.
- * This is cached within the object to allow helper queries to be performed
- * without affecting the state that the GUI is querying.
- */
-- (NSString *) getLastErrorMessage
-{
- return lastQueryErrorMessage;
-}
-
-/*
- * Sets the string for the last MySQL error message on the connection,
- * managing memory as appropriate. Supply a nil string to store the
- * last error on the connection.
- */
-- (void) setLastErrorMessage:(NSString *)theErrorMessage
-{
- if (!theErrorMessage) theErrorMessage = [self stringWithCString:mysql_error(mConnection)];
-
- if (lastQueryErrorMessage) [lastQueryErrorMessage release], lastQueryErrorMessage = nil;
- lastQueryErrorMessage = [[NSString alloc] initWithString:theErrorMessage];
-}
-
-/*
- * Returns the ErrorID of the last MySQL error on the connection.
- * This is cached within the object to allow helper queries to be performed
- * without affecting the state that the GUI is querying.
- */
-- (unsigned int) getLastErrorID
-{
- return lastQueryErrorId;
-}
-
-/*
- * Returns the number of affected rows by the last query.
- * This is cached within the object to allow helper queries to be performed
- * without affecting the state that the GUI is querying.
- */
-- (my_ulonglong) affectedRows
-{
- return lastQueryAffectedRows;
-}
-
-/*
- * Retrieve the max_allowed_packet size from the server; returns
- * false if the query fails.
- */
-- (BOOL) fetchMaxAllowedPacket
-{
- char *queryString;
-
- if ([self serverMajorVersion] == 3) queryString = "SHOW VARIABLES LIKE 'max_allowed_packet'";
- else queryString = "SELECT @@global.max_allowed_packet";
- if (0 == mysql_query(mConnection, queryString)) {
- if (mysql_field_count(mConnection) != 0) {
- CMMCPResult *r = [[CMMCPResult alloc] initWithMySQLPtr:mConnection encoding:mEncoding timeZone:mTimeZone];
- NSArray *a = [r fetchRowAsArray];
- [r autorelease];
- if([a count]) {
- maxAllowedPacketSize = [[a objectAtIndex:([self serverMajorVersion] == 3)?1:0] intValue];
- return true;
- }
- }
- }
-
- return false;
-}
-
-/*
- * Retrieves max_allowed_packet size set as global variable.
- * It returns -1 if it fails.
- */
-- (int) getMaxAllowedPacket
-{
- return maxAllowedPacketSize;
-}
-
-/*
- * 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 resetSize:(BOOL)reset
-{
- 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
- if(delegate && [delegate respondsToSelector:@selector(queryGaveError:)])
- if(reset)
- [delegate queryGaveError:[NSString stringWithFormat:@"max_allowed_packet was reset to %d for new session", newSize]];
- 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 maxAllowedPacketSize;
-}
-
-
-/*
- * It returns whether max_allowed_packet is setable for the user.
- */
-- (BOOL) isMaxAllowedPacketEditable
-{
- return(!mysql_query(mConnection, "SET GLOBAL max_allowed_packet = @@global.max_allowed_packet"));
-}
-
-/*
- * Check some common locations for the presence of a MySQL socket file, returning
- * it if successful.
- */
-- (NSString *)findSocketPath
-{
- NSFileManager *fileManager = [NSFileManager defaultManager];
- NSArray *possibleSocketLocations = [NSArray arrayWithObjects:
- @"/tmp/mysql.sock", // Default
- @"/var/run/mysqld/mysqld.sock", // As used on Debian/Gentoo
- @"/var/tmp/mysql.sock", // As used on FreeBSD
- @"/var/lib/mysql/mysql.sock", // As used by Fedora
- @"/opt/local/lib/mysql/mysql.sock", // Alternate fedora
- @"/opt/local/var/run/mysqld/mysqld.sock", // Darwinports MySQL
- @"/opt/local/var/run/mysql4/mysqld.sock", // Darwinports MySQL 4
- @"/opt/local/var/run/mysql5/mysqld.sock", // Darwinports MySQL 5
- @"/Applications/MAMP/tmp/mysql/mysql.sock", // MAMP default location
- nil];
-
- for (int i = 0; i < [possibleSocketLocations count]; i++) {
- if ([fileManager fileExistsAtPath:[possibleSocketLocations objectAtIndex:i]])
- return [possibleSocketLocations objectAtIndex:i];
- }
-
- return nil;
-}
-
-- (void) dealloc
-{
- delegate = nil;
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- if (lastQueryErrorMessage) [lastQueryErrorMessage release];
- if (connectionHost) [connectionHost release];
- if (connectionLogin) [connectionLogin release];
- if (connectionSocket) [connectionSocket release];
- if (connectionPassword) [connectionPassword release];
- if (connectionKeychainName) [connectionKeychainName release];
- if (connectionKeychainAccount) [connectionKeychainAccount release];
- if (lastKeepAliveSuccess) [lastKeepAliveSuccess release];
-
- [super dealloc];
-}
-
-@end \ No newline at end of file
diff --git a/Source/CMMCPResult.h b/Source/CMMCPResult.h
deleted file mode 100644
index e6c99fde..00000000
--- a/Source/CMMCPResult.h
+++ /dev/null
@@ -1,54 +0,0 @@
-//
-// $Id$
-//
-// CMMCPResult.h
-// sequel-pro
-//
-// Created by lorenz textor (lorenz@textor.ch) on Wed Sept 21 2005.
-// Copyright (c) 2002-2003 Lorenz Textor. 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/>
-
-#import <Cocoa/Cocoa.h>
-#import <MCPKit_bundled/MCPKit_bundled.h>
-
-#define FIELD_TYPE_BIT 16
-#define MAGIC_BINARY_CHARSET_NR 63
-
-@interface CMMCPResult : MCPResult
-
-typedef struct st_our_charset
-{
- unsigned int nr;
- const char *name;
- const char *collation;
- unsigned int char_minlen;
- unsigned int char_maxlen;
-} OUR_CHARSET;
-
-
-- (id)fetchRowAsType:(MCPReturnType)aType;
-- (NSArray *)fetchResultFieldsStructure;
-
-
-- (NSString *)mysqlTypeToStringForType:(unsigned int)type withCharsetNr:(unsigned int)charsetnr withFlags:(unsigned int)flags withLength:(unsigned long long)length;
-- (NSString *)mysqlTypeToGroupForType:(unsigned int)type withCharsetNr:(unsigned int)charsetnr withFlags:(unsigned int)flags;
-- (NSString *)find_charsetName:(unsigned int)charsetnr;
-- (NSString *)find_charsetCollation:(unsigned int)charsetnr;
-- (unsigned int)find_charsetMaxByteLengthPerChar:(unsigned int)charsetnr;
-
-@end
diff --git a/Source/CMMCPResult.m b/Source/CMMCPResult.m
deleted file mode 100644
index 610b6655..00000000
--- a/Source/CMMCPResult.m
+++ /dev/null
@@ -1,640 +0,0 @@
-//
-// $Id$
-//
-// CMMCPResult.m
-// sequel-pro
-//
-// Created by lorenz textor (lorenz@textor.ch) on Wed Sept 21 2005.
-// Copyright (c) 2002-2003 Lorenz Textor. 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/>
-
-#import "CMMCPResult.h"
-#import "SPArrayAdditions.h"
-
-@implementation CMMCPResult
-
-
-const OUR_CHARSET our_charsets60[] =
-{
- { 1, "big5","big5_chinese_ci", 1, 2},
- { 3, "dec8", "dec8_swedisch_ci", 1, 1},
- { 4, "cp850", "cp850_general_ci", 1, 1},
- { 6, "hp8", "hp8_english_ci", 1, 1},
- { 7, "koi8r", "koi8r_general_ci", 1, 1},
- { 8, "latin1", "latin1_swedish_ci", 1, 1},
- { 9, "latin2", "latin2_general_ci", 1, 1},
- { 10, "swe7", "swe7_swedish_ci", 1, 1},
- { 11, "ascii", "ascii_general_ci", 1, 1},
- { 12, "ujis", "ujis_japanese_ci", 1, 3},
- { 13, "sjis", "sjis_japanese_ci", 1, 2},
- { 16, "hebrew", "hebrew_general_ci", 1, 1},
- { 18, "tis620", "tis620_thai_ci", 1, 1},
- { 19, "euckr", "euckr_korean_ci", 1, 2},
- { 22, "koi8u", "koi8u_general_ci", 1, 1},
- { 24, "gb2312", "gb2312_chinese_ci", 1, 2},
- { 25, "greek", "greek_general_ci", 1, 1},
- { 26, "cp1250", "cp1250_general_ci", 1, 1},
- { 28, "gbk", "gbk_chinese_ci", 1, 2},
- { 30, "latin5", "latin5_turkish_ci", 1, 1},
- { 32, "armscii8", "armscii8_general_ci", 1, 1},
- { 33, "utf8", "utf8_general_ci", 1, 3},
- { 35, "ucs2", "ucs2_general_ci", 2, 2},
- { 36, "cp866", "cp866_general_ci", 1, 1},
- { 37, "keybcs2", "keybcs2_general_ci", 1, 1},
- { 38, "macce", "macce_general_ci", 1, 1},
- { 39, "macroman", "macroman_general_ci", 1, 1},
- { 40, "cp852", "cp852_general_ci", 1, 1},
- { 41, "latin7", "latin7_general_ci", 1, 1},
- { 51, "cp1251", "cp1251_general_ci", 1, 1},
- { 57, "cp1256", "cp1256_general_ci", 1, 1},
- { 59, "cp1257", "cp1257_general_ci", 1, 1},
- { 63, "binary", "binary", 1, 1},
- { 92, "geostd8", "geostd8_general_ci", 1, 1},
- { 95, "cp932", "cp932_japanese_ci", 1, 2},
- { 97, "eucjpms", "eucjpms_japanese_ci", 1, 3},
- { 2, "latin2", "latin2_czech_cs", 1, 1},
- { 5, "latin1", "latin1_german_ci", 1, 1},
- { 14, "cp1251", "cp1251_bulgarian_ci", 1, 1},
- { 15, "latin1", "latin1_danish_ci", 1, 1},
- { 17, "filename", "filename", 1, 5},
- { 20, "latin7", "latin7_estonian_cs", 1, 1},
- { 21, "latin2", "latin2_hungarian_ci", 1, 1},
- { 23, "cp1251", "cp1251_ukrainian_ci", 1, 1},
- { 27, "latin2", "latin2_croatian_ci", 1, 1},
- { 29, "cp1257", "cp1257_lithunian_ci", 1, 1},
- { 31, "latin1", "latin1_german2_ci", 1, 1},
- { 34, "cp1250", "cp1250_czech_cs", 1, 1},
- { 42, "latin7", "latin7_general_cs", 1, 1},
- { 43, "macce", "macce_bin", 1, 1},
- { 44, "cp1250", "cp1250_croatian_ci", 1, 1},
- { 45, "utf8", "utf8_general_ci", 1, 1},
- { 46, "utf8", "utf8_bin", 1, 1},
- { 47, "latin1", "latin1_bin", 1, 1},
- { 48, "latin1", "latin1_general_ci", 1, 1},
- { 49, "latin1", "latin1_general_cs", 1, 1},
- { 50, "cp1251", "cp1251_bin", 1, 1},
- { 52, "cp1251", "cp1251_general_cs", 1, 1},
- { 53, "macroman", "macroman_bin", 1, 1},
- { 58, "cp1257", "cp1257_bin", 1, 1},
- { 60, "armascii8", "armascii8_bin", 1, 1},
- { 65, "ascii", "ascii_bin", 1, 1},
- { 66, "cp1250", "cp1250_bin", 1, 1},
- { 67, "cp1256", "cp1256_bin", 1, 1},
- { 68, "cp866", "cp866_bin", 1, 1},
- { 69, "dec8", "dec8_bin", 1, 1},
- { 70, "greek", "greek_bin", 1, 1},
- { 71, "hebew", "hebrew_bin", 1, 1},
- { 72, "hp8", "hp8_bin", 1, 1},
- { 73, "keybcs2", "keybcs2_bin", 1, 1},
- { 74, "koi8r", "koi8r_bin", 1, 1},
- { 75, "koi8u", "koi8u_bin", 1, 1},
- { 77, "latin2", "latin2_bin", 1, 1},
- { 78, "latin5", "latin5_bin", 1, 1},
- { 79, "latin7", "latin7_bin", 1, 1},
- { 80, "cp850", "cp850_bin", 1, 1},
- { 81, "cp852", "cp852_bin", 1, 1},
- { 82, "swe7", "swe7_bin", 1, 1},
- { 93, "geostd8", "geostd8_bin", 1, 1},
- { 83, "utf8", "utf8_bin", 1, 3},
- { 84, "big5", "big5_bin", 1, 2},
- { 85, "euckr", "euckr_bin", 1, 2},
- { 86, "gb2312", "gb2312_bin", 1, 2},
- { 87, "gbk", "gbk_bin", 1, 2},
- { 88, "sjis", "sjis_bin", 1, 2},
- { 89, "tis620", "tis620_bin", 1, 1},
- { 90, "ucs2", "ucs2_bin", 2, 2},
- { 91, "ujis", "ujis_bin", 1, 3},
- { 94, "latin1", "latin1_spanish_ci", 1, 1},
- { 96, "cp932", "cp932_bin", 1, 2},
- { 99, "cp1250", "cp1250_polish_ci", 1, 1},
- { 98, "eucjpms", "eucjpms_bin", 1, 3},
- { 128, "ucs2", "ucs2_unicode_ci", 2, 2},
- { 129, "ucs2", "ucs2_icelandic_ci", 2, 2},
- { 130, "ucs2", "ucs2_latvian_ci", 2, 2},
- { 131, "ucs2", "ucs2_romanian_ci", 2, 2},
- { 132, "ucs2", "ucs2_slovenian_ci", 2, 2},
- { 133, "ucs2", "ucs2_polish_ci", 2, 2},
- { 134, "ucs2", "ucs2_estonian_ci", 2, 2},
- { 135, "ucs2", "ucs2_spanish_ci", 2, 2},
- { 136, "ucs2", "ucs2_swedish_ci", 2, 2},
- { 137, "ucs2", "ucs2_turkish_ci", 2, 2},
- { 138, "ucs2", "ucs2_czech_ci", 2, 2},
- { 139, "ucs2", "ucs2_danish_ci", 2, 2},
- { 140, "ucs2", "ucs2_lithunian_ci", 2, 2},
- { 141, "ucs2", "ucs2_slovak_ci", 2, 2},
- { 142, "ucs2", "ucs2_spanish2_ci", 2, 2},
- { 143, "ucs2", "ucs2_roman_ci", 2, 2},
- { 144, "ucs2", "ucs2_persian_ci", 2, 2},
- { 145, "ucs2", "ucs2_esperanto_ci", 2, 2},
- { 146, "ucs2", "ucs2_hungarian_ci", 2, 2},
- { 147, "ucs2", "ucs2_sinhala_ci", 2, 2},
- { 192, "utf8mb3", "utf8mb3_general_ci", 1, 3},
- { 193, "utf8mb3", "utf8mb3_icelandic_ci", 1, 3},
- { 194, "utf8mb3", "utf8mb3_latvian_ci", 1, 3},
- { 195, "utf8mb3", "utf8mb3_romanian_ci", 1, 3},
- { 196, "utf8mb3", "utf8mb3_slovenian_ci", 1, 3},
- { 197, "utf8mb3", "utf8mb3_polish_ci", 1, 3},
- { 198, "utf8mb3", "utf8mb3_estonian_ci", 1, 3},
- { 119, "utf8mb3", "utf8mb3_spanish_ci", 1, 3},
- { 200, "utf8mb3", "utf8mb3_swedish_ci", 1, 3},
- { 201, "utf8mb3", "utf8mb3_turkish_ci", 1, 3},
- { 202, "utf8mb3", "utf8mb3_czech_ci", 1, 3},
- { 203, "utf8mb3", "utf8mb3_danish_ci", 1, 3},
- { 204, "utf8mb3", "utf8mb3_lithunian_ci", 1, 3},
- { 205, "utf8mb3", "utf8mb3_slovak_ci", 1, 3},
- { 206, "utf8mb3", "utf8mb3_spanish2_ci", 1, 3},
- { 207, "utf8mb3", "utf8mb3_roman_ci", 1, 3},
- { 208, "utf8mb3", "utf8mb3_persian_ci", 1, 3},
- { 209, "utf8mb3", "utf8mb3_esperanto_ci", 1, 3},
- { 210, "utf8mb3", "utf8mb3_hungarian_ci", 1, 3},
- { 211, "utf8mb3", "utf8mb3_sinhala_ci", 1, 3},
- { 224, "utf8", "utf8_unicode_ci", 1, 3},
- { 225, "utf8", "utf8_icelandic_ci", 1, 3},
- { 226, "utf8", "utf8_latvian_ci", 1, 3},
- { 227, "utf8", "utf8_romanian_ci", 1, 3},
- { 228, "utf8", "utf8_slovenian_ci", 1, 3},
- { 229, "utf8", "utf8_polish_ci", 1, 3},
- { 230, "utf8", "utf8_estonian_ci", 1, 3},
- { 231, "utf8", "utf8_spanish_ci", 1, 3},
- { 232, "utf8", "utf8_swedish_ci", 1, 3},
- { 233, "utf8", "utf8_turkish_ci", 1, 3},
- { 234, "utf8", "utf8_czech_ci", 1, 3},
- { 235, "utf8", "utf8_danish_ci", 1, 3},
- { 236, "utf8", "utf8_lithuanian_ci", 1, 3},
- { 237, "utf8", "utf8_slovak_ci", 1, 3},
- { 238, "utf8", "utf8_spanish2_ci", 1, 3},
- { 239, "utf8", "utf8_roman_ci", 1, 3},
- { 240, "utf8", "utf8_persian_ci", 1, 3},
- { 241, "utf8", "utf8_esperanto_ci", 1, 3},
- { 242, "utf8", "utf8_hungarian_ci", 1, 3},
- { 243, "utf8", "utf8_sinhala_ci", 1, 3},
- { 254, "utf8mb3", "utf8mb3_general_cs", 1, 3},
- { 0, NULL, NULL, 0, 0}
-};
-
-
-/*
-modified version for use with sequel-pro
-*/
-- (id)fetchRowAsType:(MCPReturnType)aType
-{
- MYSQL_ROW theRow;
- unsigned long *theLengths;
- MYSQL_FIELD *theField;
- int i;
- id theReturn;
-
- if (mResult == NULL) {
- // If there is no results, returns nil, as after the last row...
- return nil;
- }
-
- theRow = mysql_fetch_row(mResult);
- if (theRow == NULL) {
- return nil;
- }
-
- switch (aType) {
- case MCPTypeArray:
- theReturn = [NSMutableArray arrayWithCapacity:mNumOfFields];
- break;
- case MCPTypeDictionary:
- if (mNames == nil) {
- [self fetchFieldNames];
- }
- theReturn = [NSMutableDictionary dictionaryWithCapacity:mNumOfFields];
- break;
- default :
- NSLog (@"Unknown type : %d, will return an Array!\n", aType);
- theReturn = [NSMutableArray arrayWithCapacity:mNumOfFields];
- break;
- }
-
- theLengths = mysql_fetch_lengths(mResult);
- theField = mysql_fetch_fields(mResult);
-
- for (i=0; i<mNumOfFields; i++) {
- id theCurrentObj;
-
- if (theRow[i] == NULL) {
- theCurrentObj = [NSNull null];
- } else {
- char *theData = calloc(sizeof(char),theLengths[i]+1);
- //char *theUselLess;
- memcpy(theData, theRow[i],theLengths[i]);
- theData[theLengths[i]] = '\0';
-
- switch (theField[i].type) {
- case FIELD_TYPE_TINY:
- case FIELD_TYPE_SHORT:
- case FIELD_TYPE_INT24:
- case FIELD_TYPE_LONG:
- case FIELD_TYPE_LONGLONG:
- case FIELD_TYPE_DECIMAL:
- case FIELD_TYPE_FLOAT:
- case FIELD_TYPE_DOUBLE:
- case FIELD_TYPE_NEW_DECIMAL:
- case FIELD_TYPE_TIMESTAMP:
- case FIELD_TYPE_DATE:
- case FIELD_TYPE_TIME:
- case FIELD_TYPE_DATETIME:
- case FIELD_TYPE_YEAR:
- case FIELD_TYPE_VAR_STRING:
- case FIELD_TYPE_STRING:
- case FIELD_TYPE_SET:
- case FIELD_TYPE_ENUM:
- case FIELD_TYPE_NEWDATE: // Don't know what the format for this type is...
- theCurrentObj = [self stringWithCString:theData];
- break;
-
- case FIELD_TYPE_BIT:
- theCurrentObj = [NSString stringWithFormat:@"%u", theData[0]];
- break;
-
- case FIELD_TYPE_TINY_BLOB:
- case FIELD_TYPE_BLOB:
- case FIELD_TYPE_MEDIUM_BLOB:
- case FIELD_TYPE_LONG_BLOB:
- theCurrentObj = [NSData dataWithBytes:theData length:theLengths[i]];
- if (!(theField[i].flags & BINARY_FLAG)) { // It is TEXT and NOT BLOB...
- theCurrentObj = [self stringWithText:theCurrentObj];
- } // #warning Should check for TEXT (using theField[i].flag BINARY_FLAG)
- break;
-
- case FIELD_TYPE_NULL:
- theCurrentObj = [NSNull null];
- break;
-
- default:
- NSLog (@"in fetchRowAsType : Unknown type : %d for column %d, send back a NSData object", (int)theField[i].type, (int)i);
- theCurrentObj = [NSData dataWithBytes:theData length:theLengths[i]];
- break;
- }
-
- free(theData);
-
- // Some of the creators return nil object...
- if (theCurrentObj == nil) {
- theCurrentObj = [NSNull null];
- }
- }
-
- switch (aType) {
- case MCPTypeDictionary :
- [theReturn setObject:theCurrentObj forKey:NSArrayObjectAtIndex(mNames, i)];
- break;
-
- case MCPTypeArray :
- default :
- [theReturn addObject:theCurrentObj];
- break;
- }
- }
-
- return theReturn;
-}
-
-/*
- * Return an array of dicts containg column data of the last executed query
- */
-- (NSArray *)fetchResultFieldsStructure
-{
- MYSQL_FIELD *theField;
-
- NSMutableArray *structureResult = [NSMutableArray array];
-
- unsigned int i;
- unsigned int numFields = mysql_num_fields(mResult);
-
- if (mResult == NULL) return nil;
-
- theField = mysql_fetch_fields(mResult);
-
- for (i=0; i < numFields; i++)
- {
- NSMutableDictionary *fieldStructure = [NSMutableDictionary dictionaryWithCapacity:39];
-
- /* Original column position */
- [fieldStructure setObject:[NSNumber numberWithInt:i] forKey:@"datacolumnindex"];
-
- /* Name of column */
- [fieldStructure setObject:[self stringWithCString:theField[i].name] forKey:@"name"];
- // [fieldStructure setObject:[NSNumber numberWithUnsignedInt:theField[i].name_length] forKey:@"name_length"];
-
- /* Original column name, if an alias */
- [fieldStructure setObject:[self stringWithCString:theField[i].org_name] forKey:@"org_name"];
- // [fieldStructure setObject:[NSNumber numberWithUnsignedInt:theField[i].org_name_length] forKey:@"org_name_length"];
-
- /* Table of column if column was a field */
- [fieldStructure setObject:[self stringWithCString:theField[i].table] forKey:@"table"];
- // [fieldStructure setObject:[NSNumber numberWithUnsignedInt:theField[i].table_length] forKey:@"table_length"];
-
- /* Org table name, if table was an alias */
- [fieldStructure setObject:[self stringWithCString:theField[i].org_table] forKey:@"org_table"];
- // [fieldStructure setObject:[NSNumber numberWithUnsignedInt:theField[i].org_table_length] forKey:@"org_table_length"];
-
- /* Database for table */
- [fieldStructure setObject:[self stringWithCString:theField[i].db] forKey:@"db"];
- // [fieldStructure setObject:[NSNumber numberWithUnsignedInt:theField[i].db_length] forKey:@"db_length"];
-
- /* Catalog for table */
- // [fieldStructure setObject:[self stringWithCString:theField[i].catalog] forKey:@"catalog"];
- // [fieldStructure setObject:[NSNumber numberWithUnsignedInt:theField[i].catalog_length] forKey:@"catalog_length"];
-
- /* Default value (set by mysql_list_fields) */
- // [fieldStructure setObject:[self stringWithCString:theField[i].def] forKey:@"def"];
- // [fieldStructure setObject:[NSNumber numberWithUnsignedInt:theField[i].def_length] forKey:@"def_length"];
-
- /* Width of column (real length in bytes) */
- [fieldStructure setObject:[NSNumber numberWithUnsignedLongLong:theField[i].length] forKey:@"byte_length"];
- /* Width of column (as in create)*/
- [fieldStructure setObject:[NSNumber numberWithUnsignedLongLong:theField[i].length/[self find_charsetMaxByteLengthPerChar:theField[i].charsetnr]]
- forKey:@"char_length"];
- /* Max width (bytes) for selected set */
- [fieldStructure setObject:[NSNumber numberWithUnsignedLongLong:theField[i].max_length] forKey:@"max_byte_length"];
- /* Max width (chars) for selected set */
- // [fieldStructure setObject:[NSNumber numberWithUnsignedLongLong:theField[i].max_length/[self find_charsetMaxByteLengthPerChar:theField[i].charsetnr]]
- // forKey:@"max_char_length"];
-
- /* Div flags */
- [fieldStructure setObject:[NSNumber numberWithUnsignedInt:theField[i].flags] forKey:@"flags"];
- [fieldStructure setObject:[NSNumber numberWithBool:(theField[i].flags & NOT_NULL_FLAG) ? YES : NO] forKey:@"null"];
- [fieldStructure setObject:[NSNumber numberWithBool:(theField[i].flags & PRI_KEY_FLAG) ? YES : NO] forKey:@"PRI_KEY_FLAG"];
- [fieldStructure setObject:[NSNumber numberWithBool:(theField[i].flags & UNIQUE_KEY_FLAG) ? YES : NO] forKey:@"UNIQUE_KEY_FLAG"];
- [fieldStructure setObject:[NSNumber numberWithBool:(theField[i].flags & MULTIPLE_KEY_FLAG) ? YES : NO] forKey:@"MULTIPLE_KEY_FLAG"];
- [fieldStructure setObject:[NSNumber numberWithBool:(theField[i].flags & BLOB_FLAG) ? YES : NO] forKey:@"BLOB_FLAG"];
- [fieldStructure setObject:[NSNumber numberWithBool:(theField[i].flags & UNSIGNED_FLAG) ? YES : NO] forKey:@"UNSIGNED_FLAG"];
- [fieldStructure setObject:[NSNumber numberWithBool:(theField[i].flags & ZEROFILL_FLAG) ? YES : NO] forKey:@"ZEROFILL_FLAG"];
- [fieldStructure setObject:[NSNumber numberWithBool:(theField[i].flags & BINARY_FLAG) ? YES : NO] forKey:@"BINARY_FLAG"];
- [fieldStructure setObject:[NSNumber numberWithBool:(theField[i].flags & ENUM_FLAG) ? YES : NO] forKey:@"ENUM_FLAG"];
- [fieldStructure setObject:[NSNumber numberWithBool:(theField[i].flags & AUTO_INCREMENT_FLAG) ? YES : NO] forKey:@"AUTO_INCREMENT_FLAG"];
- [fieldStructure setObject:[NSNumber numberWithBool:(theField[i].flags & SET_FLAG) ? YES : NO] forKey:@"SET_FLAG"];
- [fieldStructure setObject:[NSNumber numberWithBool:(theField[i].flags & NUM_FLAG) ? YES : NO] forKey:@"NUM_FLAG"];
- [fieldStructure setObject:[NSNumber numberWithBool:(theField[i].flags & PART_KEY_FLAG) ? YES : NO] forKey:@"PART_KEY_FLAG"];
- // [fieldStructure setObject:[NSNumber numberWithInt:(theField[i].flags & GROUP_FLAG) ? 1 : 0] forKey:@"GROUP_FLAG"];
- // [fieldStructure setObject:[NSNumber numberWithInt:(theField[i].flags & UNIQUE_FLAG) ? 1 : 0] forKey:@"UNIQUE_FLAG"];
- // [fieldStructure setObject:[NSNumber numberWithInt:(theField[i].flags & BINCMP_FLAG) ? 1 : 0] forKey:@"BINCMP_FLAG"];
-
- /* Number of decimals in field */
- [fieldStructure setObject:[NSNumber numberWithUnsignedInt:theField[i].decimals] forKey:@"decimals"];
-
- /* Character set */
- [fieldStructure setObject:[NSNumber numberWithUnsignedInt:theField[i].charsetnr] forKey:@"charsetnr"];
- [fieldStructure setObject:[self find_charsetName:theField[i].charsetnr] forKey:@"charset_name"];
- [fieldStructure setObject:[self find_charsetCollation:theField[i].charsetnr] forKey:@"charset_collation"];
-
- /* Table type */
- [fieldStructure setObject:[self mysqlTypeToStringForType:theField[i].type
- withCharsetNr:theField[i].charsetnr
- withFlags:theField[i].flags
- withLength:theField[i].length
- ] forKey:@"type"];
-
- /* Table type group*/
- [fieldStructure setObject:[self mysqlTypeToGroupForType:theField[i].type
- withCharsetNr:theField[i].charsetnr
- withFlags:theField[i].flags
- ] forKey:@"typegrouping"];
-
- [structureResult addObject:fieldStructure];
-
- }
-
- return structureResult;
-
-}
-
-/*
- * Convert a mysql_type to a string
- */
-- (NSString *)mysqlTypeToStringForType:(unsigned int)type withCharsetNr:(unsigned int)charsetnr withFlags:(unsigned int)flags withLength:(unsigned long long)length
-{
- // BOOL isUnsigned = (flags & UNSIGNED_FLAG) != 0;
- // BOOL isZerofill = (flags & ZEROFILL_FLAG) != 0;
-
- switch (type) {
- case FIELD_TYPE_BIT:
- return @"BIT";
- case MYSQL_TYPE_DECIMAL:
- case FIELD_TYPE_NEW_DECIMAL:
- //return isUnsigned ? (isZerofill? @"DECIMAL UNSIGNED ZEROFILL" : @"DECIMAL UNSIGNED"):
- return @"DECIMAL";
- case MYSQL_TYPE_TINY:
- // return isUnsigned ? (isZerofill? @"TINYINT UNSIGNED ZEROFILL" : @"TINYINT UNSIGNED"):
- return @"TINYINT";
- case MYSQL_TYPE_SHORT:
- // return isUnsigned ? (isZerofill? @"SMALLINT UNSIGNED ZEROFILL" : @"SMALLINT UNSIGNED"):
- return @"SMALLINT";
- case MYSQL_TYPE_LONG:
- // return isUnsigned ? (isZerofill? @"INT UNSIGNED ZEROFILL" : @"INT UNSIGNED"):
- return @"INT";
- case MYSQL_TYPE_FLOAT:
- // return isUnsigned ? (isZerofill? @"FLOAT UNSIGNED ZEROFILL" : @"FLOAT UNSIGNED"):
- return @"FLOAT";
- case MYSQL_TYPE_DOUBLE:
- // return isUnsigned ? (isZerofill? @"DOUBLE UNSIGNED ZEROFILL" : @"DOUBLE UNSIGNED"):
- return @"DOUBLE";
- case MYSQL_TYPE_NULL:
- return @"NULL";
- case MYSQL_TYPE_TIMESTAMP:
- return @"TIMESTAMP";
- case MYSQL_TYPE_LONGLONG:
- // return isUnsigned ? (isZerofill? @"BIGINT UNSIGNED ZEROFILL" : @"BIGINT UNSIGNED") :
- return @"BIGINT";
- case MYSQL_TYPE_INT24:
- // return isUnsigned ? (isZerofill? @"MEDIUMINT UNSIGNED ZEROFILL" : @"MEDIUMINT UNSIGNED") :
- return @"MEDIUMINT";
- case MYSQL_TYPE_DATE:
- return @"DATE";
- case MYSQL_TYPE_TIME:
- return @"TIME";
- case MYSQL_TYPE_DATETIME:
- return @"DATETIME";
- case MYSQL_TYPE_TINY_BLOB:// should no appear over the wire
- case MYSQL_TYPE_MEDIUM_BLOB:// should no appear over the wire
- case MYSQL_TYPE_LONG_BLOB:// should no appear over the wire
- case MYSQL_TYPE_BLOB:
- {
- BOOL isBlob = (charsetnr == MAGIC_BINARY_CHARSET_NR);
- switch ((int)length/[self find_charsetMaxByteLengthPerChar:charsetnr]) {
- case 255: return isBlob? @"TINYBLOB":@"TINYTEXT";
- case 65535: return isBlob? @"BLOB":@"TEXT";
- case 16777215: return isBlob? @"MEDIUMBLOB":@"MEDIUMTEXT";
- case 4294967295: return isBlob? @"LONGBLOB":@"LONGTEXT";
- default:
- switch (length) {
- case 255: return isBlob? @"TINYBLOB":@"TINYTEXT";
- case 65535: return isBlob? @"BLOB":@"TEXT";
- case 16777215: return isBlob? @"MEDIUMBLOB":@"MEDIUMTEXT";
- case 4294967295: return isBlob? @"LONGBLOB":@"LONGTEXT";
- default:
- return @"UNKNOWN";
- }
- }
- }
- case MYSQL_TYPE_VAR_STRING:
- if (flags & ENUM_FLAG) {
- return @"ENUM";
- }
- if (flags & SET_FLAG) {
- return @"SET";
- }
- if (charsetnr == MAGIC_BINARY_CHARSET_NR) {
- return @"VARBINARY";
- }
- return @"VARCHAR";
- case MYSQL_TYPE_STRING:
- if (flags & ENUM_FLAG) {
- return @"ENUM";
- }
- if (flags & SET_FLAG) {
- return @"SET";
- }
- if ((flags & BINARY_FLAG) && charsetnr == MAGIC_BINARY_CHARSET_NR) {
- return @"BINARY";
- }
- return @"CHAR";
- case MYSQL_TYPE_ENUM:
- /* This should never happen */
- return @"ENUM";
- case MYSQL_TYPE_YEAR:
- return @"YEAR";
- case MYSQL_TYPE_SET:
- /* This should never happen */
- return @"SET";
- case MYSQL_TYPE_GEOMETRY:
- return @"GEOMETRY";
- default:
- return @"UNKNOWN";
- }
-}
-
-/*
- * Merge mysql_types into type groups
- */
-- (NSString *)mysqlTypeToGroupForType:(unsigned int)type withCharsetNr:(unsigned int)charsetnr withFlags:(unsigned int)flags
-{
- switch(type){
- case FIELD_TYPE_BIT:
- return @"bit";
- case MYSQL_TYPE_TINY:
- case MYSQL_TYPE_SHORT:
- case MYSQL_TYPE_LONG:
- case MYSQL_TYPE_LONGLONG:
- case MYSQL_TYPE_INT24:
- return @"integer";
- case MYSQL_TYPE_FLOAT:
- case MYSQL_TYPE_DOUBLE:
- case MYSQL_TYPE_DECIMAL:
- case FIELD_TYPE_NEW_DECIMAL:
- return @"float";
- case MYSQL_TYPE_YEAR:
- case MYSQL_TYPE_DATETIME:
- case MYSQL_TYPE_TIME:
- case MYSQL_TYPE_DATE:
- case MYSQL_TYPE_TIMESTAMP:
- return @"date";
- case MYSQL_TYPE_VAR_STRING:
- if (flags & ENUM_FLAG) {
- return @"enum";
- }
- if (flags & SET_FLAG) {
- return @"enum";
- }
- if (charsetnr == MAGIC_BINARY_CHARSET_NR) {
- return @"binary";
- }
- return @"string";
- case MYSQL_TYPE_STRING:
- if (flags & ENUM_FLAG) {
- return @"enum";
- }
- if (flags & SET_FLAG) {
- return @"enum";
- }
- if ((flags & BINARY_FLAG) && charsetnr == MAGIC_BINARY_CHARSET_NR) {
- return @"binary";
- }
- return @"string";
- case MYSQL_TYPE_TINY_BLOB:// should no appear over the wire
- case MYSQL_TYPE_MEDIUM_BLOB:// should no appear over the wire
- case MYSQL_TYPE_LONG_BLOB:// should no appear over the wire
- case MYSQL_TYPE_BLOB:
- {
- if (charsetnr == MAGIC_BINARY_CHARSET_NR) {
- return @"blobdata";
- } else {
- return @"textdata";
- }
- }
- case MYSQL_TYPE_GEOMETRY:
- return @"geometry";
- default:
- return @"blobdata";
-
- }
-}
-
-/*
- * Convert a mysql_charsetnr into a charset name as string
- */
-- (NSString *)find_charsetName:(unsigned int)charsetnr
-{
- const OUR_CHARSET * c = our_charsets60;
-
- do {
- if (c->nr == charsetnr)
- return [self stringWithCString:c->name];
- ++c;
- } while (c[0].nr != 0);
- return @"UNKNOWN";
-}
-
-/*
- * Convert a mysql_charsetnr into a collation name as string
- */
-- (NSString *)find_charsetCollation:(unsigned int)charsetnr
-{
- const OUR_CHARSET * c = our_charsets60;
-
- do {
- if (c->nr == charsetnr)
- return [self stringWithCString:c->collation];
- ++c;
- } while (c[0].nr != 0);
- return @"UNKNOWN";
-}
-
-/*
- * Return the max byte length to store a char by using
- * a specific mysql_charsetnr
- */
-- (unsigned int)find_charsetMaxByteLengthPerChar:(unsigned int)charsetnr
-{
- const OUR_CHARSET * c = our_charsets60;
-
- do {
- if (c->nr == charsetnr)
- return c->char_maxlen;
- ++c;
- } while (c[0].nr != 0);
- return 1;
-}
-
-
-@end
diff --git a/Source/CMTextView.h b/Source/CMTextView.h
index 152450b0..5272ab24 100644
--- a/Source/CMTextView.h
+++ b/Source/CMTextView.h
@@ -23,12 +23,11 @@
// More info at <http://code.google.com/p/sequel-pro/>
#import <Cocoa/Cocoa.h>
+#import <MCPKit/MCPKit.h>
+
#import "NoodleLineNumberView.h"
-#import <MCPKit_bundled/MCPKit_bundled.h>
#import "CMCopyTable.h"
#import "CMTextView.h"
-#import "CMMCPConnection.h"
-#import "CMMCPResult.h"
#define SP_TEXT_SIZE_TRIGGER_FOR_PARTLY_PARSING 10000
@@ -57,7 +56,7 @@ static inline void NSMutableAttributedStringAddAttributeValueRange (NSMutableAtt
NSUserDefaults *prefs;
- CMMCPConnection *mySQLConnection;
+ MCPConnection *mySQLConnection;
int mySQLmajorVersion;
}
@@ -87,7 +86,7 @@ static inline void NSMutableAttributedStringAddAttributeValueRange (NSMutableAtt
- (unsigned int) getLineNumberForCharacterIndex:(unsigned int)anIndex;
- (void) autoHelp;
- (void) doSyntaxHighlighting;
-- (void) setConnection:(CMMCPConnection *)theConnection withVersion:(int)majorVersion;
+- (void) setConnection:(MCPConnection *)theConnection withVersion:(int)majorVersion;
- (void) doCompletion;
- (NSArray *)suggestionsForSQLCompletionWith:(NSString *)currentWord dictMode:(BOOL)isDictMode;
- (void) selectCurrentQuery;
diff --git a/Source/CMTextView.m b/Source/CMTextView.m
index 3720a521..2ce6022d 100644
--- a/Source/CMTextView.m
+++ b/Source/CMTextView.m
@@ -30,8 +30,6 @@
#import "SPTextViewAdditions.h"
#import "SPNarrowDownCompletion.h"
-
-
#pragma mark -
#pragma mark lex init
@@ -104,7 +102,7 @@ YY_BUFFER_STATE yy_scan_string (const char *);
prefs = [[NSUserDefaults standardUserDefaults] retain];
}
-- (void) setConnection:(CMMCPConnection *)theConnection withVersion:(int)majorVersion
+- (void) setConnection:(MCPConnection *)theConnection withVersion:(int)majorVersion
{
mySQLConnection = theConnection;
mySQLmajorVersion = majorVersion;
diff --git a/Source/CustomQuery.h b/Source/CustomQuery.h
index 57b8ee85..fe2865ab 100644
--- a/Source/CustomQuery.h
+++ b/Source/CustomQuery.h
@@ -24,18 +24,17 @@
// More info at <http://code.google.com/p/sequel-pro/>
#import <Cocoa/Cocoa.h>
+#import <MCPKit/MCPKit.h>
#import <WebKit/WebKit.h>
-#import <MCPKit_bundled/MCPKit_bundled.h>
+
#import "CMCopyTable.h"
#import "CMTextView.h"
-#import "CMMCPConnection.h"
-#import "CMMCPResult.h"
#import "RegexKitLite.h"
#define SP_HELP_TOC_SEARCH_STRING @"contents"
-@interface CustomQuery : NSObject {
-
+@interface CustomQuery : NSObject
+{
IBOutlet id tableWindow;
IBOutlet id queryFavoritesButton;
IBOutlet id queryHistoryButton;
@@ -77,7 +76,7 @@
NSUserDefaults *prefs;
NSMutableArray *queryFavorites;
- CMMCPConnection *mySQLConnection;
+ MCPConnection *mySQLConnection;
NSString *usedQuery;
NSRange currentQueryRange;
@@ -135,7 +134,7 @@
// Accessors
- (NSArray *)currentResult;
-- (NSArray *)fetchResultAsArray:(CMMCPResult *)theResult;
+- (NSArray *)fetchResultAsArray:(MCPResult *)theResult;
// MySQL Help
- (NSString *)getHTMLformattedMySQLHelpFor:(NSString *)aString;
@@ -147,7 +146,7 @@
// Other
-- (void)setConnection:(CMMCPConnection *)theConnection;
+- (void)setConnection:(MCPConnection *)theConnection;
- (void)setFavorites;
- (void)doPerformQueryService:(NSString *)query;
- (void)selectCurrentQuery;
diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m
index 9ca44003..b6499431 100644
--- a/Source/CustomQuery.m
+++ b/Source/CustomQuery.m
@@ -397,7 +397,7 @@
NSArray *theColumns;
NSTableColumn *theCol;
- CMMCPResult *theResult = nil;
+ MCPResult *theResult = nil;
NSMutableArray *menuItems = [NSMutableArray array];
NSMutableString *errors = [NSMutableString string];
@@ -426,7 +426,10 @@
[customQueryView removeTableColumn:NSArrayObjectAtIndex(theColumns, 0)];
}
}
-
+
+ // Disable automatic query retries on failure for the custom queries
+ [mySQLConnection setAllowQueryRetries:NO];
+
long queryCount = [queries count];
NSMutableArray *tempQueries = [NSMutableArray arrayWithCapacity:queryCount];
@@ -627,6 +630,8 @@
}
}
+ // Restore automatic query retries
+ [mySQLConnection setAllowQueryRetries:YES];
// If no results were returned, redraw the empty table and post notifications before returning.
if ( !theResult || ![theResult numOfRows] ) {
@@ -714,7 +719,7 @@
/*
* Fetches the result as an array, with an array for each row in it
*/
-- (NSArray *)fetchResultAsArray:(CMMCPResult *)theResult
+- (NSArray *)fetchResultAsArray:(MCPResult *)theResult
{
// NSArray *columns;
unsigned long numOfRows = [theResult numOfRows];
@@ -1094,7 +1099,7 @@
/*
* Sets the connection (received from TableDocument) and makes things that have to be done only once
*/
-- (void)setConnection:(CMMCPConnection *)theConnection
+- (void)setConnection:(MCPConnection *)theConnection
{
NSArray *tableColumns = [queryFavoritesView tableColumns];
NSEnumerator *enumerator = [tableColumns objectEnumerator];
@@ -2053,7 +2058,7 @@
if(![searchString length]) return @"";
NSRange aRange;
- CMMCPResult *theResult = nil;
+ MCPResult *theResult = nil;
NSDictionary *tableDetails;
NSMutableString *theHelp = [NSMutableString string];
diff --git a/Source/KeyChain.m b/Source/KeyChain.m
index 94270cd6..58dc2451 100644
--- a/Source/KeyChain.m
+++ b/Source/KeyChain.m
@@ -24,8 +24,9 @@
// More info at <http://code.google.com/p/sequel-pro/>
#import "KeyChain.h"
-#include <CoreFoundation/CoreFoundation.h>
-#include <Security/Security.h>
+
+#import <CoreFoundation/CoreFoundation.h>
+#import <Security/Security.h>
@implementation KeyChain
diff --git a/Source/SPArrayAdditions.h b/Source/SPArrayAdditions.h
index 2d59d055..45b81e03 100644
--- a/Source/SPArrayAdditions.h
+++ b/Source/SPArrayAdditions.h
@@ -28,7 +28,6 @@ static inline id NSArrayObjectAtIndex(NSArray* self, NSUInteger i) {
return (id)CFArrayGetValueAtIndex((CFArrayRef)self, i);
}
-
@interface NSArray (SPArrayAdditions)
- (NSString *)componentsJoinedAndBacktickQuoted;
diff --git a/Source/SPConnectionController.h b/Source/SPConnectionController.h
index 03245d26..0ab3cc2e 100644
--- a/Source/SPConnectionController.h
+++ b/Source/SPConnectionController.h
@@ -24,10 +24,11 @@
// More info at <http://code.google.com/p/sequel-pro/>
#import <Cocoa/Cocoa.h>
+#import <MCPKit/MCPKit.h>
+
#import "TableDocument.h"
#import "KeyChain.h"
#import "SPSSHTunnel.h"
-#import "CMMCPConnection.h"
enum spconnection_types
{
@@ -36,7 +37,8 @@ enum spconnection_types
SP_CONNECTION_SSHTUNNEL = 2
};
-@interface SPConnectionController : NSObject {
+@interface SPConnectionController : NSObject
+{
TableDocument *tableDocument;
NSWindow *documentWindow;
NSSplitView *contentView;
@@ -44,7 +46,7 @@ enum spconnection_types
NSUserDefaults *prefs;
NSMutableArray *favorites;
SPSSHTunnel *sshTunnel;
- CMMCPConnection *mySQLConnection;
+ MCPConnection *mySQLConnection;
BOOL automaticFavoriteSelection;
int previousType;
@@ -60,7 +62,7 @@ enum spconnection_types
NSString *sshUser;
NSString *sshPassword;
NSString *sshPort;
-
+
NSString *connectionKeychainItemName;
NSString *connectionKeychainItemAccount;
NSString *connectionSSHKeychainItemName;
@@ -104,6 +106,11 @@ enum spconnection_types
@property (readwrite, retain) NSString *sshPassword;
@property (readwrite, retain) NSString *sshPort;
+@property (readwrite, retain) NSString *connectionKeychainItemName;
+@property (readwrite, retain) NSString *connectionKeychainItemAccount;
+@property (readwrite, retain) NSString *connectionSSHKeychainItemName;
+@property (readwrite, retain) NSString *connectionSSHKeychainItemAccount;
+
- (id) initWithDocument:(TableDocument *)theTableDocument;
// Connection processes
@@ -133,9 +140,8 @@ enum spconnection_types
@end
-
@interface SPFlippedView: NSView
-{
-}
+
- (BOOL)isFlipped;
+
@end
diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m
index 8d09e0d5..b401219a 100644
--- a/Source/SPConnectionController.m
+++ b/Source/SPConnectionController.m
@@ -43,6 +43,11 @@
@synthesize sshPassword;
@synthesize sshPort;
+@synthesize connectionKeychainItemName;
+@synthesize connectionKeychainItemAccount;
+@synthesize connectionSSHKeychainItemName;
+@synthesize connectionSSHKeychainItemAccount;
+
/**
* Initialise the connection controller, linking it to the
* parent document and setting up the parent window.
@@ -209,7 +214,7 @@
// Set up the tunnel details
sshTunnel = [[SPSSHTunnel alloc] initToHost:[self sshHost] port:([[self sshPort] length]?[[self sshPort] intValue]:22) login:[self sshUser] tunnellingToPort:([[self port] length]?[[self port] intValue]:3306) onHost:[self host]];
[sshTunnel setParentWindow:documentWindow];
-
+
// Add keychain or plaintext password as appropriate - note the checks in initiateConnection.
if (connectionSSHKeychainItemName) {
[sshTunnel setPasswordKeychainName:connectionSSHKeychainItemName account:connectionSSHKeychainItemAccount];
@@ -234,10 +239,10 @@
{
int newState = [theTunnel state];
- if (newState == SPSSH_STATE_IDLE) {
+ if (newState == PROXY_STATE_IDLE) {
[tableDocument setTitlebarStatus:@"SSH Disconnected"];
[self failConnectionWithTitle:NSLocalizedString(@"SSH connection failed!", @"SSH connection failed title") errorMessage:[theTunnel lastError] detail:[sshTunnel debugMessages]];
- } else if (newState == SPSSH_STATE_CONNECTED) {
+ } else if (newState == PROXY_STATE_CONNECTED) {
[tableDocument setTitlebarStatus:@"SSH Connected"];
[self initiateMySQLConnection];
} else {
@@ -258,29 +263,34 @@
// Initialise to socket if appropriate.
if ([self type] == SP_CONNECTION_SOCKET) {
- mySQLConnection = [[CMMCPConnection alloc] initToSocket:[self socket] withLogin:[self user]];
+ mySQLConnection = [[MCPConnection alloc] initToSocket:[self socket] withLogin:[self user]];
// Otherwise, initialise to host, using tunnel if appropriate
} else {
if ([self type] == SP_CONNECTION_SSHTUNNEL) {
- mySQLConnection = [[CMMCPConnection alloc] initToHost:@"127.0.0.1"
+ mySQLConnection = [[MCPConnection alloc] initToHost:@"127.0.0.1"
withLogin:[self user]
usingPort:[sshTunnel localPort]];
- [mySQLConnection setSSHTunnel:sshTunnel];
+ [mySQLConnection setConnectionProxy:sshTunnel];
} else {
- mySQLConnection = [[CMMCPConnection alloc] initToHost:[self host]
+ mySQLConnection = [[MCPConnection alloc] initToHost:[self host]
withLogin:[self user]
usingPort:([[self port] length]?[[self port] intValue]:3306)];
}
}
- [mySQLConnection setParentWindow:documentWindow];
- // Set the password as appropriate
- if (connectionKeychainItemName) {
- [mySQLConnection setPasswordKeychainName:connectionKeychainItemName account:connectionKeychainItemAccount];
- } else {
+ // Only set the password if there is no Keychain item set. The connection will ask the delegate for passwords in the Keychain.
+ if (!connectionKeychainItemName) {
[mySQLConnection setPassword:[self password]];
}
+
+ // Connection delegate must be set before actual connection attempt is made
+ [mySQLConnection setDelegate:tableDocument];
+
+ // Set options from preferences
+ [mySQLConnection setConnectionTimeout:[[prefs objectForKey:@"ConnectionTimeoutValue"] intValue]];
+ [mySQLConnection setUseKeepAlive:[[prefs objectForKey:@"UseKeepAlive"] boolValue]];
+ [mySQLConnection setKeepAliveInterval:[[prefs objectForKey:@"KeepAliveInterval"] floatValue]];
// Connect
[mySQLConnection connect];
@@ -292,7 +302,7 @@
[[NSRunLoop currentRunLoop] runMode:NSModalPanelRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.2]];
// If the state is connection refused, attempt the MySQL connection again with the host using the hostfield value.
- if ([sshTunnel state] == SPSSH_STATE_FORWARDING_FAILED) {
+ if ([sshTunnel state] == PROXY_STATE_FORWARDING_FAILED) {
if ([sshTunnel localPortFallback]) {
[mySQLConnection setPort:[sshTunnel localPortFallback]];
[mySQLConnection connect];
@@ -305,7 +315,7 @@
if (![mySQLConnection isConnected]) {
NSString *errorMessage;
- if (sshTunnel && [sshTunnel state] == SPSSH_STATE_FORWARDING_FAILED) {
+ if (sshTunnel && [sshTunnel state] == PROXY_STATE_FORWARDING_FAILED) {
errorMessage = [NSString stringWithFormat:NSLocalizedString(@"Unable to connect to host %@ because the port connection via SSH was refused.\n\nPlease ensure that your MySQL host is set up to allow TCP/IP connections (no --skip-networking) and is configured to allow connections from the host you are tunnelling via.\n\nYou may also want to check the port is correct and that you have the necessary privileges.\n\nChecking the error detail will show the SSH debug log which may provide more details.\n\nMySQL said: %@", @"message of panel when SSH port forwarding failed"), [self host], [mySQLConnection getLastErrorMessage]];
[self failConnectionWithTitle:NSLocalizedString(@"SSH port forwarding failed", @"title when ssh tunnel port forwarding failed") errorMessage:errorMessage detail:[sshTunnel debugMessages]];
} else if ([mySQLConnection getLastErrorID] == 1045) { // "Access denied" error
diff --git a/Source/SPDataAdditions.h b/Source/SPDataAdditions.h
index 207921ec..1b787484 100644
--- a/Source/SPDataAdditions.h
+++ b/Source/SPDataAdditions.h
@@ -24,7 +24,6 @@
#import <Cocoa/Cocoa.h>
-
@interface NSData (SPDataAdditions)
- (NSString *) base64EncodingWithLineLength:(unsigned int)lineLength;
diff --git a/Source/SPDataCellFormatter.h b/Source/SPDataCellFormatter.h
index dc229e9b..9c2e8c3a 100644
--- a/Source/SPDataCellFormatter.h
+++ b/Source/SPDataCellFormatter.h
@@ -25,7 +25,8 @@
#import <Cocoa/Cocoa.h>
-@interface SPDataCellFormatter : NSFormatter {
+@interface SPDataCellFormatter : NSFormatter
+{
int textLimit;
}
diff --git a/Source/SPDatabaseData.h b/Source/SPDatabaseData.h
index 13eeb4b4..b03a59b4 100644
--- a/Source/SPDatabaseData.h
+++ b/Source/SPDatabaseData.h
@@ -24,8 +24,7 @@
// More info at <http://code.google.com/p/sequel-pro/>
#import <Cocoa/Cocoa.h>
-
-@class CMMCPConnection;
+#import <MCPKit/MCPKit.h>
typedef struct _CHAR_SETS
{
@@ -43,10 +42,10 @@ typedef struct _CHAR_SETS
NSMutableArray *storageEngines;
NSMutableArray *characterSetEncodings;
- CMMCPConnection *connection;
+ MCPConnection *connection;
}
-@property (readwrite, assign) CMMCPConnection *connection;
+@property (readwrite, assign) MCPConnection *connection;
- (void)resetAllData;
diff --git a/Source/SPDatabaseData.m b/Source/SPDatabaseData.m
index a9c86ccc..f3fbc582 100644
--- a/Source/SPDatabaseData.m
+++ b/Source/SPDatabaseData.m
@@ -24,8 +24,6 @@
// More info at <http://code.google.com/p/sequel-pro/>
#import "SPDatabaseData.h"
-#import "CMMCPConnection.h"
-#import "CMMCPResult.h"
#import "SPStringAdditions.h"
@interface SPDatabaseData (PrivateAPI)
@@ -236,7 +234,7 @@ const CHAR_SETS charsets[] =
if ([collations count] == 0) {
// Check the information_schema.collations table is accessible
- CMMCPResult *result = [connection queryString:@"SHOW TABLES IN information_schema LIKE 'collations'"];
+ MCPResult *result = [connection queryString:@"SHOW TABLES IN information_schema LIKE 'collations'"];
if ([result numOfRows] == 1) {
// Table is accessible so get available collations
@@ -272,7 +270,7 @@ const CHAR_SETS charsets[] =
characterSetEncoding = [[NSString alloc] initWithString:encoding];
// Check the information_schema.collations table is accessible
- CMMCPResult *result = [connection queryString:@"SHOW TABLES IN information_schema LIKE 'collations'"];
+ MCPResult *result = [connection queryString:@"SHOW TABLES IN information_schema LIKE 'collations'"];
if ([result numOfRows] == 1) {
// Table is accessible so get available collations for the supplied encoding
@@ -308,7 +306,7 @@ const CHAR_SETS charsets[] =
[storageEngines addObject:[NSDictionary dictionaryWithObject:@"MyISAM" forKey:@"Engine"]];
// Check if InnoDB support is enabled
- CMMCPResult *result = [connection queryString:@"SHOW VARIABLES LIKE 'have_innodb'"];
+ MCPResult *result = [connection queryString:@"SHOW VARIABLES LIKE 'have_innodb'"];
if ([result numOfRows] == 1) {
if ([[[result fetchRowAsDictionary] objectForKey:@"Value"] isEqualToString:@"YES"]) {
@@ -350,7 +348,7 @@ const CHAR_SETS charsets[] =
([connection serverReleaseVersion] >= 5))
{
// Check the information_schema.engines table is accessible
- CMMCPResult *result = [connection queryString:@"SHOW TABLES IN information_schema LIKE 'engines'"];
+ MCPResult *result = [connection queryString:@"SHOW TABLES IN information_schema LIKE 'engines'"];
if ([result numOfRows] == 1) {
// Table is accessible so get available storage engines
@@ -388,7 +386,7 @@ const CHAR_SETS charsets[] =
if ([characterSetEncodings count] == 0) {
// Check the information_schema.collations table is accessible
- CMMCPResult *result = [connection queryString:@"SHOW TABLES IN information_schema LIKE 'character_sets'"];
+ MCPResult *result = [connection queryString:@"SHOW TABLES IN information_schema LIKE 'character_sets'"];
if ([result numOfRows] == 1) {
// Table is accessible so get available encodings for the supplied encoding
@@ -439,7 +437,7 @@ const CHAR_SETS charsets[] =
{
NSMutableArray *array = [NSMutableArray array];
- CMMCPResult *result = [connection queryString:query];
+ MCPResult *result = [connection queryString:query];
// Log any errors
if ([[connection getLastErrorMessage] isEqualToString:@""]) {
diff --git a/Source/SPEditSheetTextView.h b/Source/SPEditSheetTextView.h
index c333fd30..1c6ee563 100644
--- a/Source/SPEditSheetTextView.h
+++ b/Source/SPEditSheetTextView.h
@@ -24,14 +24,9 @@
#import <Cocoa/Cocoa.h>
-
@interface SPEditSheetTextView : NSTextView
-{
-
-}
- (unsigned int)characterIndexOfPoint:(NSPoint)aPoint;
- (void)insertFileContentOfFile:(NSString *)aPath;
-
@end
diff --git a/Source/SPEditSheetTextView.m b/Source/SPEditSheetTextView.m
index cb597f08..7f7e0d6c 100644
--- a/Source/SPEditSheetTextView.m
+++ b/Source/SPEditSheetTextView.m
@@ -25,7 +25,6 @@
#import "SPEditSheetTextView.h"
#import "SPTextViewAdditions.h"
-
@implementation SPEditSheetTextView
- (void) keyDown:(NSEvent *)theEvent
diff --git a/Source/SPExportController.h b/Source/SPExportController.h
index 57b13012..63d1c78b 100644
--- a/Source/SPExportController.h
+++ b/Source/SPExportController.h
@@ -23,11 +23,10 @@
// More info at <http://code.google.com/p/sequel-pro/>
#import <Cocoa/Cocoa.h>
-#import "CMMCPConnection.h"
-#import "CMMCPResult.h"
-
-@interface SPExportController : NSObject {
+#import <MCPKit/MCPKit.h>
+@interface SPExportController : NSObject
+{
// Table Document
IBOutlet id tableDocumentInstance;
IBOutlet id tableWindow;
@@ -76,7 +75,7 @@
IBOutlet id exampleNameLabel;
// Local Variables
- CMMCPConnection *mySQLConnection;
+ MCPConnection *mySQLConnection;
NSMutableArray *tables;
}
@@ -85,7 +84,7 @@
- (IBAction)closeSheet:(id)sender;
// Utility Methods
-- (void)setConnection:(CMMCPConnection *)theConnection;
+- (void)setConnection:(MCPConnection *)theConnection;
- (void)loadTables;
- (IBAction)switchTab:(id)sender;
- (IBAction)switchInput:(id)sender;
diff --git a/Source/SPExportController.m b/Source/SPExportController.m
index b76ea41f..ed850a10 100644
--- a/Source/SPExportController.m
+++ b/Source/SPExportController.m
@@ -60,18 +60,18 @@
#pragma mark -
#pragma mark Utility Methods
-- (void)setConnection:(CMMCPConnection *)theConnection
+- (void)setConnection:(MCPConnection *)theConnection
{
mySQLConnection = theConnection;
}
- (void)loadTables
{
- CMMCPResult *queryResult;
+ MCPResult *queryResult;
int i;
[tables removeAllObjects];
- queryResult = (CMMCPResult *)[mySQLConnection listTables];
+ queryResult = (MCPResult *)[mySQLConnection listTables];
if ([queryResult numOfRows])
[queryResult dataSeek:0];
diff --git a/Source/SPExtendedTableInfo.h b/Source/SPExtendedTableInfo.h
index 8cdea5e4..ac0f6096 100644
--- a/Source/SPExtendedTableInfo.h
+++ b/Source/SPExtendedTableInfo.h
@@ -24,8 +24,9 @@
// More info at <http://code.google.com/p/sequel-pro/>
#import <Cocoa/Cocoa.h>
+#import <MCPKit/MCPKit.h>
-@class SPTableData, SPDatabaseData, CMMCPConnection;
+@class SPTableData, SPDatabaseData;
@interface SPExtendedTableInfo : NSObject
{
@@ -52,10 +53,10 @@
NSString *selectedTable;
- CMMCPConnection *connection;
+ MCPConnection *connection;
}
-@property (readwrite, assign) CMMCPConnection *connection;
+@property (readwrite, assign) MCPConnection *connection;
// IBAction methods
- (IBAction)reloadTable:(id)sender;
diff --git a/Source/SPExtendedTableInfo.m b/Source/SPExtendedTableInfo.m
index 0485281a..11a0188e 100644
--- a/Source/SPExtendedTableInfo.m
+++ b/Source/SPExtendedTableInfo.m
@@ -27,7 +27,6 @@
#import "SPTableData.h"
#import "RegexKitLite.h"
#import "SPDatabaseData.h"
-#import "CMMCPConnection.h"
#import "SPStringAdditions.h"
@interface SPExtendedTableInfo (PrivateAPI)
diff --git a/Source/SPFieldEditorController.h b/Source/SPFieldEditorController.h
index 1b54cfab..5e61207e 100644
--- a/Source/SPFieldEditorController.h
+++ b/Source/SPFieldEditorController.h
@@ -24,9 +24,8 @@
#import <Cocoa/Cocoa.h>
-
-@interface SPFieldEditorController : NSWindowController {
-
+@interface SPFieldEditorController : NSWindowController
+{
IBOutlet id editSheetProgressBar;
IBOutlet id editSheetSegmentControl;
IBOutlet id editSheetQuickLookButton;
diff --git a/Source/SPFieldEditorController.m b/Source/SPFieldEditorController.m
index 085a4933..e62a2beb 100644
--- a/Source/SPFieldEditorController.m
+++ b/Source/SPFieldEditorController.m
@@ -29,7 +29,6 @@
#import "SPDataAdditions.h"
#import "QLPreviewPanel.h"
-
@implementation SPFieldEditorController
- (id) init
diff --git a/Source/SPNarrowDownCompletion.h b/Source/SPNarrowDownCompletion.h
index 6d69b549..6a2d4d1b 100644
--- a/Source/SPNarrowDownCompletion.h
+++ b/Source/SPNarrowDownCompletion.h
@@ -30,8 +30,8 @@
#define SP_NARROWDOWNLIST_MAX_ROWS 15
-@interface SPNarrowDownCompletion : NSWindow {
-
+@interface SPNarrowDownCompletion : NSWindow
+{
NSArray* suggestions;
NSMutableString* mutablePrefix;
NSString* staticPrefix;
diff --git a/Source/SPNarrowDownCompletion.m b/Source/SPNarrowDownCompletion.m
index e2a52882..729e9e6d 100644
--- a/Source/SPNarrowDownCompletion.m
+++ b/Source/SPNarrowDownCompletion.m
@@ -26,11 +26,11 @@
//
// More info at <http://code.google.com/p/sequel-pro/>
+#import <Foundation/NSObjCRuntime.h>
+
#import "SPNarrowDownCompletion.h"
#import "SPArrayAdditions.h"
#import "ImageAndTextCell.h"
-#import <Foundation/NSObjCRuntime.h>
-
@interface NSTableView (MovingSelectedRow)
- (BOOL)SP_NarrowDownCompletion_canHandleEvent:(NSEvent*)anEvent;
diff --git a/Source/SPPrintAccessory.h b/Source/SPPrintAccessory.h
index b1975b7e..d1b8498d 100644
--- a/Source/SPPrintAccessory.h
+++ b/Source/SPPrintAccessory.h
@@ -1,7 +1,31 @@
+//
+// $Id$
+//
+// SPPrintAccessory.h
+// sequel-pro
+//
+// Created by Marius Ursache
+// Copyright (c) 2009 Marius Ursache. 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/>
+
#import <Cocoa/Cocoa.h>
#import <WebKit/WebKit.h>
-
@interface SPPrintAccessory : NSViewController <NSPrintPanelAccessorizing>
{
IBOutlet NSView *printAccessoryView;
diff --git a/Source/SPPrintAccessory.m b/Source/SPPrintAccessory.m
index d0f3dc14..0ec18b26 100644
--- a/Source/SPPrintAccessory.m
+++ b/Source/SPPrintAccessory.m
@@ -1,3 +1,28 @@
+//
+// $Id$
+//
+// SPPrintAccessory.m
+// sequel-pro
+//
+// Created by Marius Ursache
+// Copyright (c) 2009 Marius Ursache. 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/>
+
#import "SPPrintAccessory.h"
@implementation SPPrintAccessory
@@ -31,7 +56,8 @@
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([(NSString *)context isEqualToString:@"PrinterSettingsChanged"]) {
- if (printWebView) [[printWebView preferences] setShouldPrintBackgrounds:[[defaultsController valueForKeyPath:@"values.PrintBackground"] boolValue]];
+ if (printWebView)
+ [[printWebView preferences] setShouldPrintBackgrounds:[[defaultsController valueForKeyPath:@"values.PrintBackground"] boolValue]];
} else {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
diff --git a/Source/SPSSHTunnel.h b/Source/SPSSHTunnel.h
index db01c98e..e9b06cb6 100644
--- a/Source/SPSSHTunnel.h
+++ b/Source/SPSSHTunnel.h
@@ -1,13 +1,28 @@
-#import <Cocoa/Cocoa.h>
+//
+// SPSSHTunnel.h
+// sequel-pro
+//
+// Created by Rowan Beentje on April 26, 2009. Inspired by code by
+// Yann Bizuel for SSH Tunnel Manager 2.
+//
+// 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/>
-enum spsshtunnel_states
-{
- SPSSH_STATE_IDLE = 0,
- SPSSH_STATE_CONNECTING = 1,
- SPSSH_STATE_WAITING_FOR_AUTH = 2,
- SPSSH_STATE_CONNECTED = 3,
- SPSSH_STATE_FORWARDING_FAILED = 4
-};
+#import <Cocoa/Cocoa.h>
+#import <MCPKit/MCPKit.h>
enum spsshtunnel_password_modes
{
@@ -15,8 +30,7 @@ enum spsshtunnel_password_modes
SPSSH_PASSWORD_ASKS_UI = 1
};
-
-@interface SPSSHTunnel : NSObject
+@interface SPSSHTunnel : NSObject <MCPConnectionProxy>
{
IBOutlet NSWindow *sshQuestionDialog;
IBOutlet NSTextField *sshQuestionText;
diff --git a/Source/SPSSHTunnel.m b/Source/SPSSHTunnel.m
index 62fc61b2..5b765525 100644
--- a/Source/SPSSHTunnel.m
+++ b/Source/SPSSHTunnel.m
@@ -26,7 +26,6 @@
#import "KeyChain.h"
#import <netinet/in.h>
-
@implementation SPSSHTunnel
/*
@@ -73,7 +72,7 @@
requestedResponse = NO;
task = nil;
localPort = 0;
- connectionState = SPSSH_STATE_IDLE;
+ connectionState = PROXY_STATE_IDLE;
return self;
}
@@ -160,8 +159,9 @@
- (void) connect
{
localPort = 0;
+
+ if (connectionState != PROXY_STATE_IDLE || (!passwordInKeychain && !password)) return;
[debugMessages removeAllObjects];
- if (connectionState != SPSSH_STATE_IDLE || (!passwordInKeychain && !password)) return;
[NSThread detachNewThreadSelector:@selector(launchTask:) toTarget: self withObject: nil ];
}
@@ -172,18 +172,18 @@
*/
- (void) launchTask:(id) dummy
{
- if (connectionState != SPSSH_STATE_IDLE || task) return;
+ if (connectionState != PROXY_STATE_IDLE || task) return;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSMutableArray *taskArguments;
NSMutableDictionary *taskEnvironment;
NSString *authenticationAppPath;
- connectionState = SPSSH_STATE_CONNECTING;
+ connectionState = PROXY_STATE_CONNECTING;
if (delegate) [delegate performSelectorOnMainThread:stateChangeSelector withObject:self waitUntilDone:NO];
// Enforce a parent window being present for dialogs
if (!parentWindow) {
- connectionState = SPSSH_STATE_IDLE;
+ connectionState = PROXY_STATE_IDLE;
if (delegate) [delegate performSelectorOnMainThread:stateChangeSelector withObject:self waitUntilDone:NO];
if (lastError) [lastError release];
lastError = [[NSString alloc] initWithString:@"SSH Tunnel started without a parent window. A parent window must be present."];
@@ -191,7 +191,7 @@
return;
}
- int connectionTimeout = [[[NSUserDefaults standardUserDefaults] objectForKey:@"ConnectionTimeout"] intValue];
+ int connectionTimeout = [[[NSUserDefaults standardUserDefaults] objectForKey:@"ConnectionTimeoutValue"] intValue];
if (!connectionTimeout) connectionTimeout = 10;
BOOL useKeepAlive = [[[NSUserDefaults standardUserDefaults] objectForKey:@"UseKeepAlive"] doubleValue];
double keepAliveInterval = [[[NSUserDefaults standardUserDefaults] objectForKey:@"KeepAliveInterval"] doubleValue];
@@ -233,7 +233,7 @@
// Abort if no local free port could be allocated
if (!localPort || (useHostFallback && !localPortFallback)) {
- connectionState = SPSSH_STATE_IDLE;
+ connectionState = PROXY_STATE_IDLE;
if (delegate) [delegate performSelectorOnMainThread:stateChangeSelector withObject:self waitUntilDone:NO];
if (lastError) [lastError release];
lastError = [[NSString alloc] initWithString:NSLocalizedString(@"No local port could be allocated for the SSH Tunnel.", @"SSH tunnel could not be created because no local port could be allocated")];
@@ -320,8 +320,8 @@
[task waitUntilExit];
// If the task closed unexpectedly, alert appropriately
- if (connectionState != SPSSH_STATE_IDLE) {
- connectionState = SPSSH_STATE_IDLE;
+ if (connectionState != PROXY_STATE_IDLE) {
+ connectionState = PROXY_STATE_IDLE;
if (lastError) [lastError release];
lastError = [[NSString alloc] initWithString:NSLocalizedString(@"The SSH Tunnel has unexpectedly closed.", @"SSH tunnel unexpectedly closed")];
if (delegate) [delegate performSelectorOnMainThread:stateChangeSelector withObject:self waitUntilDone:NO];
@@ -344,9 +344,9 @@
*/
- (void)disconnect
{
- if (connectionState == SPSSH_STATE_IDLE) return;
+ if (connectionState == PROXY_STATE_IDLE) return;
[task terminate];
- connectionState = SPSSH_STATE_IDLE;
+ connectionState = PROXY_STATE_IDLE;
if (delegate) [delegate performSelectorOnMainThread:stateChangeSelector withObject:self waitUntilDone:NO];
}
@@ -370,36 +370,36 @@
[debugMessages addObject:[NSString stringWithString:message]];
if ([message rangeOfString:@"Entering interactive session."].location != NSNotFound) {
- connectionState = SPSSH_STATE_CONNECTED;
+ connectionState = PROXY_STATE_CONNECTED;
if (delegate) [delegate performSelectorOnMainThread:stateChangeSelector withObject:self waitUntilDone:NO];
}
if ([message rangeOfString:@"Connection established"].location != NSNotFound) {
- connectionState = SPSSH_STATE_WAITING_FOR_AUTH;
+ connectionState = PROXY_STATE_WAITING_FOR_AUTH;
if (delegate) [delegate performSelectorOnMainThread:stateChangeSelector withObject:self waitUntilDone:NO];
}
if ([message rangeOfString:@"closed by remote host." ].location != NSNotFound) {
- connectionState = SPSSH_STATE_IDLE;
+ connectionState = PROXY_STATE_IDLE;
[task terminate];
if (lastError) [lastError release];
lastError = [[NSString alloc] initWithString:NSLocalizedString(@"The SSH Tunnel was closed 'by the remote host'. This may indicate a networking issue or a network timeout.", @"SSH tunnel was closed by remote host message")];
if (delegate) [delegate performSelectorOnMainThread:stateChangeSelector withObject:self waitUntilDone:NO];
}
if ([message rangeOfString:@"Permission denied (" ].location != NSNotFound || [message rangeOfString:@"No more authentication methods to try" ].location != NSNotFound) {
- connectionState = SPSSH_STATE_IDLE;
+ connectionState = PROXY_STATE_IDLE;
[task terminate];
if (lastError) [lastError release];
lastError = [[NSString alloc] initWithString:NSLocalizedString(@"The SSH Tunnel could not authenticate with the remote host. Please check your password and ensure you still have access.", @"SSH tunnel authentication failed message")];
if (delegate) [delegate performSelectorOnMainThread:stateChangeSelector withObject:self waitUntilDone:NO];
}
if ([message rangeOfString:@"connect failed: Connection refused" ].location != NSNotFound) {
- connectionState = SPSSH_STATE_FORWARDING_FAILED;
+ connectionState = PROXY_STATE_FORWARDING_FAILED;
if (lastError) [lastError release];
lastError = [[NSString alloc] initWithString:NSLocalizedString(@"The SSH Tunnel was established successfully, but could not forward data to the remote port as the remote port refused the connection.", @"SSH tunnel forwarding port connection refused message")];
}
if ([message rangeOfString:@"Operation timed out" ].location != NSNotFound) {
- connectionState = SPSSH_STATE_IDLE;
+ connectionState = PROXY_STATE_IDLE;
[task terminate];
if (lastError) [lastError release];
lastError = [[NSString alloc] initWithFormat:NSLocalizedString(@"The SSH Tunnel was unable to connect to host %@, or the request timed out.\n\nBe sure that the address is correct and that you have the necessary privileges, or try increasing the connection timeout (currently %i seconds).", @"SSH tunnel failed or timed out message"), sshHost, [[[NSUserDefaults standardUserDefaults] objectForKey:@"ConnectionTimeoutValue"] intValue]];
@@ -408,7 +408,7 @@
}
}
- if (connectionState != SPSSH_STATE_IDLE) {
+ if (connectionState != PROXY_STATE_IDLE) {
[[standardError fileHandleForReading] waitForDataInBackgroundAndNotify];
}
@@ -565,7 +565,7 @@
{
delegate = nil;
[[NSNotificationCenter defaultCenter] removeObserver:self];
- if (connectionState != SPSSH_STATE_IDLE) [self disconnect];
+ if (connectionState != PROXY_STATE_IDLE) [self disconnect];
[sshHost release];
[sshLogin release];
[remoteHost release];
diff --git a/Source/SPStringAdditions.h b/Source/SPStringAdditions.h
index 47863370..764e6b24 100644
--- a/Source/SPStringAdditions.h
+++ b/Source/SPStringAdditions.h
@@ -38,18 +38,6 @@ static inline const char* NSStringUTF8String(NSString* self) {
return to_return;
}
-/*
- * NSStringDataUsingLossyEncoding(aStr, enc, lossy) := [aStr dataUsingEncoding:enc allowLossyConversion:lossy]
- */
-static inline NSData* NSStringDataUsingLossyEncoding(NSString* self, int encoding, int lossy) {
- typedef NSData* (*SPStringDataUsingLossyEncodingMethodPtr)(NSString*, SEL, int, int);
- static SPStringDataUsingLossyEncodingMethodPtr SPNSStringDataUsingLossyEncoding;
- if (!SPNSStringDataUsingLossyEncoding) SPNSStringDataUsingLossyEncoding = (SPStringDataUsingLossyEncodingMethodPtr)[self methodForSelector:@selector(dataUsingEncoding:allowLossyConversion:)];
- NSData* to_return = SPNSStringDataUsingLossyEncoding(self, @selector(dataUsingEncoding:allowLossyConversion:), encoding, lossy);
- return to_return;
-}
-
-
@interface NSString (SPStringAdditions)
+ (NSString *)stringForByteSize:(int)byteSize;
diff --git a/Source/SPStringAdditions.m b/Source/SPStringAdditions.m
index ff7efc88..81c501f9 100644
--- a/Source/SPStringAdditions.m
+++ b/Source/SPStringAdditions.m
@@ -26,7 +26,6 @@
#import "SPStringAdditions.h"
#import "RegexKitLite.h"
-
@interface NSString (Private)
- (int)smallestOf:(int)a andOf:(int)b andOf:(int)c;
@end
diff --git a/Source/SPTableData.h b/Source/SPTableData.h
index 7ed99edd..4df13719 100644
--- a/Source/SPTableData.h
+++ b/Source/SPTableData.h
@@ -38,10 +38,10 @@
NSString *tableEncoding;
NSString *tableCreateSyntax;
- CMMCPConnection *mySQLConnection;
+ MCPConnection *mySQLConnection;
}
-- (void) setConnection:(CMMCPConnection *)theConnection;
+- (void) setConnection:(MCPConnection *)theConnection;
- (NSString *) tableEncoding;
- (NSString *) tableCreateSyntax;
- (NSArray *) columns;
diff --git a/Source/SPTableData.m b/Source/SPTableData.m
index 69b2a336..f62daabd 100644
--- a/Source/SPTableData.m
+++ b/Source/SPTableData.m
@@ -23,9 +23,8 @@
//
// More info at <http://code.google.com/p/sequel-pro/>
-#import "CMMCPConnection.h"
-#import "CMMCPResult.h"
-#import <MCPKit_bundled/MCPKit_bundled.h>
+#import <MCPKit/MCPKit.h>
+
#import "SPTableData.h"
#import "SPSQLParser.h"
#import "TableDocument.h"
@@ -33,7 +32,6 @@
#import "SPStringAdditions.h"
#import "SPArrayAdditions.h"
-
@implementation SPTableData
@@ -57,7 +55,7 @@
* Set the connection for use.
* Called by the connect sheet methods.
*/
-- (void) setConnection:(CMMCPConnection *)theConnection
+- (void) setConnection:(MCPConnection *)theConnection
{
mySQLConnection = theConnection;
[mySQLConnection retain];
@@ -322,7 +320,7 @@
if ([tableName isEqualToString:@""] || !tableName) return nil;
// Retrieve the CREATE TABLE syntax for the table
- CMMCPResult *theResult = [mySQLConnection queryString: [NSString stringWithFormat: @"SHOW CREATE TABLE %@",
+ MCPResult *theResult = [mySQLConnection queryString: [NSString stringWithFormat: @"SHOW CREATE TABLE %@",
[tableName backtickQuotedString]
]];
@@ -614,7 +612,7 @@
if ([viewName isEqualToString:@""] || !viewName) return nil;
// Retrieve the CREATE TABLE syntax for the table
- CMMCPResult *theResult = [mySQLConnection queryString: [NSString stringWithFormat: @"SHOW CREATE TABLE %@",
+ MCPResult *theResult = [mySQLConnection queryString: [NSString stringWithFormat: @"SHOW CREATE TABLE %@",
[viewName backtickQuotedString]
]];
@@ -728,7 +726,7 @@
// Run the status query and retrieve as a dictionary.
NSMutableString *escapedTableName = [NSMutableString stringWithString:[tableListInstance tableName]];
[escapedTableName replaceOccurrencesOfString:@"'" withString:@"\\\'" options:0 range:NSMakeRange(0, [escapedTableName length])];
- CMMCPResult *tableStatusResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SHOW TABLE STATUS LIKE '%@'", escapedTableName ]];
+ MCPResult *tableStatusResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SHOW TABLE STATUS LIKE '%@'", escapedTableName ]];
// Check for any errors, only displaying them if the connection hasn't been terminated
if (![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) {
diff --git a/Source/SPTableInfo.m b/Source/SPTableInfo.m
index 3a2b67b8..5b369207 100644
--- a/Source/SPTableInfo.m
+++ b/Source/SPTableInfo.m
@@ -23,17 +23,15 @@
//
// More info at <http://code.google.com/p/sequel-pro/>
+#import <MCPKit/MCPKit.h>
+
#import "SPTableInfo.h"
#import "ImageAndTextCell.h"
-#import "CMMCPConnection.h"
-#import "CMMCPResult.h"
#import "TableDocument.h"
#import "TablesList.h"
#import "SPTableData.h"
#import "SPStringAdditions.h"
-#import <MCPKit_bundled/MCPKit_bundled.h>
-
@interface SPTableInfo (PrivateAPI)
- (NSString *)_getUserDefinedDateStringFromMySQLDate:(NSString *)mysqlDate;
diff --git a/Source/SPTableRelations.h b/Source/SPTableRelations.h
index 72806b77..61328e59 100644
--- a/Source/SPTableRelations.h
+++ b/Source/SPTableRelations.h
@@ -24,9 +24,9 @@
// More info at <http://code.google.com/p/sequel-pro/>
#import <Cocoa/Cocoa.h>
-#import <MCPKit_bundled/MCPKit_bundled.h>
+#import <MCPKit/MCPKit.h>
-@class CMMCPConnection, CMMCPResult, CMCopyTable;
+@class CMCopyTable;
@interface SPTableRelations : NSObject
{
@@ -52,12 +52,12 @@
IBOutlet NSPopUpButton *onDeletePopUpButton;
IBOutlet NSButton *confirmAddRelationButton;
- CMMCPConnection *connection;
+ MCPConnection *connection;
NSMutableArray *relationData;
}
-@property (readwrite, assign) CMMCPConnection *connection;
+@property (readwrite, assign) MCPConnection *connection;
// IB action methods
- (IBAction)addRelation:(id)sender;
diff --git a/Source/SPTableRelations.m b/Source/SPTableRelations.m
index bb165710..5f687257 100644
--- a/Source/SPTableRelations.m
+++ b/Source/SPTableRelations.m
@@ -26,8 +26,6 @@
#import "SPTableRelations.h"
#import "TableDocument.h"
#import "TablesList.h"
-#import "CMMCPConnection.h"
-#import "CMMCPResult.h"
#import "SPTableData.h"
#import "SPStringAdditions.h"
@@ -141,7 +139,7 @@
[refTablePopUpButton removeAllItems];
// Get all InnoDB tables in the current database
- CMMCPResult *result = [connection queryString:[NSString stringWithFormat:@"SELECT table_name FROM information_schema.tables WHERE table_type = 'BASE TABLE' AND engine = 'InnoDB' AND table_schema = '%@' AND table_name != '%@'", [tableDocumentInstance database], [tablesListInstance tableName]]];
+ MCPResult *result = [connection queryString:[NSString stringWithFormat:@"SELECT table_name FROM information_schema.tables WHERE table_type = 'BASE TABLE' AND engine = 'InnoDB' AND table_schema = '%@' AND table_name != '%@'", [tableDocumentInstance database], [tablesListInstance tableName]]];
[result dataSeek:0];
diff --git a/Source/SPTableView.h b/Source/SPTableView.h
index b9b3bfc4..4dc10875 100644
--- a/Source/SPTableView.h
+++ b/Source/SPTableView.h
@@ -24,8 +24,6 @@
#import <Cocoa/Cocoa.h>
-
@interface SPTableView : NSTableView
-
@end
diff --git a/Source/SPTableView.m b/Source/SPTableView.m
index 30ba9674..a338d506 100644
--- a/Source/SPTableView.m
+++ b/Source/SPTableView.m
@@ -24,7 +24,6 @@
#import "SPTableView.h"
-
@implementation SPTableView
/*
diff --git a/Source/TableContent.h b/Source/TableContent.h
index 3053db1b..254fe9c9 100644
--- a/Source/TableContent.h
+++ b/Source/TableContent.h
@@ -26,9 +26,9 @@
// More info at <http://code.google.com/p/sequel-pro/>
#import <Cocoa/Cocoa.h>
-#import <MCPKit_bundled/MCPKit_bundled.h>
+#import <MCPKit/MCPKit.h>
-@class CMMCPConnection, CMMCPResult, CMCopyTable, SPTextAndLinkCell;
+@class CMCopyTable, SPTextAndLinkCell;
@interface TableContent : NSObject
{
@@ -52,7 +52,7 @@
IBOutlet id limitRowsStepper;
IBOutlet id limitRowsText;
- CMMCPConnection *mySQLConnection;
+ MCPConnection *mySQLConnection;
NSString *selectedTable, *usedQuery;
NSMutableArray *fullResult, *filteredResult, *dataColumns, *keys, *oldRow;
@@ -87,11 +87,11 @@
- (NSArray *)currentDataResult;
//additional methods
-- (void)setConnection:(CMMCPConnection *)theConnection;
+- (void)setConnection:(MCPConnection *)theConnection;
- (void)clickLinkArrow:(SPTextAndLinkCell *)theArrowCell;
- (IBAction)setCompareTypes:(id)sender;
- (IBAction)stepLimitRows:(id)sender;
-- (NSArray *)fetchResultAsArray:(CMMCPResult *)theResult;
+- (NSArray *)fetchResultAsArray:(MCPResult *)theResult;
- (BOOL)addRowToDB;
- (NSString *)argumentForRow:(int)row;
- (BOOL)tableContainsBlobOrTextColumns;
diff --git a/Source/TableContent.m b/Source/TableContent.m
index 2e7d32c2..5e0def75 100644
--- a/Source/TableContent.m
+++ b/Source/TableContent.m
@@ -25,13 +25,13 @@
//
// More info at <http://code.google.com/p/sequel-pro/>
+#import <MCPKit/MCPKit.h>
+
#import "TableContent.h"
#import "TableDocument.h"
#import "TablesList.h"
#import "CMImageView.h"
#import "CMCopyTable.h"
-#import "CMMCPConnection.h"
-#import "CMMCPResult.h"
#import "SPDataCellFormatter.h"
#import "SPTableData.h"
#import "SPQueryConsole.h"
@@ -43,7 +43,6 @@
#import "QLPreviewPanel.h"
#import "SPFieldEditorController.h"
-
@implementation TableContent
/**
@@ -95,7 +94,7 @@
NSDictionary *columnDefinition;
NSTableColumn *theCol;
NSString *query;
- CMMCPResult *queryResult;
+ MCPResult *queryResult;
BOOL preserveCurrentView = [aTable isEqualToString:selectedTable];
NSString *preservedFilterField = nil, *preservedFilterComparison, *preservedFilterValue;
@@ -437,7 +436,7 @@
- (IBAction)reloadTableValues:(id)sender
{
NSString *queryString;
- CMMCPResult *queryResult;
+ MCPResult *queryResult;
//query started
[[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryWillBePerformed" object:self];
@@ -500,7 +499,7 @@
*/
- (IBAction)filterTable:(id)sender
{
- CMMCPResult *theResult;
+ MCPResult *theResult;
int tag = [[compareField selectedItem] tag];
NSString *compareOperator = @"";
NSMutableString *argument = [[NSMutableString alloc] initWithString:[argumentField stringValue]];
@@ -796,7 +795,7 @@
*/
{
NSMutableArray *tempRow;
- CMMCPResult *queryResult;
+ MCPResult *queryResult;
NSDictionary *row;
NSArray *dbDataRow = nil;
int i;
@@ -993,12 +992,12 @@
return currentResult;
}
+// Additional methods
-//additional methods
-- (void)setConnection:(CMMCPConnection *)theConnection
-/*
- sets the connection (received from TableDocument) and makes things that have to be done only once
+/**
+ * Sets the connection (received from TableDocument) and makes things that have to be done only once
*/
+- (void)setConnection:(MCPConnection *)theConnection
{
mySQLConnection = theConnection;
@@ -1140,7 +1139,7 @@
/*
* Fetches the result as an array, with an array for each row in it
*/
-- (NSArray *)fetchResultAsArray:(CMMCPResult *)theResult
+- (NSArray *)fetchResultAsArray:(MCPResult *)theResult
{
unsigned long numOfRows = [theResult numOfRows];
NSMutableArray *tempResult = [NSMutableArray arrayWithCapacity:numOfRows];
@@ -1199,7 +1198,7 @@
NSArray *columnNames;
NSMutableString *queryString;
NSString *query;
- CMMCPResult *queryResult;
+ MCPResult *queryResult;
id rowObject;
NSMutableString *rowValue = [NSMutableString string];
NSString *currentTime = [[NSDate date] descriptionWithCalendarFormat:@"%H:%M:%S" timeZone:nil locale:nil];
@@ -1393,7 +1392,7 @@
*/
- (NSString *)argumentForRow:(int)row
{
- CMMCPResult *theResult;
+ MCPResult *theResult;
NSDictionary *theRow;
id tempValue;
NSMutableString *value = [NSMutableString string];
@@ -1531,7 +1530,7 @@
NSMutableArray *tempArray = [NSMutableArray array];
NSMutableArray *tempResult = [NSMutableArray array];
NSString *queryString, *wherePart;
- CMMCPResult *queryResult;
+ MCPResult *queryResult;
int i, errors;
if ( [contextInfo isEqualToString:@"addrow"] ) {
@@ -1782,7 +1781,7 @@
*/
{
NSString *queryString;
- CMMCPResult *queryResult;
+ MCPResult *queryResult;
if ( [selectedTable isEqualToString:@""] || !selectedTable )
return;
@@ -1941,7 +1940,7 @@
NSArray *tempRow;
NSMutableArray *modifiedRow = [NSMutableArray array];
// id theValue;
- CMMCPResult *tempResult;
+ MCPResult *tempResult;
// If not isEditingRow and the preference value for not showing blobs is set, check whether the row contains any blobs.
if ( [prefs boolForKey:@"LoadBlobsAsNeeded"] && !isEditingRow ) {
diff --git a/Source/TableDocument.h b/Source/TableDocument.h
index 8272cd62..6b3acaef 100644
--- a/Source/TableDocument.h
+++ b/Source/TableDocument.h
@@ -26,10 +26,10 @@
// More info at <http://code.google.com/p/sequel-pro/>
#import <Cocoa/Cocoa.h>
-#import <MCPKit_bundled/MCPKit_bundled.h>
+#import <MCPKit/MCPKit.h>
#import <WebKit/WebKit.h>
-@class CMMCPConnection, CMMCPResult, SPConnectionController;
+@class SPConnectionController;
/**
* The TableDocument class controls the primary database view window.
@@ -79,10 +79,11 @@
IBOutlet id syntaxView;
IBOutlet id syntaxViewContent;
IBOutlet NSWindow *createTableSyntaxWindow;
+ IBOutlet NSWindow *connectionErrorDialog;
SPConnectionController *connectionController;
- CMMCPConnection *mySQLConnection;
+ MCPConnection *mySQLConnection;
NSArray *variables;
NSString *selectedDatabase;
@@ -95,6 +96,7 @@
BOOL _encodingViaLatin1;
BOOL _shouldOpenConnectionAutomatically;
BOOL _isConnected;
+ BOOL _mainNibLoaded;
NSToolbar *mainToolbar;
NSToolbarItem *chooseDatabaseToolbarItem;
@@ -107,11 +109,11 @@
- (NSString *)getHTMLforPrint;
// Connection callback and methods
-- (void) setConnection:(CMMCPConnection *)theConnection;
+- (void) setConnection:(MCPConnection *)theConnection;
- (void)setShouldAutomaticallyConnect:(BOOL)shouldAutomaticallyConnect;
- (BOOL)shouldAutomaticallyConnect;
-//database methods
+// Database methods
- (IBAction)setDatabases:(id)sender;
- (IBAction)chooseDatabase:(id)sender;
- (IBAction)addDatabase:(id)sender;
@@ -121,18 +123,18 @@
- (IBAction)saveServerVariables:(id)sender;
- (NSArray *)allDatabaseNames;
-//encoding methods
+// Encoding methods
- (void)setConnectionEncoding:(NSString *)mysqlEncoding reloadingViews:(BOOL)reloadViews;
- (NSString *)databaseEncoding;
- (NSString *)connectionEncoding;
-- (BOOL)connectionEncodingViaLatin1;
+- (BOOL)connectionEncodingViaLatin1:(id)connection;
- (IBAction)chooseEncoding:(id)sender;
- (BOOL)supportsEncoding;
- (void)updateEncodingMenuWithSelectedEncoding:(NSString *)encoding;
- (NSString *)encodingNameFromMySQLEncoding:(NSString *)mysqlEncoding;
- (NSString *)mysqlEncodingFromDisplayEncoding:(NSString *)encodingName;
-//table methods
+// Table methods
- (IBAction)showCreateTableSyntax:(id)sender;
- (IBAction)copyCreateTableSyntax:(id)sender;
- (NSArray *)columnNames;
@@ -143,8 +145,10 @@
- (IBAction)flushTable:(id)sender;
- (IBAction)checksumTable:(id)sender;
-//other methods
+// Other methods
- (NSString *)host;
+- (IBAction)closeSheet:(id)sender;
+- (IBAction)closeErrorConnectionSheet:(id)sender;
- (void)doPerformQueryService:(NSString *)query;
- (void)flushPrivileges:(id)sender;
- (void)showVariables:(id)sender;
@@ -152,19 +156,19 @@
- (NSWindow *)getCreateTableSyntaxWindow;
- (void) refreshCurrentDatabase;
-//getter methods
+// Getter methods
- (NSString *)name;
- (NSString *)database;
- (NSString *)table;
- (NSString *)mySQLVersion;
- (NSString *)user;
-//notification center methods
+// Notification center methods
- (void)willPerformQuery:(NSNotification *)notification;
- (void)hasPerformedQuery:(NSNotification *)notification;
- (void)applicationWillTerminate:(NSNotification *)notification;
-//menu methods
+// Menu methods
- (BOOL)validateMenuItem:(NSMenuItem *)anItem;
- (IBAction)import:(id)sender;
- (IBAction)export:(id)sender;
@@ -177,12 +181,12 @@
- (IBAction)viewRelations:(id)sender;
- (IBAction)addConnectionToFavorites:(id)sender;
-// titlebar methods
+// Titlebar methods
- (void)setStatusIconToImageWithName:(NSString *)imagePath;
- (void)setTitlebarStatus:(NSString *)status;
- (void)clearStatusIcon;
-//toolbar methods
+// Toolbar methods
- (void)setupToolbar;
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag;
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar;
@@ -190,10 +194,4 @@
- (BOOL)validateToolbarItem:(NSToolbarItem *)toolbarItem;
- (void)updateChooseDatabaseToolbarItemWidth;
-//SMySQL delegate methods
-- (void)willQueryString:(NSString *)query;
-- (void)queryGaveError:(NSString *)error;
-
-- (IBAction)closeSheet:(id)sender;
-
@end
diff --git a/Source/TableDocument.m b/Source/TableDocument.m
index a01c4ed4..ae2457e3 100644
--- a/Source/TableDocument.m
+++ b/Source/TableDocument.m
@@ -40,8 +40,6 @@
#import "SPDatabaseData.h"
#import "SPStringAdditions.h"
#import "SPArrayAdditions.h"
-#import "CMMCPConnection.h"
-#import "CMMCPResult.h"
#import "MainController.h"
#import "SPExtendedTableInfo.h"
#import "SPConnectionController.h"
@@ -59,6 +57,7 @@
{
if ((self = [super init])) {
+ _mainNibLoaded = NO;
_encoding = [[NSString alloc] initWithString:@"utf8"];
_isConnected = NO;
chooseDatabaseButton = nil;
@@ -81,6 +80,8 @@
- (void)awakeFromNib
{
+ if (_mainNibLoaded) return;
+ _mainNibLoaded = YES;
// The first window should use autosaving; subsequent windows should cascade
BOOL usedAutosave = [tableWindow setFrameAutosaveName:[self windowNibName]];
@@ -106,6 +107,9 @@
// Register observers for when the logging preference changes
[prefs addObserver:[SPQueryConsole sharedQueryConsole] forKeyPath:@"ConsoleEnableLogging" options:NSKeyValueObservingOptionNew context:NULL];
+
+ // Register a second observer for when the logging preference changes so we can tell the current connection about it
+ [prefs addObserver:self forKeyPath:@"ConsoleEnableLogging" options:NSKeyValueObservingOptionNew context:NULL];
// Find the Database -> Database Encoding menu (it's not in our nib, so we can't use interface builder)
selectEncodingMenu = [[[[[NSApp mainMenu] itemWithTag:1] submenu] itemWithTag:1] submenu];
@@ -123,22 +127,24 @@
av.size.width,
av.size.height);
[titleAccessoryView setFrame:initialAccessoryViewFrame];
- [windowFrame addSubview:titleAccessoryView];
+ [windowFrame addSubview:titleAccessoryView];
+
+ // Load additional nibs
+ if (![NSBundle loadNibNamed:@"ConnectionErrorDialog" owner:self]) {
+ NSLog(@"Connection error dialog could not be loaded; connection failure handling will not function correctly.");
+ }
}
#pragma mark -
#pragma mark Connection callback and methods
-- (void) setConnection:(CMMCPConnection *)theConnection
+- (void) setConnection:(MCPConnection *)theConnection
{
- CMMCPResult *theResult;
+ MCPResult *theResult;
id version;
_isConnected = YES;
mySQLConnection = [theConnection retain];
-
- // Register as the connection delegate
- [mySQLConnection setDelegate:self];
// Set the connection encoding
NSString *encodingName = [prefs objectForKey:@"DefaultEncoding"];
@@ -574,7 +580,7 @@
// Notify listeners that a query has started
[[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryWillBePerformed" object:self];
- CMMCPResult *theResult = [mySQLConnection queryString:@"SELECT DATABASE()"];
+ MCPResult *theResult = [mySQLConnection queryString:@"SELECT DATABASE()"];
if ( [[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) {
int i;
int r = [theResult numOfRows];
@@ -658,7 +664,7 @@
if ( [[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) {
if (_encodingViaLatin1)
[mySQLConnection queryString:@"SET CHARACTER_SET_RESULTS=latin1"];
- [mySQLConnection setEncoding:[CMMCPConnection encodingForMySQLEncoding:[mysqlEncoding UTF8String]]];
+ [mySQLConnection setEncoding:[MCPConnection encodingForMySQLEncoding:[mysqlEncoding UTF8String]]];
[_encoding release];
_encoding = [[NSString alloc] initWithString:mysqlEncoding];
} else {
@@ -695,9 +701,10 @@
}
/**
- * Returns whether the current encoding should display results via Latin1 transport for backwards compatibility
+ * Returns whether the current encoding should display results via Latin1 transport for backwards compatibility.
+ * This is a delegate method of MCPKit's MCPConnection class.
*/
-- (BOOL)connectionEncodingViaLatin1
+- (BOOL)connectionEncodingViaLatin1:(id)connection
{
return _encodingViaLatin1;
}
@@ -863,7 +870,7 @@
if( query == nil )
return;
- CMMCPResult *theResult = [mySQLConnection queryString:query];
+ MCPResult *theResult = [mySQLConnection queryString:query];
// Check for errors, only displaying if the connection hasn't been terminated
if (![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) {
@@ -918,7 +925,7 @@
if( query == nil )
return;
- CMMCPResult *theResult = [mySQLConnection queryString:query];
+ MCPResult *theResult = [mySQLConnection queryString:query];
// Check for errors, only displaying if the connection hasn't been terminated
if (![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) {
@@ -974,7 +981,7 @@
*/
- (IBAction)checkTable:(id)sender
{
- CMMCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"CHECK TABLE %@", [[self table] backtickQuotedString]]];
+ MCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"CHECK TABLE %@", [[self table] backtickQuotedString]]];
// Check for errors, only displaying if the connection hasn't been terminated
if (![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) {
@@ -1019,7 +1026,7 @@
*/
- (IBAction)analyzeTable:(id)sender
{
- CMMCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"ANALYZE TABLE %@", [[self table] backtickQuotedString]]];
+ MCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"ANALYZE TABLE %@", [[self table] backtickQuotedString]]];
// Check for errors, only displaying if the connection hasn't been terminated
if (![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) {
@@ -1064,7 +1071,7 @@
*/
- (IBAction)optimizeTable:(id)sender
{
- CMMCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"OPTIMIZE TABLE %@", [[self table] backtickQuotedString]]];
+ MCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"OPTIMIZE TABLE %@", [[self table] backtickQuotedString]]];
// Check for errors, only displaying if the connection hasn't been terminated
if (![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) {
@@ -1109,7 +1116,7 @@
*/
- (IBAction)repairTable:(id)sender
{
- CMMCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"REPAIR TABLE %@", [[self table] backtickQuotedString]]];
+ MCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"REPAIR TABLE %@", [[self table] backtickQuotedString]]];
// Check for errors, only displaying if the connection hasn't been terminated
if (![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) {
@@ -1190,7 +1197,7 @@
*/
- (IBAction)checksumTable:(id)sender
{
- CMMCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"CHECKSUM TABLE %@", [[self table] backtickQuotedString]]];
+ MCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"CHECKSUM TABLE %@", [[self table] backtickQuotedString]]];
// Check for errors, only displaying if the connection hasn't been terminated
if (![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) {
@@ -1236,6 +1243,14 @@
}
/**
+ * Invoked when user dismisses the error sheet displayed as a result of the current connection being lost.
+ */
+- (IBAction)closeErrorConnectionSheet:(id)sender
+{
+ [NSApp stopModalWithCode:[sender tag]];
+}
+
+/**
* Passes query to tablesListInstance
*/
- (void)doPerformQueryService:(NSString *)query
@@ -1266,7 +1281,7 @@
*/
- (void)showVariables:(id)sender
{
- CMMCPResult *theResult;
+ MCPResult *theResult;
NSMutableArray *tempResult = [NSMutableArray array];
int i;
@@ -1302,6 +1317,16 @@
notificationName:@"Disconnected"];
}
+/**
+ * This method is called as part of Key Value Observing which is used to watch for prefernce changes which effect the interface.
+ */
+- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
+{
+ if ([keyPath isEqualToString:@"ConsoleEnableLogging"]) {
+ [mySQLConnection setDelegateQueryLogging:[[change objectForKey:NSKeyValueChangeNewKey] boolValue]];
+ }
+}
+
#pragma mark -
#pragma mark Getter methods
@@ -1996,12 +2021,12 @@
#pragma mark -
-#pragma mark SMySQL delegate methods
+#pragma mark MCPKit connection delegate methods
/**
- * Invoked when framework will perform a query
+ * Invoked when framework is about to perform a query.
*/
-- (void)willQueryString:(NSString *)query
+- (void)willQueryString:(NSString *)query connection:(id)connection
{
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"ConsoleEnableLogging"]) {
[[SPQueryConsole sharedQueryConsole] showMessageInConsole:query];
@@ -2009,20 +2034,53 @@
}
/**
- * Invoked when query gave an error
+ * Invoked when the query just executed resulted in an error.
*/
-- (void)queryGaveError:(NSString *)error
+- (void)queryGaveError:(NSString *)error connection:(id)connection
{
[[SPQueryConsole sharedQueryConsole] showErrorInConsole:error];
}
+/**
+ * Invoked when the current connection needs a password from the Keychain.
+ */
+- (NSString *)keychainPasswordForConnection:(MCPConnection *)connection
+{
+ KeyChain *keychain = [[KeyChain alloc] init];
+
+ NSString *password = [keychain getPasswordForName:[connectionController connectionKeychainItemName] account:[connectionController connectionKeychainItemAccount]];
+
+ [keychain release];
+
+ return password;
+}
+
+/**
+ * Invoked when the connection fails and the framework needs to know how to proceed.
+ */
+- (MCPConnectionCheck)connectionLost:(id)connection
+{
+ [NSApp beginSheet:connectionErrorDialog modalForWindow:tableWindow modalDelegate:self didEndSelector:nil contextInfo:nil];
+ int connectionErrorCode = [NSApp runModalForWindow:connectionErrorDialog];
+
+ [NSApp endSheet:connectionErrorDialog];
+ [connectionErrorDialog orderOut:nil];
+
+ // If "disconnect" was selected, trigger a window close.
+ [self windowWillClose:nil];
+ if (connectionErrorCode == MCPConnectionCheckDisconnect)
+ [tableWindow performSelector:@selector(close) withObject:nil afterDelay:0.0];
+
+ return connectionErrorCode;
+}
+
#pragma mark -
#pragma mark Database name field delegate methods
/**
* When adding a database, enable the button only if the new name has a length.
*/
-- (void) controlTextDidChange:(NSNotification *)aNotification
+- (void)controlTextDidChange:(NSNotification *)aNotification
{
if ([aNotification object] == databaseNameField) {
[addDatabaseButton setEnabled:([[databaseNameField stringValue] length] > 0)];
diff --git a/Source/TableDump.h b/Source/TableDump.h
index 01c502df..e0ee2c59 100644
--- a/Source/TableDump.h
+++ b/Source/TableDump.h
@@ -25,13 +25,10 @@
// Or mail to <lorenz@textor.ch>
#import <Cocoa/Cocoa.h>
-#import <MCPKit_bundled/MCPKit_bundled.h>
-#import "CMMCPConnection.h"
-#import "CMMCPResult.h"
-
-
-@interface TableDump : NSObject {
+#import <MCPKit/MCPKit.h>
+@interface TableDump : NSObject
+{
IBOutlet id tableDocumentInstance;
IBOutlet id tablesListInstance;
IBOutlet id tableSourceInstance;
@@ -94,7 +91,7 @@
IBOutlet id rowDownButton;
IBOutlet id recordCountLabel;
- CMMCPConnection *mySQLConnection;
+ MCPConnection *mySQLConnection;
NSMutableArray *tables;
NSArray *importArray;
@@ -132,12 +129,12 @@
// Export methods
- (BOOL)dumpSelectedTablesAsSqlToFileHandle:(NSFileHandle *)fileHandle;
- (BOOL)dumpSchemaAsDotToFileHandle:(NSFileHandle *)fileHandle;
-- (BOOL)writeCsvForArray:(NSArray *)array orQueryResult:(CMMCPResult *)queryResult
+- (BOOL)writeCsvForArray:(NSArray *)array orQueryResult:(MCPResult *)queryResult
toFileHandle:(NSFileHandle *)fileHandle
outputFieldNames:(BOOL)firstLine terminatedBy:(NSString *)terminated
enclosedBy:(NSString *)enclosed escapedBy:(NSString *)escaped
lineEnds:(NSString *)lineEnds withNumericColumns:(NSArray *)tableColumnNumericStatus silently:(BOOL)silently;
-- (BOOL)writeXmlForArray:(NSArray *)array orQueryResult:(CMMCPResult *)queryResult
+- (BOOL)writeXmlForArray:(NSArray *)array orQueryResult:(MCPResult *)queryResult
toFileHandle:(NSFileHandle *)fileHandle
tableName:(NSString *)table withHeader:(BOOL)header silently:(BOOL)silently;
- (NSString *)htmlEscapeString:(NSString *)string;
@@ -151,7 +148,7 @@
- (IBAction)switchInput:(id)sender;
//additional methods
-- (void)setConnection:(CMMCPConnection *)theConnection;
+- (void)setConnection:(MCPConnection *)theConnection;
// Import/export delegate notifications
- (void)panelSelectionDidChange:(id)sender;
diff --git a/Source/TableDump.m b/Source/TableDump.m
index 94aa7a0a..7f65196d 100644
--- a/Source/TableDump.m
+++ b/Source/TableDump.m
@@ -43,12 +43,12 @@
get the tables in db
*/
{
- CMMCPResult *queryResult;
+ MCPResult *queryResult;
int i;
//get tables
[tables removeAllObjects];
- queryResult = (CMMCPResult *)[mySQLConnection listTables];
+ queryResult = (MCPResult *)[mySQLConnection listTables];
if ([queryResult numOfRows]) [queryResult dataSeek:0];
for ( i = 0 ; i < [queryResult numOfRows] ; i++ ) {
@@ -423,7 +423,7 @@
if (!importSQLAsUTF8 || [fileType isEqualToString:@"CSV"]) {
DLog(@"Reading using connection encoding");
dumpFile = [SPSQLParser stringWithContentsOfFile:filename
- encoding:[CMMCPConnection encodingForMySQLEncoding:[[tableDocumentInstance connectionEncoding] UTF8String]]
+ encoding:[MCPConnection encodingForMySQLEncoding:[[tableDocumentInstance connectionEncoding] UTF8String]]
error:&errorStr];
}
@@ -588,9 +588,9 @@
[pool release];
return;
}
- CMMCPResult *theResult;
+ MCPResult *theResult;
int i;
- theResult = (CMMCPResult *) [mySQLConnection listTables];
+ theResult = (MCPResult *) [mySQLConnection listTables];
if ([theResult numOfRows]) [theResult dataSeek:0];
[fieldMappingPopup removeAllItems];
for ( i = 0 ; i < [theResult numOfRows] ; i++ ) {
@@ -835,7 +835,7 @@
int i,j,t,rowCount, colCount, lastProgressValue, queryLength;
// int progressBarWidth;
int tableType = SP_TABLETYPE_TABLE; //real tableType will be setup later
- CMMCPResult *queryResult;
+ MCPResult *queryResult;
NSString *tableName, *tableColumnTypeGrouping, *previousConnectionEncoding;
NSArray *fieldNames;
NSArray *theRow;
@@ -903,7 +903,7 @@
// Store the current connection encoding so it can be restored after the dump.
previousConnectionEncoding = [tableDocumentInstance connectionEncoding];
- previousConnectionEncodingViaLatin1 = [tableDocumentInstance connectionEncodingViaLatin1];
+ previousConnectionEncodingViaLatin1 = [tableDocumentInstance connectionEncodingViaLatin1:nil];
// Set the connection to UTF8 to be able to export correctly.
[tableDocumentInstance setConnectionEncoding:@"utf8" reloadingViews:NO];
@@ -1196,7 +1196,7 @@
// store connection encoding
previousConnectionEncoding = [tableDocumentInstance connectionEncoding];
- previousConnectionEncodingViaLatin1 = [tableDocumentInstance connectionEncodingViaLatin1];
+ previousConnectionEncodingViaLatin1 = [tableDocumentInstance connectionEncodingViaLatin1:nil];
NSMutableArray *fkInfo = [[NSMutableArray alloc] init];
@@ -1297,7 +1297,7 @@
/*
Takes an array and writes it in CSV format to the supplied NSFileHandle
*/
-- (BOOL)writeCsvForArray:(NSArray *)array orQueryResult:(CMMCPResult *)queryResult toFileHandle:(NSFileHandle *)fileHandle
+- (BOOL)writeCsvForArray:(NSArray *)array orQueryResult:(MCPResult *)queryResult toFileHandle:(NSFileHandle *)fileHandle
outputFieldNames:(BOOL)outputFieldNames
terminatedBy:(NSString *)fieldSeparatorString
enclosedBy:(NSString *)enclosingString
@@ -1306,7 +1306,7 @@
withNumericColumns:(NSArray *)tableColumnNumericStatus
silently:(BOOL)silently;
{
- NSStringEncoding tableEncoding = [CMMCPConnection encodingForMySQLEncoding:[[tableDocumentInstance connectionEncoding] UTF8String]];
+ NSStringEncoding tableEncoding = [MCPConnection encodingForMySQLEncoding:[[tableDocumentInstance connectionEncoding] UTF8String]];
NSMutableString *csvCell = [NSMutableString string];
NSMutableArray *csvRow = [NSMutableArray array];
NSMutableString *csvString = [NSMutableString string];
@@ -1655,9 +1655,9 @@
/*
Takes an array and writes it in XML format to the supplied NSFileHandle
*/
-- (BOOL)writeXmlForArray:(NSArray *)array orQueryResult:(CMMCPResult *)queryResult toFileHandle:(NSFileHandle *)fileHandle tableName:(NSString *)table withHeader:(BOOL)header silently:(BOOL)silently
+- (BOOL)writeXmlForArray:(NSArray *)array orQueryResult:(MCPResult *)queryResult toFileHandle:(NSFileHandle *)fileHandle tableName:(NSString *)table withHeader:(BOOL)header silently:(BOOL)silently
{
- NSStringEncoding tableEncoding = [CMMCPConnection encodingForMySQLEncoding:[[tableDocumentInstance connectionEncoding] UTF8String]];
+ NSStringEncoding tableEncoding = [MCPConnection encodingForMySQLEncoding:[[tableDocumentInstance connectionEncoding] UTF8String]];
NSMutableArray *xmlTags = [NSMutableArray array];
NSMutableArray *xmlRow = [NSMutableArray array];
NSMutableString *xmlString = [NSMutableString string];
@@ -1815,7 +1815,7 @@
- (BOOL)exportTables:(NSArray *)selectedTables toFileHandle:(NSFileHandle *)fileHandle usingFormat:(NSString *)type usingMulti:(BOOL)multi
{
int i, j;
- CMMCPResult *queryResult;
+ MCPResult *queryResult;
NSString *tableName, *tableColumnTypeGrouping;
NSMutableString *infoString = [NSMutableString string];
NSMutableString *errors = [NSMutableString string];
@@ -2173,7 +2173,7 @@
}
//additional methods
-- (void)setConnection:(CMMCPConnection *)theConnection
+- (void)setConnection:(MCPConnection *)theConnection
/*
sets the connection (received from TableDocument) and makes things that have to be done only once
*/
diff --git a/Source/TableSource.h b/Source/TableSource.h
index aeef8190..5d32e334 100644
--- a/Source/TableSource.h
+++ b/Source/TableSource.h
@@ -24,9 +24,7 @@
// More info at <http://code.google.com/p/sequel-pro/>
#import <Cocoa/Cocoa.h>
-#import <MCPKit_bundled/MCPKit_bundled.h>
-#import "CMMCPConnection.h"
-#import "CMMCPResult.h"
+#import <MCPKit/MCPKit.h>
@interface TableSource : NSObject
{
@@ -50,9 +48,9 @@
IBOutlet id structureGrabber;
IBOutlet id editTableButton;
- CMMCPConnection *mySQLConnection;
- CMMCPResult *tableSourceResult;
- CMMCPResult *indexResult;
+ MCPConnection *mySQLConnection;
+ MCPResult *tableSourceResult;
+ MCPResult *indexResult;
NSString *selectedTable;
NSMutableArray *tableFields, *indexes;
@@ -85,8 +83,8 @@
- (IBAction)closeKeySheet:(id)sender;
//additional methods
-- (void)setConnection:(CMMCPConnection *)theConnection;
-- (NSArray *)fetchResultAsArray:(CMMCPResult *)theResult;
+- (void)setConnection:(MCPConnection *)theConnection;
+- (NSArray *)fetchResultAsArray:(MCPResult *)theResult;
- (BOOL)saveRowOnDeselect;
- (BOOL)addRowToDB;
diff --git a/Source/TableSource.m b/Source/TableSource.m
index d44efe3c..7fb0cdfd 100644
--- a/Source/TableSource.m
+++ b/Source/TableSource.m
@@ -30,7 +30,6 @@
#import "SPStringAdditions.h"
#import "SPArrayAdditions.h"
-
@implementation TableSource
/*
@@ -519,7 +518,7 @@ closes the keySheet
/*
sets the connection (received from TableDocument) and makes things that have to be done only once
*/
-- (void)setConnection:(CMMCPConnection *)theConnection
+- (void)setConnection:(MCPConnection *)theConnection
{
NSEnumerator *indexColumnsEnumerator = [[indexView tableColumns] objectEnumerator];
NSEnumerator *fieldColumnsEnumerator = [[tableSourceView tableColumns] objectEnumerator];
@@ -554,7 +553,7 @@ sets the connection (received from TableDocument) and makes things that have to
/*
fetches the result as an array with a dictionary for each row in it
*/
-- (NSArray *)fetchResultAsArray:(CMMCPResult *)theResult
+- (NSArray *)fetchResultAsArray:(MCPResult *)theResult
{
unsigned long numOfRows = [theResult numOfRows];
NSMutableArray *tempResult = [NSMutableArray arrayWithCapacity:numOfRows];
@@ -995,7 +994,7 @@ returns a dictionary containing enum/set field names as key and possible values
- (NSArray *)tableStructureForPrint
{
- CMMCPResult *queryResult;
+ MCPResult *queryResult;
NSMutableArray *tempResult = [NSMutableArray array];
int i;
diff --git a/Source/TablesList.h b/Source/TablesList.h
index 5b6214ea..bd1e36e9 100644
--- a/Source/TablesList.h
+++ b/Source/TablesList.h
@@ -24,7 +24,7 @@
// More info at <http://code.google.com/p/sequel-pro/>
#import <Cocoa/Cocoa.h>
-#import <MCPKit_bundled/MCPKit_bundled.h>
+#import <MCPKit/MCPKit.h>
enum sp_table_types
{
@@ -35,10 +35,10 @@ enum sp_table_types
SP_TABLETYPE_FUNC = 3
};
-@class CMMCResult, CMMCPConnection;
-
-@interface TablesList : NSObject {
+@class CMMCResult, MCPConnection;
+@interface TablesList : NSObject
+{
IBOutlet id tableDocumentInstance;
IBOutlet id tableSourceInstance;
IBOutlet id tableContentInstance;
@@ -73,14 +73,13 @@ enum sp_table_types
IBOutlet NSMenuItem *renameTableMenuItem;
IBOutlet NSMenuItem *separatorTableMenuItem;
+ MCPConnection *mySQLConnection;
+
IBOutlet NSMenuItem *removeTableContextMenuItem;
IBOutlet NSMenuItem *duplicateTableContextMenuItem;
IBOutlet NSMenuItem *renameTableContextMenuItem;
IBOutlet NSMenuItem *separatorTableContextMenuItem;
-
- CMMCPConnection *mySQLConnection;
-
NSMutableArray *tables;
NSMutableArray *tableTypes;
@@ -101,8 +100,8 @@ enum sp_table_types
// Additional methods
- (void)removeTable;
+- (void)setConnection:(MCPConnection *)theConnection;
- (void)truncateTable;
-- (void)setConnection:(CMMCPConnection *)theConnection;
- (void)doPerformQueryService:(NSString *)query;
// Getters
diff --git a/Source/TablesList.m b/Source/TablesList.m
index ac0be0d8..10be699a 100644
--- a/Source/TablesList.m
+++ b/Source/TablesList.m
@@ -30,8 +30,6 @@
#import "SPTableData.h"
#import "TableDump.h"
#import "ImageAndTextCell.h"
-#import "CMMCPConnection.h"
-#import "CMMCPResult.h"
#import "SPStringAdditions.h"
#import "SPArrayAdditions.h"
#import "RegexKitLite.h"
@@ -46,7 +44,7 @@
*/
- (IBAction)updateTables:(id)sender
{
- CMMCPResult *theResult;
+ MCPResult *theResult;
NSArray *resultRow;
int i;
BOOL containsViews = NO;
@@ -120,7 +118,7 @@
[tables addObject:NSArrayObjectAtIndex(resultRow, 3)];
if( [NSArrayObjectAtIndex(resultRow, 4) isEqualToString:@"PROCEDURE"] ) {
[tableTypes addObject:[NSNumber numberWithInt:SP_TABLETYPE_PROC]];
- } else {
+ } else {
[tableTypes addObject:[NSNumber numberWithInt:SP_TABLETYPE_FUNC]];
}
}
@@ -401,7 +399,7 @@
*/
- (IBAction)copyTable:(id)sender
{
- CMMCPResult *queryResult;
+ MCPResult *queryResult;
int code;
NSString *tableType;
int tblType;
@@ -493,7 +491,7 @@
else if(tblType == SP_TABLETYPE_FUNC || tblType == SP_TABLETYPE_PROC)
{
// get the create syntax
- CMMCPResult *theResult;
+ MCPResult *theResult;
if([self tableType] == SP_TABLETYPE_PROC)
theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SHOW CREATE PROCEDURE %@", [[tables objectAtIndex:[tablesListView selectedRow]] backtickQuotedString]]];
else if([self tableType] == SP_TABLETYPE_FUNC)
@@ -631,7 +629,7 @@
} else {
// procedures and functions can only be renamed if one creates the new one and delete the old one
// get the create syntax
- CMMCPResult *theResult;
+ MCPResult *theResult;
if([self tableType] == SP_TABLETYPE_PROC)
theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SHOW CREATE PROCEDURE %@", [[self tableName] backtickQuotedString]]];
else if([self tableType] == SP_TABLETYPE_FUNC)
@@ -833,7 +831,7 @@
/**
* Sets the connection (received from TableDocument) and makes things that have to be done only once
*/
-- (void)setConnection:(CMMCPConnection *)theConnection
+- (void)setConnection:(MCPConnection *)theConnection
{
mySQLConnection = theConnection;
[self updateTables:self];
@@ -1135,7 +1133,7 @@
tableType = @"FUNCTION";
break;
}
- CMMCPResult *theResult;
+ MCPResult *theResult;
if([self tableType] == SP_TABLETYPE_PROC)
theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SHOW CREATE PROCEDURE %@", [[tables objectAtIndex:rowIndex] backtickQuotedString]]];
else if([self tableType] == SP_TABLETYPE_FUNC)