* EOAdaptors/Postgres95/Postgres95Private.m/h: New files

based on EOControl/EOPriv.m/h.
        * EOAdaptors/Postgres95/GNUmakefile.in: Build
        Postgres95Private.m.
        * EOAdaptors/Postgres95/Postgres95Adaptor.m: Do not depend on
        EOControl/EOPriv.m/h but on own private files.
        (+assignExternalInfoForEntity): Use objectAtIndex: instead of
        enumerator for speed.
        * EOAdaptors/Postgres95/Postgres95Channel.m: (+initialize)
        (-lowLevelResultFieldNames:, -fetchRowWithZone:)
        (-insertRow:forEntity:, -_describeResults, -describeTableNames)
        (-updateValues:inRowsDescribedByQualifier:entity:)
        (-_describeBasicEntityWithName:forModel:)
        (-_describeForeignKeysForEntity:forModel:)
        (-primaryKeyForNewRowWithEntity:): Do not depend on
        EOControl/EOPriv.m/h but on own private files.  Improve
        optimizations.
        (pgResultDictionary): Simplify unused static local be
        reverting optimizations.
        * EOAdaptors/Postgres95/Postgres95SQLExpression.m:
        (+initialize, +formatValue:forAttribute:)
        (+sqlPatternFromShellPattern:)
        (+sqlPatternFromShellPattern:withEscapeCharacter:): Do not
        depend on EOControl/EOPriv.m/h but on own private files.  Improve
        optimizations.
        * EOAdaptors/Postgres95/Postgres95Values.h/m
        (Postgres95CalendarFormat, Postgres95ValuesClass)
        (Postgres95Values_newValueForBytesLengthAttributeSEL)
        (Postgres95Values_newValueForBytesLengthAttributeIMP)
        (Postgres95Values_newValueForBytesLengthAttribute): Remove.
        ([NSCalendarDate+setPostgres95Format:]): Remove.
        ([NSCalendarDate+postgres95Format]): Deprecate.
        (LPSQLA_StringDefaultCStringEncoding): New local static.
        (+initialize, +newValueForNumberType:length:attribute:)
        (+newValueForCharactersType:length:attribute:)
        (+newValueForDateType:length:attribute:):  Do not depend on
        EOControl/EOPriv.m/h but on own private files.  Improve
        optimizations.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@20750 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
David Ayers 2005-02-19 12:13:22 +00:00
parent 74a8e976bf
commit 7c80ffaf65
9 changed files with 566 additions and 228 deletions

View file

@ -1,3 +1,43 @@
2005-02-19 David Ayers <d.ayers@inode.at>
* EOAdaptors/Postgres95/Postgres95Private.m/h: New files
based on EOControl/EOPriv.m/h.
* EOAdaptors/Postgres95/GNUmakefile.in: Build Postgres95Private.m.
* EOAdaptors/Postgres95/Postgres95Adaptor.m: Do not depend on
EOControl/EOPriv.m/h but on own private files.
(+assignExternalInfoForEntity): Use objectAtIndex: instead of
enumerator for speed.
* EOAdaptors/Postgres95/Postgres95Channel.m: (+initialize)
(-lowLevelResultFieldNames:, -fetchRowWithZone:)
(-insertRow:forEntity:, -_describeResults, -describeTableNames)
(-updateValues:inRowsDescribedByQualifier:entity:)
(-_describeBasicEntityWithName:forModel:)
(-_describeForeignKeysForEntity:forModel:)
(-primaryKeyForNewRowWithEntity:): Do not depend on
EOControl/EOPriv.m/h but on own private files. Improve
optimizations.
(pgResultDictionary): Simplify unused static local be reverting
optimizations.
* EOAdaptors/Postgres95/Postgres95SQLExpression.m:
(+initialize, +formatValue:forAttribute:)
(+sqlPatternFromShellPattern:)
(+sqlPatternFromShellPattern:withEscapeCharacter:): Do not depend
on EOControl/EOPriv.m/h but on own private files. Improve
optimizations.
* EOAdaptors/Postgres95/Postgres95Values.h/m
(Postgres95CalendarFormat, Postgres95ValuesClass)
(Postgres95Values_newValueForBytesLengthAttributeSEL)
(Postgres95Values_newValueForBytesLengthAttributeIMP)
(Postgres95Values_newValueForBytesLengthAttribute): Remove.
([NSCalendarDate+setPostgres95Format:]): Remove.
([NSCalendarDate+postgres95Format]): Deprecate.
(LPSQLA_StringDefaultCStringEncoding): New local static.
(+initialize, +newValueForNumberType:length:attribute:)
(+newValueForCharactersType:length:attribute:)
(+newValueForDateType:length:attribute:): Do not depend on
EOControl/EOPriv.m/h but on own private files. Improve
optimizations.
2005-02-18 Matt Rice <ratmice@yahoo.com>
* EOAccess/EOModel.m (-addEntity:, -setName:): Call -willChange:

View file

@ -44,7 +44,8 @@ Postgres95Adaptor.m \
Postgres95Context.m \
Postgres95Channel.m \
Postgres95SQLExpression.m \
Postgres95Values.m
Postgres95Values.m \
Postgres95Private.m
Postgres95EOAdaptor_HEADER_FILES = \
Postgres95Adaptor.h \

View file

