diff options
author | rowanbeentje <rowan@beent.je> | 2012-02-23 02:13:56 +0000 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2012-02-23 02:13:56 +0000 |
commit | 05f1612cbb7e33cf9135a346fc2505cc0e87e853 (patch) | |
tree | 785824be4e44a61389271343d958851fa4ff7dd0 /Frameworks/SPMySQLFramework/Source | |
parent | a889340b9cb1eca0d3ff022e8e6e2c718480bf44 (diff) | |
download | sequelpro-05f1612cbb7e33cf9135a346fc2505cc0e87e853.tar.gz sequelpro-05f1612cbb7e33cf9135a346fc2505cc0e87e853.tar.bz2 sequelpro-05f1612cbb7e33cf9135a346fc2505cc0e87e853.zip |
Warning: this branch commit is largely untested, and known to throw exceptions as database structure retrieval is currently missing!
Further work on SPMySQLFramework integration:
- Improve SPMySQL framework build settings including correct ppc builds and a Distribution configuration for the build distributions to match
- Add new convenience querying and result methods to the framework
- Amend Sequel Pro source to use the new SPMySQL.framework methods everywhere, replacing MCPKit methods where they differ and improving some functions
- Remove MCPKit from the source
- Fix a number of warnings on Release-style builds
Diffstat (limited to 'Frameworks/SPMySQLFramework/Source')
10 files changed, 144 insertions, 6 deletions
diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQL.h b/Frameworks/SPMySQLFramework/Source/SPMySQL.h index a9150f46..3c4c78f8 100644 --- a/Frameworks/SPMySQLFramework/Source/SPMySQL.h +++ b/Frameworks/SPMySQLFramework/Source/SPMySQL.h @@ -57,6 +57,7 @@ #import "SPMySQLStreamingResult.h" #import "SPMySQLFastStreamingResult.h" #import "Field Definitions.h" +#import "Convenience Methods.h" // Result data objects -#import "SPMySQLGeometryData.h"
\ No newline at end of file +#import "SPMySQLGeometryData.h" diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Querying & Preparation.h b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Querying & Preparation.h index ff55f796..9ab8bc6a 100644 --- a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Querying & Preparation.h +++ b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Querying & Preparation.h @@ -45,6 +45,10 @@ - (id)streamingQueryString:(NSString *)theQueryString useLowMemoryBlockingStreaming:(BOOL)fullStreaming; - (id)queryString:(NSString *)theQueryString usingEncoding:(NSStringEncoding)theEncoding withResultType:(SPMySQLResultType)theReturnType; +// Query convenience functions +- (NSArray *)getAllRowsFromQuery:(NSString *)theQueryString; +- (id)getFirstFieldFromQuery:(NSString *)theQueryString; + // Query information - (unsigned long long)rowsAffectedByLastQuery; - (unsigned long long)lastInsertID; @@ -100,4 +104,4 @@ static inline id SPMySQLConnectionQueryString(SPMySQLConnection* self, NSString if (!cachedMethodPointer) cachedMethodPointer = (SPMySQLConnectionQueryStringMethodPtr)[self methodForSelector:cachedSelector]; return cachedMethodPointer(self, cachedSelector, theQueryString, theEncoding, theReturnType); -}
\ No newline at end of file +} diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Querying & Preparation.m b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Querying & Preparation.m index 4134880c..e3ce599a 100644 --- a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Querying & Preparation.m +++ b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Querying & Preparation.m @@ -357,6 +357,27 @@ } #pragma mark - +#pragma mark Query convenience functions + +/** + * Run a query and retrieve the entire result set as an array of dictionaries. + * Returns nil if there was a problem running the query or retrieving any results. + */ +- (NSArray *)getAllRowsFromQuery:(NSString *)theQueryString +{ + return [[self queryString:theQueryString] getAllRows]; +} + +/** + * Run a query and retrieve the first field of any response. Returns nil if there + * was a problem running the query or retrieving any results. + */ +- (id)getFirstFieldFromQuery:(NSString *)theQueryString +{ + return [[[self queryString:theQueryString] getRowAsArray] objectAtIndex:0]; +} + +#pragma mark - #pragma mark Query information /** diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection.h b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection.h index db6dc0af..5d1a5d11 100644 --- a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection.h +++ b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection.h @@ -174,4 +174,4 @@ + (NSString *)findSocketPath; -@end
\ No newline at end of file +@end diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLConnectionDelegate.h b/Frameworks/SPMySQLFramework/Source/SPMySQLConnectionDelegate.h index f1a1f911..97e94170 100644 --- a/Frameworks/SPMySQLFramework/Source/SPMySQLConnectionDelegate.h +++ b/Frameworks/SPMySQLFramework/Source/SPMySQLConnectionDelegate.h @@ -30,6 +30,8 @@ // // More info at <http://code.google.com/p/sequel-pro/> +#import "SPMySQLConstants.h" + @protocol SPMySQLConnectionDelegate <NSObject> @optional diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLConnectionProxy.h b/Frameworks/SPMySQLFramework/Source/SPMySQLConnectionProxy.h index afd7c95a..2da553c6 100644 --- a/Frameworks/SPMySQLFramework/Source/SPMySQLConnectionProxy.h +++ b/Frameworks/SPMySQLFramework/Source/SPMySQLConnectionProxy.h @@ -74,4 +74,4 @@ typedef enum { */ - (BOOL)setConnectionStateChangeSelector:(SEL)theStateChangeSelector delegate:(id)theDelegate; -@end
\ No newline at end of file +@end diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLConstants.h b/Frameworks/SPMySQLFramework/Source/SPMySQLConstants.h index 6fb3d279..b1689569 100644 --- a/Frameworks/SPMySQLFramework/Source/SPMySQLConstants.h +++ b/Frameworks/SPMySQLFramework/Source/SPMySQLConstants.h @@ -73,4 +73,4 @@ typedef enum { SPMySQLResultAsResult = 0, SPMySQLResultAsFastStreamingResult = 1, SPMySQLResultAsLowMemStreamingResult = 2 -} SPMySQLResultType;
\ No newline at end of file +} SPMySQLResultType; diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLResult Categories/Convenience Methods.h b/Frameworks/SPMySQLFramework/Source/SPMySQLResult Categories/Convenience Methods.h new file mode 100644 index 00000000..7d870a93 --- /dev/null +++ b/Frameworks/SPMySQLFramework/Source/SPMySQLResult Categories/Convenience Methods.h @@ -0,0 +1,38 @@ +// +// $Id$ +// +// Convenience Methods.h +// SPMySQLFramework +// +// Created by Rowan Beentje (rowan.beent.je) on February 20, 2012 +// Copyright (c) 2012 Rowan Beentje. All rights reserved. +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +// +// More info at <http://code.google.com/p/sequel-pro/> + + +@interface SPMySQLResult (Convenience_Methods) + +- (NSArray *)getAllRows; + +@end diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLResult Categories/Convenience Methods.m b/Frameworks/SPMySQLFramework/Source/SPMySQLResult Categories/Convenience Methods.m new file mode 100644 index 00000000..7e3619e1 --- /dev/null +++ b/Frameworks/SPMySQLFramework/Source/SPMySQLResult Categories/Convenience Methods.m @@ -0,0 +1,71 @@ +// +// $Id$ +// +// Convenience Methods.h +// SPMySQLFramework +// +// Created by Rowan Beentje (rowan.beent.je) on February 20, 2012 +// Copyright (c) 2012 Rowan Beentje. All rights reserved. +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +// +// More info at <http://code.google.com/p/sequel-pro/> + +#import "Convenience Methods.h" + +@implementation SPMySQLResult (Convenience_Methods) + +/** + * Iterates over the result set, retrieving all the rows, and returns them + * as an array. + * The rows are in the default format for this instance, as controlled via + * -setDefaultRowReturnType:. + * Returns nil if there are no rows to return. + */ +- (NSArray *)getAllRows +{ + unsigned long long previousSeekPosition = currentRowIndex; + + NSMutableArray *rowsToReturn; + + // If the number of rows is known, pre-set the size; otherwise just create an array + if (numberOfRows != NSNotFound) { + rowsToReturn = [[NSMutableArray alloc] initWithCapacity:numberOfRows]; + } else { + rowsToReturn = [[NSMutableArray alloc] init]; + } + + // Loop through the rows in the instance-specified return format + for (id eachRow in self) { + [rowsToReturn addObject:eachRow]; + } + + // Seek to the previous position if appropriate + if (previousSeekPosition) [self seekToRow:previousSeekPosition]; + + // Instead of empty arrays, return nil if there are no rows. + if (![rowsToReturn count]) return nil; + + return rowsToReturn; +} + +@end diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLResult.h b/Frameworks/SPMySQLFramework/Source/SPMySQLResult.h index baddf8aa..29518b5d 100644 --- a/Frameworks/SPMySQLFramework/Source/SPMySQLResult.h +++ b/Frameworks/SPMySQLFramework/Source/SPMySQLResult.h @@ -73,6 +73,7 @@ typedef enum { // Result set information - (NSUInteger)numberOfFields; - (unsigned long long)numberOfRows; +- (double)queryExecutionTime; // Column information - (NSArray *)fieldNames; @@ -117,4 +118,4 @@ static inline id SPMySQLResultGetRow(SPMySQLResult* self, SPMySQLResultRowType r if (!cachedMethodPointer) cachedMethodPointer = (SPMySQLResultGetRowMethodPtr)[self methodForSelector:cachedSelector]; return cachedMethodPointer(self, cachedSelector, rowType); -}
\ No newline at end of file +} |