[Solved] PostgreSQL: Problems inserting timestamp into table
Posted: 17.12.2017, 20:13
Hi there everyone,
I am using Zeos 7.2.1rc and I have a serious problem that has been bugging me for over two weeks. I am using NewPascal mORMot server to update a PostgreSQL 9.5 database. I've even used the same mORMot server to update another PostgreSQL 10 database and everything is fine so far.
However a serious problem has arisen. I am trying to update a table with timestamp fields. I want to insert a value like 2017-12-11T15:30:00 into the table. I have used the following code one after the other and it all failed
Error: "2017-12-11T15:30:00" is not a valid time
I then removed the 'T' and tried the following code
Error: "2017-12-11" is not a valid date format
SQL Error: ERROR: invalid input syntax for type timestamp: “ ”
SQL Error: ERROR: invalid input syntax for type timestamp: “ ”.
The screencap of the error is as follows:
As you can see, the error is from line 705 in ZDbcPostgreSqlUtils.pas
Can anyone help me?
Thanks,
JD
P.S I have also posted this onto the mORMot forum in case anyone wonders. Here is the link https://synopse.info/forum/viewtopic.ph ... 914#p25914
I am using Zeos 7.2.1rc and I have a serious problem that has been bugging me for over two weeks. I am using NewPascal mORMot server to update a PostgreSQL 9.5 database. I've even used the same mORMot server to update another PostgreSQL 10 database and everything is fine so far.
However a serious problem has arisen. I am trying to update a table with timestamp fields. I want to insert a value like 2017-12-11T15:30:00 into the table. I have used the following code one after the other and it all failed
Code: Select all
aServer.fDbProps.ExecuteNoResult(
'INSERT INTO public.tvp_event (starttime, endtime) ' +
'VALUES (?,?) ',
[DateTimeToSQL(StrToDateTime(VariantToUTF8(vJSEvents.Value(0).StartTime))),
DateTimeToSQL(StrToDateTime(VariantToUTF8(vJSEvents.Value(0).EndTime)))]);
I then removed the 'T' and tried the following code
Code: Select all
aServer.fDbProps.ExecuteNoResult(
'INSERT INTO public.tvp_event (starttime, endtime) ' +
'VALUES (?,?) ',
[DateTimeToSQL(StrToDateTime(StringReplace(VariantToUTF8(vJSEvents.Value(0).StartTime), 'T', ' ', [rfReplaceAll]))),
DateTimeToSQL(StrToDateTime(StringReplace(VariantToUTF8(vJSEvents.Value(0).EndTime), 'T', ' ', [rfReplaceAll])))]);
Code: Select all
aServer.fDbProps.ExecuteNoResult(
'INSERT INTO public.tvp_event (debut, fin) ' +
'VALUES (?,?) ',
[VariantToUTF8(vJSEvents.Value(0).StartTime),
VariantToUTF8(vJSEvents.Value(0).EndTime)]);
Code: Select all
aServer.fDbProps.ExecuteNoResult(
'INSERT INTO association_la_chorba.tvp_event (starttime, endtime) ' +
'VALUES (?,?) ',
[Iso8601ToSQL(VariantToUTF8(vJSEvents.Value(0).StartTime)),
Iso8601ToSQL(VariantToUTF8(vJSEvents.Value(0).EndTime))]);
The screencap of the error is as follows:
As you can see, the error is from line 705 in ZDbcPostgreSqlUtils.pas
Can anyone help me?
Thanks,
JD
P.S I have also posted this onto the mORMot forum in case anyone wonders. Here is the link https://synopse.info/forum/viewtopic.ph ... 914#p25914