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.
27
#include "PostgreSQL72Channel.h"
30
@implementation NSString(PostgreSQL72Values)
32
static Class NSStringClass = Nil;
33
static Class EOExprClass = Nil;
35
+ (id)valueFromCString:(const char *)_cstr length:(int)_length
36
postgreSQLType:(NSString *)_type
37
attribute:(EOAttribute *)_attribute
38
adaptorChannel:(PostgreSQL72Channel *)_channel
40
if (_cstr == NULL) return nil;
41
if (*_cstr == '\0') return @"";
42
if (NSStringClass == Nil) NSStringClass = [NSString class];
44
// TODO: cache IMP of selector
45
return [NSStringClass stringWithCString:_cstr];
48
+ (id)valueFromBytes:(const void *)_bytes length:(int)_length
49
postgreSQLType:(NSString *)_type
50
attribute:(EOAttribute *)_attribute
51
adaptorChannel:(PostgreSQL72Channel *)_channel
53
#if COCOA_Foundation_LIBRARY || NeXT_Foundation_LIBRARY
54
NSLog(@"%s: not implemented!", __PRETTY_FUNCTION__);
57
return [self notImplemented:_cmd];
61
- (NSString *)stringValueForPostgreSQLType:(NSString *)_type
62
attribute:(EOAttribute *)_attribute
64
// TODO: all this looks slow ...
68
if ((len = [_type length]) == 0)
71
c1 = [_type characterAtIndex:0];
77
EOQuotedExpression *expr;
82
_type = [_type lowercaseString];
84
if (!([_type hasPrefix:@"char"] ||
85
[_type hasPrefix:@"varchar"] ||
86
[_type hasPrefix:@"text"]))
89
/* TODO: creates too many autoreleased strings :-( */
91
s = [self stringByReplacingString:@"\\" withString:@"\\\\"];
93
if (EOExprClass == Nil) EOExprClass = [EOQuotedExpression class];
94
expr = [[EOExprClass alloc] initWithExpression:s quote:@"'" escape:@"\\'"];
95
s = [[expr expressionValueForContext:nil] retain];
97
return [s autorelease];
101
if ([[_type lowercaseString] hasPrefix:@"money"])
102
return [@"$" stringByAppendingString:self];
110
@end /* NSString(PostgreSQL72Values) */