]> err.no Git - sope/blob - sope-gdl1/GDLAccess/EOSelectSQLExpression.m
added missing inline pathes
[sope] / sope-gdl1 / GDLAccess / EOSelectSQLExpression.m
1 /* 
2    EOSQLExpression.m
3
4    Copyright (C) 1996 Free Software Foundation, Inc.
5
6    Author: Ovidiu Predescu <ovidiu@bx.logicnet.ro>
7    Date: September 1996
8
9    This file is part of the GNUstep Database Library.
10
11    This library is free software; you can redistribute it and/or
12    modify it under the terms of the GNU Library General Public
13    License as published by the Free Software Foundation; either
14    version 2 of the License, or (at your option) any later version.
15
16    This library is distributed in the hope that it will be useful,
17    but WITHOUT ANY WARRANTY; without even the implied warranty of
18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19    Library General Public License for more details.
20
21    You should have received a copy of the GNU Library General Public
22    License along with this library; see the file COPYING.LIB.
23    If not, write to the Free Software Foundation,
24    59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 */
26
27 #include "EOSQLExpression.h"
28 #include "EOAttribute.h"
29 #include "EOAdaptor.h"
30 #include "common.h"
31
32 #if LIB_FOUNDATION_LIBRARY
33 #  include <extensions/DefaultScannerHandler.h>
34 #  include <extensions/PrintfFormatScanner.h>
35 #else
36 #  include "DefaultScannerHandler.h"
37 #  include "PrintfFormatScanner.h"
38 #endif
39
40 @interface EOSelectScannerHandler : DefaultScannerHandler
41 {
42     EOAttribute *attribute;
43     EOAdaptor   *adaptor;
44     NSString    *alias;
45 }
46
47 - (void)setAttribute:(EOAttribute*)attribute
48   adaptor:(EOAdaptor*)adaptor
49   alias:(NSString*)alias;
50
51 @end
52
53 @implementation EOSelectSQLExpression
54
55 - (NSString *)expressionValueForAttribute:(EOAttribute *)attribute
56   context:(id)context
57 {
58   NSString *alias;
59   NSString *columnName;
60   
61   alias = [entitiesAndPropertiesAliases objectForKey:context];
62   
63   //NSLog(@"entitiesAndPropertiesAliases: %@", entitiesAndPropertiesAliases);
64   
65     columnName = adaptor
66       ? [adaptor formatAttribute:attribute]
67       : [attribute columnName];
68
69     if (alias) {
70       return [([[NSString alloc] initWithFormat:@"%@.%@",
71                                  alias, columnName]) autorelease];
72     }
73     
74     return columnName;
75 }
76
77 @end /* EOSelectSQLExpression */
78
79 @implementation EOSelectScannerHandler
80
81 - (id)init {
82   if ((self = [super init]) != nil) {
83     specHandler['A']
84       = [self methodForSelector:@selector(convertAttribute:scanner:)];
85   }
86   return self;
87 }
88
89 - (void)dealloc {
90   [self->attribute release];
91   [self->adaptor   release];
92   [self->alias     release];
93   [super dealloc];
94 }
95
96 - (void)setAttribute:(EOAttribute*)_attribute
97   adaptor:(EOAdaptor*)_adaptor
98   alias:(NSString*)_alias
99 {
100     ASSIGN(self->attribute, _attribute);
101     ASSIGN(self->adaptor,   _adaptor);
102     ASSIGN(self->alias,     _alias);
103 }
104
105 - (NSString *)convertAttribute:(va_list *)pString
106   scanner:(FormatScanner *)scanner
107 {
108   NSString *columnName;
109
110   columnName = (adaptor)
111     ? [adaptor formatAttribute:self->attribute]
112     : [self->attribute columnName];
113
114   if (alias)
115     return [NSString stringWithFormat:@"%@.%@", alias, columnName];
116
117   return columnName;
118 }
119
120 @end /* EOSelectScannerHandler */