Skip to Content.
Sympa Menu

freetds - Re: [freetds] db-lib: support for new MS SQL 2008 data types - part 2

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: LacaK <lacak AT zoznam.sk>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] db-lib: support for new MS SQL 2008 data types - part 2
  • Date: Fri, 11 Apr 2014 09:54:49 +0200

Frediano Ziglio wrote / napĂ­sal(a):
2014-04-04 11:00 GMT+01:00 LacaK <lacak AT zoznam.sk>:
Now I can read successfuly:
- dbcoltype() returning SYBMSDATE, SYBMSTIME, SYBMSDATETIME2

I am trying do next small step.
As far as I understand dbdata() function for SYBMSDATE, SYBMSTIME,
SYBMSDATETIME2 return pointer to TDS_DATETIMEALL struct.
(dbdata() internally uses: return (BYTE *) colinfo->column_data)


Well.... dbdata returns any possible column_data stored. This does not
exactly means that is correct for these types. All other types are
coded as wire data while these type use an internal encoding defined
by our library.

If it is so I need some way how to convert TDS_DATETIMEALL struct to
DBDATEREC struct.
(which is good readable)

There is already function:
dbdatecrack(DBPROCESS * dbproc, DBDATEREC * output, DBDATETIME * datetime)
but it takes as 3rd parameter DBDATETIME struct, which is struct used by old
"datetime" data type SYBDATETIME)

So my idea is introduce new API function:
tdsdbdatecrack(DBPROCESS * dbproc, INT datetype, DBDATEREC * output, const
void *datetime)
(like we have tdsdbopen() vs dbopen())
Where datetime can be pointer to either old DBDATETIME or new
TDS_DATETIMEALL, depending on datetype supplied


Could work. You can use tds_datecrack to help you.

What is your opinion on that?
I am asking for sure about every step, because I am not so familiar with
internals.

Thanks
-Laco.


Here the problem is not internals but dblib. There is no definition on
how to extend this library. There's also a problem on the precision of
DBDATEREC which do not take into account fraction of seconds beside
milliseconds
For now I have realized that I do not need conversion from TDS_DATETIMEALL to DBDATEREC.
I can easy parse TDS_DATETIMEALL and convert it direct to FreePascal TDateTime data type, which is my destination type.

I attach small patches for
- src/dblib/dblib.c: "Adjust dbconvert() to support SYBMSDATE, SYBMSTIME, SYBMSDATETIME2, SYBMSDATETIMEOFFSET data types"
- src/tds/token.c: "add data type name for SYBMSXML, SYBMSDATETIMEOFFSET to tds_prtype()"

Thanks
-Laco.

--- dblib.c.ori Thu Apr 03 13:39:42 2014
+++ dblib.c Fri Apr 11 09:41:32 2014
@@ -2325,6 +2325,14 @@ dbconvert(DBPROCESS * dbproc, int srctyp
memcpy(dest, src, ret);
break;

+ case SYBMSDATE:
+ case SYBMSTIME:
+ case SYBMSDATETIME2:
+ case SYBMSDATETIMEOFFSET:
+ ret = sizeof(TDS_DATETIMEALL);
+ memcpy(dest, src, ret);
+ break;
+
default:
ret = -1;
break;
@@ -2447,6 +2455,13 @@ dbconvert(DBPROCESS * dbproc, int srctyp
memcpy(dest, &(dres.u), sizeof(TDS_UNIQUE));
ret = sizeof(TDS_UNIQUE);
break;
+ case SYBMSDATE:
+ case SYBMSTIME:
+ case SYBMSDATETIME2:
+ case SYBMSDATETIMEOFFSET:
+ memcpy(dest, &(dres.dta), sizeof(TDS_DATETIMEALL));
+ ret = sizeof(TDS_DATETIMEALL);
+ break;
case SYBCHAR:
case SYBVARCHAR:
case SYBTEXT:
@@ -7166,6 +7181,11 @@ tds_prdatatype(TDS_SERVER_TYPE datatype_
case SYBUINT8: return "SYBUINT8";
case SYBUNIQUE: return "SYBUNIQUE";
case SYBVARIANT: return "SYBVARIANT";
+ case SYBMSXML: return "SYBMSXML";
+ case SYBMSDATE: return "SYBMSDATE";
+ case SYBMSTIME: return "SYBMSTIME";
+ case SYBMSDATETIME2: return "SYBMSDATETIME2";
+ case SYBMSDATETIMEOFFSET: return "SYBMSDATETIMEOFFSET";
default: break;
}
return "(unknown)";
--- token.c.ori Thu Apr 03 11:04:48 2014
+++ token.c Wed Apr 09 07:55:34 2014
@@ -3014,9 +3014,11 @@ tds_prtype(int type)
TYPE(XSYBNVARCHAR, "x UCS-2 varchar");
TYPE(XSYBVARBINARY, "xvarbinary");
TYPE(XSYBVARCHAR, "xvarchar");
+ TYPE(SYBMSXML, "xml");
TYPE(SYBMSDATE, "date");
TYPE(SYBMSTIME, "time");
TYPE(SYBMSDATETIME2, "datetime2");
+ TYPE(SYBMSDATETIMEOFFSET, "datetimeoffset");
default:
break;
}



Archive powered by MHonArc 2.6.24.

Top of Page