diff options
-rw-r--r-- | Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj | 34 | ||||
-rw-r--r-- | Frameworks/QueryKit/Source/QKQuery.h | 8 | ||||
-rw-r--r-- | Frameworks/QueryKit/Source/QKQuery.m | 53 | ||||
-rw-r--r-- | Frameworks/QueryKit/Source/QKQueryConstants.h | 32 | ||||
-rw-r--r-- | Frameworks/QueryKit/Source/QKQueryGenericParameter.h | 53 | ||||
-rw-r--r-- | Frameworks/QueryKit/Source/QKQueryGenericParameter.m | 61 | ||||
-rw-r--r-- | Frameworks/QueryKit/Source/QKQueryParameter.h | 19 | ||||
-rw-r--r-- | Frameworks/QueryKit/Source/QKQueryParameter.m | 17 | ||||
-rw-r--r-- | Frameworks/QueryKit/Source/QKQueryUpdateParameter.h | 19 | ||||
-rw-r--r-- | Frameworks/QueryKit/Source/QKQueryUpdateParameter.m | 16 | ||||
-rw-r--r-- | Frameworks/QueryKit/Tests/QKSelectQueryGroupByTests.m | 35 | ||||
-rw-r--r-- | Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.m | 58 | ||||
-rw-r--r-- | Frameworks/QueryKit/Tests/QKSelectQueryTests.m | 56 | ||||
-rw-r--r-- | Frameworks/QueryKit/Tests/QKTestConstants.h | 41 | ||||
-rw-r--r-- | Frameworks/QueryKit/Tests/QKTestConstants.m | 41 | ||||
-rw-r--r-- | Frameworks/QueryKit/Tests/QKUpdateQueryTests.m | 39 |
16 files changed, 445 insertions, 137 deletions
diff --git a/Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj b/Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj index 83ebd099..c4c1e8d2 100644 --- a/Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj +++ b/Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj @@ -12,6 +12,10 @@ 1719E47D151E8CA7003F98C5 /* QKQueryUpdateParameter.h in Headers */ = {isa = PBXBuildFile; fileRef = 1719E47B151E8CA7003F98C5 /* QKQueryUpdateParameter.h */; settings = {ATTRIBUTES = (Public, ); }; }; 1719E47E151E8CA7003F98C5 /* QKQueryUpdateParameter.m in Sources */ = {isa = PBXBuildFile; fileRef = 1719E47C151E8CA7003F98C5 /* QKQueryUpdateParameter.m */; }; 1719E4BD151F51F1003F98C5 /* QKUpdateQueryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 1719E4BA151F51EA003F98C5 /* QKUpdateQueryTests.m */; }; + 17577F6715A98FEA00CDF67A /* QKTestConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 17577F6615A98FEA00CDF67A /* QKTestConstants.m */; }; + 17577FC615A99AC000CDF67A /* QKQueryConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = 17577FC415A99AC000CDF67A /* QKQueryConstants.h */; }; + 1757801E15A9A14400CDF67A /* QKQueryGenericParameter.h in Headers */ = {isa = PBXBuildFile; fileRef = 1757801C15A9A14400CDF67A /* QKQueryGenericParameter.h */; }; + 1757801F15A9A14400CDF67A /* QKQueryGenericParameter.m in Sources */ = {isa = PBXBuildFile; fileRef = 1757801D15A9A14400CDF67A /* QKQueryGenericParameter.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, ); }; }; @@ -46,6 +50,11 @@ 1719E47C151E8CA7003F98C5 /* QKQueryUpdateParameter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QKQueryUpdateParameter.m; sourceTree = "<group>"; }; 1719E4B9151F51EA003F98C5 /* QKUpdateQueryTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QKUpdateQueryTests.h; sourceTree = "<group>"; }; 1719E4BA151F51EA003F98C5 /* QKUpdateQueryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QKUpdateQueryTests.m; sourceTree = "<group>"; }; + 17577F6515A98FEA00CDF67A /* QKTestConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QKTestConstants.h; sourceTree = "<group>"; }; + 17577F6615A98FEA00CDF67A /* QKTestConstants.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QKTestConstants.m; sourceTree = "<group>"; }; + 17577FC415A99AC000CDF67A /* QKQueryConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QKQueryConstants.h; sourceTree = "<group>"; }; + 1757801C15A9A14400CDF67A /* QKQueryGenericParameter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QKQueryGenericParameter.h; sourceTree = "<group>"; }; + 1757801D15A9A14400CDF67A /* QKQueryGenericParameter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QKQueryGenericParameter.m; sourceTree = "<group>"; }; 17E5951614F301DF0054EE08 /* QKQuery.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QKQuery.h; sourceTree = "<group>"; }; 17E5951714F301DF0054EE08 /* QKQuery.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QKQuery.m; sourceTree = "<group>"; }; 17E5951814F301DF0054EE08 /* QKQueryOperators.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QKQueryOperators.h; sourceTree = "<group>"; }; @@ -135,6 +144,7 @@ 17E5951D14F301DF0054EE08 /* QKQueryUtilities.m */, 1719E47A151E8C87003F98C5 /* Model */, 17E5952814F301F40054EE08 /* Constants */, + 17577FC315A99AA500CDF67A /* Other */, ); path = Source; sourceTree = "<group>"; @@ -146,6 +156,8 @@ 17E5951A14F301DF0054EE08 /* QKQueryParameter.m */, 1719E47B151E8CA7003F98C5 /* QKQueryUpdateParameter.h */, 1719E47C151E8CA7003F98C5 /* QKQueryUpdateParameter.m */, + 1757801C15A9A14400CDF67A /* QKQueryGenericParameter.h */, + 1757801D15A9A14400CDF67A /* QKQueryGenericParameter.m */, ); name = Model; sourceTree = "<group>"; @@ -186,6 +198,23 @@ name = "INSERT Tests"; sourceTree = "<group>"; }; + 17577FA015A994EB00CDF67A /* Common */ = { + isa = PBXGroup; + children = ( + 17577F6515A98FEA00CDF67A /* QKTestConstants.h */, + 17577F6615A98FEA00CDF67A /* QKTestConstants.m */, + ); + name = Common; + sourceTree = "<group>"; + }; + 17577FC315A99AA500CDF67A /* Other */ = { + isa = PBXGroup; + children = ( + 17577FC415A99AC000CDF67A /* QKQueryConstants.h */, + ); + name = Other; + sourceTree = "<group>"; + }; 17E5952814F301F40054EE08 /* Constants */ = { isa = PBXGroup; children = ( @@ -198,6 +227,7 @@ 17E5969614F3079E0054EE08 /* Tests */ = { isa = PBXGroup; children = ( + 17577FA015A994EB00CDF67A /* Common */, 17322A7614FA648100F0CF9B /* INSERT Tests */, 17322A7514FA647200F0CF9B /* DELETE Tests */, 17322A7414FA646000F0CF9B /* UPDATE Tests */, @@ -220,6 +250,8 @@ 17E5952514F301DF0054EE08 /* QKQueryUtilities.h in Headers */, 17E5952714F301DF0054EE08 /* QueryKit.h in Headers */, 1719E47D151E8CA7003F98C5 /* QKQueryUpdateParameter.h in Headers */, + 17577FC615A99AC000CDF67A /* QKQueryConstants.h in Headers */, + 1757801E15A9A14400CDF67A /* QKQueryGenericParameter.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -324,6 +356,7 @@ 1713ECB014F96A5C0013C4F0 /* QKSelectQueryOrderByTests.m in Sources */, 1713ECD814F970BB0013C4F0 /* QKSelectQueryGroupByTests.m in Sources */, 1719E4BD151F51F1003F98C5 /* QKUpdateQueryTests.m in Sources */, + 17577F6715A98FEA00CDF67A /* QKTestConstants.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -335,6 +368,7 @@ 17E5952314F301DF0054EE08 /* QKQueryParameter.m in Sources */, 17E5952614F301DF0054EE08 /* QKQueryUtilities.m in Sources */, 1719E47E151E8CA7003F98C5 /* QKQueryUpdateParameter.m in Sources */, + 1757801F15A9A14400CDF67A /* QKQueryGenericParameter.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Frameworks/QueryKit/Source/QKQuery.h b/Frameworks/QueryKit/Source/QKQuery.h index c0f925bb..1cb93d15 100644 --- a/Frameworks/QueryKit/Source/QKQuery.h +++ b/Frameworks/QueryKit/Source/QKQuery.h @@ -55,7 +55,7 @@ QKQueryType _queryType; - BOOL _quoteFields; + BOOL _useQuotes; BOOL _orderDescending; } @@ -90,9 +90,9 @@ @property (readwrite, assign, getter=queryType, setter=setQueryType:) QKQueryType _queryType; /** - * @property _quoteFields Indicates whether or not the query's fields should be quoted. + * @property _useQuotes Indicates whether or not the query's fields should be quoted. */ -@property (readwrite, assign, getter=quoteFields, setter=setQuoteFields:) BOOL _quoteFields; +@property (readwrite, assign, getter=useQuotes) BOOL _useQuotes; + (QKQuery *)queryTable:(NSString *)table; + (QKQuery *)selectQueryFromTable:(NSString *)table; @@ -102,6 +102,8 @@ - (NSString *)query; - (void)clear; +- (void)setUseQuotes:(BOOL)quote; + - (void)addField:(NSString *)field; - (void)addFields:(NSArray *)fields; diff --git a/Frameworks/QueryKit/Source/QKQuery.m b/Frameworks/QueryKit/Source/QKQuery.m index bb876006..124bb5d2 100644 --- a/Frameworks/QueryKit/Source/QKQuery.m +++ b/Frameworks/QueryKit/Source/QKQuery.m @@ -29,6 +29,8 @@ // OTHER DEALINGS IN THE SOFTWARE. #import "QKQuery.h" +#import "QKQueryConstants.h" +#import "QKQueryGenericParameter.h" static NSString *QKNoQueryTypeException = @"QKNoQueryType"; static NSString *QKNoQueryTableException = @"QKNoQueryTable"; @@ -57,7 +59,7 @@ static NSString *QKNoQueryTableException = @"QKNoQueryTable"; @synthesize _queryType; @synthesize _fields; @synthesize _updateParameters; -@synthesize _quoteFields; +@synthesize _useQuotes; #pragma mark - #pragma mark Initialization @@ -84,7 +86,7 @@ static NSString *QKNoQueryTableException = @"QKNoQueryTable"; [self setUpdateParameters:[[NSMutableArray alloc] init]]; [self setParameters:[[NSMutableArray alloc] init]]; [self setQueryType:(QKQueryType)-1]; - [self setQuoteFields:NO]; + [self setUseQuotes:YES]; _orderDescending = NO; @@ -127,6 +129,24 @@ static NSString *QKNoQueryTableException = @"QKNoQueryTable"; } #pragma mark - +#pragma mark Accessors + +- (void)setUseQuotes:(BOOL)quote +{ + _useQuotes = quote; + + for (QKQueryParameter *param in _parameters) + { + [param setUseQuotes:_useQuotes]; + } + + for (QKQueryUpdateParameter *param in _updateParameters) + { + [param setUseQuotes:_useQuotes]; + } +} + +#pragma mark - #pragma mark Fields /** @@ -160,7 +180,7 @@ static NSString *QKNoQueryTableException = @"QKNoQueryTable"; */ - (void)addParameter:(QKQueryParameter *)parameter { - if ([parameter field] && ([[parameter field] length] > 0) && ((NSInteger)[parameter operator] > -1) && [parameter value]) { + if ([parameter field] && ([[parameter field] length] > 0) && ((NSInteger)[parameter operator] > -1) && [parameter value]) { [_parameters addObject:parameter]; } } @@ -183,7 +203,7 @@ static NSString *QKNoQueryTableException = @"QKNoQueryTable"; */ - (void)addFieldToUpdate:(QKQueryUpdateParameter *)parameter { - if ([parameter field] && ([[parameter field] length] > 0) && [parameter value]) { + if ([parameter field] && ([[parameter field] length] > 0) && [parameter value]) { [_updateParameters addObject:parameter]; } } @@ -287,10 +307,10 @@ static NSString *QKNoQueryTableException = @"QKNoQueryTable"; } if (_database && [_database length] > 0) { - [_query appendFormat:@"%@.", _database]; + [_query appendFormat:@"%@%@%@.", _useQuotes ? QUERY_QUOTE : EMPTY_STRING, _database, _useQuotes ? QUERY_QUOTE : EMPTY_STRING]; } - [_query appendString:_table]; + [_query appendFormat:@"%@%@%@", _useQuotes ? QUERY_QUOTE : EMPTY_STRING, _table, _useQuotes ? QUERY_QUOTE : EMPTY_STRING]; if (isUpdate) { [_query appendFormat:@" %@", [self _buildUpdateClause]]; @@ -326,17 +346,7 @@ static NSString *QKNoQueryTableException = @"QKNoQueryTable"; if ([field length] == 0) continue; - if (_quoteFields) { - [fields appendString:@"`"]; - } - - [fields appendString:field]; - - if (_quoteFields) { - [fields appendString:@"`"]; - } - - [fields appendString:@", "]; + [fields appendFormat:@"%@%@%@, ", _useQuotes ? QUERY_QUOTE : EMPTY_STRING, field, _useQuotes ? QUERY_QUOTE : EMPTY_STRING]; } if ([fields hasSuffix:@", "]) { @@ -357,8 +367,7 @@ static NSString *QKNoQueryTableException = @"QKNoQueryTable"; for (QKQueryParameter *param in _parameters) { - [constraints appendFormat:@"%@", param]; - + [constraints appendString:[param description]]; [constraints appendString:@" AND "]; } @@ -384,8 +393,7 @@ static NSString *QKNoQueryTableException = @"QKNoQueryTable"; for (NSString *field in _groupByFields) { - [groupBy appendString:field]; - [groupBy appendString:@", "]; + [groupBy appendFormat:@"%@%@%@, ", _useQuotes ? QUERY_QUOTE : EMPTY_STRING, field, _useQuotes ? QUERY_QUOTE : EMPTY_STRING]; } if ([groupBy hasSuffix:@", "]) { @@ -410,8 +418,7 @@ static NSString *QKNoQueryTableException = @"QKNoQueryTable"; for (NSString *field in _orderByFields) { - [orderBy appendString:field]; - [orderBy appendString:@", "]; + [orderBy appendFormat:@"%@%@%@, ", _useQuotes ? QUERY_QUOTE : EMPTY_STRING, field, _useQuotes ? QUERY_QUOTE : EMPTY_STRING]; } if ([orderBy hasSuffix:@", "]) { diff --git a/Frameworks/QueryKit/Source/QKQueryConstants.h b/Frameworks/QueryKit/Source/QKQueryConstants.h new file mode 100644 index 00000000..9d843169 --- /dev/null +++ b/Frameworks/QueryKit/Source/QKQueryConstants.h @@ -0,0 +1,32 @@ +// +// $Id$ +// +// QKQueryConstants.h +// QueryKit +// +// Created by Stuart Connolly (stuconnolly.com) on July 8, 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. + +#define QUERY_QUOTE @"`" +#define EMPTY_STRING @"" diff --git a/Frameworks/QueryKit/Source/QKQueryGenericParameter.h b/Frameworks/QueryKit/Source/QKQueryGenericParameter.h new file mode 100644 index 00000000..ba1e63cd --- /dev/null +++ b/Frameworks/QueryKit/Source/QKQueryGenericParameter.h @@ -0,0 +1,53 @@ +// +// $Id$ +// +// QKQueryGenericParameter.h +// QueryKit +// +// Created by Stuart Connolly (stuconnolly.com) on July 8, 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. + +@interface QKQueryGenericParameter : NSObject +{ + id _value; + NSString *_field; + BOOL _useQuotes; +} + +/** + * @property _field The field component of the parameter. + */ +@property (readwrite, retain, getter=field, setter=setField:) NSString *_field; + +/** + * @property _quoteField Indicates whether or not this parameters field should be quoted. + */ +@property (readwrite, assign, getter=useQuotes, setter=setUseQuotes:) BOOL _useQuotes; + +/** + *@property _value The value component of the parameter. + */ +@property (readwrite, retain, getter=value, setter=setValue:) id _value; + +@end diff --git a/Frameworks/QueryKit/Source/QKQueryGenericParameter.m b/Frameworks/QueryKit/Source/QKQueryGenericParameter.m new file mode 100644 index 00000000..8648dc0a --- /dev/null +++ b/Frameworks/QueryKit/Source/QKQueryGenericParameter.m @@ -0,0 +1,61 @@ +// +// $Id$ +// +// QKQueryGenericParameter.m +// QueryKit +// +// Created by Stuart Connolly (stuconnolly.com) on July 8, 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. + +#import "QKQueryGenericParameter.h" + +@implementation QKQueryGenericParameter + +@synthesize _field; +@synthesize _useQuotes; +@synthesize _value; + +#pragma mark - +#pragma mark Initialisation + +- (id)init +{ + if ((self = [super init])) { + [self setUseQuotes:YES]; + } + + return self; +} + +#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/QKQueryParameter.h b/Frameworks/QueryKit/Source/QKQueryParameter.h index 18f87929..b2436468 100644 --- a/Frameworks/QueryKit/Source/QKQueryParameter.h +++ b/Frameworks/QueryKit/Source/QKQueryParameter.h @@ -29,6 +29,7 @@ // OTHER DEALINGS IN THE SOFTWARE. #import "QKQueryOperators.h" +#import "QKQueryGenericParameter.h" /** * @class QKQueryParameter QKQueryParameter.h @@ -37,30 +38,16 @@ * * QueryKit query parameter class. */ -@interface QKQueryParameter : NSObject -{ - NSString *_field; - +@interface QKQueryParameter : QKQueryGenericParameter +{ 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; diff --git a/Frameworks/QueryKit/Source/QKQueryParameter.m b/Frameworks/QueryKit/Source/QKQueryParameter.m index c95bf585..c4f9cc29 100644 --- a/Frameworks/QueryKit/Source/QKQueryParameter.m +++ b/Frameworks/QueryKit/Source/QKQueryParameter.m @@ -30,12 +30,11 @@ #import "QKQueryParameter.h" #import "QKQueryUtilities.h" +#import "QKQueryConstants.h" @implementation QKQueryParameter -@synthesize _field; @synthesize _operator; -@synthesize _value; #pragma mark - #pragma mark Initialisation @@ -64,21 +63,11 @@ NSString *field = [_field stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; - [string appendString:field]; + [string appendFormat:@"%@%@%@", [self useQuotes] ? QUERY_QUOTE : EMPTY_STRING, field, [self useQuotes] ? QUERY_QUOTE : EMPTY_STRING]; [string appendFormat:@" %@ ", [QKQueryUtilities operatorRepresentationForType:_operator]]; - [string appendFormat:(![_value isKindOfClass:[NSNumber class]]) ? @"'%@'" : @"%@", [_value description]]; + [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/QKQueryUpdateParameter.h b/Frameworks/QueryKit/Source/QKQueryUpdateParameter.h index 5231d272..d8f01310 100644 --- a/Frameworks/QueryKit/Source/QKQueryUpdateParameter.h +++ b/Frameworks/QueryKit/Source/QKQueryUpdateParameter.h @@ -28,6 +28,8 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. +#import "QKQueryGenericParameter.h" + /** * @class QKQueryUpdateParameter QKQueryUpdateParameter.h * @@ -35,22 +37,7 @@ * * QueryKit update query parameter class. */ -@interface QKQueryUpdateParameter : NSObject -{ - NSString *_field; - - id _value; -} - -/** - * @property _field The field component of the parameter. - */ -@property (readwrite, retain, getter=field, setter=setField:) NSString *_field; - -/** - *@property _value The value component of the parameter. - */ -@property (readwrite, retain, getter=value, setter=setValue:) id _value; +@interface QKQueryUpdateParameter : QKQueryGenericParameter + (QKQueryUpdateParameter *)queryUpdateParamWithField:(NSString *)field value:(id)value; diff --git a/Frameworks/QueryKit/Source/QKQueryUpdateParameter.m b/Frameworks/QueryKit/Source/QKQueryUpdateParameter.m index febbfa44..8df3aba5 100644 --- a/Frameworks/QueryKit/Source/QKQueryUpdateParameter.m +++ b/Frameworks/QueryKit/Source/QKQueryUpdateParameter.m @@ -29,12 +29,10 @@ // OTHER DEALINGS IN THE SOFTWARE. #import "QKQueryUpdateParameter.h" +#import "QKQueryConstants.h" @implementation QKQueryUpdateParameter -@synthesize _field; -@synthesize _value; - #pragma mark - #pragma mark Initialisation @@ -61,21 +59,11 @@ NSString *field = [_field stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; - [string appendString:field]; + [string appendFormat:@"%@%@%@", [self useQuotes] ? QUERY_QUOTE : EMPTY_STRING, field, [self useQuotes] ? QUERY_QUOTE : EMPTY_STRING]; [string appendString:@" = "]; [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/Tests/QKSelectQueryGroupByTests.m b/Frameworks/QueryKit/Tests/QKSelectQueryGroupByTests.m index c34b586a..e9edbea1 100644 --- a/Frameworks/QueryKit/Tests/QKSelectQueryGroupByTests.m +++ b/Frameworks/QueryKit/Tests/QKSelectQueryGroupByTests.m @@ -29,16 +29,12 @@ // OTHER DEALINGS IN THE SOFTWARE. #import "QKSelectQueryGroupByTests.h" - -static NSString *QKTestTableName = @"test_table"; - -static NSString *QKTestFieldOne = @"test_field1"; -static NSString *QKTestFieldTwo = @"test_field2"; +#import "QKTestConstants.h" @implementation QKSelectQueryGroupByTests #pragma mark - -#pragma mark Setup & tear down +#pragma mark Setup - (void)setUp { @@ -53,26 +49,45 @@ static NSString *QKTestFieldTwo = @"test_field2"; - (void)testSelectQueryTypeIsCorrect { - STAssertTrue([[_query query] hasPrefix:@"SELECT"], @"query type"); + STAssertTrue([[_query query] hasPrefix:@"SELECT"], @"select query type"); } - (void)testSelectQueryGroupByIsCorrect { [_query groupByField:QKTestFieldOne]; + NSString *query = [NSString stringWithFormat:@"GROUP BY `%@`", QKTestFieldOne]; + + STAssertTrue([[_query query] hasSuffix:query], @"select query group by"); +} + +- (void)testSelectQueryGroupByWithoutQuotesIsCorrect +{ + [_query setUseQuotes:NO]; + [_query groupByField:QKTestFieldOne]; + NSString *query = [NSString stringWithFormat:@"GROUP BY %@", QKTestFieldOne]; - STAssertTrue([[_query query] hasSuffix:query], @"query group by"); + STAssertTrue([[_query query] hasSuffix:query], @"select query group by without quotes"); } - (void)testSelectQueryGroupByMultipleFieldsIsCorrect { [_query groupByFields:[NSArray arrayWithObjects:QKTestFieldOne, QKTestFieldTwo, nil]]; - NSString *query = [NSString stringWithFormat:@"GROUP BY %@, %@", QKTestFieldOne, QKTestFieldTwo]; + NSString *query = [NSString stringWithFormat:@"GROUP BY `%@`, `%@`", QKTestFieldOne, QKTestFieldTwo]; - STAssertTrue([[_query query] hasSuffix:query], @"query group by"); + STAssertTrue([[_query query] hasSuffix:query], @"select query group by multiple fields"); } +- (void)testSelectQueryGroupByMultipleFieldsWithoutQuotesIsCorrect +{ + [_query setUseQuotes:NO]; + [_query groupByFields:[NSArray arrayWithObjects:QKTestFieldOne, QKTestFieldTwo, nil]]; + + NSString *query = [NSString stringWithFormat:@"GROUP BY %@, %@", QKTestFieldOne, QKTestFieldTwo]; + + STAssertTrue([[_query query] hasSuffix:query], @"select query group by multiple fields without quotes"); +} @end diff --git a/Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.m b/Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.m index ac70f0fe..cb1a472f 100644 --- a/Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.m +++ b/Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.m @@ -29,16 +29,12 @@ // OTHER DEALINGS IN THE SOFTWARE. #import "QKSelectQueryOrderByTests.h" - -static NSString *QKTestTableName = @"test_table"; - -static NSString *QKTestFieldOne = @"test_field1"; -static NSString *QKTestFieldTwo = @"test_field2"; +#import "QKTestConstants.h" @implementation QKSelectQueryOrderByTests #pragma mark - -#pragma mark Setup & tear down +#pragma mark Setup - (void)setUp { @@ -53,43 +49,83 @@ static NSString *QKTestFieldTwo = @"test_field2"; - (void)testSelectQueryTypeIsCorrect { - STAssertTrue([[_query query] hasPrefix:@"SELECT"], @"query type"); + STAssertTrue([[_query query] hasPrefix:@"SELECT"], @"select query type"); } - (void)testSelectQueryOrderByAscendingIsCorrect { [_query orderByField:QKTestFieldOne descending:NO]; + NSString *query = [NSString stringWithFormat:@"ORDER BY `%@` ASC", QKTestFieldOne]; + + STAssertTrue([[_query query] hasSuffix:query], @"select query order by"); +} + +- (void)testSelectQueryOrderByAscendingWithoutQuotesIsCorrect +{ + [_query setUseQuotes:NO]; + [_query orderByField:QKTestFieldOne descending:NO]; + NSString *query = [NSString stringWithFormat:@"ORDER BY %@ ASC", QKTestFieldOne]; - STAssertTrue([[_query query] hasSuffix:query], @"query order by"); + STAssertTrue([[_query query] hasSuffix:query], @"select query order by without quotes"); } - (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], @"select query order by multiple fields ascending when quoted"); +} + +- (void)testSelectQueryOrderByMultipleFieldsAscendingWithoutQuotesIsCorrect +{ + [_query setUseQuotes:NO]; + [_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"); + STAssertTrue([[_query query] hasSuffix:query], @"select query order by multiple fields ascending without quotes"); } - (void)testSelectQueryOrderByDescendingIsCorrect { [_query orderByField:QKTestFieldOne descending:YES]; + NSString *query = [NSString stringWithFormat:@"ORDER BY `%@` DESC", QKTestFieldOne]; + + STAssertTrue([[_query query] hasSuffix:query], @"select query order by descending"); +} + +- (void)testSelectQueryOrderByDescendingWithoutQuotesIsCorrect +{ + [_query setUseQuotes:NO]; + [_query orderByField:QKTestFieldOne descending:YES]; + NSString *query = [NSString stringWithFormat:@"ORDER BY %@ DESC", QKTestFieldOne]; - STAssertTrue([[_query query] hasSuffix:query], @"query order by"); + STAssertTrue([[_query query] hasSuffix:query], @"select query order by descending without quotes"); } - (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], @"select query order by multiple fields descending"); +} + +- (void)testSelectQueryOrderByMultipleFieldsDescendingWithoutQuotesIsCorrect +{ + [_query setUseQuotes:NO]; + [_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"); + STAssertTrue([[_query query] hasSuffix:query], @"select query order by multiple fields descending without quotes"); } @end diff --git a/Frameworks/QueryKit/Tests/QKSelectQueryTests.m b/Frameworks/QueryKit/Tests/QKSelectQueryTests.m index cb2d3599..75cf7ed2 100644 --- a/Frameworks/QueryKit/Tests/QKSelectQueryTests.m +++ b/Frameworks/QueryKit/Tests/QKSelectQueryTests.m @@ -29,20 +29,12 @@ // OTHER DEALINGS IN THE SOFTWARE. #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; +#import "QKTestConstants.h" @implementation QKSelectQueryTests #pragma mark - -#pragma mark Setup & tear down +#pragma mark Setup - (void)setUp { @@ -61,21 +53,55 @@ static NSUInteger QKTestParameterOne = 10; - (void)testSelectQueryTypeIsCorrect { - STAssertTrue([[_query query] hasPrefix:@"SELECT"], @"query type"); + STAssertTrue([[_query query] hasPrefix:@"SELECT"], @"select query type"); +} + +- (void)testSelectQueryFieldIsCorrect +{ + NSString *query = [NSString stringWithFormat:@"SELECT `%@`", QKTestFieldOne]; + + STAssertTrue([[_query query] hasPrefix:query], @"select query field"); +} + +- (void)testSelectQueryFieldWithoutQuotesIsCorrect +{ + [_query setUseQuotes:NO]; + + NSString *query = [NSString stringWithFormat:@"SELECT %@", QKTestFieldOne]; + + STAssertTrue([[_query query] hasPrefix:query], @"select query field without quotes"); +} + +- (void)testSelectQueryMultipleFieldsWhenQuotedAreCorrect +{ + NSString *query = [NSString stringWithFormat:@"SELECT `%@`, `%@`, `%@`, `%@`", QKTestFieldOne, QKTestFieldTwo, QKTestFieldThree, QKTestFieldFour]; + + STAssertTrue([[_query query] hasPrefix:query], @"select query multiple fields"); } -- (void)testSelectQueryFieldsAreCorrect +- (void)testSelectQueryMultipleFieldsWithoutQuotesAreCorrect { + [_query setUseQuotes:NO]; + NSString *query = [NSString stringWithFormat:@"SELECT %@, %@, %@, %@", QKTestFieldOne, QKTestFieldTwo, QKTestFieldThree, QKTestFieldFour]; - - STAssertTrue([[_query query] hasPrefix:query], @"query fields"); + + STAssertTrue([[_query query] hasPrefix:query], @"select query multiple fields without quotes"); } - (void)testSelectQueryConstraintsAreCorrect { + NSString *query = [NSString stringWithFormat:@"WHERE `%@` %@ %@", QKTestFieldOne, [QKQueryUtilities operatorRepresentationForType:QKEqualityOperator], [NSNumber numberWithUnsignedInteger:QKTestParameterOne]]; + + STAssertTrue(([[_query query] rangeOfString:query].location != NSNotFound), @"select query constraint"); +} + +- (void)testSelectQueryConstraintsWithoutQuotesAreCorrect +{ + [_query setUseQuotes:NO]; + NSString *query = [NSString stringWithFormat:@"WHERE %@ %@ %@", QKTestFieldOne, [QKQueryUtilities operatorRepresentationForType:QKEqualityOperator], [NSNumber numberWithUnsignedInteger:QKTestParameterOne]]; - STAssertTrue(([[_query query] rangeOfString:query].location != NSNotFound), @"query constraints"); + STAssertTrue(([[_query query] rangeOfString:query].location != NSNotFound), @"select query constraint without quotes"); } @end diff --git a/Frameworks/QueryKit/Tests/QKTestConstants.h b/Frameworks/QueryKit/Tests/QKTestConstants.h new file mode 100644 index 00000000..920ff060 --- /dev/null +++ b/Frameworks/QueryKit/Tests/QKTestConstants.h @@ -0,0 +1,41 @@ +// +// $Id$ +// +// QKTestConstants.h +// QueryKit +// +// Created by Stuart Connolly (stuconnolly.com) on July 8, 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. + +extern NSString *QKTestTableName; + +extern NSString *QKTestFieldOne; +extern NSString *QKTestFieldTwo; +extern NSString *QKTestFieldThree; +extern NSString *QKTestFieldFour; + +extern NSString *QKTestUpdateValueOne; +extern NSString *QKTestUpdateValueTwo; + +extern NSUInteger QKTestParameterOne;
\ No newline at end of file diff --git a/Frameworks/QueryKit/Tests/QKTestConstants.m b/Frameworks/QueryKit/Tests/QKTestConstants.m new file mode 100644 index 00000000..419d2987 --- /dev/null +++ b/Frameworks/QueryKit/Tests/QKTestConstants.m @@ -0,0 +1,41 @@ +// +// $Id$ +// +// QKTestConstants.m +// QueryKit +// +// Created by Stuart Connolly (stuconnolly.com) on July 8, 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. + +NSString *QKTestTableName = @"test_table"; + +NSString *QKTestFieldOne = @"test_field1"; +NSString *QKTestFieldTwo = @"test_field2"; +NSString *QKTestFieldThree = @"test_field3"; +NSString *QKTestFieldFour = @"test_field4"; + +NSString *QKTestUpdateValueOne = @"update_one"; +NSString *QKTestUpdateValueTwo = @"update_two"; + +NSUInteger QKTestParameterOne = 10;
\ No newline at end of file diff --git a/Frameworks/QueryKit/Tests/QKUpdateQueryTests.m b/Frameworks/QueryKit/Tests/QKUpdateQueryTests.m index fa3bb766..6a24881d 100644 --- a/Frameworks/QueryKit/Tests/QKUpdateQueryTests.m +++ b/Frameworks/QueryKit/Tests/QKUpdateQueryTests.m @@ -29,21 +29,12 @@ // OTHER DEALINGS IN THE SOFTWARE. #import "QKUpdateQueryTests.h" - -static NSString *QKTestTableName = @"test_table"; - -static NSString *QKTestFieldOne = @"test_field1"; -static NSString *QKTestFieldTwo = @"test_field2"; - -static NSString *QKTestUpdateValueOne = @"update_one"; -static NSString *QKTestUpdateValueTwo = @"update_two"; - -static NSUInteger QKTestParameterOne = 10; +#import "QKTestConstants.h" @implementation QKUpdateQueryTests #pragma mark - -#pragma mark Setup & tear down +#pragma mark Setup - (void)setUp { @@ -62,21 +53,39 @@ static NSUInteger QKTestParameterOne = 10; - (void)testUpdateQueryTypeIsCorrect { - STAssertTrue([[_query query] hasPrefix:@"UPDATE"], @"query type"); + STAssertTrue([[_query query] hasPrefix:@"UPDATE"], @"update query type"); } - (void)testUpdateQueryFieldsAreCorrect { + NSString *query = [NSString stringWithFormat:@"UPDATE `%@` SET `%@` = '%@', `%@` = '%@'", QKTestTableName, QKTestFieldOne, QKTestUpdateValueOne, QKTestFieldTwo, QKTestUpdateValueTwo]; + + STAssertTrue([[_query query] hasPrefix:query], @"update query fields"); +} + +- (void)testUpdateQueryFieldsWithoutQuotesAreCorrect +{ + [_query setUseQuotes:NO]; + NSString *query = [NSString stringWithFormat:@"UPDATE %@ SET %@ = '%@', %@ = '%@'", QKTestTableName, QKTestFieldOne, QKTestUpdateValueOne, QKTestFieldTwo, QKTestUpdateValueTwo]; + + STAssertTrue([[_query query] hasPrefix:query], @"update query fields without quotes"); +} + +- (void)testUpdateQueryConstraintIsCorrect +{ + NSString *query = [NSString stringWithFormat:@"WHERE `%@` %@ %@", QKTestFieldOne, [QKQueryUtilities operatorRepresentationForType:QKEqualityOperator], [NSNumber numberWithUnsignedInteger:QKTestParameterOne]]; - STAssertTrue([[_query query] hasPrefix:query], @"query fields"); + STAssertTrue(([[_query query] rangeOfString:query].location != NSNotFound), @"update query constraint"); } -- (void)testUpdateQueryConstraintsAreCorrect +- (void)testUpdateQueryConstraintWithoutQuotesIsCorrect { + [_query setUseQuotes:NO]; + NSString *query = [NSString stringWithFormat:@"WHERE %@ %@ %@", QKTestFieldOne, [QKQueryUtilities operatorRepresentationForType:QKEqualityOperator], [NSNumber numberWithUnsignedInteger:QKTestParameterOne]]; - STAssertTrue(([[_query query] rangeOfString:query].location != NSNotFound), @"query constraints"); + STAssertTrue(([[_query query] rangeOfString:query].location != NSNotFound), @"update query constraint without quotes"); } @end |