/*
- Copyright (C) 2004-2005 SKYRIX Software AG
+ Copyright (C) 2004-2007 SKYRIX Software AG
This file is part of OpenGroupware.org.
toString:(NSMutableString *)_ms
{
id val;
-
- [_ms appendString:[_q key]];
-
+ NSString *qKey, *qOperator, *qValue, *qFormat;
+ BOOL isCI;
+
+ qKey = [_q key];
+
if ((val = [_q value])) {
SEL op = [_q selector];
-
+
if ([val isNotNull]) {
+ isCI = NO;
+
if (sel_eq(op, EOQualifierOperatorEqual))
- [_ms appendString:@" = "];
+ qOperator = @"=";
else if (sel_eq(op, EOQualifierOperatorNotEqual))
- [_ms appendString:@" != "];
+ qOperator = @"!=";
else if (sel_eq(op, EOQualifierOperatorLessThan))
- [_ms appendString:@" < "];
+ qOperator = @"<";
else if (sel_eq(op, EOQualifierOperatorGreaterThan))
- [_ms appendString:@" > "];
+ qOperator = @">";
else if (sel_eq(op, EOQualifierOperatorLessThanOrEqualTo))
- [_ms appendString:@" <= "];
+ qOperator = @"<=";
else if (sel_eq(op, EOQualifierOperatorGreaterThanOrEqualTo))
- [_ms appendString:@" >= "];
+ qOperator = @">=";
else if (sel_eq(op, EOQualifierOperatorLike))
- [_ms appendString:@" LIKE "];
+ qOperator = @"LIKE";
else if (sel_eq(op, EOQualifierOperatorCaseInsensitiveLike)) {
- // TODO: this is PostgreSQL specific, use UPPER?
- [_ms appendString:@" ILIKE "];
+ isCI = YES;
+ qOperator = @"LIKE";
}
else {
[self errorWithFormat:@"%s: unsupported operation for null: %@",
}
if ([val isKindOfClass:[NSNumber class]])
- [_ms appendString:[val stringValue]];
+ qValue = [val stringValue];
else if ([val isKindOfClass:[NSString class]]) {
- [_ms appendString:@"'"];
- [_ms appendString:val];
- [_ms appendString:@"'"];
+ qValue = [NSString stringWithFormat: @"'%@'", val];
}
else {
[self errorWithFormat:@"%s: unsupported value class: %@",
}
}
else {
- if (sel_eq(op, EOQualifierOperatorEqual))
- [_ms appendString:@" IS NULL"];
- else if (sel_eq(op, EOQualifierOperatorEqual))
- [_ms appendString:@" IS NOT NULL"];
+ if (sel_eq(op, EOQualifierOperatorEqual)) {
+ qOperator = @"IS";
+ qValue = @"NULL";
+ }
+ else if (sel_eq(op, EOQualifierOperatorEqual)) {
+ qOperator = @"IS NOT";
+ qValue = @"NULL";
+ }
else {
[self errorWithFormat:@"%s: invalid operation for null: %@",
__PRETTY_FUNCTION__, NSStringFromSelector(op)];
}
}
}
+ else {
+ qOperator = @"IS";
+ qValue = @"NULL";
+ }
+
+ if (isCI)
+ qFormat = @"UPPER(%@) %@ UPPER(%@)";
else
- [_ms appendString:@" IS NULL"];
+ qFormat = @"%@ %@ %@";
+
+ [_ms appendFormat: qFormat, qKey, qOperator, qValue];
}
- (void)_appendQualifier:(EOQualifier *)_q toString:(NSMutableString *)_ms {