]> err.no Git - sope/blob - sope-gdl1/SQLite3/SQLiteExpression.m
fixed gdltest
[sope] / sope-gdl1 / SQLite3 / SQLiteExpression.m
1 /* 
2    SQLiteExpression.m
3    
4    Copyright (C) 2003-2005 Helge Hess
5    
6    Author: Helge Hess (helge.hess@opengroupware.org)
7    
8    This file is part of the SQLite Adaptor Library
9
10    This library is free software; you can redistribute it and/or
11    modify it under the terms of the GNU Library General Public
12    License as published by the Free Software Foundation; either
13    version 2 of the License, or (at your option) any later version.
14
15    This library is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    Library General Public License for more details.
19
20    You should have received a copy of the GNU Library General Public
21    License along with this library; see the file COPYING.LIB.
22    If not, write to the Free Software Foundation,
23    59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 */
25
26 #include <Foundation/Foundation.h>
27 #include <GDLAccess/GDLAccess.h>
28 #include "SQLiteExpression.h"
29
30 @implementation SQLiteExpression
31
32 + (Class)selectExpressionClass  {
33   return [SQLiteSelectSQLExpression class];
34 }
35
36 @end /* SQLiteExpression */
37
38 @implementation SQLiteSelectSQLExpression
39
40 - (id)selectExpressionForAttributes:(NSArray *)attributes
41   lock:(BOOL)flag
42   qualifier:(EOSQLQualifier *)qualifier
43   fetchOrder:(NSArray *)fetchOrder
44   channel:(EOAdaptorChannel *)channel {
45
46   lock = flag;
47   [super selectExpressionForAttributes:attributes
48          lock:flag
49          qualifier:qualifier
50          fetchOrder:fetchOrder
51          channel:channel];
52   return self;
53 }
54
55 - (NSString *)fromClause {
56   NSMutableString *fromClause;
57   NSEnumerator    *enumerator;
58   BOOL            first       = YES;
59   id              key;
60
61   fromClause = [NSMutableString stringWithCString:" "];
62   enumerator = [fromListEntities objectEnumerator];
63   
64   // Compute the FROM list from all the aliases found in
65   // entitiesAndPropertiesAliases dictionary. Note that this dictionary
66   // contains entities and relationships. The last ones are there for
67   // flattened attributes over reflexive relationships.
68   
69   while((key = [enumerator nextObject])) {
70     if(first) first = NO;
71     else      [fromClause appendString:@", "];
72
73     [fromClause appendFormat:@"%@ %@",
74                   [key isKindOfClass:[EORelationship class]]
75                   ? [[key destinationEntity] externalName] // flattened attribute
76                   : [key externalName],                    // EOEntity
77                   [entitiesAndPropertiesAliases objectForKey:key]];
78
79 #if 0    
80     if (lock) [fromClause appendString:@" HOLDLOCK"];
81 #endif    
82   }
83
84   return fromClause;
85 }
86
87 @end /* SQLiteSelectSQLExpression */
88
89 void __link_SQLiteExpression() {
90   // used to force linking of object file
91   __link_SQLiteExpression();
92 }