aboutsummaryrefslogtreecommitdiffstats
path: root/Frameworks
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2012-07-15 10:15:11 +0000
committerstuconnolly <stuart02@gmail.com>2012-07-15 10:15:11 +0000
commitcb00d18102f8c3f88e8a15bb4d9fb7825cf29a59 (patch)
tree8c266026ae92013dbc028a09d7d98e22bbcfbd5f /Frameworks
parentdd2c7e34d265c7a4a66b7583a186456095b545ee (diff)
downloadsequelpro-cb00d18102f8c3f88e8a15bb4d9fb7825cf29a59.tar.gz
sequelpro-cb00d18102f8c3f88e8a15bb4d9fb7825cf29a59.tar.bz2
sequelpro-cb00d18102f8c3f88e8a15bb4d9fb7825cf29a59.zip
Add a new order by class.
Diffstat (limited to 'Frameworks')
-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");
}
='n1662' href='#n1662'>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