aboutsummaryrefslogtreecommitdiffstats
path: root/Frameworks/SPMySQLFramework/Source/SPMySQLResult.m
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/SPMySQLResult.m
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/SPMySQLResult.m')
-rw-r--r--Frameworks/SPMySQLFramework/Source/SPMySQLResult.m39
1 files changed, 26 insertions, 13 deletions
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];
}