2 Copyright (C) 2004-2005 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include "EOQualifier+GCS.h"
25 @implementation EOQualifier(GCS)
27 - (void)_appendAndQualifier:(EOAndQualifier *)_q
28 toString:(NSMutableString *)_ms
30 // TODO: move to EOQualifier category
35 if ((count = [qs count]) == 0)
38 for (i = 0; i < count; i++) {
39 if (i != 0) [_ms appendString:@" AND "];
40 if (count > 1) [_ms appendString:@"("];
41 [[qs objectAtIndex:i] _gcsAppendToString:_ms];
42 if (count > 1) [_ms appendString:@")"];
45 - (void)_appendOrQualifier:(EOAndQualifier *)_q
46 toString:(NSMutableString *)_ms
48 // TODO: move to EOQualifier category
53 if ((count = [qs count]) == 0)
56 for (i = 0; i < count; i++) {
57 if (i != 0) [_ms appendString:@" OR "];
58 if (count > 1) [_ms appendString:@"("];
59 [[qs objectAtIndex:i] _gcsAppendToString:_ms];
60 if (count > 1) [_ms appendString:@")"];
63 - (void)_appendKeyValueQualifier:(EOKeyValueQualifier *)_q
64 toString:(NSMutableString *)_ms
68 [_ms appendString:[_q key]];
70 if ((val = [_q value])) {
71 SEL op = [_q selector];
73 if ([val isNotNull]) {
74 if (sel_eq(op, EOQualifierOperatorEqual))
75 [_ms appendString:@" = "];
76 else if (sel_eq(op, EOQualifierOperatorNotEqual))
77 [_ms appendString:@" != "];
78 else if (sel_eq(op, EOQualifierOperatorLessThan))
79 [_ms appendString:@" < "];
80 else if (sel_eq(op, EOQualifierOperatorGreaterThan))
81 [_ms appendString:@" > "];
82 else if (sel_eq(op, EOQualifierOperatorLessThanOrEqualTo))
83 [_ms appendString:@" <= "];
84 else if (sel_eq(op, EOQualifierOperatorGreaterThanOrEqualTo))
85 [_ms appendString:@" >= "];
86 else if (sel_eq(op, EOQualifierOperatorLike))
87 [_ms appendString:@" LIKE "];
88 else if (sel_eq(op, EOQualifierOperatorCaseInsensitiveLike)) {
89 // TODO: this is PostgreSQL specific, use UPPER?
90 [_ms appendString:@" ILIKE "];
93 [self logWithFormat:@"ERROR(%s): unsupported operation for null: %@",
94 __PRETTY_FUNCTION__, NSStringFromSelector(op)];
97 if ([val isKindOfClass:[NSNumber class]])
98 [_ms appendString:[val stringValue]];
99 else if ([val isKindOfClass:[NSString class]]) {
100 [_ms appendString:@"'"];
101 [_ms appendString:val];
102 [_ms appendString:@"'"];
105 [self logWithFormat:@"ERROR(%s): unsupported value class: %@",
106 __PRETTY_FUNCTION__, NSStringFromClass([val class])];
110 if (sel_eq(op, EOQualifierOperatorEqual))
111 [_ms appendString:@" IS NULL"];
112 else if (sel_eq(op, EOQualifierOperatorEqual))
113 [_ms appendString:@" IS NOT NULL"];
115 [self logWithFormat:@"ERROR(%s): invalid operation for null: %@",
116 __PRETTY_FUNCTION__, NSStringFromSelector(op)];
121 [_ms appendString:@" IS NULL"];
124 - (void)_appendQualifier:(EOQualifier *)_q toString:(NSMutableString *)_ms {
125 if (_q == nil) return;
127 if ([_q isKindOfClass:[EOAndQualifier class]])
128 [self _appendAndQualifier:(id)_q toString:_ms];
129 else if ([_q isKindOfClass:[EOOrQualifier class]])
130 [self _appendOrQualifier:(id)_q toString:_ms];
131 else if ([_q isKindOfClass:[EOKeyValueQualifier class]])
132 [self _appendKeyValueQualifier:(id)_q toString:_ms];
134 NSLog(@"ERROR: unknown qualifier: %@", _q);
137 - (void)_gcsAppendToString:(NSMutableString *)_ms {
138 [self _appendQualifier:self toString:_ms];
141 @end /* EOQualifier(GCS) */