aboutsummaryrefslogtreecommitdiffstats
path: root/Frameworks/SPMySQLFramework/Source
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2013-03-11 23:03:28 +0000
committerrowanbeentje <rowan@beent.je>2013-03-11 23:03:28 +0000
commitf4967d21057a1363cacc9607b5ace0149a45ca11 (patch)
tree987e9786303429596420858cec43702f5957790b /Frameworks/SPMySQLFramework/Source
parente88ea3b18a1e9bd1f1e5bef51d982992ce211933 (diff)
downloadsequelpro-f4967d21057a1363cacc9607b5ace0149a45ca11.tar.gz
sequelpro-f4967d21057a1363cacc9607b5ace0149a45ca11.tar.bz2
sequelpro-f4967d21057a1363cacc9607b5ace0149a45ca11.zip
- Add a new SPMySQLEmptyResult class to SPMySQLFrameowkr, returning it instead of nil if a query produces no result set. This allows per-result-set properties to be preserved, fixing issues where information like query execution time was lost - addressing Issue #1577
Diffstat (limited to 'Frameworks/SPMySQLFramework/Source')
-rw-r--r--Frameworks/SPMySQLFramework/Source/SPMySQL.h1
-rw-r--r--Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Querying & Preparation.m56
-rw-r--r--Frameworks/SPMySQLFramework/Source/SPMySQLResult.m39
3 files changed, 57 insertions, 39 deletions
diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQL.h b/Frameworks/SPMySQLFramework/Source/SPMySQL.h
index aa9008b6..904f390c 100644
--- a/Frameworks/SPMySQLFramework/Source/SPMySQL.h
+++ b/Frameworks/SPMySQLFramework/Source/SPMySQL.h
@@ -58,6 +58,7 @@
// MySQL result set, streaming subclasses of same, and associated categories
#import "SPMySQLResult.h"
+#import "SPMySQLEmptyResult.h"
#import "SPMySQLStreamingResult.h"
#import "SPMySQLFastStreamingResult.h"
#import "Field Definitions.h"
diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Querying & Preparation.m b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Querying & Preparation.m
index 22e35648..c007a07e 100644
--- a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Querying & Preparation.m
+++ b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Querying & Preparation.m
@@ -322,34 +322,38 @@
id theResult = nil;
// On success, if there is a query result, retrieve the result data type
- if (!queryStatus && mysql_field_count(mySQLConnection)) {
- MYSQL_RES *mysqlResult;
-
- switch (theReturnType) {
-
- // For standard result sets, retrieve all the results now, and afterwards
- // update the affected row count.
- case SPMySQLResultAsResult:
- mysqlResult = mysql_store_result(mySQLConnection);
- theResult = [[SPMySQLResult alloc] initWithMySQLResult:mysqlResult stringEncoding:theEncoding];
- theAffectedRowCount = mysql_affected_rows(mySQLConnection);
- break;
-
- // For fast streaming and low memory streaming result sets, set up the result
- case SPMySQLResultAsLowMemStreamingResult:
- mysqlResult = mysql_use_result(mySQLConnection);
- theResult = [[SPMySQLStreamingResult alloc] initWithMySQLResult:mysqlResult stringEncoding:theEncoding connection:self];
- break;
+ if (!queryStatus) {
+ if (mysql_field_count(mySQLConnection)) {
+ MYSQL_RES *mysqlResult;
+
+ switch (theReturnType) {
+
+ // For standard result sets, retrieve all the results now, and afterwards
+ // update the affected row count.
+ case SPMySQLResultAsResult:
+ mysqlResult = mysql_store_result(mySQLConnection);
+ theResult = [[SPMySQLResult alloc] initWithMySQLResult:mysqlResult stringEncoding:theEncoding];
+ theAffectedRowCount = mysql_affected_rows(mySQLConnection);
+ break;
+
+ // For fast streaming and low memory streaming result sets, set up the result
+ case SPMySQLResultAsLowMemStreamingResult:
+ mysqlResult = mysql_use_result(mySQLConnection);
+ theResult = [[SPMySQLStreamingResult alloc] initWithMySQLResult:mysqlResult stringEncoding:theEncoding connection:self];
+ break;
+
+ case SPMySQLResultAsFastStreamingResult:
+ mysqlResult = mysql_use_result(mySQLConnection);
+ theResult = [[SPMySQLFastStreamingResult alloc] initWithMySQLResult:mysqlResult stringEncoding:theEncoding connection:self];
+ break;
+ }
- case SPMySQLResultAsFastStreamingResult:
- mysqlResult = mysql_use_result(mySQLConnection);
- theResult = [[SPMySQLFastStreamingResult alloc] initWithMySQLResult:mysqlResult stringEncoding:theEncoding connection:self];
- break;
+ // Update the error message, if appropriate, to reflect result store errors or overall success
+ theErrorMessage = [self _stringForCString:mysql_error(mySQLConnection)];
+ theErrorID = mysql_errno(mySQLConnection);
+ } else {
+ theResult = [[SPMySQLEmptyResult alloc] init];
}
-
- // Update the error message, if appropriate, to reflect result store errors or overall success
- theErrorMessage = [self _stringForCString:mysql_error(mySQLConnection)];
- theErrorID = mysql_errno(mySQLConnection);
}
// Update the connection's stored insert ID if available
diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLResult.m b/Frameworks/SPMySQLFramework/Source/SPMySQLResult.m
index 3ccd5727..ee758bad 100644
--- a/Frameworks/SPMySQLFramework/Source/SPMySQLResult.m
+++ b/Frameworks/SPMySQLFramework/Source/SPMySQLResult.m
@@ -90,12 +90,27 @@ static id NSNullPointer;
}
/**
- * Prevent SPMySQLResults from being init'd normally.
+ * Standard initialisation - not intended for external use.
*/
- (id)init
{
- [NSException raise:NSInternalInconsistencyException format:@"SPMySQLResults should not be init'd directly; use initWithMySQLResult:stringEncoding: instead."];
- return nil;
+ if ((self = [super init])) {
+ stringEncoding = NSASCIIStringEncoding;
+ queryExecutionTime = -1;
+
+ resultSet = NULL;
+ numberOfFields = 0;
+ numberOfRows = 0;
+ currentRowIndex = 0;
+
+ fieldDefinitions = NULL;
+ fieldNames = NULL;
+ fieldTypes = NULL;
+
+ defaultRowReturnType = SPMySQLResultRowAsDictionary;
+ }
+
+ return self;
}
/**
@@ -108,15 +123,13 @@ static id NSNullPointer;
// If no result set was passed in, return nil.
if (!theResult) return nil;
- if ((self = [super init])) {
+ if ((self = [self init])) {
stringEncoding = theStringEncoding;
- queryExecutionTime = -1;
// Get the result set and cache the number of fields and number of rows
resultSet = theResult;
numberOfFields = mysql_num_fields(resultSet);
numberOfRows = mysql_num_rows(resultSet);
- currentRowIndex = 0;
// Cache the field definitions and build up an array of cached field names and types
fieldDefinitions = mysql_fetch_fields(resultSet);
@@ -127,8 +140,6 @@ static id NSNullPointer;
fieldNames[i] = [[self _stringWithBytes:aField.name length:aField.name_length] retain];
fieldTypes[i] = aField.type;
}
-
- defaultRowReturnType = SPMySQLResultRowAsDictionary;
}
return self;
@@ -136,13 +147,15 @@ static id NSNullPointer;
- (void)dealloc
{
- mysql_free_result(resultSet);
+ if (resultSet) {
+ mysql_free_result(resultSet);
- for (NSUInteger i = 0; i < numberOfFields; i++) {
- [fieldNames[i] release];
+ for (NSUInteger i = 0; i < numberOfFields; i++) {
+ [fieldNames[i] release];
+ }
+ free(fieldNames);
+ free(fieldTypes);
}
- free(fieldNames);
- free(fieldTypes);
[super dealloc];
}