]> err.no Git - sope/blob - sope-gdl1/PostgreSQL72/PostgreSQL72Adaptor.m
more directory hierarchy reorganisations,
[sope] / sope-gdl1 / PostgreSQL72 / PostgreSQL72Adaptor.m
1 /* 
2    PostgreSQL72Adaptor.m
3
4    Copyright (C) 1999 MDlink online service center GmbH and Helge Hess
5    Copyright (C) 2000-2004 SKYRIX Software AG and Helge Hess
6
7    Author: Helge Hess (helge.hess@opengroupware.org)
8
9    This file is part of the PostgreSQL72 Adaptor 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 // $Id: PostgreSQL72Adaptor.m 1 2004-08-20 10:38:46Z znek $
27
28 #include "common.h"
29 #include "PostgreSQL72Adaptor.h"
30 #include "PostgreSQL72Context.h"
31 #include "PostgreSQL72Channel.h"
32 #include "PostgreSQL72Expression.h"
33 #include "PostgreSQL72Values.h"
34 #include "PGConnection.h"
35
36 @implementation PostgreSQL72Adaptor
37
38 static BOOL debugOn = NO;
39
40 - (id)initWithName:(NSString *)_name {
41   if ((self = [super initWithName:_name])) {
42   }
43   return self;
44 }
45
46 - (void)gcFinalize {
47 }
48
49 - (void)dealloc {
50   //  NSLog(@"%s", __PRETTY_FUNCTION__);
51   [self gcFinalize];
52   [super dealloc];
53 }
54
55 /* NSCopying methods */
56
57 - (id)copyWithZone:(NSZone *)_zone {
58   return [self retain];
59 }
60
61 /* connections */
62
63 - (NSString *)_copyOfConDictString:(NSString *)_key {
64   return [[[[self connectionDictionary] objectForKey:_key] copy] autorelease];
65 }
66
67 - (NSString *)serverName {
68   NSString *serverName;
69
70   serverName = [[self connectionDictionary] objectForKey:@"hostName"];
71
72   if (serverName == nil) { // lookup env-variable
73     serverName = 
74       [[[NSProcessInfo processInfo] environment] objectForKey:@"PGHOST"];
75   }
76   
77   return [[serverName copy] autorelease];
78 }
79 - (NSString *)loginName {
80   return [self _copyOfConDictString:@"userName"];
81 }
82 - (NSString *)loginPassword {
83   return [self _copyOfConDictString:@"password"];
84 }
85 - (NSString *)databaseName {
86   return [self _copyOfConDictString:@"databaseName"];
87 }
88
89 - (NSString *)port {
90   return [self _copyOfConDictString:@"port"];
91 }
92 - (NSString *)options {
93   return [self _copyOfConDictString:@"options"];
94 }
95 - (NSString *)tty {
96   return [self _copyOfConDictString:@"tty"];
97 }
98
99 /* sequence for primary key generation */
100
101 - (NSString *)primaryKeySequenceName {
102   NSString *seqName;
103
104   seqName =
105     [[self pkeyGeneratorDictionary] objectForKey:@"primaryKeySequenceName"];
106   return [[seqName copy] autorelease];
107 }
108
109 - (NSString *)newKeyExpression {
110   NSString *newKeyExpr;
111   
112   newKeyExpr =
113     [[self pkeyGeneratorDictionary] objectForKey:@"newKeyExpression"];
114   return [[newKeyExpr copy] autorelease];
115 }
116
117 /* formatting */
118
119 - (NSString *)charConvertExpressionForAttributeNamed:(NSString *)_attrName {
120   return _attrName;
121 }
122
123 - (id)formatValue:(id)value forAttribute:(EOAttribute *)attribute {
124   /*
125     This formats values into SQL constants, eg:
126       @"blah" will be converted to 'blah'
127   */
128   NSString *result;
129   
130   result = [value stringValueForPostgreSQLType:[attribute externalType]
131                   attribute:attribute];
132   if (debugOn) {
133     NSLog(@"formatting value '%@'(%@) result '%@'", 
134           value, NSStringFromClass([value class]), result);
135     NSLog(@"  value class %@ attr %@ attr type %@",
136           [value class], attribute, [attribute externalType]);
137   }
138   return result;
139 }
140
141 - (BOOL)attributeAllowedInDistinctSelects:(EOAttribute *)_attr {
142   return YES;
143 }
144
145 /* types */
146
147 - (BOOL)isValidQualifierType:(NSString *)_typeName {
148   return YES;
149 }
150
151 /* adaptor info */
152
153 - (Class)adaptorContextClass {
154   return [PostgreSQL72Context class];
155 }
156 - (Class)adaptorChannelClass {
157   return [PostgreSQL72Channel class];
158 }
159
160 - (Class)expressionClass {
161   return [PostgreSQL72Expression class];
162 }
163
164 @end /* PostgreSQL72Adaptor */
165
166 void __linkPostgreSQL72Adaptor(void) {
167   extern void __link_EOAttributePostgreSQL72();
168   extern void __link_NSStringPostgreSQL72();
169   extern void __link_PostgreSQL72ChannelModel();
170   extern void __link_PostgreSQL72Values();
171   ;
172   [PostgreSQL72Channel    class];
173   [PostgreSQL72Context    class];
174   [PostgreSQL72Exception  class];
175   [PostgreSQL72Expression class];
176   __link_EOAttributePostgreSQL72();
177   __link_NSStringPostgreSQL72();
178   //__link_PostgreSQL72ChannelModel();
179   __link_PostgreSQL72Values();
180   __linkPostgreSQL72Adaptor();
181 }