#1 2020-06-12 08:45:51

konsul41
Member
Registered: 2020-05-21
Posts: 24

Error updating TDateTime field in Postgresql database

Baza Zewnętrzna Postgresql
Obiekt typu TDokument = class (TSQLRecord) zawiera

Postgresql External Database
Object of type TDokument = class (TSQLRecord) contains property of type TDateTime

TDokument = class (TSQLRecord)
  private
    fdata_wystawienia: TDateTime;
  published
    property data_wystawienia : TDateTime read fdata_wystawienia write fdata_wystawienia;
  end;

the database is created correctly

CREATE TABLE public.dokument (
    ...
    data_wystawienia timestamp NULL,
        ...
);


then I try to update the object's property with code

var Dokument : TDokument;
    Valid : boolean;
    value : Variant;
    tek   : String;
begin
  Dokument:=TDokument.Create;
  try
    JSONToObject(Dokument,@dok[1],Valid);
//
ServerDB.UpdateField(TDokumentClass(TDokument),TID(ID),'data_wystawienia',Dokument.data_wystawienia);
The property Document.display_date contains the correct date (the delphi preview shows 01.06.2020) as assumed, but I get the error reported by Postgresql in the form

Project ... raised exception class EPGNativeException with message '[FireDAC][Phys][PG][libpq]
Error "data_wystawienia" column test type timestamp without timezone but the expression is of type character varing.
... further standard Postgres description of what to do


What to do to update the timestamp field value?

Offline

#2 2020-06-12 09:22:01

Vitaly
Member
From: UAE
Registered: 2017-01-31
Posts: 168
Website

Re: Error updating TDateTime field in Postgresql database

As far as I understood, you have already the needed value in Dokument.data_wystawienia. Then, I guess, if you have Dokument.IDValue set correctly, you can simply do:

ServerDB.Update(Dokument, 'data_wystawienia');

But even with your code, I think, it could work if you used DateToSQL/DateTimeToSQL functions, like:

ServerDB.UpdateField(TDokumentClass(TDokument),TID(ID),'data_wystawienia',DateTimeToSQL(Dokument.data_wystawienia));

Offline

#3 2020-06-12 09:36:16

konsul41
Member
Registered: 2020-05-21
Posts: 24

Re: Error updating TDateTime field in Postgresql database

Works thanks.

Last edited by konsul41 (2020-06-12 09:36:40)

Offline

Board footer

Powered by FluxBB