nano-store 0.5.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/{CHANGELOG → CHANGELOG.md} +7 -0
- data/README.md +5 -1
- data/Rakefile +1 -1
- data/lib/nano_store.rb +1 -1
- data/lib/nano_store/finder.rb +10 -2
- data/lib/nano_store/model.rb +7 -7
- data/lib/nano_store/version.rb +1 -1
- data/spec/association_spec.rb +6 -6
- data/spec/finder_spec.rb +2 -0
- data/spec/model_spec.rb +33 -3
- data/spec/nano_store_spec.rb +5 -0
- data/spec/spec_helper.rb +14 -0
- data/vendor/Podfile.lock +3 -3
- data/vendor/Pods/BuildHeaders/NanoStore/NSFNanoBag.h +6 -1
- data/vendor/Pods/BuildHeaders/NanoStore/NSFNanoEngine.h +5 -0
- data/vendor/Pods/BuildHeaders/NanoStore/NSFNanoEngine_Private.h +2 -0
- data/vendor/Pods/BuildHeaders/NanoStore/NSFNanoExpression.h +6 -0
- data/vendor/Pods/BuildHeaders/NanoStore/NSFNanoExpression_Private.h +1 -1
- data/vendor/Pods/BuildHeaders/NanoStore/NSFNanoGlobals.h +5 -1
- data/vendor/Pods/BuildHeaders/NanoStore/NSFNanoGlobals_Private.h +6 -2
- data/vendor/Pods/BuildHeaders/NanoStore/NSFNanoObject.h +15 -3
- data/vendor/Pods/BuildHeaders/NanoStore/NSFNanoObject_Private.h +4 -0
- data/vendor/Pods/BuildHeaders/NanoStore/NSFNanoPredicate.h +6 -1
- data/vendor/Pods/BuildHeaders/NanoStore/NSFNanoResult.h +5 -0
- data/vendor/Pods/BuildHeaders/NanoStore/NSFNanoSearch.h +16 -2
- data/vendor/Pods/BuildHeaders/NanoStore/NSFNanoSortDescriptor.h +7 -1
- data/vendor/Pods/BuildHeaders/NanoStore/NSFNanoStore.h +12 -0
- data/vendor/Pods/BuildHeaders/NanoStore/NSFNanoStore_Private.h +3 -1
- data/vendor/Pods/BuildHeaders/NanoStore/NSFOrderedDictionary.h +33 -0
- data/vendor/Pods/BuildHeaders/NanoStore/NanoStore.h +36 -0
- data/vendor/Pods/Headers/NanoStore/NSFNanoBag.h +6 -1
- data/vendor/Pods/Headers/NanoStore/NSFNanoEngine.h +5 -0
- data/vendor/Pods/Headers/NanoStore/NSFNanoEngine_Private.h +2 -0
- data/vendor/Pods/Headers/NanoStore/NSFNanoExpression.h +6 -0
- data/vendor/Pods/Headers/NanoStore/NSFNanoExpression_Private.h +1 -1
- data/vendor/Pods/Headers/NanoStore/NSFNanoGlobals.h +5 -1
- data/vendor/Pods/Headers/NanoStore/NSFNanoGlobals_Private.h +6 -2
- data/vendor/Pods/Headers/NanoStore/NSFNanoObject.h +15 -3
- data/vendor/Pods/Headers/NanoStore/NSFNanoObject_Private.h +4 -0
- data/vendor/Pods/Headers/NanoStore/NSFNanoPredicate.h +6 -1
- data/vendor/Pods/Headers/NanoStore/NSFNanoResult.h +5 -0
- data/vendor/Pods/Headers/NanoStore/NSFNanoSearch.h +16 -2
- data/vendor/Pods/Headers/NanoStore/NSFNanoSortDescriptor.h +7 -1
- data/vendor/Pods/Headers/NanoStore/NSFNanoStore.h +12 -0
- data/vendor/Pods/Headers/NanoStore/NSFNanoStore_Private.h +3 -1
- data/vendor/Pods/Headers/NanoStore/NSFOrderedDictionary.h +33 -0
- data/vendor/Pods/Headers/NanoStore/NanoStore.h +36 -0
- data/vendor/Pods/NanoStore/Classes/Advanced/NSFNanoEngine.h +5 -0
- data/vendor/Pods/NanoStore/Classes/Advanced/NSFNanoEngine.m +142 -131
- data/vendor/Pods/NanoStore/Classes/Advanced/NSFNanoResult.h +5 -0
- data/vendor/Pods/NanoStore/Classes/Advanced/NSFNanoResult.m +148 -51
- data/vendor/Pods/NanoStore/Classes/Advanced/NSFOrderedDictionary.h +33 -0
- data/vendor/Pods/NanoStore/Classes/Advanced/NSFOrderedDictionary.m +148 -0
- data/vendor/Pods/NanoStore/Classes/Private/NSFNanoEngine_Private.h +2 -0
- data/vendor/Pods/NanoStore/Classes/Private/NSFNanoExpression_Private.h +1 -1
- data/vendor/Pods/NanoStore/Classes/Private/NSFNanoGlobals_Private.h +6 -2
- data/vendor/Pods/NanoStore/Classes/Private/NSFNanoObject_Private.h +4 -0
- data/vendor/Pods/NanoStore/Classes/Private/NSFNanoStore_Private.h +3 -1
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoBag.h +6 -1
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoBag.m +126 -117
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoExpression.h +6 -0
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoExpression.m +32 -18
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoGlobals.h +5 -1
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoGlobals.m +6 -3
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoObject.h +15 -3
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoObject.m +152 -31
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoPredicate.h +6 -1
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoPredicate.m +51 -26
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoSearch.h +16 -2
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoSearch.m +156 -115
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoSortDescriptor.h +7 -1
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoSortDescriptor.m +34 -17
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoStore.h +12 -0
- data/vendor/Pods/NanoStore/Classes/Public/NSFNanoStore.m +210 -196
- data/vendor/Pods/NanoStore/Classes/Public/NanoStore.h +36 -0
- data/vendor/Pods/NanoStore/README.md +49 -0
- data/vendor/Pods/Pods.bridgesupport +798 -685
- metadata +30 -8
@@ -113,11 +113,16 @@
|
|
113
113
|
|
114
114
|
/** * Returns a string representation of the predicate.
|
115
115
|
* @note Check properties column, match and value to find out the current state of the predicate.
|
116
|
-
* @see \link description - (NSString *)description \endlink
|
117
116
|
*/
|
118
117
|
|
119
118
|
- (NSString *)description;
|
120
119
|
|
120
|
+
/** * Returns a JSON representation of the predicate.
|
121
|
+
* @note Check properties column, match and value to find out the current state of the predicate.
|
122
|
+
*/
|
123
|
+
|
124
|
+
- (NSString *)JSONDescription;
|
125
|
+
|
121
126
|
//@}
|
122
127
|
|
123
128
|
@end
|
@@ -26,10 +26,19 @@
|
|
26
26
|
|
27
27
|
#import "NSFNanoExpression.h"
|
28
28
|
#import "NanoStore_Private.h"
|
29
|
+
#import "NSFOrderedDictionary.h"
|
29
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, copy, readwrite) NSString *value;
|
37
|
+
/** \endcond */
|
38
|
+
|
39
|
+
@end
|
31
40
|
|
32
|
-
@
|
41
|
+
@implementation NSFNanoPredicate
|
33
42
|
|
34
43
|
// ----------------------------------------------
|
35
44
|
// Initialization / Cleanup
|
@@ -39,7 +48,7 @@
|
|
39
48
|
{
|
40
49
|
if (nil == aValue)
|
41
50
|
[[NSException exceptionWithName:NSFUnexpectedParameterException
|
42
|
-
reason:[NSString stringWithFormat:@"*** -[%@
|
51
|
+
reason:[NSString stringWithFormat:@"*** -[%@ %@]: value is nil.", [self class], NSStringFromSelector(_cmd)]
|
43
52
|
userInfo:nil]raise];
|
44
53
|
|
45
54
|
return [[self alloc]initWithColumn:type matching:matching value:aValue];
|
@@ -49,13 +58,13 @@
|
|
49
58
|
{
|
50
59
|
if (nil == aValue)
|
51
60
|
[[NSException exceptionWithName:NSFUnexpectedParameterException
|
52
|
-
reason:[NSString stringWithFormat:@"*** -[%@
|
61
|
+
reason:[NSString stringWithFormat:@"*** -[%@ %@]: value is nil.", [self class], NSStringFromSelector(_cmd)]
|
53
62
|
userInfo:nil]raise];
|
54
63
|
|
55
64
|
if ((self = [super init])) {
|
56
|
-
|
57
|
-
|
58
|
-
|
65
|
+
_column = type;
|
66
|
+
_match = matching;
|
67
|
+
_value = aValue;
|
59
68
|
}
|
60
69
|
|
61
70
|
return self;
|
@@ -63,12 +72,18 @@
|
|
63
72
|
|
64
73
|
- (NSString *)description
|
65
74
|
{
|
66
|
-
|
75
|
+
return [[self arrayDescription]lastObject];
|
76
|
+
}
|
77
|
+
|
78
|
+
- (NSArray *)arrayDescription
|
79
|
+
{
|
80
|
+
NSMutableArray *values = [NSMutableArray new];
|
81
|
+
|
82
|
+
NSString *columnValue = nil;
|
67
83
|
NSMutableString *mutatedString = nil;
|
68
84
|
NSInteger mutatedStringLength = 0;
|
69
|
-
NSString *columnValue = nil;
|
70
85
|
|
71
|
-
switch (
|
86
|
+
switch (_column) {
|
72
87
|
case NSFKeyColumn:
|
73
88
|
columnValue = NSFKey;
|
74
89
|
break;
|
@@ -81,47 +96,57 @@
|
|
81
96
|
}
|
82
97
|
|
83
98
|
// Make sure we escape quotes if present and the value is a string
|
84
|
-
|
99
|
+
_value = [_value stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
|
85
100
|
|
86
|
-
switch (
|
101
|
+
switch (_match) {
|
87
102
|
case NSFEqualTo:
|
88
|
-
[
|
103
|
+
[values addObject:[NSString stringWithFormat:@"%@ = '%@'", columnValue, _value]];
|
89
104
|
break;
|
90
105
|
case NSFBeginsWith:
|
91
|
-
mutatedString = [NSMutableString stringWithString:
|
92
|
-
mutatedStringLength = [
|
106
|
+
mutatedString = [NSMutableString stringWithString:_value];
|
107
|
+
mutatedStringLength = [_value length];
|
93
108
|
[mutatedString replaceCharactersInRange:NSMakeRange(mutatedStringLength - 1, 1) withString:[NSString stringWithFormat:@"%c", [mutatedString characterAtIndex:mutatedStringLength - 1]+1]];
|
94
|
-
[
|
109
|
+
[values addObject:[NSString stringWithFormat:@"(%@ >= '%@' AND %@ < '%@')", columnValue, _value, columnValue, mutatedString]];
|
95
110
|
break;
|
96
111
|
case NSFContains:
|
97
|
-
[
|
112
|
+
[values addObject:[NSString stringWithFormat:@"%@ GLOB '*%@*'", columnValue, _value]];
|
98
113
|
break;
|
99
114
|
case NSFEndsWith:
|
100
|
-
[
|
115
|
+
[values addObject:[NSString stringWithFormat:@"%@ GLOB '*%@'", columnValue, _value]];
|
101
116
|
break;
|
102
117
|
case NSFInsensitiveEqualTo:
|
103
|
-
[
|
118
|
+
[values addObject:[NSString stringWithFormat:@"upper(%@) = '%@'", columnValue, [_value uppercaseString]]];
|
104
119
|
break;
|
105
120
|
case NSFInsensitiveBeginsWith:
|
106
|
-
mutatedString = [NSMutableString stringWithString:
|
107
|
-
mutatedStringLength = [
|
121
|
+
mutatedString = [NSMutableString stringWithString:_value];
|
122
|
+
mutatedStringLength = [_value length];
|
108
123
|
[mutatedString replaceCharactersInRange:NSMakeRange(mutatedStringLength - 1, 1) withString:[NSString stringWithFormat:@"%c", [mutatedString characterAtIndex:mutatedStringLength - 1]+1]];
|
109
|
-
[
|
124
|
+
[values addObject:[NSString stringWithFormat:@"(upper(%@) >= '%@' AND upper(%@) < '%@')", columnValue, [_value uppercaseString], columnValue, [mutatedString uppercaseString]]];
|
110
125
|
break;
|
111
126
|
case NSFInsensitiveContains:
|
112
|
-
[
|
127
|
+
[values addObject:[NSString stringWithFormat:@"%@ LIKE '%@%@%@'", columnValue, @"%", _value, @"%"]];
|
113
128
|
break;
|
114
129
|
case NSFInsensitiveEndsWith:
|
115
|
-
[
|
130
|
+
[values addObject:[NSString stringWithFormat:@"%@ LIKE '%@%@'", columnValue, @"%", _value]];
|
116
131
|
break;
|
117
132
|
case NSFGreaterThan:
|
118
|
-
[
|
133
|
+
[values addObject:[NSString stringWithFormat:@"%@ > '%@'", columnValue, _value]];
|
119
134
|
break;
|
120
135
|
case NSFLessThan:
|
121
|
-
[
|
136
|
+
[values addObject:[NSString stringWithFormat:@"%@ < '%@'", columnValue, _value]];
|
122
137
|
break;
|
123
138
|
}
|
124
139
|
|
140
|
+
return values;
|
141
|
+
}
|
142
|
+
|
143
|
+
- (NSString *)JSONDescription
|
144
|
+
{
|
145
|
+
NSArray *values = [self arrayDescription];
|
146
|
+
|
147
|
+
NSError *outError = nil;
|
148
|
+
NSString *description = [NSFNanoObject _NSObjectToJSONString:values error:&outError];
|
149
|
+
|
125
150
|
return description;
|
126
151
|
}
|
127
152
|
|
@@ -175,7 +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, copy, readwrite) NSString *filterClass;
|
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
|
+
@property (nonatomic, assign, readwrite) NSUInteger offset;
|
181
|
+
/** * The limit clause is used to place an upper bound on the number of rows returned by a Search operation. */
|
182
|
+
@property (nonatomic, assign, readwrite) NSUInteger limit;
|
179
183
|
|
180
184
|
/** @name Creating and Initializing a Search
|
181
185
|
*/
|
@@ -277,7 +281,7 @@
|
|
277
281
|
* NSFNanoSearch *search = [NSFNanoSearch searchWithStore:nanoStore];
|
278
282
|
*
|
279
283
|
* // Perform the search
|
280
|
-
* // The query will be rewritten as @"SELECT NSFKey,
|
284
|
+
* // The query will be rewritten as @"SELECT NSFKey, NSFKeyedArchive, NSFObjectClass FROM NSFKeys"
|
281
285
|
* NSDictionary *results = [search executeSQL:@"SELECT foo, bar FROM NSFKeys" returnType:NSFReturnObjects error:nil];
|
282
286
|
* @endcode
|
283
287
|
* @note The sort descriptor will be ignored when executing custom SQL statements.
|
@@ -380,4 +384,14 @@
|
|
380
384
|
|
381
385
|
//@}
|
382
386
|
|
387
|
+
/** Returns a string representation of the search.
|
388
|
+
*/
|
389
|
+
|
390
|
+
- (NSString *)description;
|
391
|
+
|
392
|
+
/** Returns a JSON representation of the search.
|
393
|
+
*/
|
394
|
+
|
395
|
+
- (NSString *)JSONDescription;
|
396
|
+
|
383
397
|
@end
|
@@ -27,17 +27,17 @@
|
|
27
27
|
#import "NanoStore.h"
|
28
28
|
#import "NanoStore_Private.h"
|
29
29
|
#import "NSFNanoSearch_Private.h"
|
30
|
+
#import "NSFNanoExpression_Private.h"
|
30
31
|
|
31
|
-
@
|
32
|
-
{
|
33
|
-
/** \cond */
|
34
|
-
@protected
|
35
|
-
NSFReturnType returnedObjectType;
|
36
|
-
/** \endcond */
|
37
|
-
}
|
32
|
+
@interface NSFNanoSearch ()
|
38
33
|
|
34
|
+
/** \cond */
|
35
|
+
@property (nonatomic, copy, readwrite) NSString *sql;
|
36
|
+
@property (nonatomic) NSFReturnType returnedObjectType;
|
37
|
+
/** \endcond */
|
38
|
+
@end
|
39
39
|
|
40
|
-
@
|
40
|
+
@implementation NSFNanoSearch
|
41
41
|
|
42
42
|
// ----------------------------------------------
|
43
43
|
// Initialization / Cleanup
|
@@ -52,12 +52,12 @@
|
|
52
52
|
{
|
53
53
|
if (nil == store) {
|
54
54
|
[[NSException exceptionWithName:NSFUnexpectedParameterException
|
55
|
-
reason:[NSString stringWithFormat:@"*** -[%@
|
55
|
+
reason:[NSString stringWithFormat:@"*** -[%@ %@]: store is nil.", [self class], NSStringFromSelector(_cmd)]
|
56
56
|
userInfo:nil]raise];
|
57
57
|
}
|
58
58
|
|
59
59
|
if ((self = [self init])) {
|
60
|
-
|
60
|
+
_nanoStore = store;
|
61
61
|
[self reset];
|
62
62
|
}
|
63
63
|
|
@@ -77,30 +77,10 @@
|
|
77
77
|
|
78
78
|
- (NSString *)sql
|
79
79
|
{
|
80
|
-
if (nil ==
|
80
|
+
if (nil == _sql)
|
81
81
|
return [self _preparedSQL];
|
82
82
|
|
83
|
-
return
|
84
|
-
}
|
85
|
-
|
86
|
-
- (NSString *)description
|
87
|
-
{
|
88
|
-
NSMutableString *description = [NSMutableString string];
|
89
|
-
|
90
|
-
[description appendString:@"\n"];
|
91
|
-
[description appendString:[NSString stringWithFormat:@"NanoSearch address : 0x%x\n", self]];
|
92
|
-
[description appendString:[NSString stringWithFormat:@"Document store : 0x%x\n", nanoStore]];
|
93
|
-
[description appendString:[NSString stringWithFormat:@"Attributes to be returned : %@\n", (attributesToBeReturned ? [attributesToBeReturned componentsJoinedByString:@","] : @"All")]];
|
94
|
-
[description appendString:[NSString stringWithFormat:@"Key : %@\n", key]];
|
95
|
-
[description appendString:[NSString stringWithFormat:@"Attribute : %@\n", attribute]];
|
96
|
-
[description appendString:[NSString stringWithFormat:@"Value : %@\n", value]];
|
97
|
-
[description appendString:[NSString stringWithFormat:@"Match : %@\n", NSFStringFromMatchType(match)]];
|
98
|
-
[description appendString:[NSString stringWithFormat:@"Expressions : %@\n", expressions]];
|
99
|
-
[description appendString:[NSString stringWithFormat:@"Group values? : %@\n", (groupValues ? @"YES" : @"NO")]];
|
100
|
-
[description appendString:[NSString stringWithFormat:@"Sort : %@\n", sort]];
|
101
|
-
[description appendString:[NSString stringWithFormat:@"Filter class : %@\n", filterClass]];
|
102
|
-
|
103
|
-
return description;
|
83
|
+
return _sql;
|
104
84
|
}
|
105
85
|
|
106
86
|
#pragma mark -
|
@@ -109,13 +89,13 @@
|
|
109
89
|
{
|
110
90
|
if (nil == theSQLStatement) {
|
111
91
|
[[NSException exceptionWithName:NSFUnexpectedParameterException
|
112
|
-
reason:[NSString stringWithFormat:@"*** -[%@
|
92
|
+
reason:[NSString stringWithFormat:@"*** -[%@ %@]: the SQL statement is nil.", [self class], NSStringFromSelector(_cmd)]
|
113
93
|
userInfo:nil]raise];
|
114
94
|
}
|
115
95
|
|
116
96
|
if (0 == [theSQLStatement length]) {
|
117
97
|
[[NSException exceptionWithName:NSFUnexpectedParameterException
|
118
|
-
reason:[NSString stringWithFormat:@"*** -[%@
|
98
|
+
reason:[NSString stringWithFormat:@"*** -[%@ %@]: the SQL statement is empty.", [self class], NSStringFromSelector(_cmd)]
|
119
99
|
userInfo:nil]raise];
|
120
100
|
}
|
121
101
|
|
@@ -124,8 +104,8 @@
|
|
124
104
|
[self reset];
|
125
105
|
self.sort = savedSort;
|
126
106
|
|
127
|
-
|
128
|
-
|
107
|
+
_returnedObjectType = theReturnType;
|
108
|
+
_sql = theSQLStatement;
|
129
109
|
|
130
110
|
NSDictionary *results = [self _retrieveDataWithError:outError];
|
131
111
|
|
@@ -136,63 +116,64 @@
|
|
136
116
|
{
|
137
117
|
if (nil == theSQLStatement) {
|
138
118
|
[[NSException exceptionWithName:NSFUnexpectedParameterException
|
139
|
-
reason:[NSString stringWithFormat:@"*** -[%@
|
119
|
+
reason:[NSString stringWithFormat:@"*** -[%@ %@]: the SQL statement is nil.", [self class], NSStringFromSelector(_cmd)]
|
140
120
|
userInfo:nil]raise];
|
141
121
|
}
|
142
122
|
|
143
123
|
if (0 == [theSQLStatement length]) {
|
144
124
|
[[NSException exceptionWithName:NSFUnexpectedParameterException
|
145
|
-
reason:[NSString stringWithFormat:@"*** -[%@
|
125
|
+
reason:[NSString stringWithFormat:@"*** -[%@ %@]: the SQL statement is empty.", [self class], NSStringFromSelector(_cmd)]
|
146
126
|
userInfo:nil]raise];
|
147
127
|
}
|
148
128
|
|
149
129
|
// Make sure we don't have any lingering parameters that could mess with the results...
|
150
130
|
[self reset];
|
151
131
|
|
152
|
-
|
132
|
+
_sql = theSQLStatement;
|
153
133
|
|
154
|
-
return [
|
134
|
+
return [_nanoStore _executeSQL:theSQLStatement];
|
155
135
|
}
|
156
136
|
|
157
137
|
- (NSFNanoResult *)explainSQL:(NSString *)theSQLStatement
|
158
138
|
{
|
159
139
|
if (nil == theSQLStatement) {
|
160
140
|
[[NSException exceptionWithName:NSFUnexpectedParameterException
|
161
|
-
reason:[NSString stringWithFormat:@"*** -[%@
|
141
|
+
reason:[NSString stringWithFormat:@"*** -[%@ %@]: the SQL statement is nil.", [self class], NSStringFromSelector(_cmd)]
|
162
142
|
userInfo:nil]raise];
|
163
143
|
}
|
164
144
|
|
165
145
|
if (0 == [theSQLStatement length]) {
|
166
146
|
[[NSException exceptionWithName:NSFUnexpectedParameterException
|
167
|
-
reason:[NSString stringWithFormat:@"*** -[%@
|
147
|
+
reason:[NSString stringWithFormat:@"*** -[%@ %@]: the SQL statement is empty.", [self class], NSStringFromSelector(_cmd)]
|
168
148
|
userInfo:nil]raise];
|
169
149
|
}
|
170
150
|
|
171
|
-
return [
|
151
|
+
return [_nanoStore _executeSQL:[NSString stringWithFormat:@"EXPLAIN %@", theSQLStatement]];
|
172
152
|
}
|
173
153
|
|
174
154
|
- (void)reset
|
175
155
|
{
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
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;
|
186
167
|
}
|
187
168
|
|
188
169
|
#pragma mark -
|
189
170
|
|
190
171
|
- (id)searchObjectsWithReturnType:(NSFReturnType)theReturnType error:(out NSError **)outError
|
191
172
|
{
|
192
|
-
|
173
|
+
_returnedObjectType = theReturnType;
|
193
174
|
|
194
175
|
// Make sure we don't have a SQL statement around...
|
195
|
-
|
176
|
+
_sql = nil;
|
196
177
|
|
197
178
|
id results = [self _retrieveDataWithError:outError];
|
198
179
|
|
@@ -201,10 +182,10 @@
|
|
201
182
|
|
202
183
|
- (id)searchObjectsAdded:(NSFDateMatchType)theDateMatch date:(NSDate *)theDate returnType:(NSFReturnType)theReturnType error:(out NSError **)outError
|
203
184
|
{
|
204
|
-
|
185
|
+
_returnedObjectType = theReturnType;
|
205
186
|
|
206
187
|
// Make sure we don't have a SQL statement around...
|
207
|
-
|
188
|
+
_sql = nil;
|
208
189
|
|
209
190
|
id results = [self _retrieveDataAdded:theDateMatch calendarDate:theDate error:outError];
|
210
191
|
|
@@ -217,11 +198,11 @@
|
|
217
198
|
|
218
199
|
- (NSNumber *)aggregateOperation:(NSFAggregateFunctionType)theFunctionType onAttribute:(NSString *)theAttribute
|
219
200
|
{
|
220
|
-
NSFReturnType savedObjectTypeReturned =
|
221
|
-
|
201
|
+
NSFReturnType savedObjectTypeReturned = _returnedObjectType;
|
202
|
+
_returnedObjectType = NSFReturnKeys;
|
222
203
|
|
223
|
-
NSString *savedSQL =
|
224
|
-
|
204
|
+
NSString *savedSQL = _sql;
|
205
|
+
_sql = nil;
|
225
206
|
|
226
207
|
NSString *theSearchSQLStatement = [self sql];
|
227
208
|
NSMutableString *theAggregatedSQLStatement = [NSMutableString new];
|
@@ -250,10 +231,10 @@
|
|
250
231
|
break;
|
251
232
|
}
|
252
233
|
|
253
|
-
NSFNanoResult *result = [
|
234
|
+
NSFNanoResult *result = [_nanoStore _executeSQL:theAggregatedSQLStatement];
|
254
235
|
|
255
|
-
|
256
|
-
|
236
|
+
_returnedObjectType = savedObjectTypeReturned;
|
237
|
+
_sql = savedSQL;
|
257
238
|
|
258
239
|
return [NSNumber numberWithFloat:[[result firstValue]floatValue]];
|
259
240
|
}
|
@@ -266,13 +247,13 @@
|
|
266
247
|
|
267
248
|
- (NSDictionary *)_retrieveDataWithError:(out NSError **)outError
|
268
249
|
{
|
269
|
-
if (YES == [
|
250
|
+
if (YES == [_nanoStore isClosed]) {
|
270
251
|
return nil;
|
271
252
|
}
|
272
253
|
|
273
254
|
NSMutableDictionary *searchResults = [NSMutableDictionary dictionary];
|
274
255
|
|
275
|
-
NSString *aSQLQuery =
|
256
|
+
NSString *aSQLQuery = _sql;
|
276
257
|
|
277
258
|
if (nil != aSQLQuery) {
|
278
259
|
// We are going to check whether the user has specified the proper columns based on the search type selected.
|
@@ -281,13 +262,13 @@
|
|
281
262
|
// We basically honor the specified query but replace the columns with the expected ones per returned type.
|
282
263
|
|
283
264
|
NSString *subStatement = [aSQLQuery substringFromIndex:[aSQLQuery rangeOfString:@"FROM" options:NSCaseInsensitiveSearch].location];
|
284
|
-
NSFReturnType returnType =
|
265
|
+
NSFReturnType returnType = _returnedObjectType;
|
285
266
|
switch (returnType) {
|
286
267
|
case NSFReturnKeys:
|
287
268
|
aSQLQuery = [NSString stringWithFormat:@"SELECT NSFKey %@", subStatement];
|
288
269
|
break;
|
289
270
|
case NSFReturnObjects:
|
290
|
-
aSQLQuery = [NSString stringWithFormat:@"SELECT NSFKey,
|
271
|
+
aSQLQuery = [NSString stringWithFormat:@"SELECT NSFKey, NSFKeyedArchive, NSFObjectClass %@", subStatement];
|
291
272
|
break;
|
292
273
|
}
|
293
274
|
} else {
|
@@ -296,7 +277,7 @@
|
|
296
277
|
|
297
278
|
_NSFLog(@"_dataWithKey SQL query: %@", aSQLQuery);
|
298
279
|
|
299
|
-
sqlite3 *sqliteStore = [[
|
280
|
+
sqlite3 *sqliteStore = [[_nanoStore nanoStoreEngine]sqlite];
|
300
281
|
sqlite3_stmt *theSQLiteStatement = NULL;
|
301
282
|
|
302
283
|
int status = sqlite3_prepare_v2 (sqliteStore, [aSQLQuery UTF8String], -1, &theSQLiteStatement, NULL );
|
@@ -304,7 +285,7 @@
|
|
304
285
|
status = [NSFNanoEngine NSFP_stripBitsFromExtendedResultCode:status];
|
305
286
|
|
306
287
|
if (SQLITE_OK == status) {
|
307
|
-
switch (
|
288
|
+
switch (_returnedObjectType) {
|
308
289
|
case NSFReturnKeys:
|
309
290
|
while (SQLITE_ROW == sqlite3_step (theSQLiteStatement)) {
|
310
291
|
// Sanity check: some queries return NULL, which would cause a crash below.
|
@@ -322,26 +303,25 @@
|
|
322
303
|
default:
|
323
304
|
while (SQLITE_ROW == sqlite3_step (theSQLiteStatement)) {
|
324
305
|
char *keyUTF8 = (char *)sqlite3_column_text (theSQLiteStatement, 0);
|
325
|
-
|
306
|
+
NSData *dictBinData = [[NSData alloc] initWithBytes:sqlite3_column_blob(theSQLiteStatement, 1) length: sqlite3_column_bytes(theSQLiteStatement, 1)];
|
326
307
|
char *objectClassUTF8 = (char *)sqlite3_column_text (theSQLiteStatement, 2);
|
327
308
|
|
328
309
|
// Sanity check: some queries return NULL, which would a crash below.
|
329
310
|
// Since these are values that are NanoStore's resposibility, they should *never* be NULL. Log it for posterity.
|
330
|
-
|
331
|
-
|
311
|
+
|
312
|
+
if ((NULL == keyUTF8) || (dictBinData == nil) || (NULL == objectClassUTF8)) {
|
313
|
+
NSLog(@"*** Warning! These values are NanoStore's resposibility and should *never* be NULL: keyUTF8 (%s) - binArchinve (%@) - objectClassUTF8 (%s)", keyUTF8, [dictBinData debugDescription], objectClassUTF8);
|
332
314
|
continue;
|
333
315
|
}
|
334
|
-
|
316
|
+
NSDictionary *info = [NSKeyedUnarchiver unarchiveObjectWithData:dictBinData];
|
335
317
|
NSString *keyValue = [[NSString alloc]initWithUTF8String:keyUTF8];
|
336
|
-
NSString *dictXML = [[NSString alloc]initWithUTF8String:dictXMLUTF8];
|
337
318
|
NSString *objectClass = [[NSString alloc]initWithUTF8String:objectClassUTF8];
|
338
319
|
|
339
|
-
NSDictionary *info = [NSFNanoEngine _plistToDictionary:dictXML];
|
340
320
|
if (nil == info) {
|
341
321
|
continue;
|
342
322
|
}
|
343
323
|
|
344
|
-
if ([
|
324
|
+
if ([_attributesToBeReturned count] == 0) {
|
345
325
|
// Will be released below...
|
346
326
|
} else {
|
347
327
|
// Since we want a subset of the attributes, we need to traverse
|
@@ -351,7 +331,7 @@
|
|
351
331
|
|
352
332
|
NSMutableDictionary *subset = [NSMutableDictionary new];
|
353
333
|
|
354
|
-
for (NSString *attributeValue in
|
334
|
+
for (NSString *attributeValue in _attributesToBeReturned) {
|
355
335
|
id theValue = [info valueForKeyPath:attributeValue];
|
356
336
|
if (nil != theValue) {
|
357
337
|
if (NSNotFound == [attributeValue rangeOfString:@"."].location) {
|
@@ -378,7 +358,7 @@
|
|
378
358
|
saveOriginalClassReference = YES;
|
379
359
|
}
|
380
360
|
|
381
|
-
id nanoObject = [[storedObjectClass alloc]initNanoObjectFromDictionaryRepresentation:info forKey:keyValue store:
|
361
|
+
id nanoObject = [[storedObjectClass alloc]initNanoObjectFromDictionaryRepresentation:info forKey:keyValue store:_nanoStore];
|
382
362
|
|
383
363
|
// If this process does not have knowledge of the original class as was saved in the store, keep a reference
|
384
364
|
// so that we can later on restore the object properly (otherwise it would be stored as a NanoObject.)
|
@@ -396,10 +376,10 @@
|
|
396
376
|
|
397
377
|
} else {
|
398
378
|
if (nil != outError) {
|
399
|
-
NSString *msg = [NSString stringWithFormat:@"SQLite error ID: %
|
379
|
+
NSString *msg = [NSString stringWithFormat:@"SQLite error ID: %d", status];
|
400
380
|
*outError = [NSError errorWithDomain:NSFDomainKey
|
401
381
|
code:NSFNanoStoreErrorKey
|
402
|
-
userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"*** -[%@
|
382
|
+
userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"*** -[%@ %@]: %@", [self class], NSStringFromSelector(_cmd), msg]
|
403
383
|
forKey:NSLocalizedFailureReasonErrorKey]];
|
404
384
|
}
|
405
385
|
searchResults = nil;
|
@@ -410,7 +390,7 @@
|
|
410
390
|
|
411
391
|
- (NSDictionary *)_retrieveDataAdded:(NSFDateMatchType)aDateMatch calendarDate:(NSDate *)aDate error:(out NSError **)outError
|
412
392
|
{
|
413
|
-
if ([
|
393
|
+
if ([_nanoStore isClosed] == YES) {
|
414
394
|
return nil;
|
415
395
|
}
|
416
396
|
|
@@ -420,46 +400,46 @@
|
|
420
400
|
switch (aDateMatch) {
|
421
401
|
case NSFBeforeDate:
|
422
402
|
if (self.filterClass.length > 0) {
|
423
|
-
theSQLStatement = [[NSString alloc]initWithFormat:@"SELECT %@, %@, %@ FROM %@ WHERE (NSFObjectClass = '%@') AND %@ < '%@'", NSFKey,
|
403
|
+
theSQLStatement = [[NSString alloc]initWithFormat:@"SELECT %@, %@, %@ FROM %@ WHERE (NSFObjectClass = '%@') AND %@ < '%@'", NSFKey, NSFKeyedArchive, NSFObjectClass, NSFKeys, self.filterClass, NSFCalendarDate, normalizedDateString];
|
424
404
|
} else {
|
425
|
-
theSQLStatement = [[NSString alloc]initWithFormat:@"SELECT %@, %@, %@ FROM %@ WHERE %@ < '%@'", NSFKey,
|
405
|
+
theSQLStatement = [[NSString alloc]initWithFormat:@"SELECT %@, %@, %@ FROM %@ WHERE %@ < '%@'", NSFKey, NSFKeyedArchive, NSFObjectClass, NSFKeys, NSFCalendarDate, normalizedDateString];
|
426
406
|
}
|
427
407
|
break;
|
428
408
|
case NSFOnDate:
|
429
409
|
if (self.filterClass.length > 0) {
|
430
|
-
theSQLStatement = [[NSString alloc]initWithFormat:@"SELECT %@, %@, %@ FROM %@ WHERE (NSFObjectClass = '%@') AND %@ = '%@'", NSFKey,
|
410
|
+
theSQLStatement = [[NSString alloc]initWithFormat:@"SELECT %@, %@, %@ FROM %@ WHERE (NSFObjectClass = '%@') AND %@ = '%@'", NSFKey, NSFKeyedArchive, NSFObjectClass, NSFKeys, self.filterClass, NSFCalendarDate, normalizedDateString];
|
431
411
|
} else {
|
432
|
-
theSQLStatement = [[NSString alloc]initWithFormat:@"SELECT %@, %@, %@ FROM %@ WHERE %@ = '%@'", NSFKey,
|
412
|
+
theSQLStatement = [[NSString alloc]initWithFormat:@"SELECT %@, %@, %@ FROM %@ WHERE %@ = '%@'", NSFKey, NSFKeyedArchive, NSFObjectClass, NSFKeys, NSFCalendarDate, normalizedDateString];
|
433
413
|
}
|
434
414
|
break;
|
435
415
|
case NSFAfterDate:
|
436
416
|
if (self.filterClass.length > 0) {
|
437
|
-
theSQLStatement = [[NSString alloc]initWithFormat:@"SELECT %@, %@, %@ FROM %@ WHERE (NSFObjectClass = '%@') AND %@ > '%@'", NSFKey,
|
417
|
+
theSQLStatement = [[NSString alloc]initWithFormat:@"SELECT %@, %@, %@ FROM %@ WHERE (NSFObjectClass = '%@') AND %@ > '%@'", NSFKey, NSFKeyedArchive, NSFObjectClass, NSFKeys, self.filterClass, NSFCalendarDate, normalizedDateString];
|
438
418
|
} else {
|
439
|
-
theSQLStatement = [[NSString alloc]initWithFormat:@"SELECT %@, %@, %@ FROM %@ WHERE %@ > '%@'", NSFKey,
|
419
|
+
theSQLStatement = [[NSString alloc]initWithFormat:@"SELECT %@, %@, %@ FROM %@ WHERE %@ > '%@'", NSFKey, NSFKeyedArchive, NSFObjectClass, NSFKeys, NSFCalendarDate, normalizedDateString];
|
440
420
|
}
|
441
421
|
break;
|
442
422
|
}
|
443
423
|
|
444
|
-
NSFNanoResult *result = [
|
424
|
+
NSFNanoResult *result = [_nanoStore _executeSQL:theSQLStatement];
|
445
425
|
|
446
426
|
NSMutableDictionary *searchResults = [NSMutableDictionary dictionaryWithCapacity:result.numberOfRows];
|
447
427
|
|
448
428
|
if (result.numberOfRows > 0) {
|
449
|
-
if (NSFReturnKeys ==
|
429
|
+
if (NSFReturnKeys == _returnedObjectType) {
|
450
430
|
NSArray *resultsKeys = [result valuesForColumn:[NSString stringWithFormat:@"%@.%@", NSFKeys, NSFKey]];
|
451
431
|
for (NSString *resultKey in resultsKeys)
|
452
432
|
[searchResults setObject:[NSNull null] forKey:resultKey];
|
453
433
|
return searchResults;
|
454
434
|
} else {
|
455
435
|
NSArray *resultsObjectClass = [result valuesForColumn:[NSString stringWithFormat:@"%@.%@", NSFKeys, NSFObjectClass]];
|
456
|
-
NSArray *resultsObjects = [result valuesForColumn:[NSString stringWithFormat:@"%@.%@", NSFKeys,
|
436
|
+
NSArray *resultsObjects = [result valuesForColumn:[NSString stringWithFormat:@"%@.%@", NSFKeys, NSFKeyedArchive]];
|
457
437
|
NSArray *resultsKeys = [result valuesForColumn:[NSString stringWithFormat:@"%@.%@", NSFKeys, NSFKey]];
|
458
438
|
NSUInteger i, count = [resultsKeys count];
|
459
439
|
|
460
440
|
for (i = 0; i < count; i++) {
|
461
441
|
@autoreleasepool {
|
462
|
-
NSDictionary *info = [
|
442
|
+
NSDictionary *info = [NSKeyedUnarchiver unarchiveObjectWithData:[resultsObjects objectAtIndex:i]];
|
463
443
|
if (nil != info) {
|
464
444
|
NSString *keyValue = [resultsKeys objectAtIndex:i];
|
465
445
|
|
@@ -471,7 +451,7 @@
|
|
471
451
|
saveOriginalClassReference = YES;
|
472
452
|
}
|
473
453
|
|
474
|
-
id nanoObject = [[storedObjectClass alloc]initNanoObjectFromDictionaryRepresentation:info forKey:keyValue store:
|
454
|
+
id nanoObject = [[storedObjectClass alloc]initNanoObjectFromDictionaryRepresentation:info forKey:keyValue store:_nanoStore];
|
475
455
|
|
476
456
|
// If this process does not have knowledge of the original class as was saved in the store, keep a reference
|
477
457
|
// so that we can later on restore the object properly (otherwise it would be stored as a NanoObject.)
|
@@ -493,10 +473,20 @@
|
|
493
473
|
{
|
494
474
|
NSString *aSQLQuery = nil;
|
495
475
|
|
496
|
-
if (nil ==
|
497
|
-
aSQLQuery = [self _prepareSQLQueryStringWithKey:
|
476
|
+
if (nil == _expressions) {
|
477
|
+
aSQLQuery = [self _prepareSQLQueryStringWithKey:_key attribute:_attribute value:_value matching:_match];
|
498
478
|
} else {
|
499
|
-
aSQLQuery = [self _prepareSQLQueryStringWithExpressions:
|
479
|
+
aSQLQuery = [self _prepareSQLQueryStringWithExpressions:_expressions];
|
480
|
+
}
|
481
|
+
|
482
|
+
// Add the limit clause if required
|
483
|
+
if (_limit > 0) {
|
484
|
+
aSQLQuery = [NSString stringWithFormat:@"%@ LIMIT %li", aSQLQuery, _limit];
|
485
|
+
}
|
486
|
+
|
487
|
+
// Add the offset clause if required
|
488
|
+
if (_offset > 0) {
|
489
|
+
aSQLQuery = [NSString stringWithFormat:@"%@ OFFSET %li", aSQLQuery, _offset];
|
500
490
|
}
|
501
491
|
|
502
492
|
return aSQLQuery;
|
@@ -512,9 +502,9 @@
|
|
512
502
|
aValue = [aValue stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
|
513
503
|
}
|
514
504
|
|
515
|
-
if (nil !=
|
505
|
+
if (nil != _attributesToBeReturned) {
|
516
506
|
// Prepare the list of attributes we need to gather. Include NSFKEY as well.
|
517
|
-
NSMutableSet *set = [[NSMutableSet alloc]initWithArray:
|
507
|
+
NSMutableSet *set = [[NSMutableSet alloc]initWithArray:_attributesToBeReturned];
|
518
508
|
NSArray *objects = [set allObjects];
|
519
509
|
NSMutableArray *quotedObjects = [NSMutableArray new];
|
520
510
|
for (NSString *object in objects) {
|
@@ -524,7 +514,7 @@
|
|
524
514
|
attributes = [quotedObjects componentsJoinedByString:@","];
|
525
515
|
}
|
526
516
|
|
527
|
-
NSFReturnType returnType =
|
517
|
+
NSFReturnType returnType = _returnedObjectType;
|
528
518
|
|
529
519
|
if ((nil == aKey) && (nil == anAttribute) && (nil == aValue)) {
|
530
520
|
switch (returnType) {
|
@@ -532,13 +522,13 @@
|
|
532
522
|
return @"SELECT NSFKEY FROM NSFKeys";
|
533
523
|
break;
|
534
524
|
default:
|
535
|
-
return @"SELECT NSFKey,
|
525
|
+
return @"SELECT NSFKey, NSFKeyedArchive, NSFObjectClass FROM NSFKeys";
|
536
526
|
break;
|
537
527
|
}
|
538
528
|
} else {
|
539
529
|
switch (returnType) {
|
540
530
|
case NSFReturnKeys:
|
541
|
-
if (NO ==
|
531
|
+
if (NO == _groupValues) {
|
542
532
|
theSQLStatement = [NSMutableString stringWithString:@"SELECT DISTINCT (NSFKEY) FROM NSFValues WHERE "];
|
543
533
|
} else {
|
544
534
|
theSQLStatement = [NSMutableString stringWithString:@"SELECT NSFKEY FROM NSFValues WHERE "];
|
@@ -573,10 +563,14 @@
|
|
573
563
|
if (NSNotFound == [anAttribute rangeOfString:@"."].location) {
|
574
564
|
segment = [NSFNanoSearch _querySegmentForAttributeColumnWithValue:anAttribute matching:aMatch valueColumnWithValue:aValue];
|
575
565
|
} else {
|
576
|
-
|
566
|
+
if (nil == aValue) {
|
577
567
|
segment = [NSFNanoSearch _querySegmentForColumn:NSFAttribute value:anAttribute matching:aMatch];
|
578
|
-
else
|
568
|
+
} else {
|
579
569
|
segment = [NSFNanoSearch _querySegmentForColumn:NSFAttribute value:anAttribute matching:NSFEqualTo];
|
570
|
+
[theSQLStatement appendString:segment];
|
571
|
+
[theSQLStatement appendString:@" AND "];
|
572
|
+
segment = [NSFNanoSearch _querySegmentForColumn:NSFValue value:aValue matching:NSFEqualTo];
|
573
|
+
}
|
580
574
|
}
|
581
575
|
|
582
576
|
[theSQLStatement appendString:segment];
|
@@ -589,15 +583,19 @@
|
|
589
583
|
}
|
590
584
|
}
|
591
585
|
|
592
|
-
if (
|
586
|
+
if ((_limit > 0) || (_offset > 0)) {
|
587
|
+
[theSQLStatement appendString:@" ORDER BY ROWID"];
|
588
|
+
}
|
589
|
+
|
590
|
+
if (YES == _groupValues) {
|
593
591
|
[theSQLStatement appendString:@" GROUP BY NSFValue"];
|
594
592
|
}
|
595
593
|
|
596
594
|
if (NSFReturnObjects == returnType) {
|
597
595
|
if (self.filterClass.length > 0) {
|
598
|
-
theSQLStatement = [NSString stringWithFormat:@"SELECT DISTINCT (NSFKey),
|
596
|
+
theSQLStatement = [NSString stringWithFormat:@"SELECT DISTINCT (NSFKey),NSFKeyedArchive,NSFObjectClass FROM NSFKeys WHERE (NSFObjectClass = '%@') AND NSFKey IN (%@)", self.filterClass, theSQLStatement];
|
599
597
|
} else {
|
600
|
-
theSQLStatement = [NSString stringWithFormat:@"SELECT DISTINCT (NSFKey),
|
598
|
+
theSQLStatement = [NSString stringWithFormat:@"SELECT DISTINCT (NSFKey),NSFKeyedArchive,NSFObjectClass FROM NSFKeys WHERE NSFKey IN (%@)", theSQLStatement];
|
601
599
|
}
|
602
600
|
} else {
|
603
601
|
if (self.filterClass.length > 0) {
|
@@ -613,7 +611,7 @@
|
|
613
611
|
NSUInteger i, count = [someExpressions count];
|
614
612
|
NSMutableArray *sqlComponents = [NSMutableArray new];
|
615
613
|
NSMutableString *parentheses = [NSMutableString new];
|
616
|
-
NSFReturnType returnType =
|
614
|
+
NSFReturnType returnType = _returnedObjectType;
|
617
615
|
|
618
616
|
if (count == 0) {
|
619
617
|
if (NSFReturnObjects == returnType) {
|
@@ -648,9 +646,9 @@
|
|
648
646
|
|
649
647
|
if (NSFReturnObjects == returnType) {
|
650
648
|
if (self.filterClass.length > 0) {
|
651
|
-
theValue = [NSString stringWithFormat:@"SELECT DISTINCT (NSFKey),
|
649
|
+
theValue = [NSString stringWithFormat:@"SELECT DISTINCT (NSFKey),NSFKeyedArchive,NSFObjectClass FROM NSFKeys WHERE (NSFObjectClass = '%@') AND NSFKey IN (%@)", self.filterClass, theValue];
|
652
650
|
} else {
|
653
|
-
theValue = [NSString stringWithFormat:@"SELECT DISTINCT (NSFKey),
|
651
|
+
theValue = [NSString stringWithFormat:@"SELECT DISTINCT (NSFKey),NSFKeyedArchive,NSFObjectClass FROM NSFKeys WHERE NSFKey IN (%@)", theValue];
|
654
652
|
}
|
655
653
|
} else {
|
656
654
|
if (self.filterClass.length > 0) {
|
@@ -674,7 +672,7 @@
|
|
674
672
|
[theSQLStatement appendString:[preparedKeys componentsJoinedByString:@","]];
|
675
673
|
[theSQLStatement appendString:@")"];
|
676
674
|
|
677
|
-
theSQLStatement = [NSString stringWithFormat:@"SELECT DISTINCT (NSFKey),
|
675
|
+
theSQLStatement = [NSString stringWithFormat:@"SELECT DISTINCT (NSFKey),NSFKeyedArchive,NSFObjectClass FROM NSFKeys WHERE NSFKey IN (%@)", theSQLStatement];
|
678
676
|
|
679
677
|
return theSQLStatement;
|
680
678
|
}
|
@@ -873,10 +871,10 @@
|
|
873
871
|
{
|
874
872
|
id theResults = results;
|
875
873
|
|
876
|
-
if (
|
874
|
+
if ([_sort count] > 0) {
|
877
875
|
NSMutableArray *cocoaSortDescriptors = [NSMutableArray new];
|
878
876
|
|
879
|
-
for (NSFNanoSortDescriptor *descriptor in
|
877
|
+
for (NSFNanoSortDescriptor *descriptor in _sort) {
|
880
878
|
NSString *targetKeyPath = [[NSString alloc]initWithFormat:@"rootObject.%@", descriptor.attribute];
|
881
879
|
NSSortDescriptor *cocoaSort = [[NSSortDescriptor alloc]initWithKey:targetKeyPath ascending:descriptor.isAscending];
|
882
880
|
[cocoaSortDescriptors addObject:cocoaSort];
|
@@ -887,15 +885,58 @@
|
|
887
885
|
} else {
|
888
886
|
theResults = [results allKeys];
|
889
887
|
}
|
890
|
-
}
|
891
|
-
else if (NSFReturnKeys == theReturnType)
|
892
|
-
{
|
888
|
+
} else if (NSFReturnKeys == theReturnType) {
|
893
889
|
theResults = [results allKeys];
|
894
890
|
}
|
895
891
|
|
896
892
|
return theResults;
|
897
893
|
}
|
898
894
|
|
895
|
+
- (NSString *)description
|
896
|
+
{
|
897
|
+
return [self JSONDescription];
|
898
|
+
}
|
899
|
+
|
900
|
+
- (NSFOrderedDictionary *)dictionaryDescription
|
901
|
+
{
|
902
|
+
NSFOrderedDictionary *values = [NSFOrderedDictionary new];
|
903
|
+
|
904
|
+
values[@"NanoSearch address"] = [NSString stringWithFormat:@"%p", self];
|
905
|
+
values[@"Document store"] = [_nanoStore dictionaryDescription];
|
906
|
+
values[@"Attributes to be returned"] = (_attributesToBeReturned ? [_attributesToBeReturned componentsJoinedByString:@","] : @"All");
|
907
|
+
values[@"Key"] = (_key ? _key : @"<nil>");
|
908
|
+
values[@"Attribute"] = (_attribute ? _attribute : @"<nil>");
|
909
|
+
values[@"Value"] = (_value ? _value : @"<nil>");
|
910
|
+
values[@"Match"] = NSFStringFromMatchType(_match);
|
911
|
+
|
912
|
+
NSMutableArray *tempExpressions = [NSMutableArray new];
|
913
|
+
for (NSFNanoExpression *expression in _expressions) {
|
914
|
+
[tempExpressions addObject:[expression description]];
|
915
|
+
}
|
916
|
+
values[@"Expressions"] = ([tempExpressions count] > 0 ? tempExpressions : @"<nil>");
|
917
|
+
|
918
|
+
values[@"Group values?"] = (_groupValues ? @"YES" : @"NO");
|
919
|
+
|
920
|
+
NSString *tempSQL = [self sql];
|
921
|
+
values[@"SQL"] = (tempSQL ? tempSQL : @"<nil>");
|
922
|
+
values[@"Sort"] = (_sort ? _sort : @"<nil>");
|
923
|
+
values[@"Filter class"] = (_filterClass ? _filterClass : @"<nil>");
|
924
|
+
values[@"Offset"] = @(_offset);
|
925
|
+
values[@"Limit"] = @(_limit);
|
926
|
+
|
927
|
+
return values;
|
928
|
+
}
|
929
|
+
|
930
|
+
- (NSString *)JSONDescription
|
931
|
+
{
|
932
|
+
NSFOrderedDictionary *values = [self dictionaryDescription];
|
933
|
+
|
934
|
+
NSError *outError = nil;
|
935
|
+
NSString *description = [NSFNanoObject _NSObjectToJSONString:values error:&outError];
|
936
|
+
|
937
|
+
return description;
|
938
|
+
}
|
939
|
+
|
899
940
|
/** \endcond */
|
900
941
|
|
901
942
|
@end
|