SQL Server Date field and NetworkLibrary

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
JimMellish
Posts: 8
Joined: Wed 06 Mar 2013 21:48

SQL Server Date field and NetworkLibrary

Post by JimMellish » Sat 01 Nov 2014 17:23

I have a program with the following code:

UniQuery.SQL.Text := 'select * from Test';
UniQuery.Open;
for i := 0 to UniQuery.FieldCount - 1 do
Memo.Lines.Add (IntToStr(i) + ' ' +
UniQuery.Fields.FieldName + ' ' +
GetEnumName(TypeInfo(TFieldType),Ord(UniQuery.Fields.DataType)));

With NetworkLibrary set to prNativeClient (or prAuto) I get the following result:

0 IntColumn ftInteger
1 VarCharColumn ftString
2 DateTimeColumn ftDateTime
3 SmallDateTimeColumn ftDateTime
4 DateColumn ftDate

With NetworkLibrary set to prSQL I get the following result:

0 IntColumn ftInteger
1 VarCharColumn ftString
2 DateTimeColumn ftDateTime
3 SmallDateTimeColumn ftDateTime
4 DateColumn ftWideString

The date column has changed from ftDate to ftWideString. Is this a bug (or feature !) in the Microsoft libraries and if so is there a work around ?

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: SQL Server Date field and NetworkLibrary

Post by azyk » Mon 03 Nov 2014 10:00

The point is that the standard OLEDB provider processes date fields as string fields. If you need to map the date data type to ftDdate, you can use Data Type Mapping. For example, in the dataset before opening it:

Code: Select all

UniQuery.DataTypeMap.AddFieldNameRule('DateColumn', ftDate);
More details about Data Type Mapping can be found in our documentation: http://www.devart.com/unidac/docs/index ... apping.htm .

JimMellish
Posts: 8
Joined: Wed 06 Mar 2013 21:48

Re: SQL Server Date field and NetworkLibrary

Post by JimMellish » Tue 04 Nov 2014 09:40

I think we will have to insist that NativeClient is used. We have too many queries, with some of them being generated automatically, to apply data type mapping to every query with a date in its result set.

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: SQL Server Date field and NetworkLibrary

Post by AlexP » Wed 05 Nov 2014 07:44

Yes, in your case, it is better to use NativeClien.

Post Reply