2 EOAttribute+PostgreSQL72.m
4 Copyright (C) 1999 MDlink online service center GmbH and Helge Hess
5 Copyright (C) 2000-2004 SKYRIX Software AG and Helge Hess
7 Author: Helge Hess (helge.hess@opengroupware.org)
9 This file is part of the PostgreSQL72 Adaptor 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.
26 // $Id: EOAttribute+PostgreSQL72.m 1 2004-08-20 10:38:46Z znek $
29 #import "EOAttribute+PostgreSQL72.h"
34 #include <postgres_types.h>
36 #include <sql3types.h>
38 // Sybase dateformat: (need to be corrected for PostgreSQL)
39 static NSString *PGSQL_DATETIME_FORMAT = @"%b %d %Y %I:%M:%S:000%p";
40 static NSString *PGSQL_TIMESTAMP_FORMAT = @"%Y-%m-%d %H:%M:%S%z";
42 @implementation EOAttribute(PostgreSQL72AttributeAdditions)
44 - (void)loadValueClassAndTypeUsingPostgreSQLType:(Oid)_type
46 modification:(int)_modification
47 binary:(BOOL)_isBinary
50 [self setValueClassName:@"NSData"];
53 /* where in the PostgreSQL72 headers are these OIDs defined ??? */
55 [self setExternalType:@"bool"];
56 [self setValueClassName:@"NSNumber"];
57 [self setValueType:@"i"];
60 [self setExternalType:@"name"];
61 [self setValueClassName:@"NSString"];
64 [self setExternalType:@"textoid"];
65 [self setValueClassName:@"NSString"];
68 [self setExternalType:@"int2"];
69 [self setValueClassName:@"NSNumber"];
70 [self setValueType:@"d"];
73 [self setExternalType:@"int4"];
74 [self setValueClassName:@"NSNumber"];
75 [self setValueType:@"d"];
78 [self setExternalType:@"int8"];
79 [self setValueClassName:@"NSNumber"];
80 [self setValueType:@"d"];
84 [self setExternalType:@"char"];
85 [self setValueClassName:@"NSString"];
88 [self setExternalType:@"varchar"];
89 [self setValueClassName:@"NSString"];
92 [self setExternalType:@"numeric"];
93 [self setValueClassName:@"NSNumber"];
94 [self setValueType:@"d"];
97 [self setExternalType:@"float4"];
98 [self setValueClassName:@"NSNumber"];
99 [self setValueType:@"f"];
102 [self setExternalType:@"float8"];
103 [self setValueClassName:@"NSNumber"];
104 [self setValueType:@"f"];
108 [self setExternalType:@"datetime"];
109 [self setValueClassName:@"NSCalendarDate"];
110 [self setCalendarFormat:PGSQL_DATETIME_FORMAT];
113 [self setExternalType:@"time"];
114 [self setValueClassName:@"NSCalendarDate"];
115 [self setCalendarFormat:PGSQL_DATETIME_FORMAT];
118 [self setExternalType:@"timestamp"];
119 [self setValueClassName:@"NSCalendarDate"];
120 [self setCalendarFormat:PGSQL_DATETIME_FORMAT];
123 [self setExternalType:@"timestamptz"];
124 [self setValueClassName:@"NSCalendarDate"];
125 [self setCalendarFormat:PGSQL_DATETIME_FORMAT];
128 [self setExternalType:@"bit"];
131 NSLog(@"What is PGSQL Oid %i ???", _type);
136 - (void)loadValueClassForExternalPostgreSQLType:(NSString *)_type {
137 if ([_type isEqualToString:@"bool"]) {
138 [self setValueClassName:@"NSNumber"];
139 [self setValueType:@"i"];
141 else if ([_type isEqualToString:@"int2"]) {
142 [self setValueClassName:@"NSNumber"];
143 [self setValueType:@"i"];
145 else if ([_type isEqualToString:@"int4"]) {
146 [self setValueClassName:@"NSNumber"];
147 [self setValueType:@"i"];
149 else if ([_type isEqualToString:@"float4"]) {
150 [self setValueClassName:@"NSNumber"];
151 [self setValueType:@"f"];
153 else if ([_type isEqualToString:@"float8"]) {
154 [self setValueClassName:@"NSNumber"];
155 [self setValueType:@"d"];
157 else if ([_type isEqualToString:@"decimal"]) {
158 [self setValueClassName:@"NSNumber"];
159 [self setValueType:@"d"];
161 else if ([_type isEqualToString:@"numeric"]) {
162 [self setValueClassName:@"NSNumber"];
163 [self setValueType:@"d"];
165 else if ([_type isEqualToString:@"cardinal_number"]) {
166 // TODO: not sure whether this is correct (comes from sql_features table)
167 [self setValueClassName:@"NSNumber"];
168 [self setValueType:@"d"];
170 else if ([_type isEqualToString:@"name"]) {
171 [self setExternalType:@"name"];
172 [self setValueClassName:@"NSString"];
174 else if ([_type isEqualToString:@"varchar"]) {
175 [self setExternalType:@"varchar"];
176 [self setValueClassName:@"NSString"];
178 else if ([_type isEqualToString:@"char"]) {
179 [self setExternalType:@"char"];
180 [self setValueClassName:@"NSString"];
182 else if ([_type isEqualToString:@"character_data"]) {
183 // TODO: not sure whether this is correct (comes from sql_features table)
184 [self setExternalType:@"character_data"];
185 [self setValueClassName:@"NSString"];
187 else if ([_type isEqualToString:@"timestamp"]) {
188 [self setValueClassName:@"NSCalendarDate"];
189 [self setCalendarFormat:PGSQL_TIMESTAMP_FORMAT];
191 else if ([_type isEqualToString:@"timestamptz"]) {
192 [self setValueClassName:@"NSCalendarDate"];
193 [self setCalendarFormat:PGSQL_TIMESTAMP_FORMAT];
195 else if ([_type isEqualToString:@"datetime"]) {
196 [self setValueClassName:@"NSCalendarDate"];
197 [self setCalendarFormat:PGSQL_DATETIME_FORMAT];
199 else if ([_type isEqualToString:@"date"]) {
200 [self setValueClassName:@"NSString"];
202 else if ([_type isEqualToString:@"time"]) {
203 [self setValueClassName:@"NSString"];
205 else if ([_type isEqualToString:@"text"]) {
206 [self setValueClassName:@"NSString"];
209 NSLog(@"%s: invalid argument %@", __PRETTY_FUNCTION__, _type);
211 #if LIB_FOUNDATION_LIBRARY
212 [InvalidArgumentException raise:@"InvalidArgumentException"
214 @"invalid PostgreSQL72 type %@ passed to "
215 @"-loadValueClassForExternalPostgreSQLType:",
218 [NSException raise:@"InvalidArgumentException"
220 @"invalid PostgreSQL72 type %@ passed to "
221 @"-loadValueClassForExternalPostgreSQLType:",
227 @end /* EOAttribute(PostgreSQL72) */
229 void __link_EOAttributePostgreSQL72() {
230 // used to force linking of object file
231 __link_EOAttributePostgreSQL72();