Browse Source

+ fix bug #7260: timestamp fields in integer_datetimes mode

git-svn-id: trunk@4485 -
joost 19 years ago
parent
commit
96ea6d18fb
1 changed files with 4 additions and 0 deletions
  1. 4 0
      fcl/db/sqldb/postgres/pqconnection.pp

+ 4 - 0
fcl/db/sqldb/postgres/pqconnection.pp

@@ -37,6 +37,7 @@ type
     FCursorCount         : word;
     FConnectString       : string;
     FSQLDatabaseHandle   : pointer;
+    FIntegerDateTimes    : boolean;
     function TranslateFldType(Type_Oid : integer) : TFieldType;
   protected
     procedure DoInternalConnect; override;
@@ -287,6 +288,8 @@ begin
     dointernaldisconnect;
     DatabaseError(sErrConnectionFailed + ' (PostgreSQL: ' + msg + ')',self);
     end;
+// This does only work for pg>=8.0, so timestamps won't work with earlier versions of pg which are compiled with integer_datetimes on
+  FIntegerDatetimes := pqparameterstatus(FSQLDatabaseHandle,'integer_datetimes') = 'on';
 end;
 
 procedure TPQConnection.DoInternalDisconnect;
@@ -626,6 +629,7 @@ begin
           begin
           pint64(buffer)^ := BEtoN(pint64(CurrBuff)^);
           dbl := pointer(buffer);
+          if FIntegerDatetimes then dbl^ := pint64(buffer)^/1000000;
           dbl^ := (dbl^+3.1558464E+009)/86400;  // postgres counts seconds elapsed since 1-1-2000
           // Now convert the mathematically-correct datetime to the
           // illogical windows/delphi/fpc TDateTime: