Recent

Author Topic: TMSSQLConnection + SQL Server  (Read 15105 times)

eny

  • Hero Member
  • *****
  • Posts: 1634
Re: TMSSQLConnection + SQL Server
« Reply #15 on: July 24, 2016, 10:49:18 pm »
AsString is a data exchange function and should report dtm values in a consistent format and not use spurious locale settings.
TDateTieField.AsString returns its value formated using FormatDateTime() function, which uses ShortDateFormat and LongTimeFormat global variables for formating. It is so from begining (also in Delphi) and it won't be changed

Here you should use AsDateTime always.
If it would work that would be great.
But it does not.
It does not work, because in 1st case you have datetime value stored in TStringField and using AsDateTime raises exception , because FPC is trying convert string representation using locale settings to TDateTime representation.

There is no wrong on FPC side, but these two ODBC drivers are just incompatible.
So if you want support both drivers with your application with DATETIME2 columns, you must handle it separately on your application side ...
Ah sorry there seems to be a misunderstanding.
I'll try to be more clear: the existence of this bug is not open for debate!
It is a quite serious bug that is very difficult to find a workaround for. The way the ODBC component handles datetime(2) fields is sloppy at best. Hence my warning for TS.
If one does not use the datetime2 SQL Server data type at all or not do mass updates with the default 'SQL Server' driver, the problem will most likely not present itself.
All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

LacaK

  • Hero Member
  • *****
  • Posts: 691
Re: TMSSQLConnection + SQL Server
« Reply #16 on: July 25, 2016, 07:58:23 am »
If it is bug, then it is bug of ODBC driver.
What should FPC do if ODBC driver reports, that column is VARCHAR type ... simply create TStringField ...

As a workaround you can define type helper for TField f.e. something like this:

type
 TFieldHelper = class helper for TField
   function GetAsDateTime2: TDateTime;
 end;

function TFieldHelper.GetAsDateTime2: TDateTime;
begin
  if Self.DataType = ftString then
   Result := StrToDateTime(Self.AsDateTime, DefaultSQLFormatSettings);
  else
   Result := Self.AsDateTime;

httpal

  • New Member
  • *
  • Posts: 14
Re: TMSSQLConnection + SQL Server
« Reply #17 on: August 11, 2016, 04:20:38 pm »
Tell me, please, who is the author of TMSSQLConnection component?

Thanks!!!
« Last Edit: August 11, 2016, 04:22:41 pm by httpal »

LacaK

  • Hero Member
  • *****
  • Posts: 691
Re: TMSSQLConnection + SQL Server
« Reply #18 on: August 12, 2016, 07:16:11 am »
It is stated in the begining of source file ...

 

TinyPortal © 2005-2018