Firebird Time and TimeStamp changes

Forum related to version 6.5.1 (alpha) and 6.6.x (beta) of ZeosLib's DBOs

Moderators: gto, cipto_kh, EgonHugeist

kellwin
Fresh Boarder
Fresh Boarder
Posts: 2
Joined: 16.10.2006, 07:34

Firebird Time and TimeStamp changes

Postby kellwin » 16.10.2006, 07:50

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

User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Postby mdaems » 16.10.2006, 08:07

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

papelhigienico
Expert Boarder
Expert Boarder
Posts: 113
Joined: 06.10.2006, 14:41
Location: Chapecó - Santa Catarina
Contact:

Postby papelhigienico » 08.10.2011, 14:10

Old post... I'm searching a way to support milliseconds...

papelhigienico
Expert Boarder
Expert Boarder
Posts: 113
Joined: 06.10.2006, 14:41
Location: Chapecó - Santa Catarina
Contact:

Postby papelhigienico » 08.10.2011, 14:20

The milliseconds separator is always '.' (dot)?

seawolf
Zeos Dev Team *
Zeos Dev Team *
Posts: 385
Joined: 04.06.2008, 19:50
Contact:

Postby seawolf » 08.10.2011, 17:45

Have you considered something like this?

User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Postby mdaems » 08.10.2011, 20:56

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
Image

papelhigienico
Expert Boarder
Expert Boarder
Posts: 113
Joined: 06.10.2006, 14:41
Location: Chapecó - Santa Catarina
Contact:

Postby papelhigienico » 08.10.2011, 21:13

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.

papelhigienico
Expert Boarder
Expert Boarder
Posts: 113
Joined: 06.10.2006, 14:41
Location: Chapecó - Santa Catarina
Contact:

Postby papelhigienico » 08.10.2011, 21:32

I'll check this format on MySQL 5.0. Can somebody check this format on others database systems?


Return to “6.5.1 (alpha) - 6.6.x (beta)”

Who is online

Users browsing this forum: No registered users and 1 guest