Discussion:
[freetds] db-lib: support for new MS SQL 2008 data types
LacaK
2014-04-03 11:48:28 UTC
Permalink
Hi,
I start with first, very small, steps to add support for DATE, TIME and
DATETIME2 data types to db-lib.
I attach patches for:
- src/dblib/dblib.c
- src/tds/token.c
let me please know if you can accept (and commit) them.
Then I will try do further steps.
Thanks
-Laco.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: token.c.diff
URL: <http://lists.ibiblio.org/pipermail/freetds/attachments/20140403/5eb25bcf/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: dblib.c.diff
URL: <http://lists.ibiblio.org/pipermail/freetds/attachments/20140403/5eb25bcf/attachment-0001.ksh>
Frediano Ziglio
2014-04-03 21:16:59 UTC
Permalink
Post by LacaK
Hi,
I start with first, very small, steps to add support for DATE, TIME and
DATETIME2 data types to db-lib.
- src/dblib/dblib.c
- src/tds/token.c
let me please know if you can accept (and commit) them.
Then I will try do further steps.
Thanks
-Laco.
--- token.c.ori Thu Apr 03 13:32:02 2014
+++ token.c Thu Apr 03 11:04:48 2014
@@ -3016,6 +3016,7 @@ tds_prtype(int type)
TYPE(XSYBVARCHAR, "xvarchar");
TYPE(SYBMSDATE, "date");
TYPE(SYBMSTIME, "time");
+ TYPE(SYBMSDATETIME2, "datetime2");
break;
}
--- dblib.c.ori Mon Mar 31 22:34:14 2014
+++ dblib.c Thu Apr 03 13:39:42 2014
@@ -224,6 +224,9 @@ DBVERSION_71;
#ifdef TDS72
DBVERSION_72;
#endif
+#ifdef TDS73
+DBVERSION_73;
+#endif
static int
@@ -942,6 +945,9 @@ dbsetlversion (LOGINREC * login, BYTE ve
tds_set_version(login->tds_login, 7, 2);
return SUCCEED;
+ tds_set_version(login->tds_login, 7, 3);
+ return SUCCEED;
}
return FAIL;
@@ -5761,7 +5767,9 @@ dbsetversion(DBINT version)
g_dblib_version = version;
return SUCCEED;
Looks ok and compile correctly. I actually launched some tests. Can
you add just a comment for the commit. I'll commit with your name.
Which name/mail address do you want in the commit, Something like
"Name Surname" <yourmail at domain>

Frediano
LacaK
2014-04-04 06:54:54 UTC
Permalink
Post by Frediano Ziglio
Post by LacaK
Hi,
I start with first, very small, steps to add support for DATE, TIME and
DATETIME2 data types to db-lib.
- src/dblib/dblib.c
- src/tds/token.c
let me please know if you can accept (and commit) them.
Then I will try do further steps.
Thanks
-Laco.
--- token.c.ori Thu Apr 03 13:32:02 2014
+++ token.c Thu Apr 03 11:04:48 2014
@@ -3016,6 +3016,7 @@ tds_prtype(int type)
TYPE(XSYBVARCHAR, "xvarchar");
TYPE(SYBMSDATE, "date");
TYPE(SYBMSTIME, "time");
+ TYPE(SYBMSDATETIME2, "datetime2");
break;
}
--- dblib.c.ori Mon Mar 31 22:34:14 2014
+++ dblib.c Thu Apr 03 13:39:42 2014
@@ -224,6 +224,9 @@ DBVERSION_71;
#ifdef TDS72
DBVERSION_72;
#endif
+#ifdef TDS73
+DBVERSION_73;
+#endif
static int
@@ -942,6 +945,9 @@ dbsetlversion (LOGINREC * login, BYTE ve
tds_set_version(login->tds_login, 7, 2);
return SUCCEED;
+ tds_set_version(login->tds_login, 7, 3);
+ return SUCCEED;
}
return FAIL;
@@ -5761,7 +5767,9 @@ dbsetversion(DBINT version)
g_dblib_version = version;
return SUCCEED;
Looks ok and compile correctly. I actually launched some tests. Can
you add just a comment for the commit.
May be:
- for db-lib.c: "add support for TDS 7.3 to db-lib dbsetversion() and
dbsetlversion() functions"
- for token.c: "add data type name for SYBMSDATETIME2 to tds_prtype()"
Post by Frediano Ziglio
I'll commit with your name.
Which name/mail address do you want in the commit, Something like
"Name Surname" <yourmail at domain>
You can use my nick-name (already used in commit from past) Lacak
<lacak at zoznam.sk>
or my full name is: Ladislav Karrach

