Subject | RE: [IBO] Inserting TIMESTAMP literals from another table |
---|---|
Author | Jason Wharton |
Post date | 2005-03-09T16:09:10Z |
If you want to be able to use the ExecuteImmediate( ) method, which it
appears would make the most sense if you have a different SQL statement each
time, then you should make sure to submit all SQL in the syntax that
Firebird/InterBase recognizes. You are assuming they are going to accept
what Delphi (by default, your Windoze client regional settings) sees as a
proper date format. This is not wise since the server usually has no idea
what your client's regional settings are.
I have provided functions in the IB_Parse unit declared:
function get_IBDateLiteral( ADateTime: TDateTime ): string;
function get_IBDateSLiteral( const ADateTime: string;
IncDays: integer ): string;
There job is to take a Delphi datetime value and give you a SQL appropriate
value.
What you probably should do, which is what Helen recommended, is to use
input parameters. Not so much for the reason of avoiding the syntax but for
reasons of performance if you are able to use a prepared statement with
input parameters you will have better overall performance for the process.
Your performance would have been really awful if you were preparing a unique
SQL statement for each execution. Always look for a way to prepare a
statement and use it over and over again with input parameters or use the
ExecuteImmediate() method which allows you to skip the process of doing a
prepare.
Jason Wharton
appears would make the most sense if you have a different SQL statement each
time, then you should make sure to submit all SQL in the syntax that
Firebird/InterBase recognizes. You are assuming they are going to accept
what Delphi (by default, your Windoze client regional settings) sees as a
proper date format. This is not wise since the server usually has no idea
what your client's regional settings are.
I have provided functions in the IB_Parse unit declared:
function get_IBDateLiteral( ADateTime: TDateTime ): string;
function get_IBDateSLiteral( const ADateTime: string;
IncDays: integer ): string;
There job is to take a Delphi datetime value and give you a SQL appropriate
value.
What you probably should do, which is what Helen recommended, is to use
input parameters. Not so much for the reason of avoiding the syntax but for
reasons of performance if you are able to use a prepared statement with
input parameters you will have better overall performance for the process.
Your performance would have been really awful if you were preparing a unique
SQL statement for each execution. Always look for a way to prepare a
statement and use it over and over again with input parameters or use the
ExecuteImmediate() method which allows you to skip the process of doing a
prepare.
Jason Wharton
> -----Original Message-----
> From: Joe Martinez [mailto:joe@...]
> Sent: Monday, March 07, 2005 4:10 AM
> To: IB Objects
> Subject: [IBO] Inserting TIMESTAMP literals from another table
>
>
>
> 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.
>
> 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?
>
> -Joe