aboutsummaryrefslogtreecommitdiffstats
path: root/Frameworks/QueryKit
diff options
context:
space:
mode:
Diffstat (limited to 'Frameworks/QueryKit')
-rw-r--r--Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj30
-rw-r--r--Frameworks/QueryKit/Source/QKQuery.h13
-rw-r--r--Frameworks/QueryKit/Source/QKQuery.m101
-rw-r--r--Frameworks/QueryKit/Source/QKQueryConstruct.h55
-rw-r--r--Frameworks/QueryKit/Source/QKQueryConstruct.m60
-rw-r--r--Frameworks/QueryKit/Source/QKQueryGenericParameter.h16
-rw-r--r--Frameworks/QueryKit/Source/QKQueryGenericParameter.m16
-rw-r--r--Frameworks/QueryKit/Source/QKQueryOrderBy.h60
-rw-r--r--Frameworks/QueryKit/Source/QKQueryOrderBy.m81
-rw-r--r--Frameworks/QueryKit/Source/QKQueryStringAdditions.m4
-rw-r--r--Frameworks/QueryKit/Source/QueryKit.h1
-rw-r--r--Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.m28
-rw-r--r--Frameworks/QueryKit/Tests/QKUpdateQueryTests.m2
13 files changed, 362 insertions, 105 deletions
diff --git a/Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj b/Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj
index decc195b..acdf559c 100644
--- a/Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj
+++ b/Frameworks/QueryKit/QueryKit.xcodeproj/project.pbxproj
@@ -32,6 +32,10 @@
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 */; };
+ 17F48BA815B27F6400C6455B /* QKQueryOrderBy.h in Headers */ = {isa = PBXBuildFile; fileRef = 17F48BA615B27F6400C6455B /* QKQueryOrderBy.h */; settings = {ATTRIBUTES = (Public, ); }; };
+ 17F48BA915B27F6500C6455B /* QKQueryOrderBy.m in Sources */ = {isa = PBXBuildFile; fileRef = 17F48BA715B27F6400C6455B /* QKQueryOrderBy.m */; };
+ 17F48BC315B289C100C6455B /* QKQueryConstruct.h in Headers */ = {isa = PBXBuildFile; fileRef = 17F48BC115B289C100C6455B /* QKQueryConstruct.h */; settings = {ATTRIBUTES = (Public, ); }; };
+ 17F48BC415B289C100C6455B /* QKQueryConstruct.m in Sources */ = {isa = PBXBuildFile; fileRef = 17F48BC215B289C100C6455B /* QKQueryConstruct.m */; };
17F620BE14F961C1003E7290 /* QueryKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8DC2EF5B0486A6940098B216 /* QueryKit.framework */; };
/* End PBXBuildFile section */
@@ -78,6 +82,10 @@
17E5969814F307B70054EE08 /* QKSelectQueryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QKSelectQueryTests.m; sourceTree = "<group>"; };
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 = "<group>"; };
+ 17F48BA615B27F6400C6455B /* QKQueryOrderBy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QKQueryOrderBy.h; sourceTree = "<group>"; };
+ 17F48BA715B27F6400C6455B /* QKQueryOrderBy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QKQueryOrderBy.m; sourceTree = "<group>"; };
+ 17F48BC115B289C100C6455B /* QKQueryConstruct.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QKQueryConstruct.h; sourceTree = "<group>"; };
+ 17F48BC215B289C100C6455B /* QKQueryConstruct.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QKQueryConstruct.m; sourceTree = "<group>"; };
32DBCF5E0370ADEE00C91783 /* QueryKit-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "QueryKit-Prefix.pch"; path = "Source/QueryKit-Prefix.pch"; sourceTree = "<group>"; };
8DC2EF5A0486A6940098B216 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = Resources/Info.plist; sourceTree = "<group>"; };
8DC2EF5B0486A6940098B216 /* QueryKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = QueryKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -161,12 +169,13 @@
1719E47A151E8C87003F98C5 /* Model */ = {
isa = PBXGroup;
children = (
+ 17F48BC515B28A4D00C6455B /* Common */,
+ 17F48BA615B27F6400C6455B /* QKQueryOrderBy.h */,
+ 17F48BA715B27F6400C6455B /* QKQueryOrderBy.m */,
17E5951914F301DF0054EE08 /* QKQueryParameter.h */,
17E5951A14F301DF0054EE08 /* QKQueryParameter.m */,
1719E47B151E8CA7003F98C5 /* QKQueryUpdateParameter.h */,
1719E47C151E8CA7003F98C5 /* QKQueryUpdateParameter.m */,
- 1757801C15A9A14400CDF67A /* QKQueryGenericParameter.h */,
- 1757801D15A9A14400CDF67A /* QKQueryGenericParameter.m */,
);
name = Model;
sourceTree = "<group>";
@@ -221,7 +230,6 @@
17577FC315A99AA500CDF67A /* Other */ = {
isa = PBXGroup;
children = (
- 17577FC415A99AC000CDF67A /* QKQueryConstants.h */,
1726979315AEE939009586E1 /* QKQueryStringAdditions.h */,
1726979415AEE939009586E1 /* QKQueryStringAdditions.m */,
);
@@ -234,6 +242,7 @@
17E5951B14F301DF0054EE08 /* QKQueryTypes.h */,
17E5951814F301DF0054EE08 /* QKQueryOperators.h */,
1726976515AC3DD2009586E1 /* QKQueryDatabases.h */,
+ 17577FC415A99AC000CDF67A /* QKQueryConstants.h */,
);
name = Constants;
sourceTree = "<group>";
@@ -250,6 +259,17 @@
path = Tests;
sourceTree = "<group>";
};
+ 17F48BC515B28A4D00C6455B /* Common */ = {
+ isa = PBXGroup;
+ children = (
+ 17F48BC115B289C100C6455B /* QKQueryConstruct.h */,
+ 17F48BC215B289C100C6455B /* QKQueryConstruct.m */,
+ 1757801C15A9A14400CDF67A /* QKQueryGenericParameter.h */,
+ 1757801D15A9A14400CDF67A /* QKQueryGenericParameter.m */,
+ );
+ name = Common;
+ sourceTree = "<group>";
+ };
/* End PBXGroup section */
/* Begin PBXHeadersBuildPhase section */
@@ -268,6 +288,8 @@
1757801E15A9A14400CDF67A /* QKQueryGenericParameter.h in Headers */,
1726976715AC3DD2009586E1 /* QKQueryDatabases.h in Headers */,
1726979515AEE939009586E1 /* QKQueryStringAdditions.h in Headers */,
+ 17F48BA815B27F6400C6455B /* QKQueryOrderBy.h in Headers */,
+ 17F48BC315B289C100C6455B /* QKQueryConstruct.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -387,6 +409,8 @@
1719E47E151E8CA7003F98C5 /* QKQueryUpdateParameter.m in Sources */,
1757801F15A9A14400CDF67A /* QKQueryGenericParameter.m in Sources */,
1726979615AEE939009586E1 /* QKQueryStringAdditions.m in Sources */,
+ 17F48BA915B27F6500C6455B /* QKQueryOrderBy.m in Sources */,
+ 17F48BC415B289C100C6455B /* QKQueryConstruct.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
diff --git a/Frameworks/QueryKit/Source/QKQuery.h b/Frameworks/QueryKit/Source/QKQuery.h
index 117da9b3..9eb0a621 100644
--- a/Frameworks/QueryKit/Source/QKQuery.h
+++ b/Frameworks/QueryKit/Source/QKQuery.h
@@ -31,8 +31,10 @@
#import "QKQueryTypes.h"
#import "QKQueryDatabases.h"
#import "QKQueryOperators.h"
-#import "QKQueryParameter.h"
-#import "QKQueryUpdateParameter.h"
+
+@class QKQueryOrderBy;
+@class QKQueryParameter;
+@class QKQueryUpdateParameter;
/**
* @class QKQuery QKQuery.h
@@ -59,7 +61,6 @@
QKQueryDatabase _queryDatabase;
BOOL _useQuotedIdentifiers;
- BOOL _orderDescending;
}
/**
@@ -100,7 +101,7 @@
/**
* @property _useQuotedIdentifiers Indicates whether or not the query's fields should be quoted.
*/
-@property(readwrite, assign, getter=useQuotedIdentifiers) BOOL _useQuotedIdentifiers;
+@property(readwrite, assign, getter=useQuotedIdentifiers, setter=setUseQuotedIdentifiers:) BOOL _useQuotedIdentifiers;
/**
* @property _groupByFields The group by fields of the query.
@@ -129,8 +130,6 @@
- (NSString *)query;
- (void)clear;
-- (void)setUseQuotedIdentifiers:(BOOL)quote;
-
- (void)addField:(NSString *)field;
- (void)addFields:(NSArray *)fields;
@@ -143,7 +142,7 @@
- (void)groupByField:(NSString *)field;
- (void)groupByFields:(NSArray *)fields;
+- (void)orderBy:(QKQueryOrderBy *)orderBy;
- (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
index 3834bd82..01dfa1fc 100644
--- a/Frameworks/QueryKit/Source/QKQuery.m
+++ b/Frameworks/QueryKit/Source/QKQuery.m
@@ -29,8 +29,12 @@
// OTHER DEALINGS IN THE SOFTWARE.
#import "QKQuery.h"
+#import "QKQueryTypes.h"
+#import "QKQueryOrderBy.h"
#import "QKQueryUtilities.h"
#import "QKQueryConstants.h"
+#import "QKQueryParameter.h"
+#import "QKQueryUpdateParameter.h"
#import "QKQueryGenericParameter.h"
static NSString *QKNoQueryTypeException = @"QKNoQueryType";
@@ -39,6 +43,7 @@ static NSString *QKNoQueryTableException = @"QKNoQueryTable";
@interface QKQuery ()
- (void)_validateRequiements;
+- (void)_configureQuoteIdentifiers;
- (NSString *)_buildQuery;
- (NSString *)_buildFieldList;
@@ -117,7 +122,6 @@ static NSString *QKNoQueryTableException = @"QKNoQueryTable";
// Default to MySQL
[self setQueryDatabase:QKDatabaseMySQL];
- _orderDescending = NO;
_identifierQuote = EMPTY_STRING;
_groupByFields = [[NSMutableArray alloc] init];
@@ -165,29 +169,6 @@ static NSString *QKNoQueryTableException = @"QKNoQueryTable";
}
#pragma mark -
-#pragma mark Accessors
-
-/**
- * Sets whether to quote identifiers in the query.
- *
- * @param quote A BOOL indicating whether quoting should be used.
- */
-- (void)setUseQuotedIdentifiers:(BOOL)quote
-{
- _useQuotedIdentifiers = quote;
-
- for (QKQueryParameter *param in _parameters)
- {
- [param setUseQuotedIdentifier:_useQuotedIdentifiers];
- }
-
- for (QKQueryUpdateParameter *param in _updateParameters)
- {
- [param setUseQuotedIdentifier:_useQuotedIdentifiers];
- }
-}
-
-#pragma mark -
#pragma mark Fields
/**
@@ -295,30 +276,26 @@ static NSString *QKNoQueryTableException = @"QKNoQueryTable";
#pragma mark Ordering
/**
- * Adds the supplied field to the query's ORDER BY clause.
+ * Adds the supplied order by instance to this query.
*
- * @param field The field to ORDER BY.
- * @param descending Indicates whether the ORDER BY should be descending.
+ * @param orderBy The order by instance to add.
*/
-- (void)orderByField:(NSString *)field descending:(BOOL)descending
+- (void)orderBy:(QKQueryOrderBy *)orderBy
{
- _orderDescending = descending;
-
- [self _addString:field toArray:_orderByFields];
+ if ([orderBy orderByField] && [[orderBy orderByField] length] > 0) {
+ [_orderByFields addObject:orderBy];
+ }
}
/**
- * Convenience method for adding more than one field to the query's ORDER BY clause.
+ * Convenience method for adding a field to ORDER BY.
*
- * @param fields An array of fields to ORDER BY.
+ * @param field The field to ORDER BY.
* @param descending Indicates whether the ORDER BY should be descending.
*/
-- (void)orderByFields:(NSArray *)fields descending:(BOOL)descending
+- (void)orderByField:(NSString *)field descending:(BOOL)descending
{
- for (NSString *field in fields)
- {
- [self orderByField:field descending:descending];
- }
+ [self orderBy:[QKQueryOrderBy orderByField:field descending:descending]];
}
#pragma mark -
@@ -339,6 +316,32 @@ static NSString *QKNoQueryTableException = @"QKNoQueryTable";
}
/**
+ * Configures the query's parameters, update parameters and order by field's quote identifier settings.
+ */
+- (void)_configureQuoteIdentifiers
+{
+ _identifierQuote = [QKQueryUtilities identifierQuoteCharacterForDatabase:_queryDatabase];
+
+ for (QKQueryParameter *param in _parameters)
+ {
+ [param setIdentifierQuote:_identifierQuote];
+ [param setUseQuotedIdentifier:_useQuotedIdentifiers];
+ }
+
+ for (QKQueryOrderBy *orderBy in _orderByFields)
+ {
+ [orderBy setIdentifierQuote:_identifierQuote];
+ [orderBy setUseQuotedIdentifier:_useQuotedIdentifiers];
+ }
+
+ for (QKQueryUpdateParameter *param in _updateParameters)
+ {
+ [param setIdentifierQuote:_identifierQuote];
+ [param setUseQuotedIdentifier:_useQuotedIdentifiers];
+ }
+}
+
+/**
* Builds the actual query.
*
* @return The built SQL query.
@@ -352,18 +355,8 @@ static NSString *QKNoQueryTableException = @"QKNoQueryTable";
BOOL isUpdate = _queryType == QKUpdateQuery;
BOOL isDelete = _queryType == QKDeleteQuery;
- if ([self useQuotedIdentifiers]) {
- _identifierQuote = [QKQueryUtilities identifierQuoteCharacterForDatabase:_queryDatabase];
-
- for (QKQueryParameter *param in _parameters)
- {
- [param setIdentifierQuote:_identifierQuote];
- }
-
- for (QKQueryUpdateParameter *param in _updateParameters)
- {
- [param setIdentifierQuote:_identifierQuote];
- }
+ if (_useQuotedIdentifiers) {
+ [self _configureQuoteIdentifiers];
}
NSString *fields = [self _buildFieldList];
@@ -495,17 +488,15 @@ static NSString *QKNoQueryTableException = @"QKNoQueryTable";
[orderBy appendString:@"ORDER BY "];
- for (NSString *field in _orderByFields)
+ for (NSString *orderByField in _orderByFields)
{
- [orderBy appendFormat:@"%1$@%2$@%1$@, ", _identifierQuote, field];
+ [orderBy appendFormat:@"%@, ", orderByField];
}
if ([orderBy hasSuffix:@", "]) {
[orderBy setString:[orderBy substringToIndex:([orderBy length] - 2)]];
}
-
- [orderBy appendString:_orderDescending ? @" DESC" : @" ASC"];
-
+
return orderBy;
}
diff --git a/Frameworks/QueryKit/Source/QKQueryConstruct.h b/Frameworks/QueryKit/Source/QKQueryConstruct.h
new file mode 100644
index 00000000..be3ab220
--- /dev/null
+++ b/Frameworks/QueryKit/Source/QKQueryConstruct.h
@@ -0,0 +1,55 @@
+//
+// $Id$
+//
+// QKQueryConstruct.h
+// QueryKit
+//
+// Created by Stuart Connolly (stuconnolly.com) on July 15, 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.
+
+/**
+ * @class QKQueryConstruct QKQueryConstruct.h
+ *
+ * @author Stuart Connolly http://stuconnolly.com/
+ *
+ * Acts as a base of all SQL constructs and provides various common properties.
+ */
+@interface QKQueryConstruct : NSObject
+{
+ BOOL _useQuotedIdentifier;
+
+ NSString *_identiferQuote;
+}
+
+/**
+ * @property _identifierQuote The quoute character to use for identifiers.
+ */
+@property(readwrite, retain, getter=identifierQuote, setter=setIdentifierQuote:) NSString *_identiferQuote;
+
+/**
+ * @property _useQuotedIdentifier Indicates whether or not identifiers should be quoted.
+ */
+@property(readwrite, assign, getter=useQuotedIdentifier, setter=setUseQuotedIdentifier:) BOOL _useQuotedIdentifier;
+
+@end
diff --git a/Frameworks/QueryKit/Source/QKQueryConstruct.m b/Frameworks/QueryKit/Source/QKQueryConstruct.m
new file mode 100644
index 00000000..db432add
--- /dev/null
+++ b/Frameworks/QueryKit/Source/QKQueryConstruct.m
@@ -0,0 +1,60 @@
+//
+// $Id$
+//
+// QKQueryConstruct.m
+// QueryKit
+//
+// Created by Stuart Connolly (stuconnolly.com) on July 15, 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 "QKQueryConstruct.h"
+
+@implementation QKQueryConstruct
+
+@synthesize _useQuotedIdentifier;
+@synthesize _identiferQuote;
+
+#pragma mark -
+#pragma mark Initialisation
+
+- (id)init
+{
+ if ((self = [super init])) {
+ [self setUseQuotedIdentifier:YES];
+ [self setIdentifierQuote:EMPTY_STRING];
+ }
+
+ return self;
+}
+
+#pragma mark -
+
+- (void)dealloc
+{
+ if (_identiferQuote) [_identiferQuote release], _identiferQuote = nil;
+
+ [super dealloc];
+}
+
+@end
diff --git a/Frameworks/QueryKit/Source/QKQueryGenericParameter.h b/Frameworks/QueryKit/Source/QKQueryGenericParameter.h
index 562689f5..1c782b6a 100644
--- a/Frameworks/QueryKit/Source/QKQueryGenericParameter.h
+++ b/Frameworks/QueryKit/Source/QKQueryGenericParameter.h
@@ -28,13 +28,13 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
-@interface QKQueryGenericParameter : NSObject
+#import "QKQueryConstruct.h"
+
+@interface QKQueryGenericParameter : QKQueryConstruct
{
id _value;
- BOOL _useQuotedIdentifier;
NSString *_field;
- NSString *_identiferQuote;
}
/**
@@ -43,16 +43,6 @@
@property(readwrite, retain, getter=field, setter=setField:) NSString *_field;
/**
- * @property _identifierQuote
- */
-@property(readwrite, retain, getter=identifierQuote, setter=setIdentifierQuote:) NSString *_identiferQuote;
-
-/**
- * @property _useQuotedIdentifier Indicates whether or not this parameters field should be quoted.
- */
-@property(readwrite, assign, getter=useQuotedIdentifier, setter=setUseQuotedIdentifier:) BOOL _useQuotedIdentifier;
-
-/**
*@property _value The value component of the parameter.
*/
@property(readwrite, retain, getter=value, setter=setValue:) id _value;
diff --git a/Frameworks/QueryKit/Source/QKQueryGenericParameter.m b/Frameworks/QueryKit/Source/QKQueryGenericParameter.m
index efaf10d3..57fe58c7 100644
--- a/Frameworks/QueryKit/Source/QKQueryGenericParameter.m
+++ b/Frameworks/QueryKit/Source/QKQueryGenericParameter.m
@@ -28,29 +28,15 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
+#import "QKQueryConstruct.h"
#import "QKQueryGenericParameter.h"
@implementation QKQueryGenericParameter
@synthesize _field;
-@synthesize _useQuotedIdentifier;
-@synthesize _identiferQuote;
@synthesize _value;
#pragma mark -
-#pragma mark Initialisation
-
-- (id)init
-{
- if ((self = [super init])) {
- [self setUseQuotedIdentifier:YES];
- [self setIdentifierQuote:EMPTY_STRING];
- }
-
- return self;
-}
-
-#pragma mark -
- (void)dealloc
{
diff --git a/Frameworks/QueryKit/Source/QKQueryOrderBy.h b/Frameworks/QueryKit/Source/QKQueryOrderBy.h
new file mode 100644
index 00000000..aa7a80e7
--- /dev/null
+++ b/Frameworks/QueryKit/Source/QKQueryOrderBy.h
@@ -0,0 +1,60 @@
+//
+// $Id$
+//
+// QKQueryOrderBy.h
+// QueryKit
+//
+// Created by Stuart Connolly (stuconnolly.com) on July 15, 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 "QKQueryConstruct.h"
+
+/**
+ * @class QKQueryOrderBy QKQueryOrderBy.h
+ *
+ * @author Stuart Connolly http://stuconnolly.com/
+ *
+ * QueryKit SELECT query ORDER BY class.
+ */
+@interface QKQueryOrderBy : QKQueryConstruct
+{
+ NSString *_orderByField;
+ BOOL _orderByDescending;
+}
+
+/**
+ * @property _orderByField
+ */
+@property(readwrite, retain, getter=orderByField, setter=setOrderByField:) NSString *_orderByField;
+
+/**
+ * @property _orderByDescending
+ */
+@property(readwrite, assign, getter=orderByDescending, setter=setOrderByDescending:) BOOL _orderByDescending;
+
++ (QKQueryOrderBy *)orderByField:(NSString *)field descending:(BOOL)descending;
+
+- (id)initWithField:(NSString *)field descending:(BOOL)descending;
+
+@end
diff --git a/Frameworks/QueryKit/Source/QKQueryOrderBy.m b/Frameworks/QueryKit/Source/QKQueryOrderBy.m
new file mode 100644
index 00000000..36b43248
--- /dev/null
+++ b/Frameworks/QueryKit/Source/QKQueryOrderBy.m
@@ -0,0 +1,81 @@
+//
+// $Id$
+//
+// QKQueryOrderBy.m
+// QueryKit
+//
+// Created by Stuart Connolly (stuconnolly.com) on July 15, 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 "QKQueryOrderBy.h"
+
+@implementation QKQueryOrderBy
+
+@synthesize _orderByField;
+@synthesize _orderByDescending;
+
+#pragma mark -
+#pragma mark Initialisation
+
++ (QKQueryOrderBy *)orderByField:(NSString *)field descending:(BOOL)descending
+{
+ return [[[QKQueryOrderBy alloc] initWithField:field descending:descending] autorelease];
+}
+
+- (id)init
+{
+ return [self initWithField:nil descending:NO];
+}
+
+- (id)initWithField:(NSString *)field descending:(BOOL)descending
+{
+ if ((self = [super init])) {
+ [self setOrderByField:field];
+ [self setOrderByDescending:descending];
+ }
+
+ return self;
+}
+
+#pragma mark -
+
+- (NSString *)description
+{
+ if (!_orderByField || [_orderByField length] == 0) return EMPTY_STRING;
+
+ NSString *field = [_orderByField stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
+
+ return [NSString stringWithFormat:@"%1$@%2$@%1$@ %3$@", [self useQuotedIdentifier] ? _identiferQuote : EMPTY_STRING, field, _orderByDescending ? @"DESC" : @"ASC"];
+}
+
+#pragma mark -
+
+- (void)dealloc
+{
+ if (_orderByField) [_orderByField release], _orderByField = nil;
+
+ [super dealloc];
+}
+
+@end
diff --git a/Frameworks/QueryKit/Source/QKQueryStringAdditions.m b/Frameworks/QueryKit/Source/QKQueryStringAdditions.m
index 7c87e458..d2167041 100644
--- a/Frameworks/QueryKit/Source/QKQueryStringAdditions.m
+++ b/Frameworks/QueryKit/Source/QKQueryStringAdditions.m
@@ -35,7 +35,9 @@
/**
* Returns the string quoted with supplied character.
*
- * @return The quoted string
+ * @param character The character (as a string) to use.
+ *
+ * @return The quoted string.
*/
- (NSString *)quotedStringWithCharacter:(NSString *)character
{
diff --git a/Frameworks/QueryKit/Source/QueryKit.h b/Frameworks/QueryKit/Source/QueryKit.h
index 624ba08b..0ae6b406 100644
--- a/Frameworks/QueryKit/Source/QueryKit.h
+++ b/Frameworks/QueryKit/Source/QueryKit.h
@@ -30,6 +30,7 @@
#import <QueryKit/QKQuery.h>
#import <QueryKit/QKQueryTypes.h>
+#import <QueryKit/QKQueryOrderBy.h>
#import <QueryKit/QKQueryOperators.h>
#import <QueryKit/QKQueryDatabases.h>
#import <QueryKit/QKQueryParameter.h>
diff --git a/Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.m b/Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.m
index 4ea01e4a..5f5c7356 100644
--- a/Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.m
+++ b/Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.m
@@ -55,10 +55,10 @@
- (void)testSelectQueryOrderByAscendingIsCorrect
{
[_query orderByField:QKTestFieldOne descending:NO];
-
+
NSString *query = [NSString stringWithFormat:@"ORDER BY `%@` ASC", QKTestFieldOne];
- STAssertTrue([[_query query] hasSuffix:query], @"select query order by");
+ STAssertTrue([[_query query] hasSuffix:query], @"");
}
- (void)testSelectQueryOrderByAscendingWithoutQuotesIsCorrect
@@ -73,9 +73,10 @@
- (void)testSelectQueryOrderByMultipleFieldsAscendingIsCorrect
{
- [_query orderByFields:[NSArray arrayWithObjects:QKTestFieldOne, QKTestFieldTwo, nil] descending:NO];
-
- NSString *query = [NSString stringWithFormat:@"ORDER BY `%@`, `%@` ASC", QKTestFieldOne, QKTestFieldTwo];
+ [_query orderByField:QKTestFieldOne descending:NO];
+ [_query orderByField:QKTestFieldTwo descending:NO];
+
+ NSString *query = [NSString stringWithFormat:@"ORDER BY `%@` ASC, `%@` ASC", QKTestFieldOne, QKTestFieldTwo];
STAssertTrue([[_query query] hasSuffix:query], @"select query order by multiple fields ascending when quoted");
}
@@ -83,9 +84,11 @@
- (void)testSelectQueryOrderByMultipleFieldsAscendingWithoutQuotesIsCorrect
{
[_query setUseQuotedIdentifiers:NO];
- [_query orderByFields:[NSArray arrayWithObjects:QKTestFieldOne, QKTestFieldTwo, nil] descending:NO];
- NSString *query = [NSString stringWithFormat:@"ORDER BY %@, %@ ASC", QKTestFieldOne, QKTestFieldTwo];
+ [_query orderByField:QKTestFieldOne descending:NO];
+ [_query orderByField:QKTestFieldTwo descending:NO];
+
+ NSString *query = [NSString stringWithFormat:@"ORDER BY %@ ASC, %@ ASC", QKTestFieldOne, QKTestFieldTwo];
STAssertTrue([[_query query] hasSuffix:query], @"select query order by multiple fields ascending without quotes");
}
@@ -111,9 +114,10 @@
- (void)testSelectQueryOrderByMultipleFieldsDescendingIsCorrect
{
- [_query orderByFields:[NSArray arrayWithObjects:QKTestFieldOne, QKTestFieldTwo, nil] descending:YES];
+ [_query orderByField:QKTestFieldOne descending:YES];
+ [_query orderByField:QKTestFieldTwo descending:YES];
- NSString *query = [NSString stringWithFormat:@"ORDER BY `%@`, `%@` DESC", QKTestFieldOne, QKTestFieldTwo];
+ NSString *query = [NSString stringWithFormat:@"ORDER BY `%@` DESC, `%@` DESC", QKTestFieldOne, QKTestFieldTwo];
STAssertTrue([[_query query] hasSuffix:query], @"select query order by multiple fields descending");
}
@@ -121,9 +125,11 @@
- (void)testSelectQueryOrderByMultipleFieldsDescendingWithoutQuotesIsCorrect
{
[_query setUseQuotedIdentifiers:NO];
- [_query orderByFields:[NSArray arrayWithObjects:QKTestFieldOne, QKTestFieldTwo, nil] descending:YES];
- NSString *query = [NSString stringWithFormat:@"ORDER BY %@, %@ DESC", QKTestFieldOne, QKTestFieldTwo];
+ [_query orderByField:QKTestFieldOne descending:YES];
+ [_query orderByField:QKTestFieldTwo descending:YES];
+
+ NSString *query = [NSString stringWithFormat:@"ORDER BY %@ DESC, %@ DESC", QKTestFieldOne, QKTestFieldTwo];
STAssertTrue([[_query query] hasSuffix:query], @"select query order by multiple fields descending without quotes");
}
diff --git a/Frameworks/QueryKit/Tests/QKUpdateQueryTests.m b/Frameworks/QueryKit/Tests/QKUpdateQueryTests.m
index 65c31dae..cd1fb848 100644
--- a/Frameworks/QueryKit/Tests/QKUpdateQueryTests.m
+++ b/Frameworks/QueryKit/Tests/QKUpdateQueryTests.m
@@ -78,6 +78,8 @@
{
NSString *query = [NSString stringWithFormat:@"WHERE `%@` %@ %@", QKTestFieldOne, [QKQueryUtilities stringRepresentationOfQueryOperator:QKEqualityOperator], [NSNumber numberWithUnsignedInteger:QKTestParameterOne]];
+ NSLog(@"%@", [_query query]);
+
STAssertTrue(([[_query query] rangeOfString:query].location != NSNotFound), @"update query constraint");
}
625'>1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523