nano-store 0.6.2 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +8 -4
- data/Rakefile +1 -1
- data/lib/nano_store.rb +2 -4
- data/lib/nano_store/version.rb +1 -1
- data/spec/model_spec.rb +14 -0
- data/spec/spec_helper.rb +4 -0
- data/vendor/Podfile.lock +4 -4
- data/vendor/Pods/BuildHeaders/NanoStore/NSFNanoGlobals.h +3 -1
- data/vendor/Pods/BuildHeaders/NanoStore/NSFNanoPredicate.h +5 -5
- data/vendor/Pods/BuildHeaders/NanoStore/NSFNanoSearch.h +5 -3
- data/vendor/Pods/BuildHeaders/NanoStore/NSFNanoSortDescriptor.h +1 -1
- data/vendor/Pods/BuildHeaders/NanoStore/NanoStore.h +36 -0
- data/vendor/Pods/Documentation/NanoStore/docset-installed.txt +2 -2
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Info.plist +3 -3
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/Documents/Classes/NSFNanoBag.html +2 -2
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/Documents/Classes/NSFNanoEngine.html +2 -2
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/Documents/Classes/NSFNanoExpression.html +2 -2
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/Documents/Classes/NSFNanoObject.html +2 -2
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/Documents/Classes/NSFNanoPredicate.html +7 -7
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/Documents/Classes/NSFNanoResult.html +2 -2
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/Documents/Classes/NSFNanoSearch.html +66 -5
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/Documents/Classes/NSFNanoSortDescriptor.html +3 -3
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/Documents/Classes/NSFNanoStore.html +2 -2
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/Documents/Classes/NSFOrderedDictionary.html +2 -2
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/Documents/Protocols/NSFNanoObjectProtocol.html +2 -2
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/Documents/css/styles.css +0 -0
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/Documents/hierarchy.html +5 -5
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/Documents/index.html +5 -5
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/Nodes.xml +1 -1
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/Tokens5.xml +6 -6
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/Tokens7.xml +24 -2
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/Tokens8.xml +2 -2
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/docSet.dsidx +0 -0
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/docSet.skidx +0 -0
- data/vendor/Pods/Documentation/NanoStore/docset/Contents/Resources/docSet.toc +0 -0
- data/vendor/Pods/Documentation/NanoStore/html/Classes/NSFNanoBag.html +2 -2
- data/vendor/Pods/Documentation/NanoStore/html/Classes/NSFNanoEngine.html +2 -2
- data/vendor/Pods/Documentation/NanoStore/html/Classes/NSFNanoExpression.html +2 -2
- data/vendor/Pods/Documentation/NanoStore/html/Classes/NSFNanoObject.html +2 -2
- data/vendor/Pods/Documentation/NanoStore/html/Classes/NSFNanoPredicate.html +7 -7
- data/vendor/Pods/Documentation/NanoStore/html/Classes/NSFNanoResult.html +2 -2
- data/vendor/Pods/Documentation/NanoStore/html/Classes/NSFNanoSearch.html +66 -5
- data/vendor/Pods/Documentation/NanoStore/html/Classes/NSFNanoSortDescriptor.html +3 -3
- data/vendor/Pods/Documentation/NanoStore/html/Classes/NSFNanoStore.html +2 -2
- data/vendor/Pods/Documentation/NanoStore/html/Classes/NSFOrderedDictionary.html +2 -2
- data/vendor/Pods/Documentation/NanoStore/html/Protocols/NSFNanoObjectProtocol.html +2 -2
- data/vendor/Pods/Documentation/NanoStore/html/css/styles.css +0 -0
- data/vendor/Pods/Documentation/NanoStore/html/hierarchy.html +5 -5
- data/vendor/Pods/Documentation/NanoStore/html/index.html +5 -5
- data/vendor/Pods/Headers/NanoStore/NSFNanoGlobals.h +3 -1
- data/vendor/Pods/Headers/NanoStore/NSFNanoPredicate.h +5 -5
- data/vendor/Pods/Headers/NanoStore/NSFNanoSearch.h +5 -3
- data/vendor/Pods/Headers/NanoStore/NSFNanoSortDescriptor.h +1 -1
- data/vendor/Pods/Headers/NanoStore/NanoStore.h +36 -0
- data/vendor/Pods/NanoStore/Classes/Advanced/NSFNanoEngine.m +40 -49
- data/vendor/Pods/NanoStore/Classes/Advanced/NSFNanoResult.m +42 -53
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoBag.m +80 -89
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoExpression.m +11 -13
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoGlobals.h +3 -1
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoGlobals.m +1 -0
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoObject.m +34 -29
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoPredicate.h +5 -5
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoPredicate.m +43 -34
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoSearch.h +5 -3
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoSearch.m +171 -97
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoSortDescriptor.h +1 -1
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoSortDescriptor.m +13 -12
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoStore.m +92 -86
- data/vendor/Pods/NanoStore/Classes/Public/NanoStore.h +36 -0
- data/vendor/Pods/Pods-resources.sh +8 -4
- data/vendor/Pods/Pods.bridgesupport +109 -101
- metadata +5 -5
@@ -31,13 +31,11 @@
|
|
31
31
|
@implementation NSFNanoExpression
|
32
32
|
{
|
33
33
|
/** \cond */
|
34
|
-
NSMutableArray
|
35
|
-
NSMutableArray
|
34
|
+
NSMutableArray *_predicates;
|
35
|
+
NSMutableArray *_operators;
|
36
36
|
/** \endcond */
|
37
37
|
}
|
38
38
|
|
39
|
-
@synthesize predicates, operators;
|
40
|
-
|
41
39
|
+ (NSFNanoExpression*)expressionWithPredicate:(NSFNanoPredicate *)aPredicate
|
42
40
|
{
|
43
41
|
return [[self alloc]initWithPredicate:aPredicate];
|
@@ -52,10 +50,10 @@
|
|
52
50
|
}
|
53
51
|
|
54
52
|
if ((self = [super init])) {
|
55
|
-
|
56
|
-
[
|
57
|
-
|
58
|
-
[
|
53
|
+
_predicates = [NSMutableArray new];
|
54
|
+
[_predicates addObject:aPredicate];
|
55
|
+
_operators = [NSMutableArray new];
|
56
|
+
[_operators addObject:[NSNumber numberWithInt:NSFAnd]];
|
59
57
|
}
|
60
58
|
|
61
59
|
return self;
|
@@ -75,8 +73,8 @@
|
|
75
73
|
reason:[NSString stringWithFormat:@"*** -[%@ %@]: the predicate is nil.", [self class], NSStringFromSelector(_cmd)]
|
76
74
|
userInfo:nil]raise];
|
77
75
|
|
78
|
-
[
|
79
|
-
[
|
76
|
+
[_predicates addObject:aPredicate];
|
77
|
+
[_operators addObject:[NSNumber numberWithInt:someOperator]];
|
80
78
|
}
|
81
79
|
|
82
80
|
- (NSString *)description
|
@@ -88,14 +86,14 @@
|
|
88
86
|
|
89
87
|
- (NSArray *)arrayDescription
|
90
88
|
{
|
91
|
-
NSUInteger i, count = [
|
89
|
+
NSUInteger i, count = [_predicates count];
|
92
90
|
NSMutableArray *values = [NSMutableArray new];
|
93
91
|
|
94
92
|
// We always have one predicate, so make sure add it
|
95
|
-
[values addObject:[[
|
93
|
+
[values addObject:[[_predicates objectAtIndex:0]description]];
|
96
94
|
|
97
95
|
for (i = 1; i < count; i++) {
|
98
|
-
NSString *compound = [[NSString alloc]initWithFormat:@" %@ %@", ([[
|
96
|
+
NSString *compound = [[NSString alloc]initWithFormat:@" %@ %@", ([[_operators objectAtIndex:i]intValue] == NSFAnd) ? @"AND" : @"OR", [[_predicates objectAtIndex:i]description]];
|
99
97
|
[values addObject:compound];
|
100
98
|
}
|
101
99
|
|
@@ -85,6 +85,7 @@ NSString * NSFStringFromMatchType (NSFMatchType aMatchType)
|
|
85
85
|
case NSFInsensitiveEndsWith: value = @"Ends with (case insensitive)"; break;
|
86
86
|
case NSFGreaterThan: value = @"Greater than"; break;
|
87
87
|
case NSFLessThan: value = @"Less than"; break;
|
88
|
+
case NSFNotEqualTo: value = @"Not equal to"; break;
|
88
89
|
}
|
89
90
|
|
90
91
|
return value;
|
@@ -30,13 +30,18 @@
|
|
30
30
|
#import "NSFNanoGlobals_Private.h"
|
31
31
|
#import "NSFOrderedDictionary.h"
|
32
32
|
|
33
|
+
@interface NSFNanoObject ()
|
34
|
+
/** \cond */
|
35
|
+
@property (nonatomic, weak, readwrite) NSFNanoStore *store;
|
36
|
+
@property (nonatomic, copy, readwrite) NSString *key;
|
37
|
+
/** \endcond */
|
38
|
+
@end
|
39
|
+
|
33
40
|
@implementation NSFNanoObject
|
34
41
|
{
|
35
|
-
NSMutableDictionary *
|
42
|
+
NSMutableDictionary *_info;
|
36
43
|
}
|
37
44
|
|
38
|
-
@synthesize info, key, originalClassString;
|
39
|
-
|
40
45
|
+ (NSFNanoObject *)nanoObject
|
41
46
|
{
|
42
47
|
return [[self alloc]initNanoObjectFromDictionaryRepresentation:nil forKey:nil store:nil];
|
@@ -69,13 +74,13 @@
|
|
69
74
|
if ((self = [self init])) {
|
70
75
|
// If we have supplied a key, honor it and overwrite the original one
|
71
76
|
if (nil != aKey) {
|
72
|
-
|
77
|
+
_key = aKey;
|
73
78
|
}
|
74
79
|
|
75
80
|
// Keep the dictionary if needed
|
76
81
|
if (nil != aDictionary) {
|
77
|
-
|
78
|
-
[
|
82
|
+
_info = [NSMutableDictionary new];
|
83
|
+
[_info addEntriesFromDictionary:aDictionary];
|
79
84
|
}
|
80
85
|
|
81
86
|
_store = aStore;
|
@@ -99,10 +104,10 @@
|
|
99
104
|
NSFOrderedDictionary *values = [NSFOrderedDictionary new];
|
100
105
|
|
101
106
|
values[@"NanoObject address"] = [NSString stringWithFormat:@"%p", self];
|
102
|
-
values[@"Original class"] = (nil !=
|
103
|
-
values[@"Key"] =
|
104
|
-
values[@"Property count"] = @([
|
105
|
-
values[@"Contents"] =
|
107
|
+
values[@"Original class"] = (nil != _originalClassString) ? _originalClassString : NSStringFromClass ([self class]);
|
108
|
+
values[@"Key"] = _key;
|
109
|
+
values[@"Property count"] = @([_info count]);
|
110
|
+
values[@"Contents"] = _info;
|
106
111
|
|
107
112
|
return values;
|
108
113
|
}
|
@@ -120,41 +125,41 @@
|
|
120
125
|
- (void)addEntriesFromDictionary:(NSDictionary *)otherDictionary
|
121
126
|
{
|
122
127
|
// Allocate the dictionary if needed
|
123
|
-
if (nil ==
|
124
|
-
|
128
|
+
if (nil == _info) {
|
129
|
+
_info = [NSMutableDictionary new];
|
125
130
|
}
|
126
131
|
|
127
|
-
[
|
132
|
+
[_info addEntriesFromDictionary:otherDictionary];
|
128
133
|
}
|
129
134
|
|
130
135
|
- (void)setObject:(id)anObject forKey:(NSString *)aKey
|
131
136
|
{
|
132
137
|
// Allocate the dictionary if needed
|
133
|
-
if (nil ==
|
134
|
-
|
138
|
+
if (nil == _info) {
|
139
|
+
_info = [NSMutableDictionary new];
|
135
140
|
}
|
136
141
|
|
137
|
-
[
|
142
|
+
[_info setObject:anObject forKey:aKey];
|
138
143
|
}
|
139
144
|
|
140
145
|
- (id)objectForKey:(NSString *)aKey
|
141
146
|
{
|
142
|
-
return [
|
147
|
+
return [_info objectForKey:aKey];
|
143
148
|
}
|
144
149
|
|
145
150
|
- (void)removeObjectForKey:(NSString *)aKey
|
146
151
|
{
|
147
|
-
[
|
152
|
+
[_info removeObjectForKey:aKey];
|
148
153
|
}
|
149
154
|
|
150
155
|
- (void)removeAllObjects
|
151
156
|
{
|
152
|
-
[
|
157
|
+
[_info removeAllObjects];
|
153
158
|
}
|
154
159
|
|
155
160
|
- (void)removeObjectsForKeys:(NSArray *)keyArray
|
156
161
|
{
|
157
|
-
[
|
162
|
+
[_info removeObjectsForKeys:keyArray];
|
158
163
|
}
|
159
164
|
|
160
165
|
- (BOOL)isEqualToNanoObject:(NSFNanoObject *)otherNanoObject
|
@@ -165,14 +170,14 @@
|
|
165
170
|
|
166
171
|
BOOL success = YES;
|
167
172
|
|
168
|
-
if (
|
169
|
-
if (NO == [
|
173
|
+
if (_originalClassString != otherNanoObject.originalClassString) {
|
174
|
+
if (NO == [_originalClassString isEqualToString:otherNanoObject.originalClassString]) {
|
170
175
|
success = NO;
|
171
176
|
}
|
172
177
|
}
|
173
178
|
|
174
179
|
if (YES == success) {
|
175
|
-
success = [
|
180
|
+
success = [_info isEqualToDictionary:otherNanoObject.info];
|
176
181
|
}
|
177
182
|
|
178
183
|
return success;
|
@@ -195,9 +200,9 @@
|
|
195
200
|
- (id)init
|
196
201
|
{
|
197
202
|
if ((self = [super init])) {
|
198
|
-
|
199
|
-
|
200
|
-
|
203
|
+
_key = [NSFNanoEngine stringWithUUID];
|
204
|
+
_info = nil;
|
205
|
+
_originalClassString = nil;
|
201
206
|
_store = nil;
|
202
207
|
}
|
203
208
|
|
@@ -225,7 +230,7 @@
|
|
225
230
|
|
226
231
|
- (id)rootObject
|
227
232
|
{
|
228
|
-
return
|
233
|
+
return _info;
|
229
234
|
}
|
230
235
|
|
231
236
|
#pragma mark -
|
@@ -234,8 +239,8 @@
|
|
234
239
|
|
235
240
|
- (void)_setOriginalClassString:(NSString *)theClassString
|
236
241
|
{
|
237
|
-
if (
|
238
|
-
|
242
|
+
if (_originalClassString != theClassString) {
|
243
|
+
_originalClassString = theClassString;
|
239
244
|
}
|
240
245
|
}
|
241
246
|
|
@@ -77,7 +77,7 @@
|
|
77
77
|
/** * The comparison operator to be used. */
|
78
78
|
@property (nonatomic, assign, readonly) NSFMatchType match;
|
79
79
|
/** * The value to be used for comparison. */
|
80
|
-
@property (nonatomic,
|
80
|
+
@property (nonatomic, readonly) id value;
|
81
81
|
|
82
82
|
/** @name Creating and Initializing a Predicate
|
83
83
|
*/
|
@@ -87,22 +87,22 @@
|
|
87
87
|
/** * Creates and returns a predicate.
|
88
88
|
* @param theType is the column type. Can be \link Globals::NSFKeyColumn NSFKeyColumn \endlink, \link Globals::NSFAttributeColumn NSFAttributeColumn \endlink or \link Globals::NSFValueColumn NSFValueColumn \endlink.
|
89
89
|
* @param theMatch is the match operator.
|
90
|
-
* @param theValue
|
90
|
+
* @param theValue can be an NSString or [NSNull null]
|
91
91
|
* @return A predicate which can be used in an NSFNanoExpression.
|
92
92
|
* @see \link initWithColumn:matching:value: - (id)initWithColumn:(NSFTableColumnType)theType matching:(NSFMatchType)theMatch value:(NSString *)theValue \endlink
|
93
93
|
*/
|
94
94
|
|
95
|
-
+ (NSFNanoPredicate*)predicateWithColumn:(NSFTableColumnType)theType matching:(NSFMatchType)theMatch value:(
|
95
|
+
+ (NSFNanoPredicate*)predicateWithColumn:(NSFTableColumnType)theType matching:(NSFMatchType)theMatch value:(id)theValue;
|
96
96
|
|
97
97
|
/** * Initializes a newly allocated predicate.
|
98
98
|
* @param theType is the column type. Can be \link Globals::NSFKeyColumn NSFKeyColumn \endlink, \link Globals::NSFAttributeColumn NSFAttributeColumn \endlink or \link Globals::NSFValueColumn NSFValueColumn \endlink.
|
99
99
|
* @param theMatch is the match operator.
|
100
|
-
* @param theValue
|
100
|
+
* @param theValue can be an NSString or [NSNull null]
|
101
101
|
* @return A predicate which can be used in an NSFNanoExpression.
|
102
102
|
* @see \link predicateWithColumn:matching:value: + (NSFNanoPredicate*)predicateWithColumn:(NSFTableColumnType)theType matching:(NSFMatchType)theMatch value:(NSString *)theValue \endlink
|
103
103
|
*/
|
104
104
|
|
105
|
-
- (id)initWithColumn:(NSFTableColumnType)theType matching:(NSFMatchType)theMatch value:(
|
105
|
+
- (id)initWithColumn:(NSFTableColumnType)theType matching:(NSFMatchType)theMatch value:(id)theValue;
|
106
106
|
|
107
107
|
//@}
|
108
108
|
|
@@ -28,35 +28,36 @@
|
|
28
28
|
#import "NanoStore_Private.h"
|
29
29
|
#import "NSFOrderedDictionary.h"
|
30
30
|
|
31
|
-
@
|
31
|
+
@interface NSFNanoPredicate ()
|
32
|
+
|
33
|
+
/** \cond */
|
34
|
+
@property (nonatomic, assign, readwrite) NSFTableColumnType column;
|
35
|
+
@property (nonatomic, assign, readwrite) NSFMatchType match;
|
36
|
+
@property (nonatomic, readwrite) id value;
|
37
|
+
/** \endcond */
|
32
38
|
|
33
|
-
@
|
39
|
+
@end
|
40
|
+
|
41
|
+
@implementation NSFNanoPredicate
|
34
42
|
|
35
43
|
// ----------------------------------------------
|
36
44
|
// Initialization / Cleanup
|
37
45
|
// ----------------------------------------------
|
38
46
|
|
39
|
-
+ (NSFNanoPredicate*)predicateWithColumn:(NSFTableColumnType)type matching:(NSFMatchType)matching value:(
|
47
|
+
+ (NSFNanoPredicate*)predicateWithColumn:(NSFTableColumnType)type matching:(NSFMatchType)matching value:(id)aValue
|
40
48
|
{
|
41
|
-
if (nil == aValue)
|
42
|
-
[[NSException exceptionWithName:NSFUnexpectedParameterException
|
43
|
-
reason:[NSString stringWithFormat:@"*** -[%@ %@]: value is nil.", [self class], NSStringFromSelector(_cmd)]
|
44
|
-
userInfo:nil]raise];
|
45
|
-
|
46
49
|
return [[self alloc]initWithColumn:type matching:matching value:aValue];
|
47
50
|
}
|
48
51
|
|
49
|
-
- (id)initWithColumn:(NSFTableColumnType)type matching:(NSFMatchType)matching value:(
|
52
|
+
- (id)initWithColumn:(NSFTableColumnType)type matching:(NSFMatchType)matching value:(id)aValue
|
50
53
|
{
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
userInfo:nil]raise];
|
55
|
-
|
54
|
+
NSAssert(nil != aValue, @"*** -[%@ %@]: value is nil.", [self class], NSStringFromSelector(_cmd));
|
55
|
+
NSAssert([aValue isKindOfClass:[NSString class]] || [aValue isKindOfClass:[NSNull class]], @"*** -[%@ %@]: value must be of type NSString or NSNull.", [self class], NSStringFromSelector(_cmd));
|
56
|
+
|
56
57
|
if ((self = [super init])) {
|
57
|
-
|
58
|
-
|
59
|
-
|
58
|
+
_column = type;
|
59
|
+
_match = matching;
|
60
|
+
_value = aValue;
|
60
61
|
}
|
61
62
|
|
62
63
|
return self;
|
@@ -75,7 +76,7 @@
|
|
75
76
|
NSMutableString *mutatedString = nil;
|
76
77
|
NSInteger mutatedStringLength = 0;
|
77
78
|
|
78
|
-
switch (
|
79
|
+
switch (_column) {
|
79
80
|
case NSFKeyColumn:
|
80
81
|
columnValue = NSFKey;
|
81
82
|
break;
|
@@ -88,44 +89,52 @@
|
|
88
89
|
}
|
89
90
|
|
90
91
|
// Make sure we escape quotes if present and the value is a string
|
91
|
-
|
92
|
+
if (YES == [_value isKindOfClass:[NSString class]]) {
|
93
|
+
_value = [_value stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
|
94
|
+
} else {
|
95
|
+
_value = NSFStringFromNanoDataType(NSFNanoTypeNULL);
|
96
|
+
columnValue = NSFDatatype;
|
97
|
+
}
|
92
98
|
|
93
|
-
switch (
|
99
|
+
switch (_match) {
|
94
100
|
case NSFEqualTo:
|
95
|
-
[values addObject:[NSString stringWithFormat:@"%@ = '%@'", columnValue,
|
101
|
+
[values addObject:[NSString stringWithFormat:@"%@ = '%@'", columnValue, _value]];
|
96
102
|
break;
|
97
103
|
case NSFBeginsWith:
|
98
|
-
mutatedString = [NSMutableString stringWithString:
|
99
|
-
mutatedStringLength = [
|
104
|
+
mutatedString = [NSMutableString stringWithString:_value];
|
105
|
+
mutatedStringLength = [_value length];
|
100
106
|
[mutatedString replaceCharactersInRange:NSMakeRange(mutatedStringLength - 1, 1) withString:[NSString stringWithFormat:@"%c", [mutatedString characterAtIndex:mutatedStringLength - 1]+1]];
|
101
|
-
[values addObject:[NSString stringWithFormat:@"(%@ >= '%@' AND %@ < '%@')", columnValue,
|
107
|
+
[values addObject:[NSString stringWithFormat:@"(%@ >= '%@' AND %@ < '%@')", columnValue, _value, columnValue, mutatedString]];
|
102
108
|
break;
|
103
109
|
case NSFContains:
|
104
|
-
[values addObject:[NSString stringWithFormat:@"%@ GLOB '*%@*'", columnValue,
|
110
|
+
[values addObject:[NSString stringWithFormat:@"%@ GLOB '*%@*'", columnValue, _value]];
|
105
111
|
break;
|
106
112
|
case NSFEndsWith:
|
107
|
-
[values addObject:[NSString stringWithFormat:@"%@ GLOB '*%@'", columnValue,
|
113
|
+
[values addObject:[NSString stringWithFormat:@"%@ GLOB '*%@'", columnValue, _value]];
|
108
114
|
break;
|
109
115
|
case NSFInsensitiveEqualTo:
|
110
|
-
[values addObject:[NSString stringWithFormat:@"upper(%@) = '%@'", columnValue, [
|
116
|
+
[values addObject:[NSString stringWithFormat:@"upper(%@) = '%@'", columnValue, [_value uppercaseString]]];
|
111
117
|
break;
|
112
118
|
case NSFInsensitiveBeginsWith:
|
113
|
-
mutatedString = [NSMutableString stringWithString:
|
114
|
-
mutatedStringLength = [
|
119
|
+
mutatedString = [NSMutableString stringWithString:_value];
|
120
|
+
mutatedStringLength = [_value length];
|
115
121
|
[mutatedString replaceCharactersInRange:NSMakeRange(mutatedStringLength - 1, 1) withString:[NSString stringWithFormat:@"%c", [mutatedString characterAtIndex:mutatedStringLength - 1]+1]];
|
116
|
-
[values addObject:[NSString stringWithFormat:@"(upper(%@) >= '%@' AND upper(%@) < '%@')", columnValue, [
|
122
|
+
[values addObject:[NSString stringWithFormat:@"(upper(%@) >= '%@' AND upper(%@) < '%@')", columnValue, [_value uppercaseString], columnValue, [mutatedString uppercaseString]]];
|
117
123
|
break;
|
118
124
|
case NSFInsensitiveContains:
|
119
|
-
[values addObject:[NSString stringWithFormat:@"%@ LIKE '%@%@%@'", columnValue, @"%",
|
125
|
+
[values addObject:[NSString stringWithFormat:@"%@ LIKE '%@%@%@'", columnValue, @"%", _value, @"%"]];
|
120
126
|
break;
|
121
127
|
case NSFInsensitiveEndsWith:
|
122
|
-
[values addObject:[NSString stringWithFormat:@"%@ LIKE '%@%@'", columnValue, @"%",
|
128
|
+
[values addObject:[NSString stringWithFormat:@"%@ LIKE '%@%@'", columnValue, @"%", _value]];
|
123
129
|
break;
|
124
130
|
case NSFGreaterThan:
|
125
|
-
[values addObject:[NSString stringWithFormat:@"%@ > '%@'", columnValue,
|
131
|
+
[values addObject:[NSString stringWithFormat:@"%@ > '%@'", columnValue, _value]];
|
126
132
|
break;
|
127
133
|
case NSFLessThan:
|
128
|
-
[values addObject:[NSString stringWithFormat:@"%@ < '%@'", columnValue,
|
134
|
+
[values addObject:[NSString stringWithFormat:@"%@ < '%@'", columnValue, _value]];
|
135
|
+
break;
|
136
|
+
case NSFNotEqualTo:
|
137
|
+
[values addObject:[NSString stringWithFormat:@"%@ <> '%@'", columnValue, _value]];
|
129
138
|
break;
|
130
139
|
}
|
131
140
|
|
@@ -175,11 +175,13 @@
|
|
175
175
|
/** * The sort holds an array of one or more sort descriptors of type \link NSFNanoSortDescriptor NSFNanoSortDescriptor \endlink. */
|
176
176
|
@property (nonatomic, strong, readwrite) NSArray *sort;
|
177
177
|
/** * The filterClass allows to filter the results based on a specific object class. */
|
178
|
-
@property (nonatomic,
|
178
|
+
@property (nonatomic, copy, readwrite) NSString *filterClass;
|
179
179
|
/** * If an expression has an offset clause, then the first M rows are omitted from the result set returned by the search operation and the next N rows are returned, where M and N are the values that the offset and limit clauses evaluate to, respectively. Or, if the search would return less than M+N rows if it did not have a limit clause, then the first M rows are skipped and the remaining rows (if any) are returned. */
|
180
180
|
@property (nonatomic, assign, readwrite) NSUInteger offset;
|
181
181
|
/** * The limit clause is used to place an upper bound on the number of rows returned by a Search operation. */
|
182
182
|
@property (nonatomic, assign, readwrite) NSUInteger limit;
|
183
|
+
/** * limit a Search to a particular bag. */
|
184
|
+
@property (nonatomic, assign, readwrite) NSFNanoBag *bag;
|
183
185
|
|
184
186
|
/** @name Creating and Initializing a Search
|
185
187
|
*/
|
@@ -213,7 +215,7 @@
|
|
213
215
|
* @param theReturnType the type of object to be returned. Can be \link Globals::NSFReturnObjects NSFReturnObjects \endlink or \link Globals::NSFReturnKeys NSFReturnKeys \endlink.
|
214
216
|
* @param outError is used if an error occurs. May be NULL.
|
215
217
|
* @return An array is returned if: 1) the sort has been specified or 2) the return type is \link Globals::NSFReturnKeys NSFReturnKeys \endlink. Otherwise, a dictionary is returned.
|
216
|
-
* @note The sort descriptor will be ignored when
|
218
|
+
* @note The sort descriptor will be ignored when the return type is NSFReturnKeys.
|
217
219
|
* @see \link searchObjectsAdded:date:returnType:error: - (id)searchObjectsAdded:(NSFDateMatchType)theDateMatch date:(NSDate *)theDate returnType:(NSFReturnType)theReturnType error:(out NSError **)outError \endlink
|
218
220
|
*/
|
219
221
|
|
@@ -225,7 +227,7 @@
|
|
225
227
|
* @param theReturnType the type of object to be returned. Can be \link Globals::NSFReturnObjects NSFReturnObjects \endlink or \link Globals::NSFReturnKeys NSFReturnKeys \endlink.
|
226
228
|
* @param outError is used if an error occurs. May be NULL.
|
227
229
|
* @return If theReturnType is \link Globals::NSFReturnObjects NSFReturnObjects \endlink, a dictionary is returned. Otherwise, an array is returned.
|
228
|
-
* @note The sort descriptor will be ignored when
|
230
|
+
* @note The sort descriptor will be ignored when the return type is NSFReturnKeys.
|
229
231
|
* @see \link searchObjectsWithReturnType:error: - (id)searchObjectsWithReturnType:(NSFReturnType)theReturnType error:(out NSError **)outError \endlink
|
230
232
|
*/
|
231
233
|
|
@@ -29,16 +29,15 @@
|
|
29
29
|
#import "NSFNanoSearch_Private.h"
|
30
30
|
#import "NSFNanoExpression_Private.h"
|
31
31
|
|
32
|
-
@
|
33
|
-
{
|
34
|
-
/** \cond */
|
35
|
-
@protected
|
36
|
-
NSFReturnType returnedObjectType;
|
37
|
-
/** \endcond */
|
38
|
-
}
|
32
|
+
@interface NSFNanoSearch ()
|
39
33
|
|
34
|
+
/** \cond */
|
35
|
+
@property (nonatomic, copy, readwrite) NSString *sql;
|
36
|
+
@property (nonatomic) NSFReturnType returnedObjectType;
|
37
|
+
/** \endcond */
|
38
|
+
@end
|
40
39
|
|
41
|
-
@
|
40
|
+
@implementation NSFNanoSearch
|
42
41
|
|
43
42
|
// ----------------------------------------------
|
44
43
|
// Initialization / Cleanup
|
@@ -58,7 +57,7 @@
|
|
58
57
|
}
|
59
58
|
|
60
59
|
if ((self = [self init])) {
|
61
|
-
|
60
|
+
_nanoStore = store;
|
62
61
|
[self reset];
|
63
62
|
}
|
64
63
|
|
@@ -78,10 +77,10 @@
|
|
78
77
|
|
79
78
|
- (NSString *)sql
|
80
79
|
{
|
81
|
-
if (nil ==
|
80
|
+
if (nil == _sql)
|
82
81
|
return [self _preparedSQL];
|
83
82
|
|
84
|
-
return
|
83
|
+
return _sql;
|
85
84
|
}
|
86
85
|
|
87
86
|
#pragma mark -
|
@@ -105,8 +104,8 @@
|
|
105
104
|
[self reset];
|
106
105
|
self.sort = savedSort;
|
107
106
|
|
108
|
-
|
109
|
-
|
107
|
+
_returnedObjectType = theReturnType;
|
108
|
+
_sql = theSQLStatement;
|
110
109
|
|
111
110
|
NSDictionary *results = [self _retrieveDataWithError:outError];
|
112
111
|
|
@@ -130,9 +129,9 @@
|
|
130
129
|
// Make sure we don't have any lingering parameters that could mess with the results...
|
131
130
|
[self reset];
|
132
131
|
|
133
|
-
|
132
|
+
_sql = theSQLStatement;
|
134
133
|
|
135
|
-
return [
|
134
|
+
return [_nanoStore _executeSQL:theSQLStatement];
|
136
135
|
}
|
137
136
|
|
138
137
|
- (NSFNanoResult *)explainSQL:(NSString *)theSQLStatement
|
@@ -149,32 +148,32 @@
|
|
149
148
|
userInfo:nil]raise];
|
150
149
|
}
|
151
150
|
|
152
|
-
return [
|
151
|
+
return [_nanoStore _executeSQL:[NSString stringWithFormat:@"EXPLAIN %@", theSQLStatement]];
|
153
152
|
}
|
154
153
|
|
155
154
|
- (void)reset
|
156
155
|
{
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
156
|
+
_attributesToBeReturned = nil;
|
157
|
+
_key = nil;
|
158
|
+
_attribute = nil;
|
159
|
+
_value = nil;
|
160
|
+
_match = NSFContains;
|
161
|
+
_groupValues = NO;
|
162
|
+
_sql = nil;
|
163
|
+
_sort = nil;
|
164
|
+
_offset = 0;
|
165
|
+
_limit = 0;
|
166
|
+
_returnedObjectType = NSFReturnObjects;
|
168
167
|
}
|
169
168
|
|
170
169
|
#pragma mark -
|
171
170
|
|
172
171
|
- (id)searchObjectsWithReturnType:(NSFReturnType)theReturnType error:(out NSError **)outError
|
173
172
|
{
|
174
|
-
|
173
|
+
_returnedObjectType = theReturnType;
|
175
174
|
|
176
175
|
// Make sure we don't have a SQL statement around...
|
177
|
-
|
176
|
+
_sql = nil;
|
178
177
|
|
179
178
|
id results = [self _retrieveDataWithError:outError];
|
180
179
|
|
@@ -183,10 +182,10 @@
|
|
183
182
|
|
184
183
|
- (id)searchObjectsAdded:(NSFDateMatchType)theDateMatch date:(NSDate *)theDate returnType:(NSFReturnType)theReturnType error:(out NSError **)outError
|
185
184
|
{
|
186
|
-
|
185
|
+
_returnedObjectType = theReturnType;
|
187
186
|
|
188
187
|
// Make sure we don't have a SQL statement around...
|
189
|
-
|
188
|
+
_sql = nil;
|
190
189
|
|
191
190
|
id results = [self _retrieveDataAdded:theDateMatch calendarDate:theDate error:outError];
|
192
191
|
|
@@ -199,11 +198,11 @@
|
|
199
198
|
|
200
199
|
- (NSNumber *)aggregateOperation:(NSFAggregateFunctionType)theFunctionType onAttribute:(NSString *)theAttribute
|
201
200
|
{
|
202
|
-
NSFReturnType savedObjectTypeReturned =
|
203
|
-
|
201
|
+
NSFReturnType savedObjectTypeReturned = _returnedObjectType;
|
202
|
+
_returnedObjectType = NSFReturnKeys;
|
204
203
|
|
205
|
-
NSString *savedSQL =
|
206
|
-
|
204
|
+
NSString *savedSQL = _sql;
|
205
|
+
_sql = nil;
|
207
206
|
|
208
207
|
NSString *theSearchSQLStatement = [self sql];
|
209
208
|
NSMutableString *theAggregatedSQLStatement = [NSMutableString new];
|
@@ -232,10 +231,10 @@
|
|
232
231
|
break;
|
233
232
|
}
|
234
233
|
|
235
|
-
NSFNanoResult *result = [
|
234
|
+
NSFNanoResult *result = [_nanoStore _executeSQL:theAggregatedSQLStatement];
|
236
235
|
|
237
|
-
|
238
|
-
|
236
|
+
_returnedObjectType = savedObjectTypeReturned;
|
237
|
+
_sql = savedSQL;
|
239
238
|
|
240
239
|
return [NSNumber numberWithFloat:[[result firstValue]floatValue]];
|
241
240
|
}
|
@@ -248,13 +247,13 @@
|
|
248
247
|
|
249
248
|
- (NSDictionary *)_retrieveDataWithError:(out NSError **)outError
|
250
249
|
{
|
251
|
-
if (YES == [
|
250
|
+
if (YES == [_nanoStore isClosed]) {
|
252
251
|
return nil;
|
253
252
|
}
|
254
253
|
|
255
254
|
NSMutableDictionary *searchResults = [NSMutableDictionary dictionary];
|
256
255
|
|
257
|
-
NSString *aSQLQuery =
|
256
|
+
NSString *aSQLQuery = _sql;
|
258
257
|
|
259
258
|
if (nil != aSQLQuery) {
|
260
259
|
// We are going to check whether the user has specified the proper columns based on the search type selected.
|
@@ -263,7 +262,7 @@
|
|
263
262
|
// We basically honor the specified query but replace the columns with the expected ones per returned type.
|
264
263
|
|
265
264
|
NSString *subStatement = [aSQLQuery substringFromIndex:[aSQLQuery rangeOfString:@"FROM" options:NSCaseInsensitiveSearch].location];
|
266
|
-
NSFReturnType returnType =
|
265
|
+
NSFReturnType returnType = _returnedObjectType;
|
267
266
|
switch (returnType) {
|
268
267
|
case NSFReturnKeys:
|
269
268
|
aSQLQuery = [NSString stringWithFormat:@"SELECT NSFKey %@", subStatement];
|
@@ -278,7 +277,7 @@
|
|
278
277
|
|
279
278
|
_NSFLog(@"_dataWithKey SQL query: %@", aSQLQuery);
|
280
279
|
|
281
|
-
sqlite3 *sqliteStore = [[
|
280
|
+
sqlite3 *sqliteStore = [[_nanoStore nanoStoreEngine]sqlite];
|
282
281
|
sqlite3_stmt *theSQLiteStatement = NULL;
|
283
282
|
|
284
283
|
int status = sqlite3_prepare_v2 (sqliteStore, [aSQLQuery UTF8String], -1, &theSQLiteStatement, NULL );
|
@@ -286,7 +285,7 @@
|
|
286
285
|
status = [NSFNanoEngine NSFP_stripBitsFromExtendedResultCode:status];
|
287
286
|
|
288
287
|
if (SQLITE_OK == status) {
|
289
|
-
switch (
|
288
|
+
switch (_returnedObjectType) {
|
290
289
|
case NSFReturnKeys:
|
291
290
|
while (SQLITE_ROW == sqlite3_step (theSQLiteStatement)) {
|
292
291
|
// Sanity check: some queries return NULL, which would cause a crash below.
|
@@ -322,7 +321,7 @@
|
|
322
321
|
continue;
|
323
322
|
}
|
324
323
|
|
325
|
-
if ([
|
324
|
+
if ([_attributesToBeReturned count] == 0) {
|
326
325
|
// Will be released below...
|
327
326
|
} else {
|
328
327
|
// Since we want a subset of the attributes, we need to traverse
|
@@ -332,7 +331,7 @@
|
|
332
331
|
|
333
332
|
NSMutableDictionary *subset = [NSMutableDictionary new];
|
334
333
|
|
335
|
-
for (NSString *attributeValue in
|
334
|
+
for (NSString *attributeValue in _attributesToBeReturned) {
|
336
335
|
id theValue = [info valueForKeyPath:attributeValue];
|
337
336
|
if (nil != theValue) {
|
338
337
|
if (NSNotFound == [attributeValue rangeOfString:@"."].location) {
|
@@ -359,7 +358,7 @@
|
|
359
358
|
saveOriginalClassReference = YES;
|
360
359
|
}
|
361
360
|
|
362
|
-
id nanoObject = [[storedObjectClass alloc]initNanoObjectFromDictionaryRepresentation:info forKey:keyValue store:
|
361
|
+
id nanoObject = [[storedObjectClass alloc]initNanoObjectFromDictionaryRepresentation:info forKey:keyValue store:_nanoStore];
|
363
362
|
|
364
363
|
// If this process does not have knowledge of the original class as was saved in the store, keep a reference
|
365
364
|
// so that we can later on restore the object properly (otherwise it would be stored as a NanoObject.)
|
@@ -391,7 +390,7 @@
|
|
391
390
|
|
392
391
|
- (NSDictionary *)_retrieveDataAdded:(NSFDateMatchType)aDateMatch calendarDate:(NSDate *)aDate error:(out NSError **)outError
|
393
392
|
{
|
394
|
-
if ([
|
393
|
+
if ([_nanoStore isClosed] == YES) {
|
395
394
|
return nil;
|
396
395
|
}
|
397
396
|
|
@@ -422,12 +421,12 @@
|
|
422
421
|
break;
|
423
422
|
}
|
424
423
|
|
425
|
-
NSFNanoResult *result = [
|
424
|
+
NSFNanoResult *result = [_nanoStore _executeSQL:theSQLStatement];
|
426
425
|
|
427
426
|
NSMutableDictionary *searchResults = [NSMutableDictionary dictionaryWithCapacity:result.numberOfRows];
|
428
427
|
|
429
428
|
if (result.numberOfRows > 0) {
|
430
|
-
if (NSFReturnKeys ==
|
429
|
+
if (NSFReturnKeys == _returnedObjectType) {
|
431
430
|
NSArray *resultsKeys = [result valuesForColumn:[NSString stringWithFormat:@"%@.%@", NSFKeys, NSFKey]];
|
432
431
|
for (NSString *resultKey in resultsKeys)
|
433
432
|
[searchResults setObject:[NSNull null] forKey:resultKey];
|
@@ -452,7 +451,7 @@
|
|
452
451
|
saveOriginalClassReference = YES;
|
453
452
|
}
|
454
453
|
|
455
|
-
id nanoObject = [[storedObjectClass alloc]initNanoObjectFromDictionaryRepresentation:info forKey:keyValue store:
|
454
|
+
id nanoObject = [[storedObjectClass alloc]initNanoObjectFromDictionaryRepresentation:info forKey:keyValue store:_nanoStore];
|
456
455
|
|
457
456
|
// If this process does not have knowledge of the original class as was saved in the store, keep a reference
|
458
457
|
// so that we can later on restore the object properly (otherwise it would be stored as a NanoObject.)
|
@@ -474,20 +473,20 @@
|
|
474
473
|
{
|
475
474
|
NSString *aSQLQuery = nil;
|
476
475
|
|
477
|
-
if (nil ==
|
478
|
-
aSQLQuery = [self _prepareSQLQueryStringWithKey:
|
476
|
+
if (nil == _expressions) {
|
477
|
+
aSQLQuery = [self _prepareSQLQueryStringWithKey:_key attribute:_attribute value:_value matching:_match];
|
479
478
|
} else {
|
480
|
-
aSQLQuery = [self _prepareSQLQueryStringWithExpressions:
|
479
|
+
aSQLQuery = [self _prepareSQLQueryStringWithExpressions:_expressions];
|
481
480
|
}
|
482
481
|
|
483
482
|
// Add the limit clause if required
|
484
|
-
if (
|
485
|
-
aSQLQuery = [NSString stringWithFormat:@"%@ LIMIT %li", aSQLQuery,
|
483
|
+
if (_limit > 0) {
|
484
|
+
aSQLQuery = [NSString stringWithFormat:@"%@ LIMIT %li", aSQLQuery, _limit];
|
486
485
|
}
|
487
486
|
|
488
487
|
// Add the offset clause if required
|
489
|
-
if (
|
490
|
-
aSQLQuery = [NSString stringWithFormat:@"%@ OFFSET %li", aSQLQuery,
|
488
|
+
if (_offset > 0) {
|
489
|
+
aSQLQuery = [NSString stringWithFormat:@"%@ OFFSET %li", aSQLQuery, _offset];
|
491
490
|
}
|
492
491
|
|
493
492
|
return aSQLQuery;
|
@@ -503,9 +502,9 @@
|
|
503
502
|
aValue = [aValue stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
|
504
503
|
}
|
505
504
|
|
506
|
-
if (nil !=
|
505
|
+
if (nil != _attributesToBeReturned) {
|
507
506
|
// Prepare the list of attributes we need to gather. Include NSFKEY as well.
|
508
|
-
NSMutableSet *set = [[NSMutableSet alloc]initWithArray:
|
507
|
+
NSMutableSet *set = [[NSMutableSet alloc]initWithArray:_attributesToBeReturned];
|
509
508
|
NSArray *objects = [set allObjects];
|
510
509
|
NSMutableArray *quotedObjects = [NSMutableArray new];
|
511
510
|
for (NSString *object in objects) {
|
@@ -515,7 +514,7 @@
|
|
515
514
|
attributes = [quotedObjects componentsJoinedByString:@","];
|
516
515
|
}
|
517
516
|
|
518
|
-
NSFReturnType returnType =
|
517
|
+
NSFReturnType returnType = _returnedObjectType;
|
519
518
|
|
520
519
|
if ((nil == aKey) && (nil == anAttribute) && (nil == aValue)) {
|
521
520
|
switch (returnType) {
|
@@ -529,7 +528,7 @@
|
|
529
528
|
} else {
|
530
529
|
switch (returnType) {
|
531
530
|
case NSFReturnKeys:
|
532
|
-
if (NO ==
|
531
|
+
if (NO == _groupValues) {
|
533
532
|
theSQLStatement = [NSMutableString stringWithString:@"SELECT DISTINCT (NSFKEY) FROM NSFValues WHERE "];
|
534
533
|
} else {
|
535
534
|
theSQLStatement = [NSMutableString stringWithString:@"SELECT NSFKEY FROM NSFValues WHERE "];
|
@@ -570,11 +569,15 @@
|
|
570
569
|
segment = [NSFNanoSearch _querySegmentForColumn:NSFAttribute value:anAttribute matching:NSFEqualTo];
|
571
570
|
[theSQLStatement appendString:segment];
|
572
571
|
[theSQLStatement appendString:@" AND "];
|
573
|
-
segment = [NSFNanoSearch _querySegmentForColumn:NSFValue value:aValue matching:
|
572
|
+
segment = [NSFNanoSearch _querySegmentForColumn:NSFValue value:aValue matching:aMatch];
|
574
573
|
}
|
575
574
|
}
|
576
575
|
|
577
576
|
[theSQLStatement appendString:segment];
|
577
|
+
if (self.bag != nil) {
|
578
|
+
NSString *selectInABag = [NSString stringWithFormat:@" AND NSFKey IN (SELECT NSFValue FROM NSFVALUES WHERE NSFKey == '%@' AND NSFAttribute == '%@')",self.bag.key,NSF_Private_NSFNanoBag_NSFObjectKeys];
|
579
|
+
[theSQLStatement appendString:selectInABag];
|
580
|
+
}
|
578
581
|
} else {
|
579
582
|
if (nil != aValue) {
|
580
583
|
if (YES == querySegmentWasAdded)
|
@@ -584,11 +587,11 @@
|
|
584
587
|
}
|
585
588
|
}
|
586
589
|
|
587
|
-
if ((
|
590
|
+
if ((_limit > 0) || (_offset > 0)) {
|
588
591
|
[theSQLStatement appendString:@" ORDER BY ROWID"];
|
589
592
|
}
|
590
593
|
|
591
|
-
if (YES ==
|
594
|
+
if (YES == _groupValues) {
|
592
595
|
[theSQLStatement appendString:@" GROUP BY NSFValue"];
|
593
596
|
}
|
594
597
|
|
@@ -612,7 +615,7 @@
|
|
612
615
|
NSUInteger i, count = [someExpressions count];
|
613
616
|
NSMutableArray *sqlComponents = [NSMutableArray new];
|
614
617
|
NSMutableString *parentheses = [NSMutableString new];
|
615
|
-
NSFReturnType returnType =
|
618
|
+
NSFReturnType returnType = _returnedObjectType;
|
616
619
|
|
617
620
|
if (count == 0) {
|
618
621
|
if (NSFReturnObjects == returnType) {
|
@@ -733,6 +736,10 @@
|
|
733
736
|
value = [[NSMutableString alloc]initWithFormat:@"%@ < '%@'", aColumn, aValue];
|
734
737
|
[segment appendString:value];
|
735
738
|
break;
|
739
|
+
case NSFNotEqualTo:
|
740
|
+
value = [[NSMutableString alloc]initWithFormat:@"%@ <> '%@'", aColumn, aValue];
|
741
|
+
[segment appendString:value];
|
742
|
+
break;
|
736
743
|
}
|
737
744
|
} else if (YES == [aValue isKindOfClass:[NSArray class]]) {
|
738
745
|
// Quote the parameters
|
@@ -750,6 +757,19 @@
|
|
750
757
|
[segment appendString:value];
|
751
758
|
|
752
759
|
// Free allocated resources
|
760
|
+
} else if (YES == [aValue isKindOfClass:[NSNull class]]){
|
761
|
+
switch (match) {
|
762
|
+
case NSFEqualTo:
|
763
|
+
value = [[NSMutableString alloc]initWithFormat:@"%@ IS NULL", aColumn];
|
764
|
+
[segment appendString:value];
|
765
|
+
break;
|
766
|
+
case NSFNotEqualTo:
|
767
|
+
value = [[NSMutableString alloc]initWithFormat:@"%@ IS NOT NULL", aColumn];
|
768
|
+
[segment appendString:value];
|
769
|
+
break;
|
770
|
+
default:
|
771
|
+
break;
|
772
|
+
}
|
753
773
|
}
|
754
774
|
|
755
775
|
return segment;
|
@@ -762,51 +782,56 @@
|
|
762
782
|
|
763
783
|
if ((YES == [aValue isKindOfClass:[NSString class]]) || (nil == aValue)) {
|
764
784
|
if (nil == aValue) {
|
765
|
-
value = [[NSMutableString alloc]initWithFormat:@"(%@ = '%@') OR (%@ GLOB '%@.*') OR (%@ GLOB '*.%@.*') OR (%@ GLOB '*.%@')", NSFAttribute, anAttributeValue, NSFAttribute, anAttributeValue, NSFAttribute, anAttributeValue, NSFAttribute, anAttributeValue];
|
785
|
+
value = [[NSMutableString alloc]initWithFormat:@"((%@ = '%@') OR (%@ GLOB '%@.*') OR (%@ GLOB '*.%@.*') OR (%@ GLOB '*.%@'))", NSFAttribute, anAttributeValue, NSFAttribute, anAttributeValue, NSFAttribute, anAttributeValue, NSFAttribute, anAttributeValue];
|
766
786
|
[segment appendString:value];
|
767
787
|
} else {
|
768
788
|
switch (match) {
|
769
789
|
case NSFEqualTo:
|
770
|
-
value = [[NSMutableString alloc]initWithFormat:@"(%@ = '%@' AND %@ = '%@') OR (%@ GLOB '%@.*' AND %@ = '%@') OR (%@ GLOB '*.%@.*' AND %@ = '%@') OR (%@ GLOB '*.%@' AND %@ = '%@')", NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue];
|
790
|
+
value = [[NSMutableString alloc]initWithFormat:@"((%@ = '%@' AND %@ = '%@') OR (%@ GLOB '%@.*' AND %@ = '%@') OR (%@ GLOB '*.%@.*' AND %@ = '%@') OR (%@ GLOB '*.%@' AND %@ = '%@'))", NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue];
|
771
791
|
[segment appendString:value];
|
772
792
|
break;
|
773
793
|
case NSFBeginsWith:
|
774
|
-
value = [[NSMutableString alloc]initWithFormat:@"(%@ = '%@' AND %@ GLOB '%@*') OR (%@ GLOB '%@.*' AND %@ GLOB '%@*') OR (%@ GLOB '*.%@.*' AND %@ GLOB '%@*') OR (%@ GLOB '*.%@' AND %@ GLOB '%@*')", NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue];
|
794
|
+
value = [[NSMutableString alloc]initWithFormat:@"((%@ = '%@' AND %@ GLOB '%@*') OR (%@ GLOB '%@.*' AND %@ GLOB '%@*') OR (%@ GLOB '*.%@.*' AND %@ GLOB '%@*') OR (%@ GLOB '*.%@' AND %@ GLOB '%@*'))", NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue];
|
775
795
|
[segment appendString:value];
|
776
796
|
break;
|
777
797
|
case NSFContains:
|
778
|
-
value = [[NSMutableString alloc]initWithFormat:@"(%@ = '%@' AND %@ GLOB '%@') OR (%@ GLOB '%@.*' AND %@ GLOB '%@') OR (%@ GLOB '*.%@.*' AND %@ GLOB '%@') OR (%@ GLOB '*.%@' AND %@ GLOB '%@')", NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue];
|
798
|
+
value = [[NSMutableString alloc]initWithFormat:@"((%@ = '%@' AND %@ GLOB '%@') OR (%@ GLOB '%@.*' AND %@ GLOB '%@') OR (%@ GLOB '*.%@.*' AND %@ GLOB '%@') OR (%@ GLOB '*.%@' AND %@ GLOB '%@'))", NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue];
|
779
799
|
[segment appendString:value];
|
780
800
|
break;
|
781
801
|
case NSFEndsWith:
|
782
|
-
value = [[NSMutableString alloc]initWithFormat:@"(%@ = '%@' AND %@ GLOB '*%@') OR (%@ GLOB '%@.*' AND %@ GLOB '*%@') OR (%@ GLOB '*.%@.*' AND %@ GLOB '*%@') OR (%@ GLOB '*.%@' AND %@ GLOB '*%@')", NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue];
|
802
|
+
value = [[NSMutableString alloc]initWithFormat:@"((%@ = '%@' AND %@ GLOB '*%@') OR (%@ GLOB '%@.*' AND %@ GLOB '*%@') OR (%@ GLOB '*.%@.*' AND %@ GLOB '*%@') OR (%@ GLOB '*.%@' AND %@ GLOB '*%@'))", NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue];
|
783
803
|
[segment appendString:value];
|
784
804
|
break;
|
785
805
|
case NSFInsensitiveEqualTo:
|
786
806
|
aValue = [aValue uppercaseString];
|
787
|
-
value = [[NSMutableString alloc]initWithFormat:@"(%@ = '%@' AND upper(%@) = '%@') OR (%@ GLOB '%@.*' AND upper(%@) = '%@') OR (%@ GLOB '*.%@.*' AND upper(%@) = '%@') OR (%@ GLOB '*.%@' AND upper(%@) = '%@')", NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue];
|
807
|
+
value = [[NSMutableString alloc]initWithFormat:@"((%@ = '%@' AND upper(%@) = '%@') OR (%@ GLOB '%@.*' AND upper(%@) = '%@') OR (%@ GLOB '*.%@.*' AND upper(%@) = '%@') OR (%@ GLOB '*.%@' AND upper(%@) = '%@'))", NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue];
|
788
808
|
[segment appendString:value];
|
789
809
|
break;
|
790
810
|
case NSFInsensitiveBeginsWith:
|
791
811
|
aValue = [aValue uppercaseString];
|
792
|
-
value = [[NSMutableString alloc]initWithFormat:@"(%@ = '%@' AND upper(%@) GLOB '%@*') OR (%@ GLOB '%@.*' AND upper(%@) GLOB '%@*') OR (%@ GLOB '*.%@.*' AND upper(%@) GLOB '%@*') OR (%@ GLOB '*.%@' AND upper(%@) GLOB '%@*')", NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue];
|
812
|
+
value = [[NSMutableString alloc]initWithFormat:@"((%@ = '%@' AND upper(%@) GLOB '%@*') OR (%@ GLOB '%@.*' AND upper(%@) GLOB '%@*') OR (%@ GLOB '*.%@.*' AND upper(%@) GLOB '%@*') OR (%@ GLOB '*.%@' AND upper(%@) GLOB '%@*'))", NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue];
|
793
813
|
[segment appendString:value];
|
794
814
|
break;
|
795
815
|
case NSFInsensitiveContains:
|
796
|
-
value = [[NSMutableString alloc]initWithFormat:@"(%@ = '%@' AND %@ LIKE '%@') OR (%@ GLOB '%@.*' AND %@ LIKE '%@') OR (%@ GLOB '*.%@.*' AND %@ LIKE '%@') OR (%@ GLOB '*.%@' AND %@ LIKE '%@')", NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue];
|
816
|
+
value = [[NSMutableString alloc]initWithFormat:@"((%@ = '%@' AND %@ LIKE '%@') OR (%@ GLOB '%@.*' AND %@ LIKE '%@') OR (%@ GLOB '*.%@.*' AND %@ LIKE '%@') OR (%@ GLOB '*.%@' AND %@ LIKE '%@'))", NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue];
|
797
817
|
[segment appendString:value];
|
798
818
|
break;
|
799
819
|
case NSFInsensitiveEndsWith:
|
800
|
-
value = [[NSMutableString alloc]initWithFormat:@"(%@ = '%@' AND %@ LIKE '%%%@') OR (%@ GLOB '%@.*' AND %@ LIKE '%%%@') OR (%@ GLOB '*.%@.*' AND %@ LIKE '%%%@') OR (%@ GLOB '*.%@' AND %@ LIKE '%%%@')", NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue];
|
820
|
+
value = [[NSMutableString alloc]initWithFormat:@"((%@ = '%@' AND %@ LIKE '%%%@') OR (%@ GLOB '%@.*' AND %@ LIKE '%%%@') OR (%@ GLOB '*.%@.*' AND %@ LIKE '%%%@') OR (%@ GLOB '*.%@' AND %@ LIKE '%%%@'))", NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue];
|
801
821
|
[segment appendString:value];
|
802
822
|
break;
|
803
823
|
case NSFGreaterThan:
|
804
|
-
value = [[NSMutableString alloc]initWithFormat:@"(%@ = '%@' AND %@ > '%@') OR (%@ GLOB '%@.*' AND %@ > '%@') OR (%@ GLOB '*.%@.*' AND %@ > '%@') OR (%@ GLOB '*.%@' AND %@ > '%@')", NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue];
|
824
|
+
value = [[NSMutableString alloc]initWithFormat:@"((%@ = '%@' AND %@ > '%@') OR (%@ GLOB '%@.*' AND %@ > '%@') OR (%@ GLOB '*.%@.*' AND %@ > '%@') OR (%@ GLOB '*.%@' AND %@ > '%@'))", NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue];
|
805
825
|
[segment appendString:value];
|
806
826
|
break;
|
807
827
|
case NSFLessThan:
|
808
|
-
value = [[NSMutableString alloc]initWithFormat:@"(%@ = '%@' AND %@ < '%@') OR (%@ GLOB '%@.*' AND %@ < '%@') OR (%@ GLOB '*.%@.*' AND %@ < '%@') OR (%@ GLOB '*.%@' AND %@ < '%@')", NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue];
|
828
|
+
value = [[NSMutableString alloc]initWithFormat:@"((%@ = '%@' AND %@ < '%@') OR (%@ GLOB '%@.*' AND %@ < '%@') OR (%@ GLOB '*.%@.*' AND %@ < '%@') OR (%@ GLOB '*.%@' AND %@ < '%@'))", NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue];
|
829
|
+
[segment appendString:value];
|
830
|
+
break;
|
831
|
+
case NSFNotEqualTo:
|
832
|
+
value = [[NSMutableString alloc]initWithFormat:@"((%@ <> '%@' AND %@ <> '%@') OR (%@ GLOB '%@.*' AND %@ <> '%@') OR (%@ GLOB '*.%@.*' AND %@ <> '%@') OR (%@ GLOB '*.%@' AND %@ <> '%@'))", NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue, NSFAttribute, anAttributeValue, NSFValue, aValue];
|
809
833
|
[segment appendString:value];
|
834
|
+
|
810
835
|
break;
|
811
836
|
}
|
812
837
|
}
|
@@ -826,6 +851,56 @@
|
|
826
851
|
[segment appendString:value];
|
827
852
|
|
828
853
|
// Free allocated resources
|
854
|
+
} else if (YES == [aValue isKindOfClass:[NSNull class]]) {
|
855
|
+
NSString *NULLStringValue = NSFStringFromNanoDataType (NSFNanoTypeNULL);
|
856
|
+
switch (match) {
|
857
|
+
case NSFEqualTo:
|
858
|
+
value = [[NSMutableString alloc]initWithFormat:@"(%@ = '%@' AND %@ = '%@') OR (%@ GLOB '%@.*' AND %@ = '%@') OR (%@ GLOB '*.%@.*' AND %@ = '%@') OR (%@ GLOB '*.%@' AND %@ = '%@')", NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue, NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue, NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue, NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue];
|
859
|
+
[segment appendString:value];
|
860
|
+
break;
|
861
|
+
case NSFNotEqualTo:
|
862
|
+
value = [[NSMutableString alloc]initWithFormat:@"(%@ = '%@' AND %@ <> '%@') OR (%@ GLOB '%@.*' AND %@ <> '%@') OR (%@ GLOB '*.%@.*' AND %@ <> '%@') OR (%@ GLOB '*.%@' AND %@ <> '%@')", NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue, NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue, NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue, NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue];
|
863
|
+
[segment appendString:value];
|
864
|
+
break;
|
865
|
+
case NSFBeginsWith:
|
866
|
+
value = [[NSMutableString alloc]initWithFormat:@"(%@ = '%@' AND %@ GLOB '%@*') OR (%@ GLOB '%@.*' AND %@ GLOB '%@*') OR (%@ GLOB '*.%@.*' AND %@ GLOB '%@*') OR (%@ GLOB '*.%@' AND %@ GLOB '%@*')", NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue, NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue, NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue, NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue];
|
867
|
+
[segment appendString:value];
|
868
|
+
break;
|
869
|
+
case NSFContains:
|
870
|
+
value = [[NSMutableString alloc]initWithFormat:@"(%@ = '%@' AND %@ GLOB '%@') OR (%@ GLOB '%@.*' AND %@ GLOB '%@') OR (%@ GLOB '*.%@.*' AND %@ GLOB '%@') OR (%@ GLOB '*.%@' AND %@ GLOB '%@')", NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue, NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue, NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue, NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue];
|
871
|
+
[segment appendString:value];
|
872
|
+
break;
|
873
|
+
case NSFEndsWith:
|
874
|
+
value = [[NSMutableString alloc]initWithFormat:@"(%@ = '%@' AND %@ GLOB '*%@') OR (%@ GLOB '%@.*' AND %@ GLOB '*%@') OR (%@ GLOB '*.%@.*' AND %@ GLOB '*%@') OR (%@ GLOB '*.%@' AND %@ GLOB '*%@')", NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue, NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue, NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue, NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue];
|
875
|
+
[segment appendString:value];
|
876
|
+
break;
|
877
|
+
case NSFInsensitiveEqualTo:
|
878
|
+
aValue = [aValue uppercaseString];
|
879
|
+
value = [[NSMutableString alloc]initWithFormat:@"(%@ = '%@' AND upper(%@) = '%@') OR (%@ GLOB '%@.*' AND upper(%@) = '%@') OR (%@ GLOB '*.%@.*' AND upper(%@) = '%@') OR (%@ GLOB '*.%@' AND upper(%@) = '%@')", NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue, NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue, NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue, NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue];
|
880
|
+
[segment appendString:value];
|
881
|
+
break;
|
882
|
+
case NSFInsensitiveBeginsWith:
|
883
|
+
aValue = [aValue uppercaseString];
|
884
|
+
value = [[NSMutableString alloc]initWithFormat:@"(%@ = '%@' AND upper(%@) GLOB '%@*') OR (%@ GLOB '%@.*' AND upper(%@) GLOB '%@*') OR (%@ GLOB '*.%@.*' AND upper(%@) GLOB '%@*') OR (%@ GLOB '*.%@' AND upper(%@) GLOB '%@*')", NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue, NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue, NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue, NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue];
|
885
|
+
[segment appendString:value];
|
886
|
+
break;
|
887
|
+
case NSFInsensitiveContains:
|
888
|
+
value = [[NSMutableString alloc]initWithFormat:@"(%@ = '%@' AND %@ LIKE '%@') OR (%@ GLOB '%@.*' AND %@ LIKE '%@') OR (%@ GLOB '*.%@.*' AND %@ LIKE '%@') OR (%@ GLOB '*.%@' AND %@ LIKE '%@')", NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue, NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue, NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue, NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue];
|
889
|
+
[segment appendString:value];
|
890
|
+
break;
|
891
|
+
case NSFInsensitiveEndsWith:
|
892
|
+
value = [[NSMutableString alloc]initWithFormat:@"(%@ = '%@' AND %@ LIKE '%%%@') OR (%@ GLOB '%@.*' AND %@ LIKE '%%%@') OR (%@ GLOB '*.%@.*' AND %@ LIKE '%%%@') OR (%@ GLOB '*.%@' AND %@ LIKE '%%%@')", NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue, NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue, NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue, NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue];
|
893
|
+
[segment appendString:value];
|
894
|
+
break;
|
895
|
+
case NSFGreaterThan:
|
896
|
+
value = [[NSMutableString alloc]initWithFormat:@"(%@ = '%@' AND %@ > '%@') OR (%@ GLOB '%@.*' AND %@ > '%@') OR (%@ GLOB '*.%@.*' AND %@ > '%@') OR (%@ GLOB '*.%@' AND %@ > '%@')", NSFAttribute, NSFDatatype, NULLStringValue, aValue, NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue, NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue, NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue];
|
897
|
+
[segment appendString:value];
|
898
|
+
break;
|
899
|
+
case NSFLessThan:
|
900
|
+
value = [[NSMutableString alloc]initWithFormat:@"(%@ = '%@' AND %@ < '%@') OR (%@ GLOB '%@.*' AND %@ < '%@') OR (%@ GLOB '*.%@.*' AND %@ < '%@') OR (%@ GLOB '*.%@' AND %@ < '%@')", NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue, NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue, NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue, NSFAttribute, anAttributeValue, NSFDatatype, NULLStringValue];
|
901
|
+
[segment appendString:value];
|
902
|
+
break;
|
903
|
+
}
|
829
904
|
}
|
830
905
|
|
831
906
|
return segment;
|
@@ -872,16 +947,15 @@
|
|
872
947
|
{
|
873
948
|
id theResults = results;
|
874
949
|
|
875
|
-
if ([
|
876
|
-
NSMutableArray *cocoaSortDescriptors = [NSMutableArray new];
|
877
|
-
|
878
|
-
for (NSFNanoSortDescriptor *descriptor in sort) {
|
879
|
-
NSString *targetKeyPath = [[NSString alloc]initWithFormat:@"rootObject.%@", descriptor.attribute];
|
880
|
-
NSSortDescriptor *cocoaSort = [[NSSortDescriptor alloc]initWithKey:targetKeyPath ascending:descriptor.isAscending];
|
881
|
-
[cocoaSortDescriptors addObject:cocoaSort];
|
882
|
-
}
|
883
|
-
|
950
|
+
if ([_sort count] > 0) {
|
884
951
|
if (NSFReturnObjects == theReturnType) {
|
952
|
+
NSMutableArray *cocoaSortDescriptors = [NSMutableArray new];
|
953
|
+
|
954
|
+
for (NSFNanoSortDescriptor *descriptor in _sort) {
|
955
|
+
NSString *targetKeyPath = [[NSString alloc]initWithFormat:@"rootObject.%@", descriptor.attribute];
|
956
|
+
NSSortDescriptor *cocoaSort = [[NSSortDescriptor alloc]initWithKey:targetKeyPath ascending:descriptor.isAscending];
|
957
|
+
[cocoaSortDescriptors addObject:cocoaSort];
|
958
|
+
}
|
885
959
|
theResults = [[results allValues]sortedArrayUsingDescriptors:cocoaSortDescriptors];
|
886
960
|
} else {
|
887
961
|
theResults = [results allKeys];
|
@@ -903,27 +977,27 @@
|
|
903
977
|
NSFOrderedDictionary *values = [NSFOrderedDictionary new];
|
904
978
|
|
905
979
|
values[@"NanoSearch address"] = [NSString stringWithFormat:@"%p", self];
|
906
|
-
values[@"Document store"] = [
|
907
|
-
values[@"Attributes to be returned"] = (
|
908
|
-
values[@"Key"] = (
|
909
|
-
values[@"Attribute"] = (
|
910
|
-
values[@"Value"] = (
|
911
|
-
values[@"Match"] = NSFStringFromMatchType(
|
980
|
+
values[@"Document store"] = [_nanoStore dictionaryDescription];
|
981
|
+
values[@"Attributes to be returned"] = (_attributesToBeReturned ? [_attributesToBeReturned componentsJoinedByString:@","] : @"All");
|
982
|
+
values[@"Key"] = (_key ? _key : @"<nil>");
|
983
|
+
values[@"Attribute"] = (_attribute ? _attribute : @"<nil>");
|
984
|
+
values[@"Value"] = (_value ? _value : @"<nil>");
|
985
|
+
values[@"Match"] = NSFStringFromMatchType(_match);
|
912
986
|
|
913
987
|
NSMutableArray *tempExpressions = [NSMutableArray new];
|
914
|
-
for (NSFNanoExpression *expression in
|
988
|
+
for (NSFNanoExpression *expression in _expressions) {
|
915
989
|
[tempExpressions addObject:[expression description]];
|
916
990
|
}
|
917
991
|
values[@"Expressions"] = ([tempExpressions count] > 0 ? tempExpressions : @"<nil>");
|
918
992
|
|
919
|
-
values[@"Group values?"] = (
|
993
|
+
values[@"Group values?"] = (_groupValues ? @"YES" : @"NO");
|
920
994
|
|
921
995
|
NSString *tempSQL = [self sql];
|
922
996
|
values[@"SQL"] = (tempSQL ? tempSQL : @"<nil>");
|
923
|
-
values[@"Sort"] = (
|
924
|
-
values[@"Filter class"] = (
|
925
|
-
values[@"Offset"] = @(
|
926
|
-
values[@"Limit"] = @(
|
997
|
+
values[@"Sort"] = (_sort ? _sort : @"<nil>");
|
998
|
+
values[@"Filter class"] = (_filterClass ? _filterClass : @"<nil>");
|
999
|
+
values[@"Offset"] = @(_offset);
|
1000
|
+
values[@"Limit"] = @(_limit);
|
927
1001
|
|
928
1002
|
return values;
|
929
1003
|
}
|