@ -63,7 +63,6 @@ RCS_ID("$Id$")
#include <EOControl/EONSAddOns.h>
#include <EOControl/EODebug.h>
#include <EOControl/EOPriv.h>
#include <EOAccess/EOAccess.h>
#include <EOAccess/EOAttribute.h>
@ -77,6 +76,7 @@ RCS_ID("$Id$")
#include <Postgres95EOAdaptor/Postgres95SQLExpression.h>
#include <Postgres95EOAdaptor/Postgres95Values.h>
#include "Postgres95Private.h"
NSString *Postgres95Exception = @"Postgres95Exception";
static int pgConnTotalAllocated = 0;
@ -243,12 +243,18 @@ static NSString *internalTypeNames[] = {
+ (void)assignExternalInfoForEntity: (EOEntity *)entity
{
NSEnumerator *attributeEnumerator = [[entity attributes] objectEnumerator];
NSArray *attributes = [entity attributes];
EOAttribute *attribute = nil;
IMP enumNO = NULL;
IMP arrayOAI = NULL;
static SEL selfAEIFA_SEL = @selector(assignExternalInfoForAttribute:);
IMP selfAEIFA_IMP = [self methodForSelector: selfAEIFA_SEL];
unsigned i, c;
while ((attribute = GDL2NextObjectWithImpPtr(attributeEnumerator,&enumNO)))
[self assignExternalInfoForAttribute: attribute];
for (i=0, c=[attributes count]; i < c; i++)
{
attribute = PSQLA_ObjectAtIndexWithImpPtr(attributes, &arrayOAI, i);
selfAEIFA_IMP(self, selfAEIFA_SEL, attribute);
}
}
/* Inherited methods */

View file

@ -67,7 +67,6 @@ RCS_ID("$Id$")
#include <EOControl/EOFetchSpecification.h>
#include <EOControl/EONSAddOns.h>
#include <EOControl/EODebug.h>
#include <EOControl/EOPriv.h>
#include <EOAccess/EOAttribute.h>
#include <EOAccess/EOEntity.h>
@ -78,6 +77,7 @@ RCS_ID("$Id$")
#include <Postgres95EOAdaptor/Postgres95Context.h>
#include <Postgres95EOAdaptor/Postgres95Values.h>
#include "Postgres95Private.h"
static void __dummy_function_used_for_linking(void)
{
@ -99,39 +99,53 @@ pgResultDictionary(PGresult *pgResult)
NSMutableArray *fields;
NSMutableArray *tuples;
ExecStatusType statusType;
IMP fieldsAO=NULL; // addObject:
IMP tuplesAO=NULL; // addObject:
nfields = PQnfields(pgResult);
ntuples = PQntuples(pgResult);
fields = GDL2MutableArrayWithCapacity(nfields);
tuples = GDL2MutableArrayWithCapacity(ntuples);
fields = [NSMutableArray arrayWithCapacity: nfields];
tuples = [NSMutableArray arrayWithCapacity: ntuples];
for (i = 1; i <= nfields; i++)
{
char *fname;
fname = PQfname(pgResult, i);
GDL2AddObjectWithImpPtr(fields,&fieldsAO,
[NSDictionary dictionaryWithObjectsAndKeys:
[NSS_SWF:@"%s", fname], @"PQfname",
[NSS_SWF:@"%d", PQfnumber(pgResult, fname)], @"PQfnumber",
[NSS_SWF:@"%ud", PQftype(pgResult, i)], @"PQftype",
[NSS_SWF:@"%d", PQfsize(pgResult, i)], @"PQfsize",
[NSS_SWF:@"%d", PQfmod(pgResult, i)], @"PQfmod",
nil]);
NSString *fname;
NSNumber *fnumber;
NSNumber *ftype;
NSNumber *fsize;
NSNumber *fmod;
NSDictionary *dict;
char *cfname;
cfname = PQfname(pgResult, i);
fname = [NSString stringWithCString: cfname];
fnumber = [NSNumber numberWithInt: PQfnumber(pgResult, cfname)];
ftype = [NSNumber numberWithUnsignedInt: PQftype(pgResult, i)];
fsize = [NSNumber numberWithInt: PQfsize(pgResult, i)];
fmod = [NSNumber numberWithInt: PQfmod(pgResult, i)];
dict = [NSDictionary dictionaryWithObjectsAndKeys:
fname, @"PQfname",
fnumber, @"PQfnumber",
ftype, @"PQftype",
fsize, @"PQfsize",
fmod, @"PQfmod",
nil];
[fields addObject: dict];
}
for (i = 1; i <= ntuples; i++)
{
IMP tupleSOFK=NULL; // setObject:forKey:
NSMutableDictionary *tuple;
tuple = GDL2MutableDictionaryWithCapacity(nfields);
tuple = [NSMutableDictionary dictionaryWithCapacity: nfields];
for (j = 1; j <= nfields; j++)
{
NSString *tupleInfo;
NSString *tupleKey;
tupleKey = [NSS_SWF:@"%s", PQfname(pgResult, j)];
tupleKey = [NSString stringWithCString: PQfname(pgResult, j)];
if (PQgetisnull(pgResult, i, j))
{
tupleInfo = @"NULL";
@ -142,9 +156,9 @@ pgResultDictionary(PGresult *pgResult)
fmt = [NSS_SWF: @"%%%ds", PQgetlength(pgResult, i, j)];
tupleInfo = [NSS_SWF: fmt, PQgetvalue(pgResult, i, j)];
}
GDL2SetObjectForKeyWithImpPtr(tuple,&tupleSOFK,tupleInfo,tupleKey);
[tuple setObject: tupleInfo forKey: tupleKey];
}
GDL2AddObjectWithImpPtr(tuples,&tuplesAO,tuple);
[tuples addObject: tuple];
}
statusType = PQresultStatus(pgResult);
@ -173,7 +187,7 @@ pgResultDictionary(PGresult *pgResult)
if (!initialized)
{
Class aClass=Nil;
GDL2PrivInit();
PSQLA_PrivInit();
aClass=[Postgres95Values class]; // Force Initialize;
};
@ -342,16 +356,19 @@ pgResultDictionary(PGresult *pgResult)
- (NSArray*)lowLevelResultFieldNames: (PGresult*)res
{
int nb = PQnfields(res);
NSMutableArray *names = GDL2MutableArrayWithCapacity(nb);
NSMutableArray *names
= AUTORELEASE([PSQLA_alloc(NSMutableArray) initWithCapacity: nb]);
int i;
IMP namesAO=NULL; //addObject:
for (i = 0; i < nb; i++)
{
char *szName = PQfname(res,i);
NSString *name = GDL2StringWithCString(szName);
GDL2AddObjectWithImpPtr(names,&namesAO,name);
unsigned length = szName ? strlen(szName) : 0;
NSString *name = [(PSQLA_alloc(NSString)) initWithCString: szName
length: length];
PSQLA_AddObjectWithImpPtr(names,&namesAO,name);
RELEASE(name);
}
return names;
@ -430,7 +447,7 @@ zone:zone
for (i = 0; i < count; i++)
{
EOAttribute *attr = GDL2ObjectAtIndexWithImpPtr(_attributes,&attributesOAI,i);
EOAttribute *attr = PSQLA_ObjectAtIndexWithImpPtr(_attributes,&attributesOAI,i);
int length = 0;
const char *string = NULL;
@ -438,7 +455,7 @@ zone:zone
if (PQgetisnull(_pgResult, _currentResultRow, i))
{
values[i] = RETAIN(GDL2EONull); //to be compatible with others returned values
values[i] = RETAIN(PSQLA_EONull); //to be compatible with others returned values
}
else
{
@ -455,18 +472,25 @@ zone:zone
string = [self _readBinaryDataRow: (Oid)atol(string)
length:&length zone: zone];
//For efficiency reasons, the returned value is NOT autoreleased !
values[i] = Postgres95Values_newValueForBytesLengthAttribute(string,length,attr);
values[i] = PSQLA_Postgres95Values_newValueForBytesLengthAttribute(string,length,attr);
}
else
{
//For efficiency reasons, the returned value is NOT autoreleased !
values[i] = [GDL2NSNumber_alloc() initWithLong: atol(string)];
// The documentatin states that for efficiency
// reasons, the returned value is NOT autoreleased
// yet in the case of GNUstep-base it would be more
// efficient if the numberWithLong: method would be
// used as we could often skip alloc / dealloc
// and get a cached value. We could use it and
// send retain, or we could start maintaing our
// own cache.
values[i] = [PSQLA_alloc(NSNumber) initWithLong: atol(string)];
}
}
else
{
//For efficiency reasons, the returned value is NOT autoreleased !
values[i] = Postgres95Values_newValueForBytesLengthAttribute(string,length,attr);
values[i] = PSQLA_Postgres95Values_newValueForBytesLengthAttribute(string,length,attr);
}
}
@ -788,7 +812,7 @@ each key
*/
enumerator = [row keyEnumerator];
while ((attrName = GDL2NextObjectWithImpPtr(enumerator,&attrEnumNO)))
while ((attrName = PSQLA_NextObjectWithImpPtr(enumerator,&attrEnumNO)))
{
EOAttribute *attribute = nil;
NSString *externalType = nil;
@ -802,7 +826,7 @@ each key
if (!attribute)
return; //???????????
value = GDL2ObjectForKeyWithImpPtr(row,&rowOFK,attrName);
value = PSQLA_ObjectForKeyWithImpPtr(row,&rowOFK,attrName);
NSDebugMLLog(@"gsdb", @"value=%@", value);
externalType = [attribute externalType];
@ -811,7 +835,7 @@ each key
/* Insert the binary value into the binaryDataRow dictionary */
if ([externalType isEqual: @"inversion"])
{
id binValue = GDL2ObjectForKeyWithImpPtr(nrow,&nrowOFK,attrName);
id binValue = PSQLA_ObjectForKeyWithImpPtr(nrow,&nrowOFK,attrName);
Oid binOid = [self _insertBinaryData: binValue
forAttribute: attribute];
value = [NSNumber numberWithLong: binOid];
@ -822,7 +846,7 @@ each key
// [[adaptorContext adaptor] databaseEncoding]
}
GDL2SetObjectForKeyWithImpPtr(nrow,&nrowSOFK,value,attrName);
PSQLA_SetObjectForKeyWithImpPtr(nrow,&nrowSOFK,value,attrName);
}
NSDebugMLLog(@"gsdb", @"nrow=%@", nrow);
@ -1053,7 +1077,7 @@ each key
invAttributes = AUTORELEASE([[NSMutableArray alloc] initWithCapacity: [mrow count]]);
enumerator = [values keyEnumerator];
while ((attrName = GDL2NextObjectWithImpPtr(enumerator,&valueEnumNO)))
while ((attrName = PSQLA_NextObjectWithImpPtr(enumerator,&valueEnumNO)))
{
attr = [entity attributeNamed: attrName];
externalType = [attr externalType];
@ -1065,8 +1089,8 @@ each key
[values objectForKey:attrName]]
forKey:attrName];
*/
GDL2SetObjectForKeyWithImpPtr(mrow,&mrowSOFK,
GDL2ObjectForKeyWithImpPtr(values,&valuesOFK,attrName),
PSQLA_SetObjectForKeyWithImpPtr(mrow,&mrowSOFK,
PSQLA_ObjectForKeyWithImpPtr(values,&valuesOFK,attrName),
attrName);
if ([externalType isEqual: @"inversion"])
@ -1107,7 +1131,7 @@ each key
// Update the large objects and modify the row to update with Oid's
enumerator = [invAttributes objectEnumerator];
while ((attr = GDL2NextObjectWithImpPtr(enumerator,&invAttributesNO)))
while ((attr = PSQLA_NextObjectWithImpPtr(enumerator,&invAttributesNO)))
{
Oid oldOid;
Oid newOid;
@ -1119,7 +1143,7 @@ each key
oldOid = [[dbRow objectForKey:attrName] longValue];
newOid = [self _updateBinaryDataRow: oldOid data: data];
GDL2SetObjectForKeyWithImpPtr(mrow,&mrowSOFK,
PSQLA_SetObjectForKeyWithImpPtr(mrow,&mrowSOFK,
[NSNumber numberWithUnsignedLong: newOid],
attrName);
}
@ -1377,13 +1401,12 @@ each key
if (colsNumber == 0)
{
[self setAttributesToFetch: GDL2Array()];
[self setAttributesToFetch: PSQLA_NSArray];
}
else if (!_attributes) //??
{
int i;
id *attributes = NULL;
IMP attributeNewIMP=[GDL2EOAttributeClass methodForSelector:GDL2_newSEL];
IMP origAttributesOAI=NULL;
IMP oidToTypeNameOFK=NULL;
@ -1391,7 +1414,8 @@ each key
for (i = 0; i < colsNumber; i++)
{
EOAttribute *attribute = AUTORELEASE(((*attributeNewIMP)(GDL2EOAttributeClass,GDL2_newSEL)));
EOAttribute *attribute
= AUTORELEASE([PSQLA_alloc(EOAttribute) init]);
NSString *externalType;
NSString *valueClass = @"NSString";
NSString *valueType = nil;
@ -1399,7 +1423,7 @@ each key
if (_origAttributes)
{
EOAttribute *origAttr = (EOAttribute *)
GDL2ObjectAtIndexWithImpPtr(_origAttributes,&origAttributesOAI,i);
PSQLA_ObjectAtIndexWithImpPtr(_origAttributes,&origAttributesOAI,i);
[attribute setName: [origAttr name]];
[attribute setColumnName: [origAttr columnName]];
@ -1412,7 +1436,7 @@ each key
NSNumber *externalTypeNumber;
externalTypeNumber
= [NSNumber numberWithLong: PQftype(_pgResult, i)];
externalType = GDL2ObjectForKeyWithImpPtr(_oidToTypeName,
externalType = PSQLA_ObjectForKeyWithImpPtr(_oidToTypeName,
&oidToTypeNameOFK,externalTypeNumber);
if (!externalType)
@ -1511,13 +1535,14 @@ each key
}
count = PQntuples(_pgResult);
results=GDL2MutableArrayWithCapacity(count);
results= AUTORELEASE([PSQLA_alloc(NSMutableArray) initWithCapacity: count]);
for (i = 0; i < count; i++)
{
char *oid = PQgetvalue(_pgResult, i, 0);
GDL2AddObjectWithImpPtr(results,&resultsAO,[NSString stringWithUTF8String: oid]);
PSQLA_AddObjectWithImpPtr(results,&resultsAO,
[NSString stringWithUTF8String: oid]);
}
PQclear(_pgResult);
@ -1588,13 +1613,18 @@ each key
if (count>0)
{
IMP attributeNewIMP=NULL;[GDL2EOAttributeClass methodForSelector:GDL2_newSEL];
for (n = 0; n < count; n++)
{
NSString *columnName;
NSString *externalType;
char *name;
unsigned length;
name = PQgetvalue(_pgResult,n,1);
length = name ? strlen(name) : 0;
externalType = GDL2StringWithCString(PQgetvalue(_pgResult,n,1));
externalType = [(PSQLA_alloc(NSString)) initWithCString: name
length: length];
//TODO optimize ?
if ([externalType isEqual: @"bool"])
@ -1626,14 +1656,22 @@ each key
else if ([externalType isEqual: @"text"])
valueClass = @"NSString", valueType = nil;
attribute = AUTORELEASE(((*attributeNewIMP)(GDL2EOAttributeClass,GDL2_newSEL)));
columnName = GDL2StringWithCString(PQgetvalue(_pgResult, n, 0));
name = PQgetvalue(_pgResult, n, 0);
length = name ? strlen(name) : 0;
columnName = [(PSQLA_alloc(NSString)) initWithCString: name
length: length];
attribute = [PSQLA_alloc(EOAttribute) init];
[attribute setName: columnName];
[attribute setColumnName: columnName];
[attribute setExternalType: externalType];
[attribute setValueType: valueType];
[attribute setValueClassName: valueClass];
[entity addAttribute: attribute];
RELEASE(externalType);
RELEASE(attribute);
RELEASE(columnName);
}
};
@ -1648,7 +1686,8 @@ each key
_pgResult = PQexec(_pgConn,[stmt cString]);
if (PQntuples(_pgResult))
{
NSString *pkAttNum = GDL2StringWithCString(PQgetvalue(_pgResult,0,0));
NSString *pkAttNum
= [NSString stringWithCString: PQgetvalue(_pgResult,0,0)];
pkAttNum = [pkAttNum stringByReplacingString:@" "
withString: @", "];
@ -1662,23 +1701,31 @@ each key
if (PQntuples(_pgResult))
{
NSArray *pkeys = GDL2Array();
NSMutableArray *pkeys;
count = PQntuples(_pgResult);
pkeys = [PSQLA_alloc(NSMutableArray) initWithCapacity: count];
for (k = 0; k < count; k++)
{
const char *cName;
//TODO: Optimize, it's probably faster to use a mutable
// string here instead of alloc/dealloing new strings.
NSString *name;
const char *cName;
unsigned length;
cName = PQgetvalue(_pgResult,k,0);
name = GDL2StringWithCString(cName);
length = cName ? strlen(cName) : 0;
name = [(PSQLA_alloc(NSString)) initWithCString: cName
length: length];
attribute = [entity attributeNamed: name];
NSDebugMLLog(@"adaptor", @"pk(%d) name: %@", k, name);
pkeys = [pkeys arrayByAddingObject: attribute];
[pkeys addObject: attribute];
RELEASE(name);
}
NSDebugMLLog(@"adaptor", @"pkeys %@", pkeys);
[entity setPrimaryKeyAttributes: pkeys];
RELEASE(pkeys);
}
}
/* </primary key stuff> */
@ -1715,8 +1762,13 @@ each key
EORelationship *relationship;
NSSet *dstPKSet;
NSMutableSet *dstAttribNames;
char *name;
unsigned length;
fkString = GDL2StringWithCString(PQgetvalue(_pgResult,i,0));
name = PQgetvalue(_pgResult,i,0);
length = name ? strlen(name) : 0;
fkString = AUTORELEASE([(PSQLA_alloc(NSString)) initWithCString: name
length: length]);
NSDebugMLLog(@"adaptor", @"foreign key: %@\n",fkString);
fkComp = [fkString componentsSeparatedByString: @"\\000"];
@ -1955,12 +2007,12 @@ each key
}
else
{
EOAttribute *attr;
string = PQgetvalue(_pgResult, _currentResultRow, 0);
length = PQgetlength(_pgResult, _currentResultRow, 0);
pkValue = AUTORELEASE(Postgres95Values_newValueForBytesLengthAttribute(string,
length,
[_pkAttributeArray objectAtIndex: 0]));
attr = [_pkAttributeArray objectAtIndex: 0];
pkValue = AUTORELEASE(PSQLA_Postgres95Values_newValueForBytesLengthAttribute(string,length,attr));
NSAssert(pkValue, @"no pk value");
key = [[entity primaryKeyAttributeNames] objectAtIndex: 0];

View file

@ -0,0 +1,163 @@
/* -*-objc-*-
Postgres95Private.h
Copyright (C) 2005 Free Software Foundation, Inc.
Author: Manuel Guesdon <mguesdon@orange-concept.com>
Date: Jan 2005
This file is part of the GNUstep Database 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 __Postgres95Private_h__
#define __Postgres95Private_h__
@class NSNumber;
@class EONull;
// ==== Classes ====
extern Class PSQLA_NSStringClass;
extern Class PSQLA_NSNumberClass;
extern Class PSQLA_NSDecimalNumberClass;
extern Class PSQLA_NSCalendarDateClass;
extern Class PSQLA_NSDateClass;
extern Class PSQLA_NSMutableArrayClass;
extern Class PSQLA_EOAttributeClass;
extern Class PSQLA_Postgres95ValuesClass;
// ==== IMPs ====
extern IMP PSQLA_NSNumber_allocWithZoneIMP;
extern IMP PSQLA_NSDecimalNumber_allocWithZoneIMP;
extern IMP PSQLA_NSString_allocWithZoneIMP;
extern IMP PSQLA_NSCalendarDate_allocWithZoneIMP;
extern IMP PSQLA_NSMutableArray_allocWithZoneIMP;
extern IMP PSQLA_EOAttribute_allocWithZoneIMP;
extern IMP PSQLA_Postgres95Values_newValueForBytesLengthAttributeIMP;
// ==== Constants ====
extern NSNumber *PSQLA_NSNumberBool_Yes;
extern NSNumber *PSQLA_NSNumberBool_No;
extern EONull *PSQLA_EONull;
extern NSArray *PSQLA_NSArray;
extern NSString *PSQLA_postgresCalendarFormat;
// ==== Init Method ====
extern void PSQLA_PrivInit(void);
// ==== IMP Helpers ====
static inline BOOL
_isNilOrEONull(id obj) __attribute__ ((unused));
static inline BOOL
_isNilOrEONull(id obj)
{
if (PSQLA_EONull == nil) PSQLA_PrivInit();
return (obj == nil || obj == PSQLA_EONull) ? YES : NO;
}
// ---- Postgres95Values newValueForBytes:length:attribute ----
#define PSQLA_Postgres95Values_newValueForBytesLengthAttribute(bytes, \
length, \
attribute) \
(*PSQLA_Postgres95Values_newValueForBytesLengthAttributeIMP) \
(PSQLA_Postgres95ValuesClass, \
@selector(newValueForBytes:length:attribute:), \
(bytes), (length), (attribute))
// ---- NSEnumerator nextObject ----
static inline id
PSQLA_NextObjectWithImpPtr(id object,IMP* impPtr)
{
if (object)
{
if (!*impPtr)
*impPtr=[object methodForSelector:@selector(nextObject)];
return (**impPtr)(object,@selector(nextObject));
}
else
return nil;
};
// ---- NSMutableString appendString: ----
#define PSQLA_AppendStringWithImp(string,methodIMP,aString) \
(*(methodIMP))((string),@selector(appendString:),(aString))
// ---- NSMutableArray addObject: ----
static inline void
PSQLA_AddObjectWithImpPtr(id object,IMP* impPtr,id objectToAdd)
{
if (object)
{
if (!*impPtr)
*impPtr=[object methodForSelector:@selector(addObject:)];
(**impPtr)(object,@selector(addObject:),objectToAdd);
};
};
// ---- NSArray objectAtIndex: ----
static inline id
PSQLA_ObjectAtIndexWithImpPtr(id object,IMP* impPtr,unsigned index)
{
if (object)
{
if (!*impPtr)
*impPtr=[object methodForSelector:@selector(objectAtIndex:)];
return (**impPtr)(object,@selector(objectAtIndex:),index);
}
else
return nil;
};
// ---- Dictionary objectForKey: ----
static inline id
PSQLA_ObjectForKeyWithImpPtr(id object,IMP* impPtr,id key)
{
if (object)
{
if (!*impPtr)
*impPtr=[object methodForSelector:@selector(objectForKey:)];
return (**impPtr)(object,@selector(objectForKey:),key);
}
else
return nil;
};
// ---- Dictionary setObject:forKey: ----
static inline void
PSQLA_SetObjectForKeyWithImpPtr(id object,IMP* impPtr,id value, id key)
{
if (object)
{
if (!*impPtr)
*impPtr=[object methodForSelector:@selector(setObject:forKey:)];
(**impPtr)(object,@selector(setObject:forKey:),value,key);
}
};
// ---- +alloc/+allocWithZone: ----
#define PSQLA_alloc(CLASS_NAME) \
(*PSQLA_##CLASS_NAME##_allocWithZoneIMP) \
(PSQLA_##CLASS_NAME##Class,@selector(allocWithZone:),NULL)
#endif /* __Postgres95Private_h__ */

View file

@ -0,0 +1,122 @@
/**
Postgres95Private.m <title>Postgres95Private: various definitions</title>
Copyright (C) 2005 Free Software Foundation, Inc.
Date: Jan 2005
$Revision$
$Date$
<abstract></abstract>
This file is part of the GNUstep Database Library.
<license>
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.
</license>
**/
#include "config.h"
RCS_ID("$Id$")
#include <Foundation/Foundation.h>
#ifndef GNUSTEP
#include <GNUstepBase/GNUstep.h>
#include <GNUstepBase/GSCategories.h>
#endif
#include <EOControl/EONull.h>
#include <EOAccess/EOAttribute.h>
#include "Postgres95Values.h"
// ==== Classes ====
Class PSQLA_NSStringClass=Nil;
Class PSQLA_NSNumberClass=Nil;
Class PSQLA_NSDecimalNumberClass=Nil;
Class PSQLA_NSCalendarDateClass=Nil;
Class PSQLA_NSDateClass=Nil;
Class PSQLA_NSMutableArrayClass;
Class PSQLA_EOAttributeClass=Nil;
Class PSQLA_Postgres95ValuesClass=Nil;
// ==== IMPs ====
IMP PSQLA_NSNumber_allocWithZoneIMP=NULL;
IMP PSQLA_NSDecimalNumber_allocWithZoneIMP=NULL;
IMP PSQLA_NSString_allocWithZoneIMP=NULL;
IMP PSQLA_NSCalendarDate_allocWithZoneIMP=NULL;
IMP PSQLA_NSMutableArray_allocWithZoneIMP=NULL;
IMP PSQLA_EOAttribute_allocWithZoneIMP=NULL;
IMP PSQLA_Postgres95Values_newValueForBytesLengthAttributeIMP=NULL;
// ==== Constants ====
NSNumber *PSQLA_NSNumberBool_Yes=nil;
NSNumber *PSQLA_NSNumberBool_No=nil;
EONull *PSQLA_EONull=nil;
NSArray *PSQLA_NSArray=nil;
NSString *PSQLA_postgresCalendarFormat=@"%Y-%m-%d %H:%M:%S%z";
// ==== Init Method ====
void
PSQLA_PrivInit(void)
{
static BOOL initialized=NO;
if (!initialized)
{
// ==== Classes ====
PSQLA_NSMutableArrayClass=[NSMutableArray class];
PSQLA_NSStringClass=[NSString class];
PSQLA_NSNumberClass=[NSNumber class];
PSQLA_NSDecimalNumberClass=[NSDecimalNumber class];
PSQLA_NSCalendarDateClass=[NSCalendarDate class];
PSQLA_EOAttributeClass = [EOAttribute class];
PSQLA_Postgres95ValuesClass = [Postgres95Values class];
// ==== IMPs ====
PSQLA_NSNumber_allocWithZoneIMP=
[PSQLA_NSNumberClass methodForSelector:@selector(allocWithZone:)];
PSQLA_NSDecimalNumber_allocWithZoneIMP=
[PSQLA_NSDecimalNumberClass methodForSelector:@selector(allocWithZone:)];
PSQLA_NSString_allocWithZoneIMP=
[PSQLA_NSStringClass methodForSelector:@selector(allocWithZone:)];
PSQLA_NSCalendarDate_allocWithZoneIMP=
[PSQLA_NSCalendarDateClass methodForSelector:@selector(allocWithZone:)];
PSQLA_NSMutableArray_allocWithZoneIMP=
[PSQLA_NSMutableArrayClass methodForSelector:@selector(allocWithZone:)];
PSQLA_EOAttribute_allocWithZoneIMP=
[PSQLA_EOAttributeClass methodForSelector:@selector(allocWithZone:)];
PSQLA_Postgres95Values_newValueForBytesLengthAttributeIMP=
[PSQLA_Postgres95ValuesClass methodForSelector:@selector(newValueForBytes:length:attribute:)];
// ==== Constants ====
ASSIGN(PSQLA_NSNumberBool_Yes,[PSQLA_NSNumberClass numberWithBool:YES]);
ASSIGN(PSQLA_NSNumberBool_No,[PSQLA_NSNumberClass numberWithBool:NO]);
ASSIGN(PSQLA_EONull,[EONull null]);
ASSIGN(PSQLA_NSArray,[NSArray array]);
};
}

View file

@ -54,7 +54,6 @@ RCS_ID("$Id$")
#include <EOControl/EONull.h>
#include <EOControl/EONSAddOns.h>
#include <EOControl/EODebug.h>
#include <EOControl/EOPriv.h>
#include <EOAccess/EOAttribute.h>
#include <EOAccess/EOEntity.h>
@ -66,10 +65,7 @@ RCS_ID("$Id$")
#include "Postgres95Values.h"
#include "Postgres95Compatibility.h"
static SEL postgres95FormatSEL=NULL;
static IMP NSCalendarDatePostgres95FormatIMP=NULL;
#include "Postgres95Private.h"
/* These methods are undocumented but exist in GDL2 and WO4.5.
Ayers: Review (Don't rely on them) */
@ -90,12 +86,7 @@ static IMP NSCalendarDatePostgres95FormatIMP=NULL;
static BOOL initialized=NO;
if (!initialized)
{
GDL2PrivInit();
postgres95FormatSEL=@selector(postgres95Format);
NSCalendarDatePostgres95FormatIMP=[GDL2NSCalendarDateClass
methodForSelector:postgres95FormatSEL];
PSQLA_PrivInit();
};
};
@ -176,32 +167,36 @@ static IMP NSCalendarDatePostgres95FormatIMP=NULL;
else
{
NSDecimalNumber* decimalValue=nil;
if ([value isKindOfClass: GDL2NSDecimalNumberClass] == NO)
if ([value isKindOfClass: PSQLA_NSDecimalNumberClass] == NO)
{
if ([value isKindOfClass: GDL2NSStringClass] == YES)
if ([value isKindOfClass: PSQLA_NSStringClass] == YES)
{
decimalValue=[NSDecimalNumber decimalNumberWithString:value];
decimalValue
= AUTORELEASE([PSQLA_alloc(NSDecimalNumber) initWithString:value]);
EOFLOGObjectLevelArgs(@"EOSQLExpression",
@"float case - value [%@]=%@ ==> decimalValue=%@",
value,[value class],decimalValue);
}
else if ([value respondsToSelector: @selector(doubleValue)])
{
decimalValue=(NSDecimalNumber*)[[[NSDecimalNumber alloc]initWithDouble:[value doubleValue]] autorelease];
decimalValue
= AUTORELEASE([PSQLA_alloc(NSDecimalNumber) initWithDouble:[value doubleValue]]);
EOFLOGObjectLevelArgs(@"EOSQLExpression",
@"float case - value [%@]=%@ ==> decimalValue=%@",
value,[value class],decimalValue);
}
else if ([value respondsToSelector: @selector(floatValue)])
{
decimalValue=(NSDecimalNumber*)[[[NSDecimalNumber alloc]initWithFloat:[value floatValue]] autorelease];
decimalValue
= AUTORELEASE([PSQLA_alloc(NSDecimalNumber) initWithFloat:[value floatValue]]);
EOFLOGObjectLevelArgs(@"EOSQLExpression",
@"float case - value [%@]=%@ ==> decimalValue=%@",
value,[value class],decimalValue);
}
else if ([value respondsToSelector: @selector(intValue)])
{
decimalValue=(NSDecimalNumber*)[[[NSDecimalNumber alloc]initWithInt:[value intValue]] autorelease];
decimalValue
= AUTORELEASE([PSQLA_alloc(NSDecimalNumber) initWithInt:[value intValue]]);
EOFLOGObjectLevelArgs(@"EOSQLExpression",
@"float case - value [%@]=%@ ==> decimalValue=%@",
value,[value class],decimalValue);
@ -238,7 +233,7 @@ static IMP NSCalendarDatePostgres95FormatIMP=NULL;
@"BOOL case - value=%@ class=%@",
value, [value class]);
if ([value isKindOfClass: GDL2NSNumberClass] == YES)
if ([value isKindOfClass: PSQLA_NSNumberClass] == YES)
{
BOOL boolValue = [value boolValue];
@ -298,16 +293,17 @@ static IMP NSCalendarDatePostgres95FormatIMP=NULL;
value, value, [value class]);
}
// Value can also be a string...
if ([value isKindOfClass: GDL2NSDateClass])
if ([value isKindOfClass: PSQLA_NSDateClass])
{
NSString *format = (*NSCalendarDatePostgres95FormatIMP)
(GDL2NSCalendarDateClass,postgres95FormatSEL);
NSString *format;
formatted = [NSString stringWithFormat: @"'%@'",
[value
descriptionWithCalendarFormat:format
timeZone: nil
locale: nil]];
format = [value descriptionWithCalendarFormat:
PSQLA_postgresCalendarFormat
timeZone: nil
locale: nil];
formatted = [NSString stringWithFormat: @"'%@'", format];
}
else
formatted = [NSString stringWithFormat: @"'%@'",value];
@ -791,9 +787,10 @@ static IMP NSCalendarDatePostgres95FormatIMP=NULL;
else
{
const char *s, *p, *init = [pattern cString];
NSString *tmp;
NSMutableString *str = [NSMutableString stringWithCapacity:
patternLength];
IMP appendStringIMP = [str methodForSelector:GDL2_appendStringSEL];
IMP appendStringIMP = [str methodForSelector:@selector(appendString:)];
for (s = p = init; *s; s++)
{
@ -801,49 +798,60 @@ static IMP NSCalendarDatePostgres95FormatIMP=NULL;
{
case '*':
if (s != p)
GDL2AppendStringWithImp(str,appendStringIMP,
GDL2StringWithCStringAndLength(p,s-p));
{
tmp = [(PSQLA_alloc(NSString)) initWithCString: p
length: s-p];
PSQLA_AppendStringWithImp(str, appendStringIMP, tmp);
[tmp release];
}
[str appendString: @"%"];
p = s+1;
break;
case '?':
if (s != p)
GDL2AppendStringWithImp(str,appendStringIMP,
GDL2StringWithCStringAndLength(p,s-p));
(*appendStringIMP)(str,GDL2_appendStringSEL,@"_");
{
tmp = [(PSQLA_alloc(NSString)) initWithCString: p
length: s-p];
PSQLA_AppendStringWithImp(str, appendStringIMP, tmp);
[tmp release];
}
(*appendStringIMP)(str,@selector(appendString:),@"_");
p = s+1;
break;
case '%':
if (s != p)
GDL2AppendStringWithImp(str,appendStringIMP,
GDL2StringWithCStringAndLength(p,s-p));
{
tmp = [(PSQLA_alloc(NSString)) initWithCString: p
length: s-p];
PSQLA_AppendStringWithImp(str, appendStringIMP, tmp);
[tmp release];
}
if (s != init && *(s-1) == '[' && *(s+1) == ']')
{
(*appendStringIMP)(str,GDL2_appendStringSEL,@"%]");
(*appendStringIMP)(str,@selector(appendString:),@"%]");
p = s+2; s++;
}
else
{
(*appendStringIMP)(str,GDL2_appendStringSEL,@"[%]");
(*appendStringIMP)(str,@selector(appendString:),@"[%]");
p = s+1;
}
break;
/*Postgresql doesn't want [_] but want _
case '_':
if (s != p)
(*appendStringIMP)(str,GDL2_appendStringSEL,
(*appendStringIMP)(str,@selector(appendString:),
(*stringWithCString_lengthIMP)
(GDL2NSStringClass,GDL2_stringWithCString_lengthSEL,p,s-p));
(PSQLA_NSStringClass,PSQLA_stringWithCString_lengthSEL,p,s-p));
if (s != init && *(s-1) == '[' && *(s+1) == ']')
{
(*appendStringIMP)(str,GDL2_appendStringSEL,@"_]");
(*appendStringIMP)(str,@selector(appendString:),@"_]");
p = s+2; p++;
}
else
{
(*appendStringIMP)(str,GDL2_appendStringSEL,@"[_]");
(*appendStringIMP)(str,@selector(appendString:),@"[_]");
p = s+1;
}
break;
@ -852,7 +860,7 @@ static IMP NSCalendarDatePostgres95FormatIMP=NULL;
}
if (*p)
(*appendStringIMP)(str,GDL2_appendStringSEL,[NSString stringWithCString:p]);
(*appendStringIMP)(str,@selector(appendString:),[NSString stringWithCString:p]);
sqlPattern=str;
};
@ -867,9 +875,10 @@ static IMP NSCalendarDatePostgres95FormatIMP=NULL;
withEscapeCharacter: (unichar)escapeCharacter
{
const char *s, *p, *init = [pattern cString];
NSString *tmp;
NSMutableString *str = [NSMutableString stringWithCapacity:
[pattern length]];
IMP appendStringIMP = [str methodForSelector:GDL2_appendStringSEL];
IMP appendStringIMP = [str methodForSelector:@selector(appendString:)];
for (s = p = init; *s; s++)
{
@ -877,49 +886,60 @@ static IMP NSCalendarDatePostgres95FormatIMP=NULL;
{
case '*':
if (s != p)
GDL2AppendStringWithImp(str,appendStringIMP,
GDL2StringWithCStringAndLength(p,s-p));
GDL2AppendStringWithImp(str,appendStringIMP,@"%");
{
tmp = [(PSQLA_alloc(NSString)) initWithCString: p
length: s-p];
PSQLA_AppendStringWithImp(str, appendStringIMP, tmp);
[tmp release];
}
PSQLA_AppendStringWithImp(str,appendStringIMP,@"%");
p = s+1;
break;
case '?':
if (s != p)
GDL2AppendStringWithImp(str,appendStringIMP,
GDL2StringWithCStringAndLength(p,s-p));
GDL2AppendStringWithImp(str,appendStringIMP,@"_");
{
tmp = [(PSQLA_alloc(NSString)) initWithCString: p
length: s-p];
PSQLA_AppendStringWithImp(str, appendStringIMP, tmp);
[tmp release];
}
PSQLA_AppendStringWithImp(str,appendStringIMP,@"_");
p = s+1;
break;
case '%':
if (s != p)
GDL2AppendStringWithImp(str,appendStringIMP,
GDL2StringWithCStringAndLength(p,s-p));
{
tmp = [(PSQLA_alloc(NSString)) initWithCString: p
length: s-p];
PSQLA_AppendStringWithImp(str, appendStringIMP, tmp);
[tmp release];
}
if (s != init && *(s-1) == '[' && *(s+1) == ']')
{
GDL2AppendStringWithImp(str,appendStringIMP,@"%]");
PSQLA_AppendStringWithImp(str,appendStringIMP,@"%]");
p = s+2; s++;
}
else
{
GDL2AppendStringWithImp(str,appendStringIMP,@"[%]");
PSQLA_AppendStringWithImp(str,appendStringIMP,@"[%]");
p = s+1;
}
break;
/*Postgresql doesn't want [_] but want _
case '_':
if (s != p)
GDL2AppendStringWithImp(str,appendStringIMP,
PSQLA_AppendStringWithImp(str,appendStringIMP,
(*stringWithCString_lengthIMP)
(GDL2NSStringClass,GDL2_stringWithCString_lengthSEL,p,s-p));
(PSQLA_NSStringClass,PSQLA_stringWithCString_lengthSEL,p,s-p));
if (s != init && *(s-1) == '[' && *(s+1) == ']')
{
GDL2AppendStringWithImp(str,appendStringIMP,@"_]");
PSQLA_AppendStringWithImp(str,appendStringIMP,@"_]");
p = s+2; p++;
}
else
{
GDL2AppendStringWithImp(str,appendStringIMP,@"[_]");
PSQLA_AppendStringWithImp(str,appendStringIMP,@"[_]");
p = s+1;
}
break;
@ -928,7 +948,7 @@ static IMP NSCalendarDatePostgres95FormatIMP=NULL;
}
if (*p)
GDL2AppendStringWithImp(str,appendStringIMP,[NSString stringWithCString:p]);
PSQLA_AppendStringWithImp(str,appendStringIMP,[NSString stringWithCString:p]);
return str;
}

View file

@ -41,12 +41,6 @@
@class Postgres95Channel;
extern NSString *Postgres95CalendarFormat;
extern Class Postgres95ValuesClass;
extern SEL Postgres95Values_newValueForBytesLengthAttributeSEL;
extern IMP Postgres95Values_newValueForBytesLengthAttributeIMP;
@interface Postgres95Values:NSObject
{
}
@ -74,17 +68,4 @@ extern IMP Postgres95Values_newValueForBytesLengthAttributeIMP;
@end
@interface NSCalendarDate (Postgres95ValueCreation)
+ (void)setPostgres95Format: (NSString *)_format;
+ (NSString *)postgres95Format;
@end
#define Postgres95Values_newValueForBytesLengthAttribute(bytes,length,attribute) \
(*Postgres95Values_newValueForBytesLengthAttributeIMP)(Postgres95ValuesClass, \
Postgres95Values_newValueForBytesLengthAttributeSEL, \
(const void *)(bytes), \
(int)(length), \
(EOAttribute*)(attribute))
#endif /* __Postgres95Values_h__ */

View file

@ -35,7 +35,6 @@
RCS_ID("$Id$")
#ifdef GNUSTEP
#include <Foundation/NSData.h>
#include <Foundation/NSDate.h>
@ -57,25 +56,21 @@ RCS_ID("$Id$")
#include <EOAccess/EOAttribute.h>
#include <EOAccess/EOAttributePriv.h>
#include <EOControl/EONSAddOns.h>
#include <EOControl/EOPriv.h>
#include "Postgres95EOAdaptor/Postgres95Adaptor.h"
#include "Postgres95EOAdaptor/Postgres95Channel.h"
#include "Postgres95EOAdaptor/Postgres95Values.h"
#include "Postgres95Compatibility.h"
#include "Postgres95Private.h"
#include <stdlib.h>
void __postgres95_values_linking_function (void)
{
}
Class Postgres95ValuesClass=Nil;
static SEL postgres95FormatSEL=NULL;
SEL Postgres95Values_newValueForBytesLengthAttributeSEL=NULL;
static IMP GDL2NSCalendarDate_postgres95FormatIMP=NULL;
IMP Postgres95Values_newValueForBytesLengthAttributeIMP=NULL;
static NSStringEncoding LPSQLA_StringDefaultCStringEncoding;
@implementation Postgres95Values
@ -84,19 +79,10 @@ IMP Postgres95Values_newValueForBytesLengthAttributeIMP=NULL;
static BOOL initialized=NO;
if (!initialized)
{
GDL2PrivInit();
PSQLA_PrivInit();
ASSIGN(Postgres95ValuesClass,([Postgres95Values class]));
postgres95FormatSEL=@selector(postgres95Format);
Postgres95Values_newValueForBytesLengthAttributeSEL=@selector(newValueForBytes:length:attribute:);
GDL2NSCalendarDate_postgres95FormatIMP=[GDL2NSCalendarDateClass
methodForSelector:postgres95FormatSEL];
Postgres95Values_newValueForBytesLengthAttributeIMP=[Postgres95ValuesClass
methodForSelector:Postgres95Values_newValueForBytesLengthAttributeSEL];
};
LPSQLA_StringDefaultCStringEncoding = [NSString defaultCStringEncoding];
}
};
+ (id)newValueForBytes: (const void *)bytes
@ -147,9 +133,9 @@ to strlen(bytes)
&& [externalType isEqualToString: @"bool"])
{
if (((char *)bytes)[0] == 't' && ((char *)bytes)[1] == 0)
value=RETAIN(GDL2NSNumberBool_Yes);
value=RETAIN(PSQLA_NSNumberBool_Yes);
else if (((char *)bytes)[0] == 'f' && ((char *)bytes)[1] == 0)
value=RETAIN(GDL2NSNumberBool_No);
value=RETAIN(PSQLA_NSNumberBool_No);
else
NSAssert1(NO,@"Bad boolean: %@",[NSString stringWithCString:bytes
length:length]);
@ -158,12 +144,13 @@ to strlen(bytes)
{
Class valueClass=[attribute _valueClass];
if (valueClass==GDL2NSDecimalNumberClass)
if (valueClass==PSQLA_NSDecimalNumberClass)
{
NSString* str = [GDL2NSString_alloc() initWithCString:bytes
length:length];
//TODO: Optimize without creating NSString instance
NSString* str = [PSQLA_alloc(NSString) initWithCString:bytes
length:length];
value = [GDL2NSDecimalNumber_alloc() initWithString: str];
value = [PSQLA_alloc(NSDecimalNumber) initWithString: str];
RELEASE(str);
}
@ -173,41 +160,41 @@ to strlen(bytes)
switch(valueTypeChar)
{
case 'i':
value = [GDL2NSNumber_alloc() initWithInt: atoi(bytes)];
value = [PSQLA_alloc(NSNumber) initWithInt: atoi(bytes)];
break;
case 'I':
value = [GDL2NSNumber_alloc() initWithUnsignedInt:(unsigned int)atol(bytes)];
value = [PSQLA_alloc(NSNumber) initWithUnsignedInt:(unsigned int)atol(bytes)];
break;
case 'c':
value = [GDL2NSNumber_alloc() initWithChar: atoi(bytes)];
value = [PSQLA_alloc(NSNumber) initWithChar: atoi(bytes)];
break;
case 'C':
value = [GDL2NSNumber_alloc() initWithUnsignedChar: (unsigned char)atoi(bytes)];
value = [PSQLA_alloc(NSNumber) initWithUnsignedChar: (unsigned char)atoi(bytes)];
break;
case 's':
value = [GDL2NSNumber_alloc() initWithShort: (short)atoi(bytes)];
value = [PSQLA_alloc(NSNumber) initWithShort: (short)atoi(bytes)];
break;
case 'S':
value = [GDL2NSNumber_alloc() initWithUnsignedShort: (unsigned short)atoi(bytes)];
value = [PSQLA_alloc(NSNumber) initWithUnsignedShort: (unsigned short)atoi(bytes)];
break;
case 'l':
value = [GDL2NSNumber_alloc() initWithLong: atol(bytes)];
value = [PSQLA_alloc(NSNumber) initWithLong: atol(bytes)];
break;
case 'L':
value = [GDL2NSNumber_alloc() initWithUnsignedLong:strtoul(bytes,NULL,10)];
value = [PSQLA_alloc(NSNumber) initWithUnsignedLong:strtoul(bytes,NULL,10)];
break;
case 'u':
value = [GDL2NSNumber_alloc() initWithLongLong:atoll(bytes)];
value = [PSQLA_alloc(NSNumber) initWithLongLong:atoll(bytes)];
break;
case 'U':
value = [GDL2NSNumber_alloc() initWithUnsignedLongLong:strtoull(bytes,NULL,10)];
value = [PSQLA_alloc(NSNumber) initWithUnsignedLongLong:strtoull(bytes,NULL,10)];
break;
case 'f':
value = [GDL2NSNumber_alloc() initWithFloat: strtof(bytes,NULL)];
value = [PSQLA_alloc(NSNumber) initWithFloat: strtof(bytes,NULL)];
break;
case 'd':
case '\0':
value = [GDL2NSNumber_alloc() initWithDouble: strtod(bytes,NULL)];
value = [PSQLA_alloc(NSNumber) initWithDouble: strtod(bytes,NULL)];
break;
default:
NSAssert2(NO,@"Unknown attribute valueTypeChar: %c for attribute: %@",
@ -228,7 +215,7 @@ For efficiency reasons, the returned value is NOT autoreleased !
{
return [attribute newValueForBytes: bytes
length: length
encoding: GDL2StringDefaultCStringEncoding()];
encoding: LPSQLA_StringDefaultCStringEncoding];
}
/**
@ -266,17 +253,16 @@ For efficiency reasons, the returned value is NOT autoreleased !
attribute: (EOAttribute *)attribute
{
id date=nil;
NSString *str = [GDL2NSString_alloc() initWithCString:(const char *)bytes
length:length];
NSString *format = (*GDL2NSCalendarDate_postgres95FormatIMP)
(GDL2NSCalendarDateClass,postgres95FormatSEL);
NSString *str = [PSQLA_alloc(NSString) initWithCString:(const char *)bytes
length:length];
NSDebugMLLog(@"gsdb",@"str=%@ format=%@",str,format);
NSDebugMLLog(@"gsdb",@"str=%@ format=%@",str,PSQLA_postgresCalendarFormat);
date = [GDL2NSCalendarDate_alloc() initWithString: str
calendarFormat: format];
date = [PSQLA_alloc(NSCalendarDate) initWithString: str
calendarFormat: PSQLA_postgresCalendarFormat];
NSDebugMLLog(@"gsdb",@"str=%@ d=%@ dtz=%@ format=%@",str,date,[date timeZone],format);
NSDebugMLLog(@"gsdb",@"str=%@ d=%@ dtz=%@ format=%@",
str,date,[date timeZone],PSQLA_postgresCalendarFormat);
//We may have some 'invalid' date so it's better to stop here
NSAssert2(date,
@ -373,52 +359,19 @@ if ([type isEqual:@"bytea"])
@end // NSData (Postgres95ValueCreation)
*/
@implementation NSCalendarDate (Postgres95ValueCreation)
/*
- stringValueForPostgres95Type:(NSString*)type
attribute:(EOAttribute*)attribute
{
NSString* externalType = [attribute externalType];
if (!CALENDAR_FORMAT)
[NSCalendarDate setPostgres95Format:[NSString stringWithCString:"%b %d %Y %I:%M%p %Z"]];
if ([externalType isEqualToString:@"abstime"]) {
id tz = [attribute serverTimeZone];
id date;
if (tz) {
date = [[self copy] autorelease];
[date setTimeZone:tz];
}
else
date = self;
return [NSString stringWithFormat:@"'%@'",
[date descriptionWithCalendarFormat:CALENDAR_FORMAT]];
}
THROW([[DataTypeMappingNotSupportedException alloc]
initWithFormat:@"Postgres95 cannot map NSCalendarDate in "
@"attribute %@ to external type %@",
[attribute name], externalType]);
return nil;
}
*/
+ (NSString*)postgres95Format
{
return @"%Y-%m-%d %H:%M:%S%z";
}
+ (void)setPostgres95Format: (NSString*)dateFormat
{
NSLog(@"%@ - is deprecated. The adaptor always uses ISO format.",
NSStringFromSelector(_cmd));
return PSQLA_postgresCalendarFormat;
}
@end // NSCalendarDate (Postgres95ValueCreation)
/*
@implementation EONull (Postgres95ValueCreation)