]> err.no Git - sope/blob - sope-gdl1/GDLContentStore/EOQualifier+GCS.m
properly use system-lib-dir
[sope] / sope-gdl1 / GDLContentStore / EOQualifier+GCS.m
1 /*
2   Copyright (C) 2004-2005 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21
22 #include "EOQualifier+GCS.h"
23 #include "common.h"
24
25 @implementation EOQualifier(GCS)
26
27 - (void)_appendAndQualifier:(EOAndQualifier *)_q 
28   toString:(NSMutableString *)_ms
29 {
30   // TODO: move to EOQualifier category
31   NSArray *qs;
32   unsigned i, count;
33   
34   qs = [_q qualifiers];
35   if ((count = [qs count]) == 0)
36     return;
37   
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:@")"];
43   }
44 }
45 - (void)_appendKeyValueQualifier:(EOKeyValueQualifier *)_q 
46   toString:(NSMutableString *)_ms
47 {
48   id val;
49   
50   [_ms appendString:[_q key]];
51   
52   if ((val = [_q value])) {
53     SEL op = [_q selector];
54     
55     if ([val isNotNull]) {
56       if (sel_eq(op, EOQualifierOperatorEqual))
57         [_ms appendString:@" = "];
58       else if (sel_eq(op, EOQualifierOperatorNotEqual))
59         [_ms appendString:@" != "];
60       else if (sel_eq(op, EOQualifierOperatorLessThan))
61         [_ms appendString:@" < "];
62       else if (sel_eq(op, EOQualifierOperatorGreaterThan))
63         [_ms appendString:@" > "];
64       else if (sel_eq(op, EOQualifierOperatorLessThanOrEqualTo))
65         [_ms appendString:@" <= "];
66       else if (sel_eq(op, EOQualifierOperatorGreaterThanOrEqualTo))
67         [_ms appendString:@" >= "];
68       else if (sel_eq(op, EOQualifierOperatorLike))
69         [_ms appendString:@" LIKE "];
70       else {
71         [self logWithFormat:@"ERROR(%s): unsupported operation for null: %@",
72               __PRETTY_FUNCTION__, NSStringFromSelector(op)];
73       }
74
75       if ([val isKindOfClass:[NSNumber class]])
76         [_ms appendString:[val stringValue]];
77       else if ([val isKindOfClass:[NSString class]]) {
78         [_ms appendString:@"'"];
79         [_ms appendString:val];
80         [_ms appendString:@"'"];
81       }
82       else {
83         [self logWithFormat:@"ERROR(%s): unsupported value class: %@",
84               __PRETTY_FUNCTION__, NSStringFromClass([val class])];
85       }
86     }
87     else {
88       if (sel_eq(op, EOQualifierOperatorEqual))
89         [_ms appendString:@" IS NULL"];
90       else if (sel_eq(op, EOQualifierOperatorEqual))
91         [_ms appendString:@" IS NOT NULL"];
92       else {
93         [self logWithFormat:@"ERROR(%s): invalid operation for null: %@",
94               __PRETTY_FUNCTION__, NSStringFromSelector(op)];
95       }
96     }
97   }
98   else
99     [_ms appendString:@" IS NULL"];
100 }
101
102 - (void)_appendQualifier:(EOQualifier *)_q toString:(NSMutableString *)_ms {
103   if (_q == nil) return;
104   
105   if ([_q isKindOfClass:[EOAndQualifier class]])
106     [self _appendAndQualifier:(id)_q toString:_ms];
107   else if ([_q isKindOfClass:[EOKeyValueQualifier class]])
108     [self _appendKeyValueQualifier:(id)_q toString:_ms];
109   else
110     NSLog(@"ERROR: unknown qualifier: %@", _q);
111 }
112
113 - (void)_gcsAppendToString:(NSMutableString *)_ms {
114   [self _appendQualifier:self toString:_ms];
115 }
116
117 @end /* EOQualifier(GCS) */