4 Copyright (C) 1996 Free Software Foundation, Inc.
6 Author: Ovidiu Predescu <ovidiu@bx.logicnet.ro>
9 This file is part of the GNUstep Database Library.
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.
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.
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.
27 #include "EOSQLExpression.h"
28 #include "EOAttribute.h"
29 #include "EOAdaptor.h"
32 #if LIB_FOUNDATION_LIBRARY
33 # include <extensions/DefaultScannerHandler.h>
34 # include <extensions/PrintfFormatScanner.h>
36 # include "DefaultScannerHandler.h"
37 # include "PrintfFormatScanner.h"
40 @interface EOSelectScannerHandler : DefaultScannerHandler
42 EOAttribute *attribute;
47 - (void)setAttribute:(EOAttribute*)attribute
48 adaptor:(EOAdaptor*)adaptor
49 alias:(NSString*)alias;
53 @implementation EOSelectSQLExpression
55 - (NSString *)expressionValueForAttribute:(EOAttribute *)attribute
60 NSString *selectFormat;
62 alias = [entitiesAndPropertiesAliases objectForKey:context];
63 selectFormat = [attribute selectFormat];
65 //NSLog(@"entitiesAndPropertiesAliases: %@", entitiesAndPropertiesAliases);
68 PrintfFormatScanner *formatScanner;
69 EOSelectScannerHandler *scannerHandler;
72 [[[[PrintfFormatScanner alloc] init] setAllowOnlySpecifier:YES]
75 [[[EOSelectScannerHandler alloc] init] autorelease];
77 [scannerHandler setAttribute:attribute adaptor:adaptor alias:alias];
78 [formatScanner setFormatScannerHandler:scannerHandler];
80 return [formatScanner performSelector:
81 @selector(stringWithFormat:arguments:)
82 withObject:selectFormat
85 return [formatScanner stringWithFormat:selectFormat arguments:NULL];
90 ? [adaptor formatAttribute:attribute]
91 : [attribute columnName];
94 return [([[NSString alloc] initWithFormat:@"%@.%@",
95 alias, columnName]) autorelease];
102 @end /* EOSelectSQLExpression */
104 @implementation EOSelectScannerHandler
111 = [self methodForSelector:@selector(convertAttribute:scanner:)];
117 RELEASE(self->attribute);
118 RELEASE(self->adaptor);
119 RELEASE(self->alias);
123 - (void)setAttribute:(EOAttribute*)_attribute
124 adaptor:(EOAdaptor*)_adaptor
125 alias:(NSString*)_alias
127 ASSIGN(self->attribute, _attribute);
128 ASSIGN(self->adaptor, _adaptor);
129 ASSIGN(self->alias, _alias);
132 - (NSString *)convertAttribute:(va_list *)pString
133 scanner:(FormatScanner *)scanner
135 NSString *columnName;
137 columnName = (adaptor)
138 ? [adaptor formatAttribute:self->attribute]
139 : [self->attribute columnName];
142 return [NSString stringWithFormat:@"%@.%@", alias, columnName];
147 @end /* EOSelectScannerHandler */