[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: GDL2, postgres adaptor issues.
From: |
David Ayers |
Subject: |
Re: GDL2, postgres adaptor issues. |
Date: |
Fri, 07 May 2004 19:32:14 +0200 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.6) Gecko/20040113 |
Simon Stapleton wrote:
Next up, data types expect bpchar as their external type. This causes
me a problem, as I was needing bytea, which would seem to me to be the
most logical choice anyway. I have a hacky fix (again), but I propose a
better solution, as follows:
Postgres95Channel should check for binary types and use
PQunescapeBytea() to unescape the data before creating the attributes
(round about line 400, in -fetchRowWithZone:), and should use
PQescapeBytea() in -insertRow:ForEntity: and
updateValues:inRowDescribedByQualifier:entity: whenever we're writing
out bytea data.
An added bonus to this is that we could avoid the large object interface
entirely (although that might be needed when people are adding really
large objects to tables)
Here's my hacky fix which seems to work so far (although, it has to be
said, I haven't been thrashing it yet)
thoughts?
Well so far, I've converted it to the attached patch. Yet seems like
PGunescapeBytea and PGfreemem didn't show up until 7.3 some time. I'm
currently still using 7.2.3 so I can't test it.
Now I'm leaning toward some ./configury magic which would drop in the
needed functions (ie make them part of the Adaptor) But I'd like to
know what Versions of PSQL others are using.
Cheers,
David
PS: And that date format issue is also on my TODO list. We need to
query the connection to get the right format, yet we don't have access
to an EOAdaptorChannel when we need to convert it. But I guess we could
set a global state. It would break with two differently configured
connections but I guess that's not really worth the trouble.
Index: EOAdaptors/Postgres95/Postgres95Adaptor.m
===================================================================
RCS file:
/cvsroot/gnustep/gnustep/dev-libs/gdl2/EOAdaptors/Postgres95/Postgres95Adaptor.m,v
retrieving revision 1.18
diff -u -r1.18 Postgres95Adaptor.m
--- EOAdaptors/Postgres95/Postgres95Adaptor.m 17 Apr 2004 12:41:32 -0000
1.18
+++ EOAdaptors/Postgres95/Postgres95Adaptor.m 7 May 2004 17:27:50 -0000
@@ -178,14 +178,16 @@
*/
static NSString *externalTypeNames[] = {
#warning (stephane@sente.ch) Needs to be updated!!!
- @"numeric", @"varchar", @"bpchar", @"date",
+ @"numeric", @"varchar", @"bytea", @"date",
@"boolean", @"bool",
@"char", @"char2", @"char4", @"char8", @"char16", @"filename",
@"reltime", @"time", @"tinterval", @"abstime", @"timestamp",
@"real", @"double precision", @"float4", @"float8",
@"bigint", @"int8", @"int4", @"int2",
@"oid", @"oid8", @"oidint2", @"oidint4", @"oidchar16",
- @"decimal", @"cid", @"tid", @"xid",
+ @"decimal", @"cid",
+ @"tid", @"xid",
+ @"bpchar",
nil
};
@@ -197,7 +199,9 @@
@"NSNumber", @"NSNumber", @"NSNumber", @"NSNumber",
@"NSNumber", @"NSNumber", @"NSNumber", @"NSNumber",
@"NSNumber", @"NSNumber", @"NSNumber", @"NSNumber", @"NSNumber",
- @"NSDecimalNumber", @"NSDecimalNumber", @"NSDecimalNumber",
@"NSDecimalNumber",
+ @"NSDecimalNumber", @"NSDecimalNumber",
+ @"NSDecimalNumber", @"NSDecimalNumber",
+ @"NSData",
nil
};
Index: EOAdaptors/Postgres95/Postgres95SQLExpression.m
===================================================================
RCS file:
/cvsroot/gnustep/gnustep/dev-libs/gdl2/EOAdaptors/Postgres95/Postgres95SQLExpression.m,v
retrieving revision 1.18
diff -u -r1.18 Postgres95SQLExpression.m
--- EOAdaptors/Postgres95/Postgres95SQLExpression.m 29 Mar 2004 14:40:15
-0000 1.18
+++ EOAdaptors/Postgres95/Postgres95SQLExpression.m 7 May 2004 17:27:50
-0000
@@ -213,6 +213,22 @@
else
formatted = [NSString stringWithFormat: @"'%@'",value];
}
+ else if ([externalType isEqualToString: @"bytea"])
+ {
+ size_t newLength;
+ unsigned char *escapedString;
+
+ EOFLOGObjectLevelArgs(@"EOSQLExpression",
+ @"bytea case - value=%@ class=%@",
+ value, [value class]);
+ escapedString = PQescapeBytea ([value bytes],
+ [value length],
+ &newLength);
+
+ formatted = AUTORELEASE([[NSString alloc] initWithCString: escapedString
+ length: newLength
+ freeWhenDone: YES]);
+ }
else
{
int length = 0;
Index: EOAdaptors/Postgres95/Postgres95Values.m
===================================================================
RCS file:
/cvsroot/gnustep/gnustep/dev-libs/gdl2/EOAdaptors/Postgres95/Postgres95Values.m,v
retrieving revision 1.13
diff -u -r1.13 Postgres95Values.m
--- EOAdaptors/Postgres95/Postgres95Values.m 19 Mar 2004 16:41:19 -0000
1.13
+++ EOAdaptors/Postgres95/Postgres95Values.m 7 May 2004 17:27:50 -0000
@@ -170,8 +170,23 @@
length: (int)length
attribute: (EOAttribute *)attribute
{
- return [attribute newValueForBytes: bytes
- length: length];
+ size_t newLength = length;
+ unsigned char *decodedBytes = 0;
+ id data;
+
+ if ([[attribute externalType] isEqualToString: @"bytea"])
+ {
+ decodedBytes = PQunescapeBytea(bytes, &newLength);
+ bytes = decodedBytes;
+ }
+
+ data = [attribute newValueForBytes: bytes
+ length: newLength];
+ if (decodedBytes)
+ {
+ PQfreemem (decodedBytes);
+ }
+ return data;
}