Page 1 of 1

Firebird Time and TimeStamp changes

Posted: 16.10.2006, 07:50
by kellwin
To now Interbase6/Firebird driver didn't support milliseconds in time
fields due to limitation in isc_decode_date function.
I propose to change the code in GetTimestamp from

Code: Select all

function TZResultSQLDA.GetTimestamp(const Index: Integer): TDateTime;
........
        SQL_TIMESTAMP : begin
                          FPlainDriver.isc_decode_date(PISC_QUAD(sqldata), @TempDate);
                          Result := SysUtils.EncodeDate(TempDate.tm_year + 1900,
                            TempDate.tm_mon + 1, TempDate.tm_mday) + EncodeTime(TempDate.tm_hour,
                            TempDate.tm_min, TempDate.tm_sec, 0);
                        end;
        SQL_TYPE_DATE : begin
                          FPlainDriver.isc_decode_sql_date(PISC_DATE(sqldata), @TempDate);
                          Result := SysUtils.EncodeDate(Word(TempDate.tm_year + 1900),
                            Word(TempDate.tm_mon + 1), Word(TempDate.tm_mday));
                        end;
        SQL_TYPE_TIME : begin
                          FPlainDriver.isc_decode_sql_time(PISC_TIME(sqldata), @TempDate);
                          Result := SysUtils.EncodeTime(Word(TempDate.tm_hour), Word(TempDate.tm_min),
                            Word(TempDate.tm_sec), 0);
                        end;
to

Code: Select all

const ISC_TIME_SECONDS_PRECISION=10000;
      TimeDivisor=24*60*60*ISC_TIME_SECONDS_PRECISION;
      DateDelta=15018;// days between 17.11.1858 and 31.12.1899
........
function TZResultSQLDA.GetTimestamp(const Index: Integer): TDateTime;
........
        SQL_TIMESTAMP : begin
          With PISC_QUAD(sqldata)^ do
            Result:=gds_quad_low/TimeDivisor+gds_quad_high-DateDelta;
                        end;
        SQL_TYPE_DATE : begin
          Result:=PISC_DATE(sqldata)^-DateDelta;
                        end;
        SQL_TYPE_TIME : begin
          Result:=PISC_TIME(sqldata)^/TimeDivisor;
                        end;
Looks like it will also work a bit faster.
Thanks

Posted: 16.10.2006, 08:07
by mdaems
Which compiler(s) did you test this on? Is behaviour the same for Lazarus and Delphi?
Can somebody confirm if it works on all compilers?

Mark

Posted: 08.10.2011, 14:10
by papelhigienico
Old post... I'm searching a way to support milliseconds...

Posted: 08.10.2011, 14:20
by papelhigienico
The milliseconds separator is always '.' (dot)?

Posted: 08.10.2011, 17:45
by seawolf
Have you considered something like this?

Posted: 08.10.2011, 20:56
by mdaems
seawolf,

What about the patch proposed above? Would it help retrieving millisecond data from firebird into a timestamp field? Or are those milliseconds already retrieved correctly?

I did change the code this way today and it did not break existing tests, but I have no idea how I should write a test suite test (for firebird dbc layer tests) to check if a millisecond value is retrieved correctly from the database.
No idea if inserting milliseconds works correctly either.

Mark

Posted: 08.10.2011, 21:13
by papelhigienico
I'm doing a fix that I think that will work with all database layers. I know that at least pg and sqlite works with format hh:nn:ss.zzz

If more DB systems works with this format, better :) Changes made, I'm running tests now.

Posted: 08.10.2011, 21:32
by papelhigienico
I'll check this format on MySQL 5.0. Can somebody check this format on others database systems?