Thanks
-Laco.
Frediano Ziglio
2014-04-04 08:06:45 UTC
Permalink
Post by LacaK
Post by Frediano Ziglio
Post by LacaK
Hi,
I start with first, very small, steps to add support for DATE, TIME and
DATETIME2 data types to db-lib.
- src/dblib/dblib.c
- src/tds/token.c
let me please know if you can accept (and commit) them.
Then I will try do further steps.
Thanks
-Laco.
--- token.c.ori Thu Apr 03 13:32:02 2014
+++ token.c Thu Apr 03 11:04:48 2014
@@ -3016,6 +3016,7 @@ tds_prtype(int type)
TYPE(XSYBVARCHAR, "xvarchar");
TYPE(SYBMSDATE, "date");
TYPE(SYBMSTIME, "time");
+ TYPE(SYBMSDATETIME2, "datetime2");
break;
}
--- dblib.c.ori Mon Mar 31 22:34:14 2014
+++ dblib.c Thu Apr 03 13:39:42 2014
@@ -224,6 +224,9 @@ DBVERSION_71;
#ifdef TDS72
DBVERSION_72;
#endif
+#ifdef TDS73
+DBVERSION_73;
+#endif
static int
@@ -942,6 +945,9 @@ dbsetlversion (LOGINREC * login, BYTE ve
tds_set_version(login->tds_login, 7, 2);
return SUCCEED;
+ tds_set_version(login->tds_login, 7, 3);
+ return SUCCEED;
}
return FAIL;
@@ -5761,7 +5767,9 @@ dbsetversion(DBINT version)
g_dblib_version = version;
return SUCCEED;
Looks ok and compile correctly. I actually launched some tests. Can
you add just a comment for the commit.
- for db-lib.c: "add support for TDS 7.3 to db-lib dbsetversion() and
dbsetlversion() functions"
- for token.c: "add data type name for SYBMSDATETIME2 to tds_prtype()"
Post by Frediano Ziglio
I'll commit with your name.
Which name/mail address do you want in the commit, Something like
"Name Surname" <yourmail at domain>
You can use my nick-name (already used in commit from past) Lacak
<lacak at zoznam.sk>
or my full name is: Ladislav Karrach
Thanks
-Laco.
Committed

Frediano
LacaK
2014-04-04 10:00:16 UTC
Permalink
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)

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

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

Thanks
-Laco.
Frediano Ziglio
2014-04-05 16:25:24 UTC
Permalink
Post by LacaK
- 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.
Post by LacaK
If it is so I need some way how to convert TDS_DATETIMEALL struct to
DBDATEREC struct.
(which is good readable)
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)
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.
Post by LacaK
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

Frediano
LacaK
2014-04-11 07:54:49 UTC
Permalink
Post by Frediano Ziglio
Post by LacaK
- 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.
Post by LacaK
If it is so I need some way how to convert TDS_DATETIMEALL struct to
DBDATEREC struct.
(which is good readable)
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)
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.
Post by LacaK
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.

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: dblib.c.diff
URL: <http://lists.ibiblio.org/pipermail/freetds/attachments/20140411/bbd37071/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: token.c.diff
URL: <http://lists.ibiblio.org/pipermail/freetds/attachments/20140411/bbd37071/attachment-0001.ksh>
Loading...