aboutsummaryrefslogtreecommitdiffstats
path: root/Frameworks/MCPKit/MCPFoundationKit
diff options
context:
space:
mode:
Diffstat (limited to 'Frameworks/MCPKit/MCPFoundationKit')
-rw-r--r--Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h70
-rw-r--r--Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m34
-rw-r--r--Frameworks/MCPKit/MCPFoundationKit/MCPConstants.h13
-rw-r--r--Frameworks/MCPKit/MCPFoundationKit/MCPResult.h2
-rw-r--r--Frameworks/MCPKit/MCPFoundationKit/MCPStreamingResult.h9
-rw-r--r--Frameworks/MCPKit/MCPFoundationKit/MCPStreamingResult.m4
-rw-r--r--Frameworks/MCPKit/MCPFoundationKit/MCPStringAdditions.h43
7 files changed, 128 insertions, 47 deletions
diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h
index c6d81bd6..89739e23 100644
--- a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h
+++ b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h
@@ -27,47 +27,62 @@
// More info at <http://code.google.com/p/sequel-pro/>
#import <Foundation/Foundation.h>
+#import <pthread.h>
#import "MCPConstants.h"
-
#import "mysql.h"
-#include <pthread.h>
-
-enum
-{
- MCP_NO_STREAMING = 0,
- MCP_FAST_STREAMING = 1,
- MCP_LOWMEM_STREAMING = 2
-};
-typedef NSUInteger mcp_query_streaming_types;
-@class MCPResult, MCPStreamingResult;
@protocol MCPConnectionProxy;
-/**
- * NSStringDataUsingLossyEncoding(aStr, enc, lossy) := [aStr dataUsingEncoding:enc allowLossyConversion:lossy]
- */
-static inline NSData* NSStringDataUsingLossyEncoding(NSString* self, NSInteger encoding, NSInteger lossy)
-{
- typedef NSData* (*SPStringDataUsingLossyEncodingMethodPtr)(NSString*, SEL, NSInteger, NSInteger);
- 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;
-}
+@class MCPResult, MCPStreamingResult;
-// 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;
+
+/**
+ *
+ */
- (NSString *)onReconnectShouldSelectDatabase:(id)connection;
+
+/**
+ *
+ */
- (NSString *)onReconnectShouldUseEncoding:(id)connection;
+
+/**
+ *
+ */
- (void)noConnectionAvailable:(id)connection;
+
+/**
+ *
+ */
- (MCPConnectionCheck)connectionLost:(id)connection;
-- (NSString*)connectionID;
+
+/**
+ *
+ */
+- (NSString *)connectionID;
+
@end
@interface MCPConnection : NSObject
@@ -77,9 +92,10 @@ static inline NSData* NSStringDataUsingLossyEncoding(NSString* self, NSInteger e
NSStringEncoding mEncoding; /* The encoding used by MySQL server, to ISO-1 default. */
NSTimeZone *mTimeZone; /* The time zone of the session. */
NSUInteger mConnectionFlags; /* The flags to be used for the connection to the database. */
- id delegate; /* Connection delegate */
- NSLock *queryLock; /* Anything that performs a mysql_net_read is not thread-safe: mysql queries, pings */
+ id delegate; /* Connection delegate */
+
+ NSLock *queryLock; /* Anything that performs a mysql_net_read is not thread-safe: mysql queries, pings */
BOOL useKeepAlive;
BOOL isDisconnecting;
@@ -212,7 +228,7 @@ void performThreadedKeepAlive(void *ptr);
- (MCPResult *)queryString:(NSString *)query;
- (MCPStreamingResult *)streamingQueryString:(NSString *)query;
- (MCPStreamingResult *)streamingQueryString:(NSString *)query useLowMemoryBlockingStreaming:(BOOL)fullStream;
-- (id)queryString:(NSString *) query usingEncoding:(NSStringEncoding) encoding streamingResult:(NSInteger) streamResult;
+- (id)queryString:(NSString *)query usingEncoding:(NSStringEncoding)encoding streamingResult:(NSInteger)streamResult;
- (my_ulonglong)affectedRows;
- (my_ulonglong)insertId;
- (void)cancelCurrentQuery;
diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m
index 6f516157..af3bae08 100644
--- a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m
+++ b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m
@@ -28,10 +28,11 @@
#import "MCPConnection.h"
#import "MCPResult.h"
-#import "MCPStreamingResult.h"
#import "MCPNumber.h"
#import "MCPNull.h"
+#import "MCPStreamingResult.h"
#import "MCPConnectionProxy.h"
+#import "MCPStringAdditions.h"
#include <unistd.h>
#include <mach/mach_time.h>
@@ -1285,7 +1286,7 @@ void performThreadedKeepAlive(void *ptr)
*/
- (MCPResult *)queryString:(NSString *)query
{
- return [self queryString:query usingEncoding:mEncoding streamingResult:MCP_NO_STREAMING];
+ return [self queryString:query usingEncoding:mEncoding streamingResult:MCPStreamingNone];
}
/**
@@ -1295,7 +1296,7 @@ void performThreadedKeepAlive(void *ptr)
*/
- (MCPStreamingResult *)streamingQueryString:(NSString *)query
{
- return [self queryString:query usingEncoding:mEncoding streamingResult:MCP_FAST_STREAMING];
+ return [self queryString:query usingEncoding:mEncoding streamingResult:MCPStreamingFast];
}
/**
@@ -1307,7 +1308,7 @@ void performThreadedKeepAlive(void *ptr)
*/
- (MCPStreamingResult *)streamingQueryString:(NSString *)query useLowMemoryBlockingStreaming:(BOOL)fullStream
{
- return [self queryString:query usingEncoding:mEncoding streamingResult:(fullStream?MCP_LOWMEM_STREAMING:MCP_FAST_STREAMING)];
+ return [self queryString:query usingEncoding:mEncoding streamingResult:(fullStream?MCPStreamingLowMem:MCPStreamingFast)];
}
/**
@@ -1413,7 +1414,7 @@ void performThreadedKeepAlive(void *ptr)
// Lock the connection - on this thread for normal result sets (avoiding blocking issues
// when the app is in modal mode), or ensuring a lock on the main thread for streaming queries.
- if (streamResultType == MCP_NO_STREAMING) [queryLock lock];
+ if (streamResultType == MCPStreamingNone) [queryLock lock];
else [self lockConnection];
// Run (or re-run) the query, timing the execution time of the query - note
@@ -1431,14 +1432,14 @@ void performThreadedKeepAlive(void *ptr)
if (mysql_field_count(mConnection) != 0) {
// For normal result sets, fetch the results and unlock the connection
- if (streamResultType == MCP_NO_STREAMING) {
+ if (streamResultType == MCPStreamingNone) {
theResult = [[MCPResult alloc] initWithMySQLPtr:mConnection encoding:mEncoding timeZone:mTimeZone];
if (!queryCancelled || !queryCancelUsedReconnect) [queryLock unlock];
// For streaming result sets, fetch the result pointer and leave the connection locked
- } else if (streamResultType == MCP_FAST_STREAMING) {
+ } else if (streamResultType == MCPStreamingFast) {
theResult = [[MCPStreamingResult alloc] initWithMySQLPtr:mConnection encoding:mEncoding timeZone:mTimeZone connection:self withFullStreaming:NO];
- } else if (streamResultType == MCP_LOWMEM_STREAMING) {
+ } else if (streamResultType == MCPStreamingLowMem) {
theResult = [[MCPStreamingResult alloc] initWithMySQLPtr:mConnection encoding:mEncoding timeZone:mTimeZone connection:self withFullStreaming:YES];
}
@@ -1449,20 +1450,20 @@ void performThreadedKeepAlive(void *ptr)
break;
}
} else {
- if (streamResultType == MCP_NO_STREAMING) [queryLock unlock];
+ if (streamResultType == MCPStreamingNone) [queryLock unlock];
else [self unlockConnection];
}
queryErrorMessage = [[NSString alloc] initWithString:@""];
queryErrorId = 0;
- if (streamResultType == MCP_NO_STREAMING && queryAffectedRows == -1) {
+ if (streamResultType == MCPStreamingNone && queryAffectedRows == -1) {
queryAffectedRows = mysql_affected_rows(mConnection);
}
// On failure, set the error messages and IDs
} else {
if (!queryCancelled || !queryCancelUsedReconnect) {
- if (streamResultType == MCP_NO_STREAMING) [queryLock unlock];
+ if (streamResultType == MCPStreamingNone) [queryLock unlock];
else [self unlockConnection];
}
@@ -1486,7 +1487,7 @@ void performThreadedKeepAlive(void *ptr)
break;
}
- if (streamResultType == MCP_NO_STREAMING) {
+ if (streamResultType == MCPStreamingNone) {
// If the mysql thread id has changed as a result of a connection error,
// ensure connection details are still correct
@@ -1499,8 +1500,13 @@ void performThreadedKeepAlive(void *ptr)
// Update error strings and IDs
lastQueryErrorId = queryErrorId;
- [self setLastErrorMessage:queryErrorMessage?queryErrorMessage:@""];
- if (queryErrorMessage) [queryErrorMessage release];
+
+ if (queryErrorMessage) {
+ [self setLastErrorMessage:queryErrorMessage];
+
+ [queryErrorMessage release];
+ }
+
lastQueryAffectedRows = queryAffectedRows;
lastQueryExecutionTime = queryExecutionTime;
diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPConstants.h b/Frameworks/MCPKit/MCPFoundationKit/MCPConstants.h
index 816d68ca..acdeee16 100644
--- a/Frameworks/MCPKit/MCPFoundationKit/MCPConstants.h
+++ b/Frameworks/MCPKit/MCPFoundationKit/MCPConstants.h
@@ -43,12 +43,21 @@ enum {
};
typedef NSUInteger MCPConnectionCheck;
+// Streaming result set constants
+enum
+{
+ MCPStreamingNone = 0,
+ MCPStreamingFast = 1,
+ MCPStreamingLowMem = 2
+};
+typedef NSUInteger MCPQueryStreamingType;
+
// Charcater set mapping constants
typedef struct _OUR_CHARSET
{
NSUInteger nr;
- const char *name;
- const char *collation;
+ const char *name;
+ const char *collation;
NSUInteger char_minlen;
NSUInteger char_maxlen;
} OUR_CHARSET;
diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPResult.h b/Frameworks/MCPKit/MCPFoundationKit/MCPResult.h
index ac0217de..ad50af75 100644
--- a/Frameworks/MCPKit/MCPFoundationKit/MCPResult.h
+++ b/Frameworks/MCPKit/MCPFoundationKit/MCPResult.h
@@ -27,8 +27,8 @@
// More info at <http://code.google.com/p/sequel-pro/>
#import <Foundation/Foundation.h>
-#import "MCPConstants.h"
+#import "MCPConstants.h"
#import "mysql.h"
#define MAGIC_BINARY_CHARSET_NR 63
diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPStreamingResult.h b/Frameworks/MCPKit/MCPFoundationKit/MCPStreamingResult.h
index 65ee6423..b17f8584 100644
--- a/Frameworks/MCPKit/MCPFoundationKit/MCPStreamingResult.h
+++ b/Frameworks/MCPKit/MCPFoundationKit/MCPStreamingResult.h
@@ -23,8 +23,10 @@
//
// More info at <http://code.google.com/p/sequel-pro/>
-#import <Cocoa/Cocoa.h>
+#import <Foundation/Foundation.h>
+
#import "MCPResult.h"
+#import "mysql.h"
@class MCPConnection;
@@ -39,20 +41,25 @@ typedef struct SP_MYSQL_ROWS {
MCPConnection *parentConnection;
MYSQL_FIELD *fieldDefinitions;
+
BOOL fullyStreaming;
BOOL connectionUnlocked;
BOOL dataDownloaded;
BOOL dataFreed;
+
LOCAL_ROW_DATA *localDataStore;
LOCAL_ROW_DATA *currentDataStoreEntry;
LOCAL_ROW_DATA *localDataStoreLastEntry;
+
unsigned long localDataRows;
unsigned long localDataAllocated;
unsigned long downloadedRowCount;
unsigned long processedRowCount;
unsigned long freedRowCount;
+
pthread_mutex_t dataCreationLock;
pthread_mutex_t dataFreeLock;
+
IMP isConnectedPtr;
SEL isConnectedSEL;
}
diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPStreamingResult.m b/Frameworks/MCPKit/MCPFoundationKit/MCPStreamingResult.m
index bf8a2599..f6371b03 100644
--- a/Frameworks/MCPKit/MCPFoundationKit/MCPStreamingResult.m
+++ b/Frameworks/MCPKit/MCPFoundationKit/MCPStreamingResult.m
@@ -208,7 +208,7 @@
returnArray = [NSMutableArray arrayWithCapacity:mNumOfFields];
for (i = 0; i < mNumOfFields; i++) {
id cellData = nil;
- char *theData;
+ char *theData = NULL;
// In fully streaming mode, copy across the data for the MYSQL_ROW
if (fullyStreaming) {
@@ -270,7 +270,7 @@
break;
case FIELD_TYPE_BIT:
- cellData = [NSString stringWithFormat:@"%u", theData[0]];
+ cellData = (theData != NULL) ? [NSString stringWithFormat:@"%u", theData[0]] : @"";
break;
case FIELD_TYPE_TINY_BLOB:
diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPStringAdditions.h b/Frameworks/MCPKit/MCPFoundationKit/MCPStringAdditions.h
new file mode 100644
index 00000000..36693703
--- /dev/null
+++ b/Frameworks/MCPKit/MCPFoundationKit/MCPStringAdditions.h
@@ -0,0 +1,43 @@
+//
+// $Id$
+//
+// MCPStringAdditions.h
+// sequel-pro
+//
+// Created by Stuart Connolly (stuconnolly.com) on March 25, 2010
+// Copyright (c) 2010 Stuart Connolly. All rights reserved.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// More info at <http://code.google.com/p/sequel-pro/>
+
+#import <Foundation/Foundation.h>
+
+/**
+ * NSStringDataUsingLossyEncoding(aStr, enc, lossy) := [aStr dataUsingEncoding:enc allowLossyConversion:lossy]
+ */
+static inline NSData *NSStringDataUsingLossyEncoding(NSString *self, NSInteger encoding, NSInteger lossy)
+{
+ typedef NSData *(*SPStringDataUsingLossyEncodingMethodPtr)(NSString*, SEL, NSInteger, NSInteger);
+ static SPStringDataUsingLossyEncodingMethodPtr SPNSStringDataUsingLossyEncoding;
+
+ if (!SPNSStringDataUsingLossyEncoding) SPNSStringDataUsingLossyEncoding = (SPStringDataUsingLossyEncodingMethodPtr)[self methodForSelector:@selector(dataUsingEncoding:allowLossyConversion:)];
+
+ return SPNSStringDataUsingLossyEncoding(self, @selector(dataUsingEncoding:allowLossyConversion:), encoding, lossy);
+}
+
+@interface NSString (MCPStringAdditions)
+
+@end