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