Page 1 of 1

PostgreSQL Timestamp

Posted: 11.07.2007, 23:25
by simpsomboy
The Timestamp fiels, was not getting milisecs information from database.
at PostgreSQL this results in a error on update a record, by comparsion
invalid, because postgresql expects milisecs on timestamp, and when comparing values its doesn't match.


The Diff File to svn revision 267 Folows:

Code: Select all

Index: src/core/ZSysUtils.pas
===================================================================
--- src/core/ZSysUtils.pas	(revision 267)
+++ src/core/ZSysUtils.pas	(working copy)
@@ -865,7 +865,7 @@
 }
 function AnsiSQLDateToDateTime(const Value: string): TDateTime;
 var
-  Year, Month, Day, Hour, Min, Sec: Word;
+  Year, Month, Day, Hour, Min, Sec, Msec: Word;
   Temp: string;
 begin
   Temp := Value;
@@ -883,17 +883,18 @@
       except
       end;
     end;
-    Temp := Copy(Temp, 12, 8);
+    Temp := Copy(Temp, 12, 12);
   end;
   if Length(Temp) >= 8 then
   begin
     Hour := StrToIntDef(Copy(Temp, 1, 2), 0);
     Min := StrToIntDef(Copy(Temp, 4, 2), 0);
     Sec := StrToIntDef(Copy(Temp, 7, 2), 0);
+    MSec := StrToIntDef(Copy(Temp, 10, 3), 0);
     try
       if Result >= 0 then
-        Result := Result + EncodeTime(Hour, Min, Sec, 0)
-      else Result := Result - EncodeTime(Hour, Min, Sec, 0)
+        Result := Result + EncodeTime(Hour, Min, Sec, MSec)
+      else Result := Result - EncodeTime(Hour, Min, Sec, MSec)
     except
     end;
   end;
Index: src/dbc/ZDbcCache.pas
===================================================================
--- src/dbc/ZDbcCache.pas	(revision 267)
+++ src/dbc/ZDbcCache.pas	(working copy)
@@ -2195,7 +2195,7 @@
       end;
     stTimestamp: SetTimestamp(ColumnIndex, Frac(Value));
     stString, stUnicodeString:
-      SetString(ColumnIndex, FormatDateTime('hh:nn:ss', Value));
+      SetString(ColumnIndex, FormatDateTime('hh:nn:ss.zzz', Value));
   end;
 end;
 
@@ -2224,7 +2224,7 @@
         PDateTime(@FBuffer.Columns[FColumnOffsets[ColumnIndex - 1] + 1])^ := Value;
       end;
     stString, stUnicodeString:
-      SetString(ColumnIndex, FormatDateTime('yyyy-mm-dd hh:nn:ss', Value));
+      SetString(ColumnIndex, FormatDateTime('yyyy-mm-dd hh:nn:ss.zzz', Value));
   end;
 end;
 
Index: src/dbc/ZDbcPostgreSqlStatement.pas
===================================================================
--- src/dbc/ZDbcPostgreSqlStatement.pas	(revision 267)
+++ src/dbc/ZDbcPostgreSqlStatement.pas	(working copy)
@@ -358,10 +358,10 @@
           [FormatDateTime('yyyy-mm-dd', SoftVarManager.GetAsDateTime(Value))]);
       stTime:
         Result := Format('''%s''::time',
-          [FormatDateTime('hh":"mm":"ss', SoftVarManager.GetAsDateTime(Value))]);
+          [FormatDateTime('hh":"mm":"ss"."zzz', SoftVarManager.GetAsDateTime(Value))]);
       stTimestamp:
         Result := Format('''%s''::timestamp',
-          [FormatDateTime('yyyy-mm-dd hh":"mm":"ss',
+          [FormatDateTime('yyyy-mm-dd hh":"mm":"ss"."zzz',
             SoftVarManager.GetAsDateTime(Value))]);
       stAsciiStream, stUnicodeStream:
         begin