#import <Foundation/NSObject.h>
@class NSString, NSURL, NSNumber, NSArray, NSException, NSMutableString;
-@class EOQualifier;
+@class EOQualifier, EOFetchSpecification;
@class EOAdaptorChannel;
@class OCSFolderManager, OCSFolderType, OCSChannelManager;
- (NSException *)writeContent:(NSString *)_content toName:(NSString *)_name;
- (NSException *)deleteContentWithName:(NSString *)_name;
+- (NSArray *)fetchFields:(NSArray *)_flds
+ fetchSpecification:(EOFetchSpecification *)_fs;
- (NSArray *)fetchFields:(NSArray *)_flds matchingQualifier:(EOQualifier *)_q;
@end
/* SQL generation */
+- (NSString *)generateSQLForSortOrderings:(NSArray *)_so {
+ NSMutableString *sql;
+ unsigned i, count;
+
+ if ((count = [_so count]) == 0)
+ return nil;
+
+ sql = [NSMutableString stringWithCapacity:(count * 16)];
+ for (i = 0; i < count; i++) {
+ EOSortOrdering *so;
+ NSString *column;
+ SEL sel;
+
+ so = [_so objectAtIndex:i];
+ sel = [so selector];
+ column = [self columnNameForFieldName:[so key]];
+
+ if (i > 0) [sql appendString:@", "];
+
+ if (sel_eq(sel, EOCompareAscending)) {
+ [sql appendString:column];
+ [sql appendString:@" ASC"];
+ }
+ else if (sel_eq(sel, EOCompareDescending)) {
+ [sql appendString:column];
+ [sql appendString:@" DESC"];
+ }
+ else if (sel_eq(sel, EOCompareCaseInsensitiveAscending)) {
+ [sql appendString:@"UPPER("];
+ [sql appendString:column];
+ [sql appendString:@") ASC"];
+ }
+ else if (sel_eq(sel, EOCompareCaseInsensitiveDescending)) {
+ [sql appendString:@"UPPER("];
+ [sql appendString:column];
+ [sql appendString:@") DESC"];
+ }
+ else {
+ [self logWithFormat:@"cannot handle sort selector in store: %@",
+ NSStringFromSelector(sel)];
+ }
+ }
+ return sql;
+}
- (NSString *)generateSQLForQualifier:(EOQualifier *)_q {
NSMutableString *ms;
/* fetching */
-- (NSArray *)fetchFields:(NSArray *)_flds matchingQualifier:(EOQualifier *)_q {
+- (NSArray *)fetchFields:(NSArray *)_flds
+ fetchSpecification:(EOFetchSpecification *)_fs
+{
+ EOQualifier *qualifier;
+ NSArray *sortOrderings;
EOAdaptorChannel *channel;
NSException *error;
NSMutableString *sql;
NSMutableArray *results;
NSDictionary *row;
+ qualifier = [_fs qualifier];
+ sortOrderings = [_fs sortOrderings];
+
#if 0
[self logWithFormat:@"FETCH: %@", _flds];
[self logWithFormat:@" MATCH: %@", _q];
[sql appendString:@" FROM "];
[sql appendString:[self quickTableName]];
- if (_q != nil) {
+ if (qualifier != nil) {
[sql appendString:@" WHERE "];
- [sql appendString:[self generateSQLForQualifier:_q]];
+ [sql appendString:[self generateSQLForQualifier:qualifier]];
+ }
+ if ([sortOrderings count] > 0) {
+ [sql appendString:@" ORDER BY "];
+ [sql appendString:[self generateSQLForSortOrderings:sortOrderings]];
}
+#if 0
+ /* limit */
+ [sql appendString:@" LIMIT "]; // count
+ [sql appendString:@" OFFSET "]; // index from 0
+#endif
/* open channel */
return results;
}
+- (NSArray *)fetchFields:(NSArray *)_flds matchingQualifier:(EOQualifier *)_q {
+ EOFetchSpecification *fs;
+
+ if (_q == nil)
+ fs = nil;
+ else {
+ fs = [EOFetchSpecification fetchSpecificationWithEntityName:
+ [self folderName]
+ qualifier:_q
+ sortOrderings:nil];
+ }
+ return [self fetchFields:_flds fetchSpecification:fs];
+}
/* description */