aboutsummaryrefslogtreecommitdiffstats
path: root/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h
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 /Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h
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 'Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h')
-rw-r--r--Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h226
1 files changed, 226 insertions, 0 deletions
diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h
new file mode 100644
index 00000000..a6457494
--- /dev/null
+++ b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h
@@ -0,0 +1,226 @@
+//
+// $Id: MCPConnection.h 1069 2009-07-19 23:12:50Z rowanb $
+//
+// MCPConnection.h
+// MCPKit
+//
+// Created by Serge Cohen (serge.cohen@m4x.org) on 08/12/2001.
+// Copyright (c) 2001 Serge Cohen. All rights reserved.
+//
+// Forked by the Sequel Pro team (sequelpro.com), April 2009
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// More info at <http://mysql-cocoa.sourceforge.net/>
+// More info at <http://code.google.com/p/sequel-pro/>
+
+#import <Foundation/Foundation.h>
+
+#import "MCPConstants.h"
+
+#import "mysql.h"
+
+@class MCPResult;
+@protocol MCPConnectionProxy;
+
+/**
+ * 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;
+}
+
+// Connection delegate interface
+@interface NSObject (MCPConnectionDelegate)
+
+- (void)willQueryString:(NSString *)query connection:(id)connection;
+- (void)queryGaveError:(NSString *)error connection:(id)connection;
+- (BOOL)connectionEncodingViaLatin1:(id)connection;
+- (NSString *)keychainPasswordForConnection:(id)connection;
+- (MCPConnectionCheck)connectionLost:(id)connection;
+
+@end
+
+@interface MCPConnection : NSObject
+{
+ MYSQL *mConnection; /* The inited MySQL connection. */
+ BOOL mConnected; /* Reflect the fact that the connection is already in place or not. */
+ NSStringEncoding mEncoding; /* The encoding used by MySQL server, to ISO-1 default. */
+ NSTimeZone *mTimeZone; /* The time zone of the session. */
+ unsigned int mConnectionFlags; /* The flags to be used for the connection to the database. */
+ id delegate; /* Connection delegate */
+
+ NSLock *queryLock; /* Anything that performs a mysql_net_read is not thread-safe: mysql queries, pings */
+
+ BOOL useKeepAlive;
+ int connectionTimeout;
+ float keepAliveInterval;
+
+ id <MCPConnectionProxy> connectionProxy;
+ NSString *connectionLogin;
+ NSString *connectionPassword;
+ NSString *connectionHost;
+ int connectionPort;
+ NSString *connectionSocket;
+ int maxAllowedPacketSize;
+ unsigned long connectionThreadId;
+
+ int currentProxyState;
+
+ double lastQueryExecutionTime;
+ double lastQueryExecutedAtTime;
+ NSString *lastQueryErrorMessage;
+ unsigned int lastQueryErrorId;
+ my_ulonglong lastQueryAffectedRows;
+
+ BOOL isMaxAllowedPacketEditable;
+
+ NSString *serverVersionString;
+
+ NSTimer *keepAliveTimer;
+ NSDate *lastKeepAliveSuccess;
+ uint64_t connectionStartTime;
+
+ BOOL retryAllowed;
+ BOOL delegateQueryLogging;
+ BOOL delegateResponseToWillQueryString;
+
+ // Pointers
+ IMP cStringPtr;
+ IMP willQueryStringPtr;
+ IMP stopKeepAliveTimerPtr;
+ IMP startKeepAliveTimerResettingStatePtr;
+ IMP timeConnectedPtr;
+
+ // Selectors
+ SEL cStringSEL;
+ SEL willQueryStringSEL;
+ SEL stopKeepAliveTimerSEL;
+ SEL startKeepAliveTimerResettingStateSEL;
+ SEL timeConnectedSEL;
+}
+
+@property (readwrite, assign) id delegate;
+@property (readwrite, assign) BOOL useKeepAlive;
+@property (readwrite, assign) BOOL delegateQueryLogging;
+@property (readwrite, assign) int connectionTimeout;
+@property (readwrite, assign) float keepAliveInterval;
+
+// Initialisation
+- (id)initToHost:(NSString *)host withLogin:(NSString *)login usingPort:(int)port;
+- (id)initToSocket:(NSString *)socket withLogin:(NSString *)login;
+
+// Connection details
+- (BOOL)setPort:(int)thePort;
+- (BOOL)setPassword:(NSString *)thePassword;
+
+// Proxy
+- (BOOL)setConnectionProxy:(id <MCPConnectionProxy>)proxy;
+- (void)connectionProxyStateChange:(id <MCPConnectionProxy>)proxy;
+
+// Connection
+- (BOOL)connect;
+- (void)disconnect;
+- (BOOL)reconnect;
+- (BOOL)isConnected;
+- (BOOL)checkConnection;
+- (BOOL)pingConnection;
+- (void)startKeepAliveTimerResettingState:(BOOL)resetState;
+- (void)stopKeepAliveTimer;
+- (void)keepAlive:(NSTimer *)theTimer;
+- (void)threadedKeepAlive;
+- (void)restoreConnectionDetails;
+- (void)setAllowQueryRetries:(BOOL)allow;
+- (double)timeConnected;
+
+// Server versions
+- (int)serverMajorVersion;
+- (int)serverMinorVersion;
+- (int)serverReleaseVersion;
+
+// MySQL defaults
++ (NSDictionary *)getMySQLLocales;
++ (NSStringEncoding)encodingForMySQLEncoding:(const char *)mysqlEncoding;
++ (NSStringEncoding)defaultMySQLEncoding;
++ (BOOL)isErrorNumberConnectionError:(int)theErrorNumber;
+
+// Class maintenance
++ (void)setTruncateLongFieldInLogs:(BOOL)iTruncFlag;
++ (BOOL)truncateLongField;
+- (BOOL)setConnectionOption:(int)option toValue:(BOOL)value;
+- (BOOL)connectWithLogin:(NSString *)login password:(NSString *)pass host:(NSString *)host port:(int)port socket:(NSString *)socket;
+
+- (BOOL)selectDB:(NSString *)dbName;
+
+// Error information
+- (NSString *)getLastErrorMessage;
+- (void)setLastErrorMessage:(NSString *)theErrorMessage;
+- (unsigned int)getLastErrorID;
++ (BOOL)isErrorNumberConnectionError:(int)theErrorNumber;
+
+// Queries
+- (NSString *)prepareBinaryData:(NSData *)theData;
+- (NSString *)prepareString:(NSString *)theString;
+- (NSString *)quoteObject:(id)theObject;
+- (MCPResult *)queryString:(NSString *)query;
+- (MCPResult *)queryString:(NSString *)query usingEncoding:(NSStringEncoding)encoding;
+- (double)lastQueryExecutionTime;
+- (my_ulonglong)affectedRows;
+- (my_ulonglong)insertId;
+
+// Database structure
+- (MCPResult *)listDBs;
+- (MCPResult *)listDBsLike:(NSString *)dbsName;
+- (MCPResult *)listTables;
+- (MCPResult *)listTablesLike:(NSString *)tablesName;
+- (MCPResult *)listTablesFromDB:(NSString *)dbName like:(NSString *)tablesName;
+- (MCPResult *)listFieldsFromTable:(NSString *)tableName;
+- (MCPResult *)listFieldsFromTable:(NSString *)tableName like:(NSString *)fieldsName;
+
+// Server information
+- (NSString *)clientInfo;
+- (NSString *)hostInfo;
+- (NSString *)serverInfo;
+- (NSNumber *)protoInfo;
+- (MCPResult *)listProcesses;
+- (BOOL)killProcess:(unsigned long)pid;
+- (NSString *)findSocketPath;
+
+// Encoding
+- (void)setEncoding:(NSStringEncoding)theEncoding;
+- (NSStringEncoding)encoding;
+
+// Time zone
+- (void)setTimeZone:(NSTimeZone *)iTimeZone;
+- (NSTimeZone *)timeZone;
+
+// Packet size
+- (BOOL)fetchMaxAllowedPacket;
+- (int)getMaxAllowedPacket;
+- (BOOL)isMaxAllowedPacketEditable;
+- (int)setMaxAllowedPacketTo:(int)newSize resetSize:(BOOL)reset;
+
+// Data conversion
+- (const char *)cStringFromString:(NSString *)theString;
+- (const char *)cStringFromString:(NSString *)theString usingEncoding:(NSStringEncoding)encoding;
+- (NSString *)stringWithCString:(const char *)theCString;
+- (NSString *)stringWithText:(NSData *)theTextData;
+
+@end