From: helge Date: Sat, 30 Sep 2006 14:08:11 +0000 (+0000) Subject: properly set client encoding after connect X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=342f9ac5f0117357b229a8bc871f29a7fbd36307;p=sope properly set client encoding after connect use UTF-8 instead of Latin1 as the charset various code cleanups git-svn-id: http://svn.opengroupware.org/SOPE/trunk@1366 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- diff --git a/sope-gdl1/PostgreSQL/ChangeLog b/sope-gdl1/PostgreSQL/ChangeLog index 941782ae..603a9ad4 100644 --- a/sope-gdl1/PostgreSQL/ChangeLog +++ b/sope-gdl1/PostgreSQL/ChangeLog @@ -1,3 +1,20 @@ +2006-09-30 Helge Hess + + * v.4.5.48 + + * always use UTF-8 as the transport encoding (was Latin1 before), + enforce that by setting the connection client encoding (when + possible) + + * added category to convert EOKeyGlobalIDs to SQL (required by OGo + trunk) + + * moved NSNull/pgval category to own file + + * moved PostgreSQL version detection to pgconfig.h file, properly + detect new PostgreSQL versions by a missing PG_MAJOR_VERSION + define (and enable NG_SET_CLIENT_ENCODING etc in this case) + 2006-07-04 Helge Hess * fixed some 64bit issues (v4.5.47) diff --git a/sope-gdl1/PostgreSQL/EOKeyGlobalID+PGVal.m b/sope-gdl1/PostgreSQL/EOKeyGlobalID+PGVal.m new file mode 100644 index 00000000..79c9eac5 --- /dev/null +++ b/sope-gdl1/PostgreSQL/EOKeyGlobalID+PGVal.m @@ -0,0 +1,45 @@ +/* + EOKeyGlobalID+PGVal.m + + Copyright (C) 2006 SKYRIX Software AG and Helge Hess + + Author: Helge Hess (helge.hess@opengroupware.org) + + This file is part of the PostgreSQL Adaptor Library + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include +#include "PostgreSQL72Channel.h" +#include "common.h" + +@implementation EOKeyGlobalID(PostgreSQL72Values) + +- (NSString *)stringValueForPostgreSQLType:(NSString *)_type + attribute:(EOAttribute *)_attribute +{ + if (self->count == 0) { + NSLog(@"ERROR(%s): got a EOKeyGlobalID w/o key values: %@", + __PRETTY_FUNCTION__, self); + return nil; + } + + return [self->values[0] stringValueForPostgreSQLType:_type + attribute:_attribute]; +} + +@end /* EOKeyGlobalID(PostgreSQL72Values) */ diff --git a/sope-gdl1/PostgreSQL/GNUmakefile b/sope-gdl1/PostgreSQL/GNUmakefile index 3ab9490b..6a427dee 100644 --- a/sope-gdl1/PostgreSQL/GNUmakefile +++ b/sope-gdl1/PostgreSQL/GNUmakefile @@ -1,7 +1,7 @@ # # GNUmakefile # -# Copyright (C) 2004-2005 SKYRIX Software AG +# Copyright (C) 2004-2006 SKYRIX Software AG # # Author: Helge Hess (helge.hess@skyrix.com) # @@ -33,19 +33,22 @@ PostgreSQL_PCH_FILE = common.h PostgreSQL_OBJC_FILES = \ PGConnection.m \ + PGResultSet.m \ PostgreSQL72Expression.m \ PostgreSQL72Adaptor.m \ PostgreSQL72Context.m \ PostgreSQL72Channel.m \ PostgreSQL72Channel+Model.m \ PostgreSQL72Exception.m \ - PostgreSQL72Values.m \ NSString+PostgreSQL72.m \ EOAttribute+PostgreSQL72.m \ NSString+PGVal.m \ NSData+PGVal.m \ NSCalendarDate+PGVal.m \ NSNumber+PGVal.m \ + EOKeyGlobalID+PGVal.m \ + NSNull+PGVal.m \ + PostgreSQL72DataTypeMappingException.m PostgreSQL_PRINCIPAL_CLASS = PostgreSQL72Adaptor diff --git a/sope-gdl1/PostgreSQL/NSData+PGVal.m b/sope-gdl1/PostgreSQL/NSData+PGVal.m index 27cb36f7..bad16e4e 100644 --- a/sope-gdl1/PostgreSQL/NSData+PGVal.m +++ b/sope-gdl1/PostgreSQL/NSData+PGVal.m @@ -73,8 +73,9 @@ static NSData *EmptyData = nil; return @""; if (enc == 0) { - enc = [NSString defaultCStringEncoding]; - NSLog(@"Note: PostgreSQL72 adaptor using '%@' encoding for data=>string " + // enc = [NSString defaultCStringEncoding]; + enc = NSUTF8StringEncoding; + NSLog(@"Note: PostgreSQL adaptor using '%@' encoding for data=>string " @"conversion.", [NSString localizedNameOfStringEncoding:enc]); } diff --git a/sope-gdl1/PostgreSQL/NSNull+PGVal.m b/sope-gdl1/PostgreSQL/NSNull+PGVal.m new file mode 100644 index 00000000..02d452d1 --- /dev/null +++ b/sope-gdl1/PostgreSQL/NSNull+PGVal.m @@ -0,0 +1,37 @@ +/* + NSNull+PGVal.m + + Copyright (C) 1999 MDlink online service center GmbH and Helge Hess + Copyright (C) 2000-2006 SKYRIX Software AG and Helge Hess + + Author: Helge Hess (helge@opengroupware.org) + + This file is part of the PostgreSQL72 Adaptor Library + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "common.h" + +@implementation NSNull(PostgreSQL72Values) + +- (NSString *)stringValueForPostgreSQLType:(NSString *)_type + attribute:(EOAttribute *)_attribute +{ + return @"null"; +} + +@end /* NSNull(PostgreSQL72Values) */ diff --git a/sope-gdl1/PostgreSQL/NSString+PGVal.m b/sope-gdl1/PostgreSQL/NSString+PGVal.m index afecb2f2..89a91f3c 100644 --- a/sope-gdl1/PostgreSQL/NSString+PGVal.m +++ b/sope-gdl1/PostgreSQL/NSString+PGVal.m @@ -1,12 +1,12 @@ /* NSString+PGVal.m - Copyright (C) 1999 MDlink online service center GmbH and Helge Hess - Copyright (C) 2000-2005 SKYRIX Software AG and Helge Hess + Copyright (C) 1999 MDlink online service center GmbH and Helge Hess + Copyright (C) 2000-2006 SKYRIX Software AG and Helge Hess Author: Helge Hess (helge.hess@opengroupware.org) - This file is part of the PostgreSQL72 Adaptor Library + This file is part of the PostgreSQL Adaptor Library This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -31,18 +31,29 @@ static Class NSStringClass = Nil; static Class EOExprClass = Nil; +static id (*ctor)(id, SEL, const char *) = NULL; + (id)valueFromCString:(const char *)_cstr length:(int)_length postgreSQLType:(NSString *)_type attribute:(EOAttribute *)_attribute adaptorChannel:(PostgreSQL72Channel *)_channel { + // TODO: would be better if this would return a retained object to avoid + // the dreaded autorelease pool if (_cstr == NULL) return nil; if (*_cstr == '\0') return @""; + if (NSStringClass == Nil) NSStringClass = [NSString class]; + if (ctor == NULL) { + ctor = (void *) + [NSStringClass methodForSelector:@selector(stringWithUTF8String:)]; + } + // TODO: cache IMP of selector - return [NSStringClass stringWithCString:_cstr]; + return ctor != NULL + ? ctor(NSStringClass, @selector(stringWithUTF8String:), _cstr) + : [NSStringClass stringWithUTF8String:_cstr]; } + (id)valueFromBytes:(const void *)_bytes length:(int)_length @@ -79,7 +90,7 @@ static Class EOExprClass = Nil; if (len < 4) return self; - _type = [_type lowercaseString]; + _type = [_type lowercaseString]; // looks slow if (!([_type hasPrefix:@"char"] || [_type hasPrefix:@"varchar"] || diff --git a/sope-gdl1/PostgreSQL/NSString+PostgreSQL72.m b/sope-gdl1/PostgreSQL/NSString+PostgreSQL72.m index 20fc4656..f0088b46 100644 --- a/sope-gdl1/PostgreSQL/NSString+PostgreSQL72.m +++ b/sope-gdl1/PostgreSQL/NSString+PostgreSQL72.m @@ -1,8 +1,8 @@ /* NSString+PostgreSQL72.m - Copyright (C) 1999 MDlink online service center GmbH and Helge Hess - Copyright (C) 2000-2005 SKYRIX Software AG and Helge Hess + Copyright (C) 1999 MDlink online service center GmbH and Helge Hess + Copyright (C) 2000-2006 SKYRIX Software AG and Helge Hess Author: Helge Hess (helge.hess@opengroupware.org) @@ -35,86 +35,90 @@ @implementation NSString(PostgreSQL72MiscStrings) - (NSString *)_pgModelMakeInstanceVarName { + unsigned clen; + unichar *us; + int cnt, cnt2; + if ([self length] == 0) return @""; - else { - unsigned clen = 0; - char *s = NULL; - int cnt, cnt2; - - clen = [self cStringLength]; - s = malloc(clen + 10); - - [self getCString:s maxLength:clen]; - - for (cnt = cnt2 = 0; cnt < clen; cnt++, cnt2++) { - if ((s[cnt] == '_') && (s[cnt + 1] != '\0')) { - s[cnt2] = toupper(s[cnt + 1]); - cnt++; - } - else if ((s[cnt] == '2') && (s[cnt + 1] != '\0')) { - s[cnt2] = s[cnt]; - cnt++; - cnt2++; - s[cnt2] = toupper(s[cnt]); - } - else - s[cnt2] = tolower(s[cnt]); + + // TODO: do use UTF-8 here + clen = [self length]; + us = malloc((clen + 10) * sizeof(unichar)); + + [self getCharacters:us]; + us[clen] = 0; + + // Note: upper/lower detection is not strictly correct ... (no unicode) + for (cnt = cnt2 = 0; cnt < clen; cnt++, cnt2++) { + if ((us[cnt] == '_') && (us[cnt + 1] != '\0')) { + us[cnt2] = toupper(us[cnt + 1]); + cnt++; } - s[cnt2] = '\0'; - - return [[[NSString alloc] - initWithCStringNoCopy:s length:strlen(s) freeWhenDone:YES] - autorelease]; + else if ((us[cnt] == '2') && (us[cnt + 1] != '\0')) { + us[cnt2] = us[cnt]; + cnt++; + cnt2++; + us[cnt2] = toupper(us[cnt]); + } + else + us[cnt2] = tolower(us[cnt]); } + us[cnt2] = '\0'; + + return [NSString stringWithCharacters:us length:cnt2]; } - (NSString *)_pgModelMakeClassName { + unsigned clen = 0; + unichar *us; + int cnt, cnt2; + if ([self length] == 0) return @""; - else { - unsigned clen = 0; - char *s = NULL; - int cnt, cnt2; - - clen = [self cStringLength]; - s = malloc(clen + 10); - [self getCString:s maxLength:clen]; - - for (cnt = cnt2 = 0; cnt < clen; cnt++, cnt2++) { - if ((s[cnt] == '_') && (s[cnt + 1] != '\0')) { - s[cnt2] = toupper(s[cnt + 1]); - cnt++; - } - else if ((s[cnt] == '2') && (s[cnt + 1] != '\0')) { - s[cnt2] = s[cnt]; - cnt++; - cnt2++; - s[cnt2] = toupper(s[cnt]); - } - else - s[cnt2] = tolower(s[cnt]); + // TODO: use UTF-8 here + clen = [self cStringLength]; + us = malloc((clen + 10) * sizeof(unichar)); + + [self getCharacters:us]; + us[clen] = 0; + + for (cnt = cnt2 = 0; cnt < clen; cnt++, cnt2++) { + if ((us[cnt] == '_') && (us[cnt + 1] != '\0')) { + us[cnt2] = toupper(us[cnt + 1]); + cnt++; } - s[cnt2] = '\0'; + else if ((us[cnt] == '2') && (us[cnt + 1] != '\0')) { + us[cnt2] = us[cnt]; + cnt++; + cnt2++; + us[cnt2] = toupper(us[cnt]); + } + else + us[cnt2] = tolower(us[cnt]); + } + us[cnt2] = '\0'; - s[0] = toupper(s[0]); + us[0] = toupper(us[0]); - return [[[NSString alloc] - initWithCStringNoCopy:s length:strlen(s) - freeWhenDone:YES] - autorelease]; - } + return [NSString stringWithCharacters:us length:cnt2]; } +static NSCharacterSet *upperSet = nil; +static NSCharacterSet *spaceSet = nil; + - (NSString *)_pgStringWithCapitalizedFirstChar { - NSCharacterSet *upperSet = [NSCharacterSet uppercaseLetterCharacterSet]; + if (upperSet == nil) + upperSet = [[NSCharacterSet uppercaseLetterCharacterSet] retain]; if ([self length] == 0) return @""; - else if ([upperSet characterIsMember:[self characterAtIndex:0]]) + + if ([upperSet characterIsMember:[self characterAtIndex:0]]) return [[self copy] autorelease]; - else { + + { NSMutableString *str = [NSMutableString stringWithCapacity:[self length]]; [str appendString:[[self substringToIndex:1] uppercaseString]]; @@ -125,20 +129,23 @@ } - (NSString *)_pgStripEndSpaces { - if ([self length] > 0) { - NSCharacterSet *spaceSet; - NSMutableString *str; - unichar (*charAtIndex)(id, SEL, int); - NSRange range; + NSMutableString *str; + unichar (*charAtIndex)(id, SEL, int); + NSRange range; - spaceSet = [NSCharacterSet whitespaceCharacterSet]; - str = [NSMutableString stringWithCapacity:[self length]]; + if ([self length] == 0) + return @""; - charAtIndex = (unichar (*)(id, SEL, int)) - [self methodForSelector:@selector(characterAtIndex:)]; - range.length = 0; + if (spaceSet == nil) + spaceSet = [[NSCharacterSet whitespaceCharacterSet] retain]; + + str = [NSMutableString stringWithCapacity:[self length]]; + + charAtIndex = (unichar (*)(id, SEL, int)) + [self methodForSelector:@selector(characterAtIndex:)]; + range.length = 0; - for (range.location = ([self length] - 1); + for (range.location = ([self length] - 1); range.location >= 0; range.location++, range.length++) { unichar c; @@ -146,14 +153,14 @@ c = charAtIndex(self, @selector(characterAtIndex:), range.location); if (![spaceSet characterIsMember:c]) break; - } + } - if (range.length > 0) { - [str appendString:self]; - [str deleteCharactersInRange:range]; - return AUTORELEASE([str copy]); - } + if (range.length > 0) { + [str appendString:self]; + [str deleteCharactersInRange:range]; + return AUTORELEASE([str copy]); } + return AUTORELEASE([self copy]); } diff --git a/sope-gdl1/PostgreSQL/PGConnection.h b/sope-gdl1/PostgreSQL/PGConnection.h index d7e8b126..5b7dd5a4 100644 --- a/sope-gdl1/PostgreSQL/PGConnection.h +++ b/sope-gdl1/PostgreSQL/PGConnection.h @@ -1,7 +1,7 @@ /* PGConnection.h - Copyright (C) 2004 SKYRIX Software AG and Helge Hess + Copyright (C) 2004-2006 SKYRIX Software AG and Helge Hess Author: Helge Hess (helge.hess@opengroupware.org) @@ -78,8 +78,15 @@ - (void)clearRawResults:(void *)_ptr; - (PGResultSet *)execute:(NSString *)_sql; +/* support */ + +- (const char *)_cstrFromString:(NSString *)_s; +- (NSString *)_stringFromCString:(const char *)_cstr; + @end + + @interface PGResultSet : NSObject { @protected diff --git a/sope-gdl1/PostgreSQL/PGConnection.m b/sope-gdl1/PostgreSQL/PGConnection.m index 97367995..7f54dcaf 100644 --- a/sope-gdl1/PostgreSQL/PGConnection.m +++ b/sope-gdl1/PostgreSQL/PGConnection.m @@ -1,7 +1,7 @@ /* PGConnection.m - Copyright (C) 2004-2005 SKYRIX Software AG and Helge Hess + Copyright (C) 2004-2006 SKYRIX Software AG and Helge Hess Author: Helge Hess (helge.hess@opengroupware.org) @@ -26,16 +26,7 @@ #include "PGConnection.h" #include "common.h" #include - -#if PG_MAJOR_VERSION >= 6 && PG_MINOR_VERSION > 3 -# define NG_HAS_NOTICE_PROCESSOR 1 -# define NG_HAS_BINARY_TUPLES 1 -# define NG_HAS_FMOD 1 -#endif - -#if PG_MAJOR_VERSION >= 7 && PG_MINOR_VERSION > 3 -# define NG_SET_CLIENT_ENCODING 1 -#endif +#include "pgconfig.h" @implementation PGConnection @@ -70,10 +61,10 @@ static BOOL debugOn = NO; - (const char *)_cstrFromString:(NSString *)_s { // TODO: fix API, check what the API string encoding is - return [_s cString]; + return [_s UTF8String]; } - (NSString *)_stringFromCString:(const char *)_cstr { - return [NSString stringWithCString:_cstr]; + return [NSString stringWithUTF8String:_cstr]; } /* accessors */ @@ -218,121 +209,3 @@ static BOOL debugOn = NO; @end /* PGConnection */ -@implementation PGResultSet - -/* wraps PGresult */ - -- (id)initWithConnection:(PGConnection *)_con handle:(void *)_handle { - if (_handle == NULL) { - [self release]; - return nil; - } - if ((self = [super init])) { - self->connection = [_con retain]; - self->results = _handle; - } - return self; -} - -- (void)dealloc { - [self clear]; - [self->connection release]; - [super dealloc]; -} - -/* accessors */ - -- (BOOL)isValid { - return self->results != NULL ? YES : NO; -} - -- (BOOL)containsBinaryTuples { -#if NG_HAS_BINARY_TUPLES - if (self->results == NULL) return NO; - return PQbinaryTuples(self->results) ? YES : NO; -#else - return NO; -#endif -} - -- (NSString *)commandStatus { - char *cstr; - - if (self->results == NULL) - return nil; - if ((cstr = PQcmdStatus(self->results)) == NULL) - return nil; - return [NSString stringWithCString:cstr]; -} - -- (NSString *)commandTuples { - char *cstr; - - if (self->results == NULL) - return nil; - if ((cstr = PQcmdTuples(self->results)) == NULL) - return nil; - return [NSString stringWithCString:cstr]; -} - -/* fields */ - -- (unsigned)fieldCount { - return self->results != NULL ? PQnfields(self->results) : 0; -} - -- (NSString *)fieldNameAtIndex:(unsigned int)_idx { - // TODO: charset - if (self->results == NULL) return nil; - return [NSString stringWithCString:PQfname(self->results, _idx)]; -} - -- (int)indexOfFieldNamed:(NSString *)_name { - return PQfnumber(self->results, [_name cString]); -} - -- (int)fieldSizeAtIndex:(unsigned int)_idx { - if (self->results == NULL) return 0; - return PQfsize(self->results, _idx); -} - -- (int)modifierAtIndex:(unsigned int)_idx { - if (self->results == NULL) return 0; -#if NG_HAS_FMOD - return PQfmod(self->results, _idx); -#else - return 0; -#endif -} - -/* tuples */ - -- (unsigned int)tupleCount { - if (self->results == NULL) return 0; - return PQntuples(self->results); -} - -- (BOOL)isNullTuple:(int)_tuple atIndex:(unsigned int)_idx { - if (self->results == NULL) return NO; - return PQgetisnull(self->results, _tuple, _idx) ? YES : NO; -} - -- (void *)rawValueOfTuple:(int)_tuple atIndex:(unsigned int)_idx { - if (self->results == NULL) return NULL; - return PQgetvalue(self->results, _tuple, _idx); -} - -- (int)lengthOfTuple:(int)_tuple atIndex:(unsigned int)_idx { - if (self->results == NULL) return 0; - return PQgetlength(self->results, _tuple, _idx); -} - -/* operations */ - -- (void)clear { - if (self->results == NULL) return; - PQclear(self->results); - self->results = NULL; -} - -@end /* PGResultSet */ diff --git a/sope-gdl1/PostgreSQL/PGResultSet.m b/sope-gdl1/PostgreSQL/PGResultSet.m new file mode 100644 index 00000000..3615302e --- /dev/null +++ b/sope-gdl1/PostgreSQL/PGResultSet.m @@ -0,0 +1,148 @@ +/* + PGConnection.m + + Copyright (C) 2004-2006 SKYRIX Software AG and Helge Hess + + Author: Helge Hess (helge.hess@opengroupware.org) + + This file is part of the PostgreSQL72 Adaptor Library + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "PGConnection.h" +#include "common.h" +#include +#include "pgconfig.h" + +@implementation PGResultSet + +/* wraps PGresult */ + +- (id)initWithConnection:(PGConnection *)_con handle:(void *)_handle { + if (_handle == NULL) { + [self release]; + return nil; + } + if ((self = [super init])) { + self->connection = [_con retain]; + self->results = _handle; + } + return self; +} + +- (void)dealloc { + [self clear]; + [self->connection release]; + [super dealloc]; +} + +/* accessors */ + +- (BOOL)isValid { + return self->results != NULL ? YES : NO; +} + +- (BOOL)containsBinaryTuples { +#if NG_HAS_BINARY_TUPLES + if (self->results == NULL) return NO; + return PQbinaryTuples(self->results) ? YES : NO; +#else + return NO; +#endif +} + +- (NSString *)commandStatus { + char *cstr; + + if (self->results == NULL) + return nil; + if ((cstr = PQcmdStatus(self->results)) == NULL) + return nil; + return [self->connection _stringFromCString:cstr]; +} + +- (NSString *)commandTuples { + char *cstr; + + if (self->results == NULL) + return nil; + if ((cstr = PQcmdTuples(self->results)) == NULL) + return nil; + return [self->connection _stringFromCString:cstr]; +} + +/* fields */ + +- (unsigned)fieldCount { + return self->results != NULL ? PQnfields(self->results) : 0; +} + +- (NSString *)fieldNameAtIndex:(unsigned int)_idx { + // TODO: charset + if (self->results == NULL) return nil; + return [self->connection _stringFromCString:PQfname(self->results, _idx)]; +} + +- (int)indexOfFieldNamed:(NSString *)_name { + return PQfnumber(self->results, [_name cString]); +} + +- (int)fieldSizeAtIndex:(unsigned int)_idx { + if (self->results == NULL) return 0; + return PQfsize(self->results, _idx); +} + +- (int)modifierAtIndex:(unsigned int)_idx { + if (self->results == NULL) return 0; +#if NG_HAS_FMOD + return PQfmod(self->results, _idx); +#else + return 0; +#endif +} + +/* tuples */ + +- (unsigned int)tupleCount { + if (self->results == NULL) return 0; + return PQntuples(self->results); +} + +- (BOOL)isNullTuple:(int)_tuple atIndex:(unsigned int)_idx { + if (self->results == NULL) return NO; + return PQgetisnull(self->results, _tuple, _idx) ? YES : NO; +} + +- (void *)rawValueOfTuple:(int)_tuple atIndex:(unsigned int)_idx { + if (self->results == NULL) return NULL; + return PQgetvalue(self->results, _tuple, _idx); +} + +- (int)lengthOfTuple:(int)_tuple atIndex:(unsigned int)_idx { + if (self->results == NULL) return 0; + return PQgetlength(self->results, _tuple, _idx); +} + +/* operations */ + +- (void)clear { + if (self->results == NULL) return; + PQclear(self->results); + self->results = NULL; +} + +@end /* PGResultSet */ diff --git a/sope-gdl1/PostgreSQL/PostgreSQL72Channel.m b/sope-gdl1/PostgreSQL/PostgreSQL72Channel.m index 994e345a..340bf51d 100644 --- a/sope-gdl1/PostgreSQL/PostgreSQL72Channel.m +++ b/sope-gdl1/PostgreSQL/PostgreSQL72Channel.m @@ -36,20 +36,13 @@ #import "EOAttribute+PostgreSQL72.h" #include "PGConnection.h" +#include "pgconfig.h" + #ifndef MIN # define MIN(x, y) ((x > y) ? y : x) #endif -#if PG_MAJOR_VERSION >= 6 && PG_MINOR_VERSION > 3 -# define NG_HAS_NOTICE_PROCESSOR 1 -# define NG_HAS_BINARY_TUPLES 1 -# define NG_HAS_FMOD 1 -#endif - -#if PG_MAJOR_VERSION >= 7 && PG_MINOR_VERSION > 3 -# define NG_SET_CLIENT_ENCODING 1 -#endif - +// TODO: what does this do? #define MAX_CHAR_BUF 16384 @interface PostgreSQL72Channel(Privates) @@ -59,7 +52,7 @@ @implementation PostgreSQL72Channel #if NG_SET_CLIENT_ENCODING -static NSString *PGClientEncoding = @"Latin1"; +static NSString *PGClientEncoding = @"UTF8"; #endif static int MaxOpenConnectionCount = -1; static BOOL debugOn = NO; @@ -132,7 +125,7 @@ static void _pgMessageProcessor(void *_channel, const char *_msg) static void _pgMessageProcessor(void *_channel, const char *_msg) { [(id)_channel receivedMessage: - _msg ? [StringClass stringWithCString:_msg] : nil]; + _msg ? [StringClass stringWithUTF8String:_msg] : nil]; } /* cleanup */ @@ -308,8 +301,8 @@ static int openConnectionCount = 0; - (NSArray *)describeResults:(BOOL)_beautifyNames { int cnt; - NSMutableArray *result = nil; - NSMutableDictionary *usedNames = nil; + NSMutableArray *result; + NSMutableDictionary *usedNames; if (![self isFetchInProgress]) { [PostgreSQL72Exception raise:@"NoFetchInProgress" @@ -318,14 +311,15 @@ static int openConnectionCount = 0; result = [[NSMutableArray alloc] initWithCapacity:self->fieldCount]; usedNames = [[MDictClass alloc] initWithCapacity:self->fieldCount]; - + for (cnt = 0; cnt < self->fieldCount; cnt++) { EOAttribute *attribute = nil; NSString *columnName; NSString *attrName; columnName = - [[StringClass alloc] initWithCString:self->fieldInfo[cnt].name]; + [[StringClass alloc] initWithUTF8String:self->fieldInfo[cnt].name]; + attrName = _beautifyNames ? [columnName _pgModelMakeInstanceVarName] : columnName; @@ -341,7 +335,7 @@ static int openConnectionCount = 0; sprintf(buf, "%i", cnt2); - s = [[StringClass alloc] initWithCString:buf]; + s = [[StringClass alloc] initWithUTF8String:buf]; newAttrName = [attrName stringByAppendingString:s]; [s release]; s= nil; diff --git a/sope-gdl1/PostgreSQL/PostgreSQL72Values.m b/sope-gdl1/PostgreSQL/PostgreSQL72DataTypeMappingException.m similarity index 92% rename from sope-gdl1/PostgreSQL/PostgreSQL72Values.m rename to sope-gdl1/PostgreSQL/PostgreSQL72DataTypeMappingException.m index 1461c28e..e6e9039d 100644 --- a/sope-gdl1/PostgreSQL/PostgreSQL72Values.m +++ b/sope-gdl1/PostgreSQL/PostgreSQL72DataTypeMappingException.m @@ -67,16 +67,6 @@ @end /* PostgreSQL72DataTypeMappingException */ -@implementation NSNull(PostgreSQL72Values) - -- (NSString *)stringValueForPostgreSQLType:(NSString *)_type - attribute:(EOAttribute *)_attribute -{ - return @"null"; -} - -@end /* NSNull(PostgreSQL72Values) */ - void __link_PostgreSQL72Values() { // used to force linking of object file diff --git a/sope-gdl1/PostgreSQL/PostgreSQL72Expression.m b/sope-gdl1/PostgreSQL/PostgreSQL72Expression.m index 63da8811..744b7a93 100644 --- a/sope-gdl1/PostgreSQL/PostgreSQL72Expression.m +++ b/sope-gdl1/PostgreSQL/PostgreSQL72Expression.m @@ -1,11 +1,12 @@ /* PostgreSQL72Expression.m - Copyright (C) 1999 MDlink online service center GmbH and Helge Hess + Copyright (C) 1999 MDlink online service center GmbH and Helge Hess + Copyright (C) 2000-2006 SKYRIX Software AG and Helge Hess + + Author: Helge Hess (helge@opengroupware.org) - Author: Helge Hess (helge@mdlink.de) - - This file is part of the PostgreSQL72 Adaptor Library + This file is part of the PostgreSQL Adaptor Library This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -56,24 +57,31 @@ NSEnumerator *enumerator; BOOL first = YES; id key; - - fromClause = [NSMutableString stringWithCString:" "]; + + fromClause = [NSMutableString stringWithCapacity:64]; enumerator = [fromListEntities objectEnumerator]; + + [fromClause appendString:@" "]; // Compute the FROM list from all the aliases found in // entitiesAndPropertiesAliases dictionary. Note that this dictionary // contains entities and relationships. The last ones are there for // flattened attributes over reflexive relationships. - while((key = [enumerator nextObject])) { + while ((key = [enumerator nextObject]) != nil) { if(first) first = NO; else [fromClause appendString:@", "]; - - [fromClause appendFormat:@"%@ %@", + + [fromClause appendString: [key isKindOfClass:[EORelationship class]] - ? [[key destinationEntity] externalName] // flattened attribute - : [key externalName], // EOEntity - [entitiesAndPropertiesAliases objectForKey:key]]; + ? [[key destinationEntity] externalName] + // flattened attribute + : [key externalName]]; + // EOEntity + + [fromClause appendString:@" "]; + [fromClause appendString: + [[entitiesAndPropertiesAliases objectForKey:key] stringValue]]; #if 0 if (lock) [fromClause appendString:@" HOLDLOCK"]; diff --git a/sope-gdl1/PostgreSQL/Version b/sope-gdl1/PostgreSQL/Version index 6b9eee57..17168ee5 100644 --- a/sope-gdl1/PostgreSQL/Version +++ b/sope-gdl1/PostgreSQL/Version @@ -1,5 +1,5 @@ # version file -SUBMINOR_VERSION:=47 +SUBMINOR_VERSION:=48 # v4.5.41 requires libGDLAccess v4.5.50 diff --git a/sope-gdl1/PostgreSQL/pgconfig.h b/sope-gdl1/PostgreSQL/pgconfig.h new file mode 100644 index 00000000..de7d0177 --- /dev/null +++ b/sope-gdl1/PostgreSQL/pgconfig.h @@ -0,0 +1,51 @@ +/* + PostgreSQL72Channel.m + + Copyright (C) 1999 MDlink online service center GmbH and Helge Hess + Copyright (C) 2000-2006 SKYRIX Software AG and Helge Hess + + Author: Helge Hess (helge.hess@opengroupware.org) + + This file is part of the PostgreSQL Adaptor Library + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#ifndef PG_MAJOR_VERSION +/* PostgreSQL 7.4 and up do not have those versioning checks */ + + +#define NG_HAS_NOTICE_PROCESSOR 1 +#define NG_HAS_BINARY_TUPLES 1 +#define NG_HAS_FMOD 1 +#define NG_SET_CLIENT_ENCODING 1 + + +#else /* PG_MAJOR_VERSION processing */ + + +#if PG_MAJOR_VERSION >= 6 && PG_MINOR_VERSION > 3 +# define NG_HAS_NOTICE_PROCESSOR 1 +# define NG_HAS_BINARY_TUPLES 1 +# define NG_HAS_FMOD 1 +#endif + +#if PG_MAJOR_VERSION >= 7 && PG_MINOR_VERSION > 3 +# define NG_SET_CLIENT_ENCODING 1 +#endif + + +#endif /* PG_MAJOR_VERSION processing */