Subject Re: [IBO] Inserting TIMESTAMP literals from another table
Author Helen Borrie
At 03:10 AM 7/03/2005 -0800, you wrote:

>I am trying to generate an Insert statement that inserts a row that
>includes some values from another table. One of these values is a
>TIMESTAMP value. I'm trying to do something like this:
>MyDSQL->SQL->Add("insert into Table1 (SomeValue,SomeTimestamp) values
>('Hello', '" +
>SomeCursor->FieldByName("AnotherTimestamp")->AsString + "'"
>When I try to execute this, I get an exception, saying:
>conversion error from string "3/7/2005 2:56:12 AM"
>I'm guessing that Firebird doesn't like the literal format that IBO's
>AsString method is generating.

You got it. Timestamps in the database and DateTimes in Delphi are
numbers, not strings.

>How can I do this correctly? Is there a way to automatically generate a
>string representation of the date that Firebird will accept as a valid
>TIMESTAMP representation?

No, and don't try.

The proper way to be correct both with synax and data type is to use
parameters. That way, you don't have to argue with Delphi or the database
about data type representation.

Make your SQL property this:
'insert into Table1 (SomeValue,SomeTimestamp) values
(:SomeValue, :SomeTimestamp)'

Once the statement is prepared, i.e. in BeforeExecute, apply whatever the
latest values are to the parameters. Don't change the SQL at all.

with MyDSQL do begin
Params[0].AsString := SomeStringVar;
Params[1].AsDateTime :=

(Sorry about the Delphi - I guess you can do your own CPPB translation). :-)