Skip to Content.
Sympa Menu

freetds - Re: killer query

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: ZIGLIO Frediano <Frediano.Ziglio AT vodafoneomnitel.it>
  • To: "'TDS Development Group'" <freetds AT franklin.metalab.unc.edu>
  • Subject: Re: killer query
  • Date: Thu, 27 Jun 2002 10:47:57 +0200


>
> Frediano,
>
> Bill's code is easy understand, but I have to say I like your version
> better, because it doesn't manhandle the byte ordering.
> Instead of #if, you
> let the compiler do more of the work.
>
> We don't even have to copy src to a TDS_UNIQUE structure.
> That's what my
> friend the pointer is for:
>
.. omissis ...

Considering all comment for unique I written patch #574490
Here it is:

diff -u -r1.16 convert.c
--- convert.c 26 Jun 2002 01:44:27 -0000 1.16
+++ convert.c 27 Jun 2002 08:33:11 -0000
@@ -41,7 +41,7 @@
TDS_DATETIME dt;
TDS_DATETIME4 dt4;
TDS_NUMERIC n;
- TDS_UNIQUE u;
+ TDS_UNIQUE u;
} DBANY;

struct diglist {
@@ -837,28 +837,30 @@
}
return TDS_FAIL;
}
+
tds_convert_unique(int srctype,TDS_CHAR *src, TDS_INT srclen,
int desttype,TDS_CHAR *dest,TDS_INT destlen)
{
-
-TDS_UCHAR buf[16];
DBANY any;
-
- memcpy(buf, src, 16);
+/* Raw data is equivalent to structure and always aligned, so this cast
+ is portable */
+TDS_UNIQUE *u = (TDS_UNIQUE*)src;
+TDS_UCHAR buf[37];

switch(desttype) {
- case SYBCHAR:
- case SYBVARCHAR:
- any.c = malloc(37);
-
sprintf(any.c,"%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%
02X%02X",
- buf[0], buf[1], buf[2], buf[3],
- buf[4], buf[5],
- buf[6], buf[7],
- buf[8], buf[9],
- buf[10], buf[11], buf[12], buf[13], buf[14], buf[15]);
+ case SYBCHAR:
+ case SYBVARCHAR:
+
sprintf(buf,"%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X",
+ (int)u->Data1,(int)u->Data2,(int)u->Data3,
+ u->Data4[0], u->Data4[1],
+ u->Data5[0], u->Data5[1], u->Data5[2],
+ u->Data5[3], u->Data5[4], u->Data5[5]);
+ any.c = buf;
break;
case SYBUNIQUE:
- memcpy (&(any.u), src, sizeof(TDS_UNIQUE));
+ /* Here we can copy raw to structure because we
adjust
+ byte order in tds_swap_datatype */
+ memcpy (&(any.u), src, sizeof(TDS_UNIQUE));
break;
default:
return TDS_FAIL;

freddy77

=================================
"STRICTLY PERSONAL AND CONFIDENTIAL

This message may contain confidential and proprietary material for the sole
use of the intended recipient. Any review or distribution by others is
strictly prohibited. If you are not the intended recipient please contact
the sender and delete all copies.
The contents of this message that do not relate to the official business of
our company shall be understood as neither given nor endorsed by it."

=================================




Archive powered by MHonArc 2.6.24.

Top of Page