From 92022eb14512d1e6aa17c6bb956f83d7b3f7e579 Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Sat, 25 Feb 2012 18:38:21 +0000 Subject: Move QueryKit to it's own project. --- Frameworks/QueryKit/QKQuery.h | 110 ---- Frameworks/QueryKit/QKQuery.m | 438 --------------- Frameworks/QueryKit/QKQueryOperators.h | 56 -- Frameworks/QueryKit/QKQueryParameter.h | 70 --- Frameworks/QueryKit/QKQueryParameter.m | 86 --- Frameworks/QueryKit/QKQueryTypes.h | 45 -- Frameworks/QueryKit/QKQueryUtilities.h | 46 -- Frameworks/QueryKit/QKQueryUtilities.m | 96 ---- Frameworks/QueryKit/QueryKit.h | 37 -- .../QueryKit/QueryKit.xcodeproj/project.pbxproj | 593 +++++++++++++++++++++ Frameworks/QueryKit/Resources/Info.plist | 22 + Frameworks/QueryKit/Resources/Tests-Info.plist | 22 + Frameworks/QueryKit/Source/QKQuery.h | 110 ++++ Frameworks/QueryKit/Source/QKQuery.m | 438 +++++++++++++++ Frameworks/QueryKit/Source/QKQueryOperators.h | 56 ++ Frameworks/QueryKit/Source/QKQueryParameter.h | 70 +++ Frameworks/QueryKit/Source/QKQueryParameter.m | 86 +++ Frameworks/QueryKit/Source/QKQueryTypes.h | 45 ++ Frameworks/QueryKit/Source/QKQueryUtilities.h | 46 ++ Frameworks/QueryKit/Source/QKQueryUtilities.m | 96 ++++ Frameworks/QueryKit/Source/QueryKit-Prefix.pch | 3 + Frameworks/QueryKit/Source/QueryKit.h | 37 ++ Frameworks/QueryKit/Tests/QKSelectQueryTests.h | 35 ++ Frameworks/QueryKit/Tests/QKSelectQueryTests.m | 76 +++ 24 files changed, 1735 insertions(+), 984 deletions(-) delete mode 100644 Frameworks/QueryKit/QKQuery.h delete mode 100644 Frameworks/QueryKit/QKQuery.m delete mode 100644 Frameworks/QueryKit/QKQueryOperators.h delete mode 100644 Frameworks/QueryKit/QKQueryParameter.h delete mode 100644 Frameworks/QueryKit/QKQueryParameter.m delete mode 100644 Frameworks/QueryKit/QKQueryTypes.h delete mode 100644 Frameworks/QueryKit/QKQueryUtilities.h delete mode 100644 Frameworks/QueryKit/QKQueryUtilities.m delete mode 100644 Frameworks/QueryKit/QueryKit.h create mode 100644 Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj create mode 100644 Frameworks/QueryKit/Resources/Info.plist create mode 100644 Frameworks/QueryKit/Resources/Tests-Info.plist create mode 100644 Frameworks/QueryKit/Source/QKQuery.h create mode 100644 Frameworks/QueryKit/Source/QKQuery.m create mode 100644 Frameworks/QueryKit/Source/QKQueryOperators.h create mode 100644 Frameworks/QueryKit/Source/QKQueryParameter.h create mode 100644 Frameworks/QueryKit/Source/QKQueryParameter.m create mode 100644 Frameworks/QueryKit/Source/QKQueryTypes.h create mode 100644 Frameworks/QueryKit/Source/QKQueryUtilities.h create mode 100644 Frameworks/QueryKit/Source/QKQueryUtilities.m create mode 100644 Frameworks/QueryKit/Source/QueryKit-Prefix.pch create mode 100644 Frameworks/QueryKit/Source/QueryKit.h create mode 100644 Frameworks/QueryKit/Tests/QKSelectQueryTests.h create mode 100644 Frameworks/QueryKit/Tests/QKSelectQueryTests.m (limited to 'Frameworks/QueryKit') diff --git a/Frameworks/QueryKit/QKQuery.h b/Frameworks/QueryKit/QKQuery.h deleted file mode 100644 index b3670808..00000000 --- a/Frameworks/QueryKit/QKQuery.h +++ /dev/null @@ -1,110 +0,0 @@ -// -// $Id$ -// -// QKQuery.h -// sequel-pro -// -// Created by Stuart Connolly (stuconnolly.com) on September 4, 2011 -// Copyright (c) 2011 Stuart Connolly. 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 - -#import "QKQueryTypes.h" -#import "QKQueryOperators.h" -#import "QKQueryParameter.h" - -/** - * @class QKQuery QKQuery.h - * - * @author Stuart Connolly http://stuconnolly.com/ - * - * Main QueryKit query class. - */ -@interface QKQuery : NSObject -{ - NSString *_database; - NSString *_table; - - NSMutableString *_query; - NSMutableArray *_parameters; - NSMutableArray *_fields; - NSMutableArray *_groupByFields; - NSMutableArray *_orderByFields; - - QKQueryType _queryType; - - BOOL _quoteFields; - BOOL _orderDescending; -} - -/** - * @property _database The database the query is to be run against (optional). - */ -@property (readwrite, retain, getter=database, setter=setDatabase:) NSString *_database; - -/** - * @property _table The table the query is to be run against. - */ -@property (readwrite, retain, getter=table, setter=setTable:) NSString *_table; - -/** - * @property _parameters The parameters (constraints) of the query. - */ -@property (readwrite, retain, getter=parameters, setter=setParameters:) NSMutableArray *_parameters; - -/** - * @property _fields The fields of the query. - */ -@property (readwrite, retain, getter=fields, setter=setFields:) NSMutableArray *_fields; - -/** - * @property _queryType The type of query to be built. - */ -@property (readwrite, assign, getter=queryType, setter=setQueryType:) QKQueryType _queryType; - -/** - * @property _quoteFields Indicates whether or not the query's fields should be quoted. - */ -@property (readwrite, assign, getter=quoteFields, setter=setQuoteFields:) BOOL _quoteFields; - -+ (QKQuery *)queryTable:(NSString *)table; -+ (QKQuery *)selectQueryFromTable:(NSString *)table; - -- (id)initWithTable:(NSString *)table; - -- (NSString *)query; - -- (void)addField:(NSString *)field; -- (void)addFields:(NSArray *)fields; - -- (void)addParameter:(QKQueryParameter *)parameter; -- (void)addParameter:(NSString *)field operator:(QKQueryOperator)operator value:(id)value; - -- (void)groupByField:(NSString *)field; -- (void)groupByFields:(NSArray *)fields; - -- (void)orderByField:(NSString *)field descending:(BOOL)descending; -- (void)orderByFields:(NSArray *)fields descending:(BOOL)descending; - -@end diff --git a/Frameworks/QueryKit/QKQuery.m b/Frameworks/QueryKit/QKQuery.m deleted file mode 100644 index 31755b6d..00000000 --- a/Frameworks/QueryKit/QKQuery.m +++ /dev/null @@ -1,438 +0,0 @@ -// -// $Id$ -// -// QKQuery.h -// sequel-pro -// -// Created by Stuart Connolly (stuconnolly.com) on September 4, 2011 -// Copyright (c) 2011 Stuart Connolly. 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 - -#import "QKQuery.h" - -static NSString *QKNoQueryTypeException = @"QKNoQueryType"; -static NSString *QKNoQueryTableException = @"QKNoQueryTable"; - -@interface QKQuery () - -- (void)_validateRequiements; - -- (NSString *)_buildQuery; -- (NSString *)_buildFieldList; -- (NSString *)_buildConstraints; -- (NSString *)_buildGroupByClause; -- (NSString *)_buildOrderByClause; - -- (BOOL)_addString:(NSString *)string toArray:(NSMutableArray *)array; - -@end - -@implementation QKQuery - -@synthesize _database; -@synthesize _table; -@synthesize _parameters; -@synthesize _queryType; -@synthesize _fields; -@synthesize _quoteFields; - -#pragma mark - -#pragma mark Initialization - -+ (QKQuery *)queryTable:(NSString *)table -{ - return [[[QKQuery alloc] initWithTable:table] autorelease]; -} - -+ (QKQuery *)selectQueryFromTable:(NSString *)table -{ - QKQuery *query = [[[QKQuery alloc] initWithTable:table] autorelease]; - - [query setQueryType:QKSelectQuery]; - - return query; -} - -- (id)initWithTable:(NSString *)table -{ - if ((self = [super init])) { - [self setTable:table]; - [self setFields:[[NSMutableArray alloc] init]]; - [self setParameters:[[NSMutableArray alloc] init]]; - [self setQueryType:-1]; - [self setQuoteFields:NO]; - - _orderDescending = NO; - - _groupByFields = [[NSMutableArray alloc] init]; - _orderByFields = [[NSMutableArray alloc] init]; - - _query = [[NSMutableString alloc] init]; - } - - return self; -} - -#pragma mark - -#pragma mark Public API - -- (NSString *)query -{ - return _query ? [self _buildQuery] : @""; -} - -#pragma mark - -#pragma mark Fields - -/** - * Shortcut for adding a new field to this query. - */ -- (void)addField:(NSString *)field -{ - [self _addString:field toArray:_fields]; -} - -/** - * Convenience method for adding more than one field. - * - * @param The array (of strings) of fields to add. - */ -- (void)addFields:(NSArray *)fields -{ - for (NSString *field in fields) - { - [self addField:field]; - } -} - -#pragma mark - -#pragma mark Parameters - -/** - * Adds the supplied parameter. - * - * @param parameter The parameter to add. - */ -- (void)addParameter:(QKQueryParameter *)parameter -{ - if ([parameter field] && ([[parameter field] length] > 0) && ((NSInteger)[parameter operator] > -1) && [parameter value]) { - [_parameters addObject:parameter]; - } -} - -/** - * Convenience method for adding a new parameter. - */ -- (void)addParameter:(NSString *)field operator:(QKQueryOperator)operator value:(id)value -{ - [self addParameter:[QKQueryParameter queryParamWithField:field operator:operator value:value]]; -} - -#pragma mark - -#pragma mark Grouping - -/** - * Adds the supplied field to the query's GROUP BY clause. - */ -- (void)groupByField:(NSString *)field -{ - [self _addString:field toArray:_groupByFields]; -} - -/** - * Convenience method for adding more than one field to the query's GROUP BY clause. - */ -- (void)groupByFields:(NSArray *)fields -{ - for (NSString *field in fields) - { - [self groupByField:field]; - } -} - -#pragma mark - -#pragma mark Ordering - -/** - * Adds the supplied field to the query's ORDER BY clause. - */ -- (void)orderByField:(NSString *)field descending:(BOOL)descending -{ - _orderDescending = descending; - - [self _addString:field toArray:_orderByFields]; -} - -/** - * Convenience method for adding more than one field to the query's ORDER BY clause. - */ -- (void)orderByFields:(NSArray *)fields descending:(BOOL)descending -{ - for (NSString *field in fields) - { - [self orderByField:field descending:descending]; - } -} - -#pragma mark - -#pragma mark Private API - -/** - * Validates that everything necessary to build the query has been set. - */ -- (void)_validateRequiements -{ - if (_queryType == -1) { - [NSException raise:QKNoQueryTypeException format:@"Attempt to build query with no query type specified."]; - } - - if (!_table || [_table length] == 0) { - [NSException raise:QKNoQueryTableException format:@"Attempt to build query with no query table specified."]; - } -} - -/** - * Builds the actual query. - */ -- (NSString *)_buildQuery -{ - [self _validateRequiements]; - - BOOL isSelect = (_queryType == QKSelectQuery); - BOOL isInsert = (_queryType == QKInsertQuery); - BOOL isUpdate = (_queryType == QKUpdateQuery); - BOOL isDelete = (_queryType == QKDeleteQuery); - - NSString *fields = [self _buildFieldList]; - - if (isSelect) { - [_query appendFormat:@"SELECT %@ FROM ", fields]; - } - else if (isInsert) { - [_query appendString:@"INSERT INTO "]; - } - else if (isUpdate) { - [_query appendString:@"UPDATE "]; - } - else if (isDelete) { - [_query appendString:@"DELETE FROM "]; - } - - if (_database && [_database length] > 0) { - [_query appendFormat:@"%@.", _database]; - } - - [_query appendString:_table]; - - if ([_parameters count] > 0) { - [_query appendString:@" WHERE "]; - [_query appendString:[self _buildConstraints]]; - } - - if (isSelect) { - NSString *groupBy = [self _buildGroupByClause]; - NSString *orderBy = [self _buildOrderByClause]; - - if ([groupBy length] > 0) { - [_query appendFormat:@" %@", groupBy]; - } - - if ([orderBy length] > 0) { - [_query appendFormat:@" %@", orderBy]; - } - } - - return _query; -} - -/** - * Builds the string representation of the query's field list. - */ -- (NSString *)_buildFieldList -{ - NSMutableString *fields = [NSMutableString string]; - - if ([_fields count] == 0) { - [fields appendString:@"*"]; - - return fields; - } - - for (NSString *field in _fields) - { - field = [field stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; - - if ([field length] == 0) continue; - - if (_quoteFields) { - [fields appendString:@"`"]; - } - - [fields appendString:field]; - - if (_quoteFields) { - [fields appendString:@"`"]; - } - - [fields appendString:@", "]; - } - - if ([fields hasSuffix:@", "]) { - [fields setString:[fields substringToIndex:([fields length] - 2)]]; - } - - return fields; -} - -/** - * Builds the string representation of the query's constraints. - */ -- (NSString *)_buildConstraints -{ - NSMutableString *constraints = [NSMutableString string]; - - if ([_parameters count] == 0) return constraints; - - for (QKQueryParameter *param in _parameters) - { - [constraints appendFormat:@"%@ ", param]; - - [constraints appendString:@" AND "]; - } - - if ([constraints hasSuffix:@" AND "]) { - [constraints setString:[constraints substringToIndex:([constraints length] - 5)]]; - } - - return constraints; -} - -/** - * Builds the string representation of the query's GROUP BY clause. - * - * @return The GROUP BY clause - */ -- (NSString *)_buildGroupByClause -{ - NSMutableString *groupBy = [NSMutableString string]; - - if ([_groupByFields count] == 0) return groupBy; - - [groupBy appendString:@"GROUP BY "]; - - for (NSString *field in _groupByFields) - { - [groupBy appendString:field]; - [groupBy appendString:@", "]; - } - - if ([groupBy hasSuffix:@", "]) { - [groupBy setString:[groupBy substringToIndex:([groupBy length] - 2)]]; - } - - return groupBy; -} - -/** - * Builds the string representation of the query's ORDER BY clause. - * - * @return The ORDER BY clause - */ -- (NSString *)_buildOrderByClause -{ - NSMutableString *orderBy = [NSMutableString string]; - - if ([_orderByFields count] == 0) return orderBy; - - [orderBy appendString:@"ORDER BY "]; - - for (NSString *field in _orderByFields) - { - [orderBy appendString:field]; - [orderBy appendString:@", "]; - } - - if ([orderBy hasSuffix:@", "]) { - [orderBy setString:[orderBy substringToIndex:([orderBy length] - 2)]]; - } - - if (_orderDescending) { - [orderBy appendString:@" DESC"]; - } - - return orderBy; -} - -/** - * Adds the supplied string to the supplied array, but only if the length is greater than zero. - * - * @param string The string to add to the array - * @param array The array to add the string to - * - * @return A BOOL indicating whether or not the string was added. - */ -- (BOOL)_addString:(NSString *)string toArray:(NSMutableArray *)array -{ - BOOL result = NO; - - if (!string || !array) return result; - - string = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; - - if ([string length] > 0) { - [array addObject:string]; - - result = YES; - } - - return result; -} - -#pragma mark - - -/** - * Same as calling -query. - */ -- (NSString *)description -{ - return [self query]; -} - -#pragma mark - - -- (void)dealloc -{ - if (_table) [_table release], _table = nil; - if (_database) [_database release], _database = nil; - if (_query) [_query release], _query = nil; - if (_parameters) [_parameters release], _parameters = nil; - if (_fields) [_fields release], _fields = nil; - if (_groupByFields) [_groupByFields release], _groupByFields = nil; - if (_orderByFields) [_orderByFields release], _orderByFields = nil; - - [super dealloc]; -} - -@end diff --git a/Frameworks/QueryKit/QKQueryOperators.h b/Frameworks/QueryKit/QKQueryOperators.h deleted file mode 100644 index 247496fd..00000000 --- a/Frameworks/QueryKit/QKQueryOperators.h +++ /dev/null @@ -1,56 +0,0 @@ -// -// $Id$ -// -// QKQueryOperators.h -// sequel-pro -// -// Created by Stuart Connolly (stuconnolly.com) on September 4, 2011 -// Copyright (c) 2011 Stuart Connolly. 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 - -/** - * @enum QKQueryOperator - * - * Used to specify the operator to use for a specific query parameter. - * - * Note that this is by no means a complete list of available operators, only the most commonly used ones. - * Other operators can be added as and when they are required. - */ -typedef enum -{ - QKEqualityOperator, - QKNotEqualOperator, - QKLikeOperator, - QKNotLikeOperator, - QKInOperator, - QKNotInOperator, - QKIsNullOperator, - QKIsNotNullOperator, - QKGreaterThanOperator, - QKLessThanOperator, - QKGreaterThanOrEqualOperator, - QKLessThanOrEqualOperator -} -QKQueryOperator; diff --git a/Frameworks/QueryKit/QKQueryParameter.h b/Frameworks/QueryKit/QKQueryParameter.h deleted file mode 100644 index 3a24eb8d..00000000 --- a/Frameworks/QueryKit/QKQueryParameter.h +++ /dev/null @@ -1,70 +0,0 @@ -// -// $Id$ -// -// QKQueryParameter.h -// sequel-pro -// -// Created by Stuart Connolly (stuconnolly.com) on September 4, 2011 -// Copyright (c) 2011 Stuart Connolly. 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 - -#import "QKQueryOperators.h" - -/** - * @class QKQueryParameter QKQueryParameter.h - * - * @author Stuart Connolly http://stuconnolly.com/ - * - * QueryKit query parameter class. - */ -@interface QKQueryParameter : NSObject -{ - NSString *_field; - - QKQueryOperator _operator; - - id _value; -} - -/** - * @property _field The field component of the parameter. - */ -@property (readwrite, retain, getter=field, setter=setField:) NSString *_field; - -/** - * @property _operator The operator component of the parameter. - */ -@property (readwrite, assign, getter=operator, setter=setOperator:) QKQueryOperator _operator; - -/** - *@property _value The value component of the parameter. - */ -@property (readwrite, retain, getter=value, setter=setValue:) id _value; - -+ (QKQueryParameter *)queryParamWithField:(NSString *)field operator:(QKQueryOperator)op value:(id)value; - -- (id)initParamWithField:(NSString *)field operator:(QKQueryOperator)op value:(id)value; - -@end diff --git a/Frameworks/QueryKit/QKQueryParameter.m b/Frameworks/QueryKit/QKQueryParameter.m deleted file mode 100644 index bc9efa2f..00000000 --- a/Frameworks/QueryKit/QKQueryParameter.m +++ /dev/null @@ -1,86 +0,0 @@ -// -// $Id$ -// -// QKQueryParameter.m -// sequel-pro -// -// Created by Stuart Connolly (stuconnolly.com) on September 4, 2011 -// Copyright (c) 2011 Stuart Connolly. 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 - -#import "QKQueryParameter.h" -#import "QKQueryUtilities.h" - -@implementation QKQueryParameter - -@synthesize _field; -@synthesize _operator; -@synthesize _value; - -#pragma mark - -#pragma mark Initialisation - -+ (QKQueryParameter *)queryParamWithField:(NSString *)field operator:(QKQueryOperator)op value:(id)value -{ - return [[[QKQueryParameter alloc] initParamWithField:field operator:op value:value] autorelease]; -} - -- (id)initParamWithField:(NSString *)field operator:(QKQueryOperator)op value:(id)value -{ - if ((self = [super init])) { - [self setField:field]; - [self setOperator:op]; - [self setValue:value]; - } - - return self; -} - -#pragma mark - - -- (NSString *)description -{ - NSMutableString *string = [NSMutableString string]; - - NSString *field = [_field stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; - - [string appendString:field]; - [string appendFormat:@" %@ ", [QKQueryUtilities operatorRepresentationForType:_operator]]; - [string appendFormat:(![_value isKindOfClass:[NSNumber class]]) ? @"'%@'" : @"%@", [_value description]]; - - return string; -} - -#pragma mark - - -- (void)dealloc -{ - if (_field) [_field release], _field = nil; - if (_value) [_value release], _value = nil; - - [super dealloc]; -} - -@end diff --git a/Frameworks/QueryKit/QKQueryTypes.h b/Frameworks/QueryKit/QKQueryTypes.h deleted file mode 100644 index 1e9e7403..00000000 --- a/Frameworks/QueryKit/QKQueryTypes.h +++ /dev/null @@ -1,45 +0,0 @@ -// -// $Id$ -// -// QKQueryTypes.h -// sequel-pro -// -// Created by Stuart Connolly (stuconnolly.com) on September 4, 2011 -// Copyright (c) 2011 Stuart Connolly. 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 - -/** - * @enum QKQueryType - * - * Used to specify the type of query to be constructed. - */ -typedef enum -{ - QKSelectQuery, - QKUpdateQuery, - QKInsertQuery, - QKDeleteQuery, -} -QKQueryType; diff --git a/Frameworks/QueryKit/QKQueryUtilities.h b/Frameworks/QueryKit/QKQueryUtilities.h deleted file mode 100644 index 352c5533..00000000 --- a/Frameworks/QueryKit/QKQueryUtilities.h +++ /dev/null @@ -1,46 +0,0 @@ -// -// $Id$ -// -// QKQueryUtilities.h -// sequel-pro -// -// Created by Stuart Connolly (stuconnolly.com) on September 4, 2011 -// Copyright (c) 2011 Stuart Connolly. 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 - -#import "QKQueryOperators.h" - -/** - * @class QKQueryUtilities QKQueryUtilities.h - * - * @author Stuart Connolly http://stuconnolly.com/ - * - * QueryKit utilities class. - */ -@interface QKQueryUtilities : NSObject - -+ (NSString *)operatorRepresentationForType:(QKQueryOperator)operator; - -@end diff --git a/Frameworks/QueryKit/QKQueryUtilities.m b/Frameworks/QueryKit/QKQueryUtilities.m deleted file mode 100644 index 5e4eb4ab..00000000 --- a/Frameworks/QueryKit/QKQueryUtilities.m +++ /dev/null @@ -1,96 +0,0 @@ -// -// $Id$ -// -// QKQueryUtilities.m -// sequel-pro -// -// Created by Stuart Connolly (stuconnolly.com) on September 4, 2011 -// Copyright (c) 2011 Stuart Connolly. 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 - -#import "QKQueryUtilities.h" - -static NSString *QKUnrecognisedQueryOperatorException = @"QKUnrecognisedQueryOperator"; - -@implementation QKQueryUtilities - -/** - * Returns a string representation of the supplied operator type. - * - * @param operator The operator - * - * @return A string represenation of the operator. - */ -+ (NSString *)operatorRepresentationForType:(QKQueryOperator)operator -{ - NSString *opString = nil; - - switch (operator) - { - case QKEqualityOperator: - opString = @"="; - break; - case QKNotEqualOperator: - opString = @"!="; - break; - case QKLikeOperator: - opString = @"LIKE"; - break; - case QKNotLikeOperator: - opString = @"NOT LIKE"; - break; - case QKInOperator: - opString = @"IN"; - break; - case QKNotInOperator: - opString = @"NOT IN"; - break; - case QKIsNullOperator: - opString = @"IS NULL"; - break; - case QKIsNotNullOperator: - opString = @"IS NOT NULL"; - break; - case QKGreaterThanOperator: - opString = @">"; - break; - case QKLessThanOperator: - opString = @"<"; - break; - case QKGreaterThanOrEqualOperator: - opString = @">="; - break; - case QKLessThanOrEqualOperator: - opString = @"<="; - break; - default: - [NSException raise:QKUnrecognisedQueryOperatorException format:@"Unrecognised query operator type: %d", operator]; - break; - } - - return opString; -} - -@end diff --git a/Frameworks/QueryKit/QueryKit.h b/Frameworks/QueryKit/QueryKit.h deleted file mode 100644 index 04c072de..00000000 --- a/Frameworks/QueryKit/QueryKit.h +++ /dev/null @@ -1,37 +0,0 @@ -// -// $Id$ -// -// QueryKit.h -// sequel-pro -// -// Created by Stuart Connolly (stuconnolly.com) on September 4, 2011 -// Copyright (c) 2011 Stuart Connolly. 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 - -#import -#import -#import -#import -#import diff --git a/Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj b/Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj new file mode 100644 index 00000000..cd1fffae --- /dev/null +++ b/Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj @@ -0,0 +1,593 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 45; + objects = { + +/* Begin PBXBuildFile section */ + 17E5951F14F301DF0054EE08 /* QKQuery.h in Headers */ = {isa = PBXBuildFile; fileRef = 17E5951614F301DF0054EE08 /* QKQuery.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 17E5952014F301DF0054EE08 /* QKQuery.m in Sources */ = {isa = PBXBuildFile; fileRef = 17E5951714F301DF0054EE08 /* QKQuery.m */; }; + 17E5952114F301DF0054EE08 /* QKQueryOperators.h in Headers */ = {isa = PBXBuildFile; fileRef = 17E5951814F301DF0054EE08 /* QKQueryOperators.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 17E5952214F301DF0054EE08 /* QKQueryParameter.h in Headers */ = {isa = PBXBuildFile; fileRef = 17E5951914F301DF0054EE08 /* QKQueryParameter.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 17E5952314F301DF0054EE08 /* QKQueryParameter.m in Sources */ = {isa = PBXBuildFile; fileRef = 17E5951A14F301DF0054EE08 /* QKQueryParameter.m */; }; + 17E5952414F301DF0054EE08 /* QKQueryTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 17E5951B14F301DF0054EE08 /* QKQueryTypes.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 17E5952514F301DF0054EE08 /* QKQueryUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 17E5951C14F301DF0054EE08 /* QKQueryUtilities.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 17E5952614F301DF0054EE08 /* QKQueryUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 17E5951D14F301DF0054EE08 /* QKQueryUtilities.m */; }; + 17E5952714F301DF0054EE08 /* QueryKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 17E5951E14F301DF0054EE08 /* QueryKit.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 17E595F214F3058F0054EE08 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 17E595F114F3058F0054EE08 /* Foundation.framework */; }; + 17E596A814F308160054EE08 /* QKSelectQueryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 17E5969814F307B70054EE08 /* QKSelectQueryTests.m */; }; + 17E596A914F308250054EE08 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 17E595F114F3058F0054EE08 /* Foundation.framework */; }; + 17F620BE14F961C1003E7290 /* QueryKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8DC2EF5B0486A6940098B216 /* QueryKit.framework */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 17E596BE14F916B40054EE08 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 0867D690FE84028FC02AAC07 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 8DC2EF4F0486A6940098B216; + remoteInfo = QueryKit; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXFileReference section */ + 17E5951614F301DF0054EE08 /* QKQuery.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QKQuery.h; sourceTree = ""; }; + 17E5951714F301DF0054EE08 /* QKQuery.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QKQuery.m; sourceTree = ""; }; + 17E5951814F301DF0054EE08 /* QKQueryOperators.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QKQueryOperators.h; sourceTree = ""; }; + 17E5951914F301DF0054EE08 /* QKQueryParameter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QKQueryParameter.h; sourceTree = ""; }; + 17E5951A14F301DF0054EE08 /* QKQueryParameter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QKQueryParameter.m; sourceTree = ""; }; + 17E5951B14F301DF0054EE08 /* QKQueryTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QKQueryTypes.h; sourceTree = ""; }; + 17E5951C14F301DF0054EE08 /* QKQueryUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QKQueryUtilities.h; sourceTree = ""; }; + 17E5951D14F301DF0054EE08 /* QKQueryUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QKQueryUtilities.m; sourceTree = ""; }; + 17E5951E14F301DF0054EE08 /* QueryKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QueryKit.h; sourceTree = ""; }; + 17E595F114F3058F0054EE08 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; + 17E5969714F307B70054EE08 /* QKSelectQueryTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QKSelectQueryTests.h; sourceTree = ""; }; + 17E5969814F307B70054EE08 /* QKSelectQueryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QKSelectQueryTests.m; sourceTree = ""; }; + 17E5969E14F307CE0054EE08 /* Tests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Tests.octest; sourceTree = BUILT_PRODUCTS_DIR; }; + 17E5969F14F307CE0054EE08 /* Tests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = "Tests-Info.plist"; path = "Resources/Tests-Info.plist"; sourceTree = ""; }; + 32DBCF5E0370ADEE00C91783 /* QueryKit-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "QueryKit-Prefix.pch"; path = "Source/QueryKit-Prefix.pch"; sourceTree = ""; }; + 8DC2EF5A0486A6940098B216 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = Resources/Info.plist; sourceTree = ""; }; + 8DC2EF5B0486A6940098B216 /* QueryKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = QueryKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 17E5969B14F307CE0054EE08 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 17E596A914F308250054EE08 /* Foundation.framework in Frameworks */, + 17F620BE14F961C1003E7290 /* QueryKit.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 8DC2EF560486A6940098B216 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 17E595F214F3058F0054EE08 /* Foundation.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 034768DFFF38A50411DB9C8B /* Products */ = { + isa = PBXGroup; + children = ( + 8DC2EF5B0486A6940098B216 /* QueryKit.framework */, + 17E5969E14F307CE0054EE08 /* Tests.octest */, + ); + name = Products; + sourceTree = ""; + }; + 0867D691FE84028FC02AAC07 /* QueryKit */ = { + isa = PBXGroup; + children = ( + 32DBCF5E0370ADEE00C91783 /* QueryKit-Prefix.pch */, + 08FB77AEFE84172EC02AAC07 /* Source */, + 17E5969614F3079E0054EE08 /* Tests */, + 089C1665FE841158C02AAC07 /* Resources */, + 0867D69AFE84028FC02AAC07 /* Frameworks */, + 034768DFFF38A50411DB9C8B /* Products */, + ); + name = QueryKit; + sourceTree = ""; + }; + 0867D69AFE84028FC02AAC07 /* Frameworks */ = { + isa = PBXGroup; + children = ( + 17E595F114F3058F0054EE08 /* Foundation.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; + 089C1665FE841158C02AAC07 /* Resources */ = { + isa = PBXGroup; + children = ( + 8DC2EF5A0486A6940098B216 /* Info.plist */, + 17E5969F14F307CE0054EE08 /* Tests-Info.plist */, + ); + name = Resources; + sourceTree = ""; + }; + 08FB77AEFE84172EC02AAC07 /* Source */ = { + isa = PBXGroup; + children = ( + 17E5951E14F301DF0054EE08 /* QueryKit.h */, + 17E5951614F301DF0054EE08 /* QKQuery.h */, + 17E5951714F301DF0054EE08 /* QKQuery.m */, + 17E5951914F301DF0054EE08 /* QKQueryParameter.h */, + 17E5951A14F301DF0054EE08 /* QKQueryParameter.m */, + 17E5951C14F301DF0054EE08 /* QKQueryUtilities.h */, + 17E5951D14F301DF0054EE08 /* QKQueryUtilities.m */, + 17E5952814F301F40054EE08 /* Constants */, + ); + path = Source; + sourceTree = ""; + }; + 17E5952814F301F40054EE08 /* Constants */ = { + isa = PBXGroup; + children = ( + 17E5951B14F301DF0054EE08 /* QKQueryTypes.h */, + 17E5951814F301DF0054EE08 /* QKQueryOperators.h */, + ); + name = Constants; + sourceTree = ""; + }; + 17E5969614F3079E0054EE08 /* Tests */ = { + isa = PBXGroup; + children = ( + 17E5969714F307B70054EE08 /* QKSelectQueryTests.h */, + 17E5969814F307B70054EE08 /* QKSelectQueryTests.m */, + ); + path = Tests; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXHeadersBuildPhase section */ + 8DC2EF500486A6940098B216 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 17E5951F14F301DF0054EE08 /* QKQuery.h in Headers */, + 17E5952114F301DF0054EE08 /* QKQueryOperators.h in Headers */, + 17E5952214F301DF0054EE08 /* QKQueryParameter.h in Headers */, + 17E5952414F301DF0054EE08 /* QKQueryTypes.h in Headers */, + 17E5952514F301DF0054EE08 /* QKQueryUtilities.h in Headers */, + 17E5952714F301DF0054EE08 /* QueryKit.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXHeadersBuildPhase section */ + +/* Begin PBXNativeTarget section */ + 17E5969D14F307CE0054EE08 /* Tests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 17E596A614F307CE0054EE08 /* Build configuration list for PBXNativeTarget "Tests" */; + buildPhases = ( + 17E5969914F307CE0054EE08 /* Resources */, + 17E5969A14F307CE0054EE08 /* Sources */, + 17E5969B14F307CE0054EE08 /* Frameworks */, + 17E5969C14F307CE0054EE08 /* ShellScript */, + ); + buildRules = ( + ); + dependencies = ( + 17E596BF14F916B40054EE08 /* PBXTargetDependency */, + ); + name = Tests; + productName = Tests; + productReference = 17E5969E14F307CE0054EE08 /* Tests.octest */; + productType = "com.apple.product-type.bundle"; + }; + 8DC2EF4F0486A6940098B216 /* QueryKit */ = { + isa = PBXNativeTarget; + buildConfigurationList = 1DEB91AD08733DA50010E9CD /* Build configuration list for PBXNativeTarget "QueryKit" */; + buildPhases = ( + 8DC2EF500486A6940098B216 /* Headers */, + 8DC2EF520486A6940098B216 /* Resources */, + 8DC2EF540486A6940098B216 /* Sources */, + 8DC2EF560486A6940098B216 /* Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = QueryKit; + productInstallPath = "$(HOME)/Library/Frameworks"; + productName = QueryKit; + productReference = 8DC2EF5B0486A6940098B216 /* QueryKit.framework */; + productType = "com.apple.product-type.framework"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 0867D690FE84028FC02AAC07 /* Project object */ = { + isa = PBXProject; + buildConfigurationList = 1DEB91B108733DA50010E9CD /* Build configuration list for PBXProject "QueryKit" */; + compatibilityVersion = "Xcode 3.1"; + developmentRegion = English; + hasScannedForEncodings = 1; + knownRegions = ( + English, + Japanese, + French, + German, + ); + mainGroup = 0867D691FE84028FC02AAC07 /* QueryKit */; + productRefGroup = 034768DFFF38A50411DB9C8B /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 8DC2EF4F0486A6940098B216 /* QueryKit */, + 17E5969D14F307CE0054EE08 /* Tests */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 17E5969914F307CE0054EE08 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 8DC2EF520486A6940098B216 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 17E5969C14F307CE0054EE08 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "# Run the unit tests in this test bundle.\n\"${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests\"\n"; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 17E5969A14F307CE0054EE08 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 17E596A814F308160054EE08 /* QKSelectQueryTests.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 8DC2EF540486A6940098B216 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 17E5952014F301DF0054EE08 /* QKQuery.m in Sources */, + 17E5952314F301DF0054EE08 /* QKQueryParameter.m in Sources */, + 17E5952614F301DF0054EE08 /* QKQueryUtilities.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 17E596BF14F916B40054EE08 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 8DC2EF4F0486A6940098B216 /* QueryKit */; + targetProxy = 17E596BE14F916B40054EE08 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin XCBuildConfiguration section */ + 17E5952D14F302740054EE08 /* Distribution */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "Source/QueryKit-Prefix.pch"; + GCC_VERSION = com.apple.compilers.llvm.clang.1_0; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + INFOPLIST_FILE = Resources/Info.plist; + INFOPLIST_PREFIX_HEADER = ""; + PREBINDING = NO; + SDKROOT = macosx10.6; + VALID_ARCHS = "i386 x86_64"; + }; + name = Distribution; + }; + 17E5952E14F302740054EE08 /* Distribution */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + FRAMEWORK_VERSION = A; + GCC_GENERATE_DEBUGGING_SYMBOLS = NO; + GCC_MODEL_TUNING = G5; + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "Source/QueryKit-Prefix.pch"; + GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO = YES; + GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES; + GCC_WARN_ABOUT_MISSING_NEWLINE = YES; + GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; + GCC_WARN_CHECK_SWITCH_STATEMENTS = YES; + GCC_WARN_FOUR_CHARACTER_CONSTANTS = YES; + GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES; + GCC_WARN_MISSING_PARENTHESES = YES; + GCC_WARN_MULTIPLE_DEFINITION_TYPES_FOR_SELECTOR = YES; + GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES; + GCC_WARN_PROTOTYPE_CONVERSION = YES; + GCC_WARN_SHADOW = YES; + GCC_WARN_SIGN_COMPARE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNKNOWN_PRAGMAS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_LABEL = YES; + GCC_WARN_UNUSED_VALUE = YES; + INFOPLIST_FILE = Resources/Info.plist; + INSTALL_PATH = "$(HOME)/Library/Frameworks"; + PRODUCT_NAME = QueryKit; + WRAPPER_EXTENSION = framework; + }; + name = Distribution; + }; + 17E596A314F307CE0054EE08 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + COPY_PHASE_STRIP = NO; + FRAMEWORK_SEARCH_PATHS = "$(DEVELOPER_LIBRARY_DIR)/Frameworks"; + GCC_DYNAMIC_NO_PIC = NO; + GCC_ENABLE_FIX_AND_CONTINUE = NO; + GCC_ENABLE_OBJC_EXCEPTIONS = YES; + GCC_MODEL_TUNING = G5; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/Cocoa.framework/Headers/Cocoa.h"; + INFOPLIST_FILE = "Resources/Tests-Info.plist"; + INSTALL_PATH = "$(USER_LIBRARY_DIR)/Bundles"; + OTHER_LDFLAGS = ( + "-framework", + Cocoa, + "-framework", + SenTestingKit, + ); + PREBINDING = NO; + PRODUCT_NAME = Tests; + WRAPPER_EXTENSION = octest; + }; + name = Debug; + }; + 17E596A414F307CE0054EE08 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + COPY_PHASE_STRIP = YES; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + FRAMEWORK_SEARCH_PATHS = "$(DEVELOPER_LIBRARY_DIR)/Frameworks"; + GCC_ENABLE_FIX_AND_CONTINUE = NO; + GCC_ENABLE_OBJC_EXCEPTIONS = YES; + GCC_MODEL_TUNING = G5; + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/Cocoa.framework/Headers/Cocoa.h"; + INFOPLIST_FILE = "Resources/Tests-Info.plist"; + INSTALL_PATH = "$(USER_LIBRARY_DIR)/Bundles"; + OTHER_LDFLAGS = ( + "-framework", + Cocoa, + "-framework", + SenTestingKit, + ); + PREBINDING = NO; + PRODUCT_NAME = Tests; + WRAPPER_EXTENSION = octest; + ZERO_LINK = NO; + }; + name = Release; + }; + 17E596A514F307CE0054EE08 /* Distribution */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + FRAMEWORK_SEARCH_PATHS = "$(DEVELOPER_LIBRARY_DIR)/Frameworks"; + GCC_ENABLE_FIX_AND_CONTINUE = NO; + GCC_ENABLE_OBJC_EXCEPTIONS = YES; + GCC_MODEL_TUNING = G5; + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/Cocoa.framework/Headers/Cocoa.h"; + INFOPLIST_FILE = "Resources/Tests-Info.plist"; + INSTALL_PATH = "$(USER_LIBRARY_DIR)/Bundles"; + OTHER_LDFLAGS = ( + "-framework", + Cocoa, + "-framework", + SenTestingKit, + ); + PREBINDING = NO; + PRODUCT_NAME = Tests; + WRAPPER_EXTENSION = octest; + }; + name = Distribution; + }; + 1DEB91AE08733DA50010E9CD /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + COPY_PHASE_STRIP = NO; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + FRAMEWORK_VERSION = A; + GCC_DYNAMIC_NO_PIC = NO; + GCC_ENABLE_FIX_AND_CONTINUE = YES; + GCC_MODEL_TUNING = G5; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "Source/QueryKit-Prefix.pch"; + GCC_SYMBOLS_PRIVATE_EXTERN = YES; + GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO = YES; + GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES; + GCC_WARN_ABOUT_MISSING_NEWLINE = YES; + GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; + GCC_WARN_CHECK_SWITCH_STATEMENTS = YES; + GCC_WARN_FOUR_CHARACTER_CONSTANTS = YES; + GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES; + GCC_WARN_MISSING_PARENTHESES = YES; + GCC_WARN_MULTIPLE_DEFINITION_TYPES_FOR_SELECTOR = YES; + GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES; + GCC_WARN_PROTOTYPE_CONVERSION = YES; + GCC_WARN_SHADOW = YES; + GCC_WARN_SIGN_COMPARE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNKNOWN_PRAGMAS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_LABEL = YES; + GCC_WARN_UNUSED_VALUE = YES; + GENERATE_PKGINFO_FILE = YES; + INFOPLIST_FILE = Resources/Info.plist; + INSTALL_PATH = "$(HOME)/Library/Frameworks"; + PRODUCT_NAME = QueryKit; + WARNING_CFLAGS = "-Wmost"; + WRAPPER_EXTENSION = framework; + }; + name = Debug; + }; + 1DEB91AF08733DA50010E9CD /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ARCHS = ( + i386, + x86_64, + ppc, + ); + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + FRAMEWORK_VERSION = A; + GCC_GENERATE_DEBUGGING_SYMBOLS = NO; + GCC_MODEL_TUNING = G5; + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "Source/QueryKit-Prefix.pch"; + GCC_SYMBOLS_PRIVATE_EXTERN = YES; + GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO = YES; + GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES; + GCC_WARN_ABOUT_MISSING_NEWLINE = YES; + GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; + GCC_WARN_CHECK_SWITCH_STATEMENTS = YES; + GCC_WARN_FOUR_CHARACTER_CONSTANTS = YES; + GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES; + GCC_WARN_MISSING_PARENTHESES = YES; + GCC_WARN_MULTIPLE_DEFINITION_TYPES_FOR_SELECTOR = YES; + GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES; + GCC_WARN_PROTOTYPE_CONVERSION = YES; + GCC_WARN_SHADOW = YES; + GCC_WARN_SIGN_COMPARE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNKNOWN_PRAGMAS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_LABEL = YES; + GCC_WARN_UNUSED_VALUE = YES; + INFOPLIST_FILE = Resources/Info.plist; + INSTALL_PATH = "$(HOME)/Library/Frameworks"; + PRODUCT_NAME = QueryKit; + SDKROOT = macosx10.5; + VALID_ARCHS = "ppc i386 x86_64"; + WRAPPER_EXTENSION = framework; + }; + name = Release; + }; + 1DEB91B208733DA50010E9CD /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "Source/QueryKit-Prefix.pch"; + GCC_VERSION = com.apple.compilers.llvm.clang.1_0; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + INFOPLIST_FILE = Resources/Info.plist; + INFOPLIST_PREFIX_HEADER = ""; + ONLY_ACTIVE_ARCH = YES; + PREBINDING = NO; + SDKROOT = macosx10.6; + VALID_ARCHS = "i386 x86_64"; + }; + name = Debug; + }; + 1DEB91B308733DA50010E9CD /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "Source/QueryKit-Prefix.pch"; + GCC_VERSION = com.apple.compilers.llvm.clang.1_0; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + INFOPLIST_FILE = Resources/Info.plist; + INFOPLIST_PREFIX_HEADER = ""; + PREBINDING = NO; + SDKROOT = macosx10.6; + VALID_ARCHS = "i386 x86_64"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 17E596A614F307CE0054EE08 /* Build configuration list for PBXNativeTarget "Tests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 17E596A314F307CE0054EE08 /* Debug */, + 17E596A414F307CE0054EE08 /* Release */, + 17E596A514F307CE0054EE08 /* Distribution */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 1DEB91AD08733DA50010E9CD /* Build configuration list for PBXNativeTarget "QueryKit" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 1DEB91AE08733DA50010E9CD /* Debug */, + 1DEB91AF08733DA50010E9CD /* Release */, + 17E5952E14F302740054EE08 /* Distribution */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 1DEB91B108733DA50010E9CD /* Build configuration list for PBXProject "QueryKit" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 1DEB91B208733DA50010E9CD /* Debug */, + 1DEB91B308733DA50010E9CD /* Release */, + 17E5952D14F302740054EE08 /* Distribution */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 0867D690FE84028FC02AAC07 /* Project object */; +} diff --git a/Frameworks/QueryKit/Resources/Info.plist b/Frameworks/QueryKit/Resources/Info.plist new file mode 100644 index 00000000..b76ed0eb --- /dev/null +++ b/Frameworks/QueryKit/Resources/Info.plist @@ -0,0 +1,22 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + QueryKit + CFBundleIdentifier + com.google.code.sequel-pro.querykit + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + + diff --git a/Frameworks/QueryKit/Resources/Tests-Info.plist b/Frameworks/QueryKit/Resources/Tests-Info.plist new file mode 100644 index 00000000..607c2ef5 --- /dev/null +++ b/Frameworks/QueryKit/Resources/Tests-Info.plist @@ -0,0 +1,22 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + Tests + CFBundleIdentifier + com.google.code.sequel-pro.querykit.tests + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + + diff --git a/Frameworks/QueryKit/Source/QKQuery.h b/Frameworks/QueryKit/Source/QKQuery.h new file mode 100644 index 00000000..b45dc556 --- /dev/null +++ b/Frameworks/QueryKit/Source/QKQuery.h @@ -0,0 +1,110 @@ +// +// $Id: QKQuery.h 3421 2011-09-10 22:58:45Z stuart02 $ +// +// QKQuery.h +// sequel-pro +// +// Created by Stuart Connolly (stuconnolly.com) on September 4, 2011 +// Copyright (c) 2011 Stuart Connolly. 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 + +#import "QKQueryTypes.h" +#import "QKQueryOperators.h" +#import "QKQueryParameter.h" + +/** + * @class QKQuery QKQuery.h + * + * @author Stuart Connolly http://stuconnolly.com/ + * + * Main QueryKit query class. + */ +@interface QKQuery : NSObject +{ + NSString *_database; + NSString *_table; + + NSMutableString *_query; + NSMutableArray *_parameters; + NSMutableArray *_fields; + NSMutableArray *_groupByFields; + NSMutableArray *_orderByFields; + + QKQueryType _queryType; + + BOOL _quoteFields; + BOOL _orderDescending; +} + +/** + * @property _database The database the query is to be run against (optional). + */ +@property (readwrite, retain, getter=database, setter=setDatabase:) NSString *_database; + +/** + * @property _table The table the query is to be run against. + */ +@property (readwrite, retain, getter=table, setter=setTable:) NSString *_table; + +/** + * @property _parameters The parameters (constraints) of the query. + */ +@property (readwrite, retain, getter=parameters, setter=setParameters:) NSMutableArray *_parameters; + +/** + * @property _fields The fields of the query. + */ +@property (readwrite, retain, getter=fields, setter=setFields:) NSMutableArray *_fields; + +/** + * @property _queryType The type of query to be built. + */ +@property (readwrite, assign, getter=queryType, setter=setQueryType:) QKQueryType _queryType; + +/** + * @property _quoteFields Indicates whether or not the query's fields should be quoted. + */ +@property (readwrite, assign, getter=quoteFields, setter=setQuoteFields:) BOOL _quoteFields; + ++ (QKQuery *)queryTable:(NSString *)table; ++ (QKQuery *)selectQueryFromTable:(NSString *)table; + +- (id)initWithTable:(NSString *)table; + +- (NSString *)query; + +- (void)addField:(NSString *)field; +- (void)addFields:(NSArray *)fields; + +- (void)addParameter:(QKQueryParameter *)parameter; +- (void)addParameter:(NSString *)field operator:(QKQueryOperator)operator value:(id)value; + +- (void)groupByField:(NSString *)field; +- (void)groupByFields:(NSArray *)fields; + +- (void)orderByField:(NSString *)field descending:(BOOL)descending; +- (void)orderByFields:(NSArray *)fields descending:(BOOL)descending; + +@end diff --git a/Frameworks/QueryKit/Source/QKQuery.m b/Frameworks/QueryKit/Source/QKQuery.m new file mode 100644 index 00000000..ded198ba --- /dev/null +++ b/Frameworks/QueryKit/Source/QKQuery.m @@ -0,0 +1,438 @@ +// +// $Id: QKQuery.m 3432 2011-09-27 00:21:35Z stuart02 $ +// +// QKQuery.h +// sequel-pro +// +// Created by Stuart Connolly (stuconnolly.com) on September 4, 2011 +// Copyright (c) 2011 Stuart Connolly. 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 + +#import "QKQuery.h" + +static NSString *QKNoQueryTypeException = @"QKNoQueryType"; +static NSString *QKNoQueryTableException = @"QKNoQueryTable"; + +@interface QKQuery () + +- (void)_validateRequiements; + +- (NSString *)_buildQuery; +- (NSString *)_buildFieldList; +- (NSString *)_buildConstraints; +- (NSString *)_buildGroupByClause; +- (NSString *)_buildOrderByClause; + +- (BOOL)_addString:(NSString *)string toArray:(NSMutableArray *)array; + +@end + +@implementation QKQuery + +@synthesize _database; +@synthesize _table; +@synthesize _parameters; +@synthesize _queryType; +@synthesize _fields; +@synthesize _quoteFields; + +#pragma mark - +#pragma mark Initialization + ++ (QKQuery *)queryTable:(NSString *)table +{ + return [[[QKQuery alloc] initWithTable:table] autorelease]; +} + ++ (QKQuery *)selectQueryFromTable:(NSString *)table +{ + QKQuery *query = [[[QKQuery alloc] initWithTable:table] autorelease]; + + [query setQueryType:QKSelectQuery]; + + return query; +} + +- (id)initWithTable:(NSString *)table +{ + if ((self = [super init])) { + [self setTable:table]; + [self setFields:[[NSMutableArray alloc] init]]; + [self setParameters:[[NSMutableArray alloc] init]]; + [self setQueryType:(QKQueryType)-1]; + [self setQuoteFields:NO]; + + _orderDescending = NO; + + _groupByFields = [[NSMutableArray alloc] init]; + _orderByFields = [[NSMutableArray alloc] init]; + + _query = [[NSMutableString alloc] init]; + } + + return self; +} + +#pragma mark - +#pragma mark Public API + +- (NSString *)query +{ + return _query ? [self _buildQuery] : @""; +} + +#pragma mark - +#pragma mark Fields + +/** + * Shortcut for adding a new field to this query. + */ +- (void)addField:(NSString *)field +{ + [self _addString:field toArray:_fields]; +} + +/** + * Convenience method for adding more than one field. + * + * @param The array (of strings) of fields to add. + */ +- (void)addFields:(NSArray *)fields +{ + for (NSString *field in fields) + { + [self addField:field]; + } +} + +#pragma mark - +#pragma mark Parameters + +/** + * Adds the supplied parameter. + * + * @param parameter The parameter to add. + */ +- (void)addParameter:(QKQueryParameter *)parameter +{ + if ([parameter field] && ([[parameter field] length] > 0) && ((NSInteger)[parameter operator] > -1) && [parameter value]) { + [_parameters addObject:parameter]; + } +} + +/** + * Convenience method for adding a new parameter. + */ +- (void)addParameter:(NSString *)field operator:(QKQueryOperator)operator value:(id)value +{ + [self addParameter:[QKQueryParameter queryParamWithField:field operator:operator value:value]]; +} + +#pragma mark - +#pragma mark Grouping + +/** + * Adds the supplied field to the query's GROUP BY clause. + */ +- (void)groupByField:(NSString *)field +{ + [self _addString:field toArray:_groupByFields]; +} + +/** + * Convenience method for adding more than one field to the query's GROUP BY clause. + */ +- (void)groupByFields:(NSArray *)fields +{ + for (NSString *field in fields) + { + [self groupByField:field]; + } +} + +#pragma mark - +#pragma mark Ordering + +/** + * Adds the supplied field to the query's ORDER BY clause. + */ +- (void)orderByField:(NSString *)field descending:(BOOL)descending +{ + _orderDescending = descending; + + [self _addString:field toArray:_orderByFields]; +} + +/** + * Convenience method for adding more than one field to the query's ORDER BY clause. + */ +- (void)orderByFields:(NSArray *)fields descending:(BOOL)descending +{ + for (NSString *field in fields) + { + [self orderByField:field descending:descending]; + } +} + +#pragma mark - +#pragma mark Private API + +/** + * Validates that everything necessary to build the query has been set. + */ +- (void)_validateRequiements +{ + if (_queryType == -1) { + [NSException raise:QKNoQueryTypeException format:@"Attempt to build query with no query type specified."]; + } + + if (!_table || [_table length] == 0) { + [NSException raise:QKNoQueryTableException format:@"Attempt to build query with no query table specified."]; + } +} + +/** + * Builds the actual query. + */ +- (NSString *)_buildQuery +{ + [self _validateRequiements]; + + BOOL isSelect = (_queryType == QKSelectQuery); + BOOL isInsert = (_queryType == QKInsertQuery); + BOOL isUpdate = (_queryType == QKUpdateQuery); + BOOL isDelete = (_queryType == QKDeleteQuery); + + NSString *fields = [self _buildFieldList]; + + if (isSelect) { + [_query appendFormat:@"SELECT %@ FROM ", fields]; + } + else if (isInsert) { + [_query appendString:@"INSERT INTO "]; + } + else if (isUpdate) { + [_query appendString:@"UPDATE "]; + } + else if (isDelete) { + [_query appendString:@"DELETE FROM "]; + } + + if (_database && [_database length] > 0) { + [_query appendFormat:@"%@.", _database]; + } + + [_query appendString:_table]; + + if ([_parameters count] > 0) { + [_query appendString:@" WHERE "]; + [_query appendString:[self _buildConstraints]]; + } + + if (isSelect) { + NSString *groupBy = [self _buildGroupByClause]; + NSString *orderBy = [self _buildOrderByClause]; + + if ([groupBy length] > 0) { + [_query appendFormat:@" %@", groupBy]; + } + + if ([orderBy length] > 0) { + [_query appendFormat:@" %@", orderBy]; + } + } + + return _query; +} + +/** + * Builds the string representation of the query's field list. + */ +- (NSString *)_buildFieldList +{ + NSMutableString *fields = [NSMutableString string]; + + if ([_fields count] == 0) { + [fields appendString:@"*"]; + + return fields; + } + + for (NSString *field in _fields) + { + field = [field stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + + if ([field length] == 0) continue; + + if (_quoteFields) { + [fields appendString:@"`"]; + } + + [fields appendString:field]; + + if (_quoteFields) { + [fields appendString:@"`"]; + } + + [fields appendString:@", "]; + } + + if ([fields hasSuffix:@", "]) { + [fields setString:[fields substringToIndex:([fields length] - 2)]]; + } + + return fields; +} + +/** + * Builds the string representation of the query's constraints. + */ +- (NSString *)_buildConstraints +{ + NSMutableString *constraints = [NSMutableString string]; + + if ([_parameters count] == 0) return constraints; + + for (QKQueryParameter *param in _parameters) + { + [constraints appendFormat:@"%@ ", param]; + + [constraints appendString:@" AND "]; + } + + if ([constraints hasSuffix:@" AND "]) { + [constraints setString:[constraints substringToIndex:([constraints length] - 5)]]; + } + + return constraints; +} + +/** + * Builds the string representation of the query's GROUP BY clause. + * + * @return The GROUP BY clause + */ +- (NSString *)_buildGroupByClause +{ + NSMutableString *groupBy = [NSMutableString string]; + + if ([_groupByFields count] == 0) return groupBy; + + [groupBy appendString:@"GROUP BY "]; + + for (NSString *field in _groupByFields) + { + [groupBy appendString:field]; + [groupBy appendString:@", "]; + } + + if ([groupBy hasSuffix:@", "]) { + [groupBy setString:[groupBy substringToIndex:([groupBy length] - 2)]]; + } + + return groupBy; +} + +/** + * Builds the string representation of the query's ORDER BY clause. + * + * @return The ORDER BY clause + */ +- (NSString *)_buildOrderByClause +{ + NSMutableString *orderBy = [NSMutableString string]; + + if ([_orderByFields count] == 0) return orderBy; + + [orderBy appendString:@"ORDER BY "]; + + for (NSString *field in _orderByFields) + { + [orderBy appendString:field]; + [orderBy appendString:@", "]; + } + + if ([orderBy hasSuffix:@", "]) { + [orderBy setString:[orderBy substringToIndex:([orderBy length] - 2)]]; + } + + if (_orderDescending) { + [orderBy appendString:@" DESC"]; + } + + return orderBy; +} + +/** + * Adds the supplied string to the supplied array, but only if the length is greater than zero. + * + * @param string The string to add to the array + * @param array The array to add the string to + * + * @return A BOOL indicating whether or not the string was added. + */ +- (BOOL)_addString:(NSString *)string toArray:(NSMutableArray *)array +{ + BOOL result = NO; + + if (!string || !array) return result; + + string = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + + if ([string length] > 0) { + [array addObject:string]; + + result = YES; + } + + return result; +} + +#pragma mark - + +/** + * Same as calling -query. + */ +- (NSString *)description +{ + return [self query]; +} + +#pragma mark - + +- (void)dealloc +{ + if (_table) [_table release], _table = nil; + if (_database) [_database release], _database = nil; + if (_query) [_query release], _query = nil; + if (_parameters) [_parameters release], _parameters = nil; + if (_fields) [_fields release], _fields = nil; + if (_groupByFields) [_groupByFields release], _groupByFields = nil; + if (_orderByFields) [_orderByFields release], _orderByFields = nil; + + [super dealloc]; +} + +@end diff --git a/Frameworks/QueryKit/Source/QKQueryOperators.h b/Frameworks/QueryKit/Source/QKQueryOperators.h new file mode 100644 index 00000000..32e64563 --- /dev/null +++ b/Frameworks/QueryKit/Source/QKQueryOperators.h @@ -0,0 +1,56 @@ +// +// $Id: QKQueryOperators.h 3423 2011-09-12 16:50:15Z stuart02 $ +// +// QKQueryOperators.h +// sequel-pro +// +// Created by Stuart Connolly (stuconnolly.com) on September 4, 2011 +// Copyright (c) 2011 Stuart Connolly. 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 + +/** + * @enum QKQueryOperator + * + * Used to specify the operator to use for a specific query parameter. + * + * Note that this is by no means a complete list of available operators, only the most commonly used ones. + * Other operators can be added as and when they are required. + */ +typedef enum +{ + QKEqualityOperator, + QKNotEqualOperator, + QKLikeOperator, + QKNotLikeOperator, + QKInOperator, + QKNotInOperator, + QKIsNullOperator, + QKIsNotNullOperator, + QKGreaterThanOperator, + QKLessThanOperator, + QKGreaterThanOrEqualOperator, + QKLessThanOrEqualOperator +} +QKQueryOperator; diff --git a/Frameworks/QueryKit/Source/QKQueryParameter.h b/Frameworks/QueryKit/Source/QKQueryParameter.h new file mode 100644 index 00000000..78c5739f --- /dev/null +++ b/Frameworks/QueryKit/Source/QKQueryParameter.h @@ -0,0 +1,70 @@ +// +// $Id: QKQueryParameter.h 3421 2011-09-10 22:58:45Z stuart02 $ +// +// QKQueryParameter.h +// sequel-pro +// +// Created by Stuart Connolly (stuconnolly.com) on September 4, 2011 +// Copyright (c) 2011 Stuart Connolly. 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 + +#import "QKQueryOperators.h" + +/** + * @class QKQueryParameter QKQueryParameter.h + * + * @author Stuart Connolly http://stuconnolly.com/ + * + * QueryKit query parameter class. + */ +@interface QKQueryParameter : NSObject +{ + NSString *_field; + + QKQueryOperator _operator; + + id _value; +} + +/** + * @property _field The field component of the parameter. + */ +@property (readwrite, retain, getter=field, setter=setField:) NSString *_field; + +/** + * @property _operator The operator component of the parameter. + */ +@property (readwrite, assign, getter=operator, setter=setOperator:) QKQueryOperator _operator; + +/** + *@property _value The value component of the parameter. + */ +@property (readwrite, retain, getter=value, setter=setValue:) id _value; + ++ (QKQueryParameter *)queryParamWithField:(NSString *)field operator:(QKQueryOperator)op value:(id)value; + +- (id)initParamWithField:(NSString *)field operator:(QKQueryOperator)op value:(id)value; + +@end diff --git a/Frameworks/QueryKit/Source/QKQueryParameter.m b/Frameworks/QueryKit/Source/QKQueryParameter.m new file mode 100644 index 00000000..7f6064e6 --- /dev/null +++ b/Frameworks/QueryKit/Source/QKQueryParameter.m @@ -0,0 +1,86 @@ +// +// $Id: QKQueryParameter.m 3432 2011-09-27 00:21:35Z stuart02 $ +// +// QKQueryParameter.m +// sequel-pro +// +// Created by Stuart Connolly (stuconnolly.com) on September 4, 2011 +// Copyright (c) 2011 Stuart Connolly. 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 + +#import "QKQueryParameter.h" +#import "QKQueryUtilities.h" + +@implementation QKQueryParameter + +@synthesize _field; +@synthesize _operator; +@synthesize _value; + +#pragma mark - +#pragma mark Initialisation + ++ (QKQueryParameter *)queryParamWithField:(NSString *)field operator:(QKQueryOperator)op value:(id)value +{ + return [[[QKQueryParameter alloc] initParamWithField:field operator:op value:value] autorelease]; +} + +- (id)initParamWithField:(NSString *)field operator:(QKQueryOperator)op value:(id)value +{ + if ((self = [super init])) { + [self setField:field]; + [self setOperator:op]; + [self setValue:value]; + } + + return self; +} + +#pragma mark - + +- (NSString *)description +{ + NSMutableString *string = [NSMutableString string]; + + NSString *field = [_field stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + + [string appendString:field]; + [string appendFormat:@" %@ ", [QKQueryUtilities operatorRepresentationForType:_operator]]; + [string appendFormat:(![_value isKindOfClass:[NSNumber class]]) ? @"'%@'" : @"%@", [_value description]]; + + return string; +} + +#pragma mark - + +- (void)dealloc +{ + if (_field) [_field release], _field = nil; + if (_value) [_value release], _value = nil; + + [super dealloc]; +} + +@end diff --git a/Frameworks/QueryKit/Source/QKQueryTypes.h b/Frameworks/QueryKit/Source/QKQueryTypes.h new file mode 100644 index 00000000..4ab338ec --- /dev/null +++ b/Frameworks/QueryKit/Source/QKQueryTypes.h @@ -0,0 +1,45 @@ +// +// $Id: QKQueryTypes.h 3423 2011-09-12 16:50:15Z stuart02 $ +// +// QKQueryTypes.h +// sequel-pro +// +// Created by Stuart Connolly (stuconnolly.com) on September 4, 2011 +// Copyright (c) 2011 Stuart Connolly. 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 + +/** + * @enum QKQueryType + * + * Used to specify the type of query to be constructed. + */ +typedef enum +{ + QKSelectQuery, + QKUpdateQuery, + QKInsertQuery, + QKDeleteQuery, +} +QKQueryType; diff --git a/Frameworks/QueryKit/Source/QKQueryUtilities.h b/Frameworks/QueryKit/Source/QKQueryUtilities.h new file mode 100644 index 00000000..9049b191 --- /dev/null +++ b/Frameworks/QueryKit/Source/QKQueryUtilities.h @@ -0,0 +1,46 @@ +// +// $Id: QKQueryUtilities.h 3421 2011-09-10 22:58:45Z stuart02 $ +// +// QKQueryUtilities.h +// sequel-pro +// +// Created by Stuart Connolly (stuconnolly.com) on September 4, 2011 +// Copyright (c) 2011 Stuart Connolly. 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 + +#import "QKQueryOperators.h" + +/** + * @class QKQueryUtilities QKQueryUtilities.h + * + * @author Stuart Connolly http://stuconnolly.com/ + * + * QueryKit utilities class. + */ +@interface QKQueryUtilities : NSObject + ++ (NSString *)operatorRepresentationForType:(QKQueryOperator)operator; + +@end diff --git a/Frameworks/QueryKit/Source/QKQueryUtilities.m b/Frameworks/QueryKit/Source/QKQueryUtilities.m new file mode 100644 index 00000000..dde1bd77 --- /dev/null +++ b/Frameworks/QueryKit/Source/QKQueryUtilities.m @@ -0,0 +1,96 @@ +// +// $Id: QKQueryUtilities.m 3421 2011-09-10 22:58:45Z stuart02 $ +// +// QKQueryUtilities.m +// sequel-pro +// +// Created by Stuart Connolly (stuconnolly.com) on September 4, 2011 +// Copyright (c) 2011 Stuart Connolly. 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 + +#import "QKQueryUtilities.h" + +static NSString *QKUnrecognisedQueryOperatorException = @"QKUnrecognisedQueryOperator"; + +@implementation QKQueryUtilities + +/** + * Returns a string representation of the supplied operator type. + * + * @param operator The operator + * + * @return A string represenation of the operator. + */ ++ (NSString *)operatorRepresentationForType:(QKQueryOperator)operator +{ + NSString *opString = nil; + + switch (operator) + { + case QKEqualityOperator: + opString = @"="; + break; + case QKNotEqualOperator: + opString = @"!="; + break; + case QKLikeOperator: + opString = @"LIKE"; + break; + case QKNotLikeOperator: + opString = @"NOT LIKE"; + break; + case QKInOperator: + opString = @"IN"; + break; + case QKNotInOperator: + opString = @"NOT IN"; + break; + case QKIsNullOperator: + opString = @"IS NULL"; + break; + case QKIsNotNullOperator: + opString = @"IS NOT NULL"; + break; + case QKGreaterThanOperator: + opString = @">"; + break; + case QKLessThanOperator: + opString = @"<"; + break; + case QKGreaterThanOrEqualOperator: + opString = @">="; + break; + case QKLessThanOrEqualOperator: + opString = @"<="; + break; + default: + [NSException raise:QKUnrecognisedQueryOperatorException format:@"Unrecognised query operator type: %d", operator]; + break; + } + + return opString; +} + +@end diff --git a/Frameworks/QueryKit/Source/QueryKit-Prefix.pch b/Frameworks/QueryKit/Source/QueryKit-Prefix.pch new file mode 100644 index 00000000..60070a9c --- /dev/null +++ b/Frameworks/QueryKit/Source/QueryKit-Prefix.pch @@ -0,0 +1,3 @@ +#ifdef __OBJC__ + #import +#endif diff --git a/Frameworks/QueryKit/Source/QueryKit.h b/Frameworks/QueryKit/Source/QueryKit.h new file mode 100644 index 00000000..f8570025 --- /dev/null +++ b/Frameworks/QueryKit/Source/QueryKit.h @@ -0,0 +1,37 @@ +// +// $Id: QueryKit.h 3431 2011-09-26 22:26:24Z stuart02 $ +// +// QueryKit.h +// sequel-pro +// +// Created by Stuart Connolly (stuconnolly.com) on September 4, 2011 +// Copyright (c) 2011 Stuart Connolly. 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 + +#import +#import +#import +#import +#import diff --git a/Frameworks/QueryKit/Tests/QKSelectQueryTests.h b/Frameworks/QueryKit/Tests/QKSelectQueryTests.h new file mode 100644 index 00000000..e8b3c3b7 --- /dev/null +++ b/Frameworks/QueryKit/Tests/QKSelectQueryTests.h @@ -0,0 +1,35 @@ +// +// $Id: QKSelectQueryTests.h 3431 2011-09-26 22:26:24Z stuart02 $ +// +// QKSelectQueryTests.h +// sequel-pro +// +// Created by Stuart Connolly (stuconnolly.com) on September 4, 2011 +// Copyright (c) 2011 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 + +#import + +#import + +@interface QKSelectQueryTests : SenTestCase +{ + QKQuery *_query; +} + +@end diff --git a/Frameworks/QueryKit/Tests/QKSelectQueryTests.m b/Frameworks/QueryKit/Tests/QKSelectQueryTests.m new file mode 100644 index 00000000..fdce3ca8 --- /dev/null +++ b/Frameworks/QueryKit/Tests/QKSelectQueryTests.m @@ -0,0 +1,76 @@ +// +// $Id: QKSelectQueryTests.m 3432 2011-09-27 00:21:35Z stuart02 $ +// +// QKSelectQueryTests.m +// sequel-pro +// +// Created by Stuart Connolly (stuconnolly.com) on September 4, 2011 +// Copyright (c) 2011 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 + +#import "QKSelectQueryTests.h" + +static NSString *QKTestTableName = @"test_table"; + +static NSString *QKTestFieldOne = @"test_field1"; +static NSString *QKTestFieldTwo = @"test_field2"; +static NSString *QKTestFieldThree = @"test_field3"; +static NSString *QKTestFieldFour = @"test_field4"; + +static NSUInteger QKTestParameterOne = 10; + +@implementation QKSelectQueryTests + +#pragma mark - +#pragma mark Setup & tear down + +- (void)setUp +{ + _query = [QKQuery selectQueryFromTable:QKTestTableName]; + + [_query addField:QKTestFieldOne]; + [_query addField:QKTestFieldTwo]; + [_query addField:QKTestFieldThree]; + [_query addField:QKTestFieldFour]; + + [_query addParameter:QKTestFieldOne operator:QKEqualityOperator value:[NSNumber numberWithUnsignedInteger:QKTestParameterOne]]; +} + +#pragma mark - +#pragma mark Tests + +- (void)testSelectQueryTypeIsCorrect +{ + STAssertTrue([[_query query] hasPrefix:@"SELECT"], @"query type"); +} + +- (void)testSelectQueryFieldsAreCorrect +{ + NSString *query = [NSString stringWithFormat:@"SELECT %@, %@, %@, %@", QKTestFieldOne, QKTestFieldTwo, QKTestFieldThree, QKTestFieldFour]; + + STAssertTrue([[_query query] hasPrefix:query], @"query fields"); +} + +- (void)testSelectQueryConstraintsAreCorrect +{ + NSString *query = [NSString stringWithFormat:@"WHERE %@ %@ %@", QKTestFieldOne, [QKQueryUtilities operatorRepresentationForType:QKEqualityOperator], [NSNumber numberWithUnsignedInteger:QKTestParameterOne]]; + + STAssertTrue(([[_query query] rangeOfString:query].location != NSNotFound), @"query constraints"); +} + +@end -- cgit v1.2.3 From 9e3d5b84e2c6a2159a534bbe9644be70b70937c9 Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Sat, 25 Feb 2012 20:03:44 +0000 Subject: Add some more QueryKit tests. --- .../QueryKit/QueryKit.xcodeproj/project.pbxproj | 12 ++++ Frameworks/QueryKit/Source/QKQuery.m | 4 +- .../QueryKit/Tests/QKSelectQueryGroupByTests.h | 41 +++++++++++ .../QueryKit/Tests/QKSelectQueryGroupByTests.m | 80 ++++++++++++++++++++++ .../QueryKit/Tests/QKSelectQueryOrderByTests.h | 41 +++++++++++ .../QueryKit/Tests/QKSelectQueryOrderByTests.m | 79 +++++++++++++++++++++ Frameworks/QueryKit/Tests/QKSelectQueryTests.h | 32 +++++---- Frameworks/QueryKit/Tests/QKSelectQueryTests.m | 31 +++++---- 8 files changed, 292 insertions(+), 28 deletions(-) create mode 100644 Frameworks/QueryKit/Tests/QKSelectQueryGroupByTests.h create mode 100644 Frameworks/QueryKit/Tests/QKSelectQueryGroupByTests.m create mode 100644 Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.h create mode 100644 Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.m (limited to 'Frameworks/QueryKit') diff --git a/Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj b/Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj index cd1fffae..6d52f5f0 100644 --- a/Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj +++ b/Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 1713ECB014F96A5C0013C4F0 /* QKSelectQueryOrderByTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 1713ECAF14F96A5C0013C4F0 /* QKSelectQueryOrderByTests.m */; }; + 1713ECD814F970BB0013C4F0 /* QKSelectQueryGroupByTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 1713ECD714F970BB0013C4F0 /* QKSelectQueryGroupByTests.m */; }; 17E5951F14F301DF0054EE08 /* QKQuery.h in Headers */ = {isa = PBXBuildFile; fileRef = 17E5951614F301DF0054EE08 /* QKQuery.h */; settings = {ATTRIBUTES = (Public, ); }; }; 17E5952014F301DF0054EE08 /* QKQuery.m in Sources */ = {isa = PBXBuildFile; fileRef = 17E5951714F301DF0054EE08 /* QKQuery.m */; }; 17E5952114F301DF0054EE08 /* QKQueryOperators.h in Headers */ = {isa = PBXBuildFile; fileRef = 17E5951814F301DF0054EE08 /* QKQueryOperators.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -33,6 +35,10 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 1713ECAE14F96A5C0013C4F0 /* QKSelectQueryOrderByTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QKSelectQueryOrderByTests.h; sourceTree = ""; }; + 1713ECAF14F96A5C0013C4F0 /* QKSelectQueryOrderByTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QKSelectQueryOrderByTests.m; sourceTree = ""; }; + 1713ECD614F970BB0013C4F0 /* QKSelectQueryGroupByTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QKSelectQueryGroupByTests.h; sourceTree = ""; }; + 1713ECD714F970BB0013C4F0 /* QKSelectQueryGroupByTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QKSelectQueryGroupByTests.m; sourceTree = ""; }; 17E5951614F301DF0054EE08 /* QKQuery.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QKQuery.h; sourceTree = ""; }; 17E5951714F301DF0054EE08 /* QKQuery.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QKQuery.m; sourceTree = ""; }; 17E5951814F301DF0054EE08 /* QKQueryOperators.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QKQueryOperators.h; sourceTree = ""; }; @@ -141,6 +147,10 @@ children = ( 17E5969714F307B70054EE08 /* QKSelectQueryTests.h */, 17E5969814F307B70054EE08 /* QKSelectQueryTests.m */, + 1713ECAE14F96A5C0013C4F0 /* QKSelectQueryOrderByTests.h */, + 1713ECAF14F96A5C0013C4F0 /* QKSelectQueryOrderByTests.m */, + 1713ECD614F970BB0013C4F0 /* QKSelectQueryGroupByTests.h */, + 1713ECD714F970BB0013C4F0 /* QKSelectQueryGroupByTests.m */, ); path = Tests; sourceTree = ""; @@ -267,6 +277,8 @@ buildActionMask = 2147483647; files = ( 17E596A814F308160054EE08 /* QKSelectQueryTests.m in Sources */, + 1713ECB014F96A5C0013C4F0 /* QKSelectQueryOrderByTests.m in Sources */, + 1713ECD814F970BB0013C4F0 /* QKSelectQueryGroupByTests.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Frameworks/QueryKit/Source/QKQuery.m b/Frameworks/QueryKit/Source/QKQuery.m index ded198ba..21053203 100644 --- a/Frameworks/QueryKit/Source/QKQuery.m +++ b/Frameworks/QueryKit/Source/QKQuery.m @@ -378,9 +378,7 @@ static NSString *QKNoQueryTableException = @"QKNoQueryTable"; [orderBy setString:[orderBy substringToIndex:([orderBy length] - 2)]]; } - if (_orderDescending) { - [orderBy appendString:@" DESC"]; - } + [orderBy appendString:_orderDescending ? @" DESC" : @" ASC"]; return orderBy; } diff --git a/Frameworks/QueryKit/Tests/QKSelectQueryGroupByTests.h b/Frameworks/QueryKit/Tests/QKSelectQueryGroupByTests.h new file mode 100644 index 00000000..56907b36 --- /dev/null +++ b/Frameworks/QueryKit/Tests/QKSelectQueryGroupByTests.h @@ -0,0 +1,41 @@ +// +// $Id$ +// +// QKSelectQueryGroupByTests.h +// sequel-pro +// +// Created by Stuart Connolly (stuconnolly.com) on February 25, 2012 +// Copyright (c) 2012 Stuart Connolly. 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 + +#import +#import + +@interface QKSelectQueryGroupByTests : SenTestCase +{ + QKQuery *_query; +} + +@end diff --git a/Frameworks/QueryKit/Tests/QKSelectQueryGroupByTests.m b/Frameworks/QueryKit/Tests/QKSelectQueryGroupByTests.m new file mode 100644 index 00000000..722d7df0 --- /dev/null +++ b/Frameworks/QueryKit/Tests/QKSelectQueryGroupByTests.m @@ -0,0 +1,80 @@ +// +// $Id$ +// +// QKSelectQueryGroupByTests.m +// sequel-pro +// +// Created by Stuart Connolly (stuconnolly.com) on February 25, 2012 +// Copyright (c) 2012 Stuart Connolly. 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 + +#import "QKSelectQueryGroupByTests.h" + +static NSString *QKTestTableName = @"test_table"; + +static NSString *QKTestFieldOne = @"test_field1"; +static NSString *QKTestFieldTwo = @"test_field2"; + +@implementation QKSelectQueryGroupByTests + +#pragma mark - +#pragma mark Setup & tear down + +- (void)setUp +{ + _query = [QKQuery selectQueryFromTable:QKTestTableName]; + + [_query addField:QKTestFieldOne]; + [_query addField:QKTestFieldTwo]; +} + +#pragma mark - +#pragma mark Tests + +- (void)testSelectQueryTypeIsCorrect +{ + STAssertTrue([[_query query] hasPrefix:@"SELECT"], @"query type"); +} + +- (void)testSelectQueryGroupByIsCorrect +{ + [_query groupByField:QKTestFieldOne]; + + NSString *query = [NSString stringWithFormat:@"GROUP BY %@", QKTestFieldOne]; + + STAssertTrue([[_query query] hasSuffix:query], @"query group by"); +} + +- (void)testSelectQueryMultipleGroupByIsCorrect +{ + [_query groupByFields:[NSArray arrayWithObjects:QKTestFieldOne, QKTestFieldTwo, nil]]; + + NSString *query = [NSString stringWithFormat:@"GROUP BY %@, %@", QKTestFieldOne, QKTestFieldTwo]; + + STAssertTrue([[_query query] hasSuffix:query], @"query group by"); +} + + +@end diff --git a/Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.h b/Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.h new file mode 100644 index 00000000..c457491a --- /dev/null +++ b/Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.h @@ -0,0 +1,41 @@ +// +// $Id$ +// +// QKSelectQueryOrderByTests.h +// sequel-pro +// +// Created by Stuart Connolly (stuconnolly.com) on February 25, 2012 +// Copyright (c) 2012 Stuart Connolly. 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 + +#import +#import + +@interface QKSelectQueryOrderByTests : SenTestCase +{ + QKQuery *_query; +} + +@end diff --git a/Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.m b/Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.m new file mode 100644 index 00000000..4f33d657 --- /dev/null +++ b/Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.m @@ -0,0 +1,79 @@ +// +// $Id$ +// +// QKSelectQueryOrderByTests.m +// sequel-pro +// +// Created by Stuart Connolly (stuconnolly.com) on February 25, 2012 +// Copyright (c) 2012 Stuart Connolly. 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 + +#import "QKSelectQueryOrderByTests.h" + +static NSString *QKTestTableName = @"test_table"; + +static NSString *QKTestFieldOne = @"test_field1"; +static NSString *QKTestFieldTwo = @"test_field2"; + +@implementation QKSelectQueryOrderByTests + +#pragma mark - +#pragma mark Setup & tear down + +- (void)setUp +{ + _query = [QKQuery selectQueryFromTable:QKTestTableName]; + + [_query addField:QKTestFieldOne]; + [_query addField:QKTestFieldTwo]; +} + +#pragma mark - +#pragma mark Tests + +- (void)testSelectQueryTypeIsCorrect +{ + STAssertTrue([[_query query] hasPrefix:@"SELECT"], @"query type"); +} + +- (void)testSelectQueryOrderByAscendingIsCorrect +{ + [_query orderByField:QKTestFieldOne descending:NO]; + + NSString *query = [NSString stringWithFormat:@"ORDER BY %@ ASC", QKTestFieldOne]; + + STAssertTrue([[_query query] hasSuffix:query], @"query order by"); +} + +- (void)testSelectQueryOrderByDescendingIsCorrect +{ + [_query orderByField:QKTestFieldOne descending:YES]; + + NSString *query = [NSString stringWithFormat:@"ORDER BY %@ DESC", QKTestFieldOne]; + + STAssertTrue([[_query query] hasSuffix:query], @"query order by"); +} + +@end diff --git a/Frameworks/QueryKit/Tests/QKSelectQueryTests.h b/Frameworks/QueryKit/Tests/QKSelectQueryTests.h index e8b3c3b7..df9e3272 100644 --- a/Frameworks/QueryKit/Tests/QKSelectQueryTests.h +++ b/Frameworks/QueryKit/Tests/QKSelectQueryTests.h @@ -1,5 +1,5 @@ // -// $Id: QKSelectQueryTests.h 3431 2011-09-26 22:26:24Z stuart02 $ +// $Id$ // // QKSelectQueryTests.h // sequel-pro @@ -7,24 +7,30 @@ // Created by Stuart Connolly (stuconnolly.com) on September 4, 2011 // Copyright (c) 2011 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. +// 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: // -// 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. +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. // -// 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 +// 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 #import - #import @interface QKSelectQueryTests : SenTestCase diff --git a/Frameworks/QueryKit/Tests/QKSelectQueryTests.m b/Frameworks/QueryKit/Tests/QKSelectQueryTests.m index fdce3ca8..620dbadd 100644 --- a/Frameworks/QueryKit/Tests/QKSelectQueryTests.m +++ b/Frameworks/QueryKit/Tests/QKSelectQueryTests.m @@ -1,5 +1,5 @@ // -// $Id: QKSelectQueryTests.m 3432 2011-09-27 00:21:35Z stuart02 $ +// $Id$ // // QKSelectQueryTests.m // sequel-pro @@ -7,19 +7,26 @@ // Created by Stuart Connolly (stuconnolly.com) on September 4, 2011 // Copyright (c) 2011 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. +// 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: // -// 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. +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. // -// 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 +// 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 -- cgit v1.2.3 From a5caf49b945179abdc0570a6ba8797b4552c793b Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Sun, 26 Feb 2012 13:01:37 +0000 Subject: More QueryKit SELECT tests. --- .../QueryKit/QueryKit.xcodeproj/project.pbxproj | 44 +++++++++++++++++++--- .../QueryKit/Tests/QKSelectQueryGroupByTests.m | 2 +- .../QueryKit/Tests/QKSelectQueryOrderByTests.m | 18 +++++++++ 3 files changed, 57 insertions(+), 7 deletions(-) (limited to 'Frameworks/QueryKit') diff --git a/Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj b/Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj index 6d52f5f0..efbdb9f1 100644 --- a/Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj +++ b/Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj @@ -133,6 +133,40 @@ path = Source; sourceTree = ""; }; + 17322A7214FA645300F0CF9B /* SELECT Tests */ = { + isa = PBXGroup; + children = ( + 17E5969714F307B70054EE08 /* QKSelectQueryTests.h */, + 17E5969814F307B70054EE08 /* QKSelectQueryTests.m */, + 1713ECAE14F96A5C0013C4F0 /* QKSelectQueryOrderByTests.h */, + 1713ECAF14F96A5C0013C4F0 /* QKSelectQueryOrderByTests.m */, + 1713ECD614F970BB0013C4F0 /* QKSelectQueryGroupByTests.h */, + 1713ECD714F970BB0013C4F0 /* QKSelectQueryGroupByTests.m */, + ); + name = "SELECT Tests"; + sourceTree = ""; + }; + 17322A7414FA646000F0CF9B /* UPDATE Tests */ = { + isa = PBXGroup; + children = ( + ); + name = "UPDATE Tests"; + sourceTree = ""; + }; + 17322A7514FA647200F0CF9B /* DELETE Tests */ = { + isa = PBXGroup; + children = ( + ); + name = "DELETE Tests"; + sourceTree = ""; + }; + 17322A7614FA648100F0CF9B /* INSERT Tests */ = { + isa = PBXGroup; + children = ( + ); + name = "INSERT Tests"; + sourceTree = ""; + }; 17E5952814F301F40054EE08 /* Constants */ = { isa = PBXGroup; children = ( @@ -145,12 +179,10 @@ 17E5969614F3079E0054EE08 /* Tests */ = { isa = PBXGroup; children = ( - 17E5969714F307B70054EE08 /* QKSelectQueryTests.h */, - 17E5969814F307B70054EE08 /* QKSelectQueryTests.m */, - 1713ECAE14F96A5C0013C4F0 /* QKSelectQueryOrderByTests.h */, - 1713ECAF14F96A5C0013C4F0 /* QKSelectQueryOrderByTests.m */, - 1713ECD614F970BB0013C4F0 /* QKSelectQueryGroupByTests.h */, - 1713ECD714F970BB0013C4F0 /* QKSelectQueryGroupByTests.m */, + 17322A7614FA648100F0CF9B /* INSERT Tests */, + 17322A7514FA647200F0CF9B /* DELETE Tests */, + 17322A7414FA646000F0CF9B /* UPDATE Tests */, + 17322A7214FA645300F0CF9B /* SELECT Tests */, ); path = Tests; sourceTree = ""; diff --git a/Frameworks/QueryKit/Tests/QKSelectQueryGroupByTests.m b/Frameworks/QueryKit/Tests/QKSelectQueryGroupByTests.m index 722d7df0..9bbe75a2 100644 --- a/Frameworks/QueryKit/Tests/QKSelectQueryGroupByTests.m +++ b/Frameworks/QueryKit/Tests/QKSelectQueryGroupByTests.m @@ -67,7 +67,7 @@ static NSString *QKTestFieldTwo = @"test_field2"; STAssertTrue([[_query query] hasSuffix:query], @"query group by"); } -- (void)testSelectQueryMultipleGroupByIsCorrect +- (void)testSelectQueryGroupByMultipleFieldsIsCorrect { [_query groupByFields:[NSArray arrayWithObjects:QKTestFieldOne, QKTestFieldTwo, nil]]; diff --git a/Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.m b/Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.m index 4f33d657..84bd5ddb 100644 --- a/Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.m +++ b/Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.m @@ -67,6 +67,15 @@ static NSString *QKTestFieldTwo = @"test_field2"; STAssertTrue([[_query query] hasSuffix:query], @"query order by"); } +- (void)testSelectQueryOrderByMultipleFieldsAscendingIsCorrect +{ + [_query orderByFields:[NSArray arrayWithObjects:QKTestFieldOne, QKTestFieldTwo, nil] descending:NO]; + + NSString *query = [NSString stringWithFormat:@"ORDER BY %@, %@ ASC", QKTestFieldOne, QKTestFieldTwo]; + + STAssertTrue([[_query query] hasSuffix:query], @"query order by"); +} + - (void)testSelectQueryOrderByDescendingIsCorrect { [_query orderByField:QKTestFieldOne descending:YES]; @@ -76,4 +85,13 @@ static NSString *QKTestFieldTwo = @"test_field2"; STAssertTrue([[_query query] hasSuffix:query], @"query order by"); } +- (void)testSelectQueryOrderByMultipleFieldsDescendingIsCorrect +{ + [_query orderByFields:[NSArray arrayWithObjects:QKTestFieldOne, QKTestFieldTwo, nil] descending:YES]; + + NSString *query = [NSString stringWithFormat:@"ORDER BY %@, %@ DESC", QKTestFieldOne, QKTestFieldTwo]; + + STAssertTrue([[_query query] hasSuffix:query], @"query order by"); +} + @end -- cgit v1.2.3 From 761e5d73bf237c4d5e33a925cfd8d8fb9a48c30d Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Sun, 26 Feb 2012 21:06:23 +0000 Subject: - Re-add QueryKit as a dependency, and correct framework paths and linking to fix errors building and running the project - Add svn ignore properties on QueryKit build and mode paths --- Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Frameworks/QueryKit') diff --git a/Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj b/Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj index efbdb9f1..89c50725 100644 --- a/Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj +++ b/Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj @@ -385,7 +385,7 @@ GCC_WARN_UNUSED_LABEL = YES; GCC_WARN_UNUSED_VALUE = YES; INFOPLIST_FILE = Resources/Info.plist; - INSTALL_PATH = "$(HOME)/Library/Frameworks"; + INSTALL_PATH = "@executable_path/../Frameworks"; PRODUCT_NAME = QueryKit; WRAPPER_EXTENSION = framework; }; @@ -507,7 +507,7 @@ GCC_WARN_UNUSED_VALUE = YES; GENERATE_PKGINFO_FILE = YES; INFOPLIST_FILE = Resources/Info.plist; - INSTALL_PATH = "$(HOME)/Library/Frameworks"; + INSTALL_PATH = "@executable_path/../Frameworks"; PRODUCT_NAME = QueryKit; WARNING_CFLAGS = "-Wmost"; WRAPPER_EXTENSION = framework; @@ -552,7 +552,7 @@ GCC_WARN_UNUSED_LABEL = YES; GCC_WARN_UNUSED_VALUE = YES; INFOPLIST_FILE = Resources/Info.plist; - INSTALL_PATH = "$(HOME)/Library/Frameworks"; + INSTALL_PATH = "@executable_path/../Frameworks"; PRODUCT_NAME = QueryKit; SDKROOT = macosx10.5; VALID_ARCHS = "ppc i386 x86_64"; -- cgit v1.2.3