freetds AT lists.ibiblio.org
Subject: FreeTDS Development Group
List archive
Re: [freetds] Ongoing work for released version of FreeTDS version0, 64, 0, 6182
- From: Frediano Ziglio <freddy77 AT gmail.com>
- To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
- Subject: Re: [freetds] Ongoing work for released version of FreeTDS version0, 64, 0, 6182
- Date: Fri, 18 Jan 2008 22:07:15 +0100
> [snip]
> > diff -ub ./convert_tds2sql.c new/convert_tds2sql.c
> > --- ./convert_tds2sql.c 2006-02-24 22:14:24.000000000 +0100
> > +++ new/convert_tds2sql.c 2008-01-16 09:40:37.938249787 +0100
> > @@ -54,6 +54,9 @@
> > DATE_STRUCT *dsp;
> > TIME_STRUCT *tsp;
> > TIMESTAMP_STRUCT *tssp;
> > +
> > + TIMESTAMP_STRUCT ts;
> > +
> > SQL_NUMERIC_STRUCT *num;
> >
> > int ret = TDS_FAIL;
> > @@ -140,11 +143,11 @@
> >
> > tds_datecrack(SYBDATETIME, &(ores.dt), &dr);
> >
> > - dsp = (DATE_STRUCT *) dest;
> > + ts.year = dr.year;
> > + ts.month = dr.month + 1;
> > + ts.day = dr.day;
> >
> > - dsp->year = dr.year;
> > - dsp->month = dr.month + 1;
> > - dsp->day = dr.day;
> > + memcpy(dest, &ts, sizeof(DATE_STRUCT));
> >
> > ret = sizeof(DATE_STRUCT);
> > break;
> > @@ -157,11 +160,11 @@
> >
> > tds_datecrack(SYBDATETIME, &(ores.dt), &dr);
> >
> > - tsp = (TIME_STRUCT *) dest;
> > + ts.hour = dr.hour;
> > + ts.minute = dr.minute;
> > + ts.second = dr.second;
> >
> > - tsp->hour = dr.hour;
> > - tsp->minute = dr.minute;
> > - tsp->second = dr.second;
> > + memcpy(dest, &ts, sizeof(TIME_STRUCT));
> >
> > ret = sizeof(TIME_STRUCT);
> > break;
> > @@ -174,15 +177,15 @@
> >
> > tds_datecrack(SYBDATETIME, &(ores.dt), &dr);
> >
> > - tssp = (TIMESTAMP_STRUCT *) dest;
> > + ts.year = dr.year;
> > + ts.month = dr.month + 1;
> > + ts.day = dr.day;
> > + ts.hour = dr.hour;
> > + ts.minute = dr.minute;
> > + ts.second = dr.second;
> > + ts.fraction = dr.millisecond * 1000000u;
> >
> > - tssp->year = dr.year;
> > - tssp->month = dr.month + 1;
> > - tssp->day = dr.day;
> > - tssp->hour = dr.hour;
> > - tssp->minute = dr.minute;
> > - tssp->second = dr.second;
> > - tssp->fraction = dr.millisecond * 1000000u;
> > + memcpy(dest, &ts, sizeof(TIMESTAMP_STRUCT));
> >
> > ret = sizeof(TIMESTAMP_STRUCT);
> > break;
> > @@ -190,7 +193,7 @@
> > #ifdef SQL_C_SBIGINT
> > case SQL_C_SBIGINT:
> > case SQL_C_UBIGINT:
> > - *((TDS_INT8 *) dest) = ores.bi;
> > + memcpy(dest, &ores, sizeof(TDS_INT8));
> > ret = sizeof(TDS_INT8);
> > break;
> > #endif
> > @@ -198,14 +201,14 @@
> > case SQL_C_LONG:
> > case SQL_C_SLONG:
> > case SQL_C_ULONG:
> > - *((TDS_INT *) dest) = ores.i;
> > + memcpy(dest, &ores, sizeof(TDS_INT));
> > ret = sizeof(TDS_INT);
> > break;
> >
> > case SQL_C_SHORT:
> > case SQL_C_SSHORT:
> > case SQL_C_USHORT:
> > - *((TDS_SMALLINT *) dest) = ores.si;
> > + memcpy(dest, &ores, sizeof(TDS_SMALLINT));
> > ret = sizeof(TDS_SMALLINT);
> > break;
> >
> > @@ -218,12 +221,12 @@
> > break;
> >
> > case SQL_C_DOUBLE:
> > - *((TDS_FLOAT *) dest) = ores.f;
> > + memcpy(dest, &ores, sizeof(TDS_FLOAT));
> > ret = sizeof(TDS_FLOAT);
> > break;
> >
> > case SQL_C_FLOAT:
> > - *((TDS_REAL *) dest) = ores.r;
> > + memcpy(dest, &ores, sizeof(TDS_REAL));
> > ret = sizeof(TDS_REAL);
> > break;
> >
> >
> >
> > This code only fixes unaligned binded data. Binded data should be
> > aligned so I don't think should be merged. Also code for TIME_STRUCT
> > introduce a read of uninitialized data, I don't think is what you
> > wanted.
>
> There are no guarantees on the addresses alignments that clients want to
> bind to.
>
> Consider:
> The client creates a memory buffer with the following properties:
> For every field there is a leading character which will be 1 if the
> field is null and zero if the field is not null. Every field will also
> be stored in the memory buffer using its exact width. Now, suppose that
> the first field in the result set is a single character. Then the next
> field will start at offset 3. For many CPUs, this will cause a bus
> error if the succeeding data is simply assigned to a pointer that wants
> alignment to a type and the type does not support character alignment.
>
> The reason that we made the changes above is that we *were* getting bus
> errors in running some of our regression tests on some platforms.
>
Mmmm... from msdn (linked from SQLBindCol reference)
http://msdn2.microsoft.com/en-us/library/ms709306(VS.85).aspx
So data should be aligned by program. It's also true that we don't live
in a perfect world so if you tested that others drivers works in all
cases it's worth to write such a workaround. Personally I currently
don't have a test environment like this.
freddy77
-
Re: [freetds] Ongoing work for released version of FreeTDS version 0, 64, 0, 6182,
ZIGLIO, Frediano, VF-IT, 01/16/2008
-
Re: [freetds] Ongoing work for released version of FreeTDS version0, 64, 0, 6182,
Dann Corbit, 01/16/2008
- Re: [freetds] Ongoing work for released version of FreeTDS version0, 64, 0, 6182, Dann Corbit, 01/16/2008
-
Message not available
- Re: [freetds] Ongoing work for released version of FreeTDS version0, 64, 0, 6182, ZIGLIO, Frediano, VF-IT, 01/18/2008
-
Re: [freetds] Ongoing work for released version of FreeTDS version0, 64, 0, 6182,
Dann Corbit, 01/16/2008
-
Re: [freetds] Ongoing work for released version of FreeTDS version0, 64, 0, 6182,
Dann Corbit, 01/18/2008
-
Re: [freetds] Ongoing work for released version of FreeTDS version0, 64, 0, 6182,
Frediano Ziglio, 01/18/2008
- Re: [freetds] Ongoing work for released version of FreeTDS version0, 64, 0, 6182, Dann Corbit, 01/18/2008
-
[freetds] Optimizing memory allocation when using dynamic SQL,
Sebastien FLAESCH, 01/19/2008
-
Re: [freetds] Optimizing memory allocation when using dynamic SQL,
ZIGLIO, Frediano, VF-IT, 01/21/2008
- Re: [freetds] Optimizing memory allocation when using dynamic SQL, Sebastien FLAESCH, 01/21/2008
-
Re: [freetds] Optimizing memory allocation when using dynamic SQL,
ZIGLIO, Frediano, VF-IT, 01/21/2008
-
Re: [freetds] Ongoing work for released version of FreeTDS version0, 64, 0, 6182,
Frediano Ziglio, 01/18/2008
Archive powered by MHonArc 2.6.24.