return _fieldName;
}
+/* SQL generation */
+
+- (void)_appendAndQualifier:(EOAndQualifier *)_q
+ toString:(NSMutableString *)_ms
+{
+ NSArray *qs;
+ unsigned i, count;
+
+ qs = [_q qualifiers];
+ if ((count = [qs count]) == 0)
+ return;
+
+ for (i = 0; i < count; i++) {
+ if (i != 0) [_ms appendString:@" AND "];
+ if (count > 1) [_ms appendString:@"("];
+ [self _appendQualifier:[qs objectAtIndex:i] toString:_ms];
+ if (count > 1) [_ms appendString:@")"];
+ }
+}
+- (void)_appendKeyValueQualifier:(EOKeyValueQualifier *)_q
+ toString:(NSMutableString *)_ms
+{
+ id val;
+
+ [_ms appendString:[_q key]];
+
+ if ((val = [_q value])) {
+ SEL op = [_q selector];
+
+ if ([val isNotNull]) {
+ if (sel_eq(op, EOQualifierOperatorEqual))
+ [_ms appendString:@" = "];
+ else if (sel_eq(op, EOQualifierOperatorNotEqual))
+ [_ms appendString:@" != "];
+ else if (sel_eq(op, EOQualifierOperatorLessThan))
+ [_ms appendString:@" < "];
+ else if (sel_eq(op, EOQualifierOperatorGreaterThan))
+ [_ms appendString:@" > "];
+ else if (sel_eq(op, EOQualifierOperatorLessThanOrEqualTo))
+ [_ms appendString:@" <= "];
+ else if (sel_eq(op, EOQualifierOperatorGreaterThanOrEqualTo))
+ [_ms appendString:@" >= "];
+ else if (sel_eq(op, EOQualifierOperatorLike))
+ [_ms appendString:@" LIKE "];
+ else {
+ [self logWithFormat:@"ERROR(%s): unsupported operation for null: %@",
+ __PRETTY_FUNCTION__, NSStringFromSelector(op)];
+ }
+
+ if ([val isKindOfClass:[NSNumber class]])
+ [_ms appendString:[val stringValue]];
+ else if ([val isKindOfClass:[NSString class]]) {
+ [_ms appendString:@"'"];
+ [_ms appendString:val];
+ [_ms appendString:@"'"];
+ }
+ else {
+ [self logWithFormat:@"ERROR(%s): unsupported value class: %@",
+ __PRETTY_FUNCTION__, NSStringFromClass([val class])];
+ }
+ }
+ else {
+ if (sel_eq(op, EOQualifierOperatorEqual))
+ [_ms appendString:@" IS NULL"];
+ else if (sel_eq(op, EOQualifierOperatorEqual))
+ [_ms appendString:@" IS NOT NULL"];
+ else {
+ [self logWithFormat:@"ERROR(%s): invalid operation for null: %@",
+ __PRETTY_FUNCTION__, NSStringFromSelector(op)];
+ }
+ }
+ }
+ else
+ [_ms appendString:@" IS NULL"];
+}
+
+- (void)_appendQualifier:(EOQualifier *)_q toString:(NSMutableString *)_ms {
+ if (_q == nil) return;
+
+ if ([_q isKindOfClass:[EOAndQualifier class]])
+ [self _appendAndQualifier:(id)_q toString:_ms];
+ else if ([_q isKindOfClass:[EOKeyValueQualifier class]])
+ [self _appendKeyValueQualifier:(id)_q toString:_ms];
+ else
+ NSLog(@"ERROR: unknown qualifier: %@", _q);
+}
+- (NSString *)generateSQLForQualifier:(EOQualifier *)_q {
+ NSMutableString *ms;
+
+ if (_q == nil) return nil;
+ ms = [NSMutableString stringWithCapacity:32];
+ [self _appendQualifier:_q toString:ms];
+ return ms;
+}
+
+/* fetching */
+
- (NSArray *)fetchFields:(NSArray *)_flds matchingQualifier:(EOQualifier *)_q {
EOAdaptorChannel *channel;
NSException *error;
}
[sql appendString:@" FROM "];
[sql appendString:[self quickTableName]];
-
+
+ if (_q != nil) {
+ [sql appendString:@" WHERE "];
+ [sql appendString:[self generateSQLForQualifier:_q]];
+ }
+
/* open channel */
if ((channel = [self acquireStoreChannel]) == nil) {