Subject Re: [firebird-support] Timestamp variable with fractional seconds
Author Helen Borrie
At 07:36 PM 7/02/2005 +0000, you wrote:


>Hello,
>
>Public thanks to those who helped me with basic API pointers the other
>day; I already sent private thanks.
>
>Question: how to insert a date variable with fractional seconds? I
>already checked the file ApiGuide.pdf in the Interbase 6.0 docs; the
>routines isc_timestamp_encode & _decode use a struct tm which does not
>include fractional seconds. The IBPP::Timestamp variable also does
>not support this, according to the list experts.
>
>I already figured out how to insert and select using CAST with a
>character variable and a date variable; however, this causes an
>exception if you insert using IBPP.
>
>The Firebird book rocks! This is how I found out about the CAST.
>But, to do this from my application, I'll have to use an immediate
>rather than a compiled statement. So, I guess my question is:
>
>How to do this in a compiled statement using a timestamp column, and
>IBPP if possible (unless there is a class library that is more
>favored; I like IBPP even with the gaps in documentation)?
>
>Any assistance would be appreciated.

If you're getting exceptions from CASTS, it is almost certainly due to
passing a date literal in a format not recognised by Firebird. There's a
big section about date literals in Ch. 10. While there's quite a big range
of possible formats for the date part, you still must use one that is
recognised. A common gotcha is using 'dd/mm/ccyy' for the date part. For
the time part, it will accept only one format, that is 'hh:nn:ss.nnnn'
(24-hour clock). If conjoined to a time part, there *must* be a leading
space character on the time part.

IBPP is just a wrapper for the API so I can't see how it could interfere
with your SQL statement strings. Don't overlook the possibility that you
are using the wrong concatenation operator. The expression

cast ('07.02.2005' || ' ' || '12:47:15.1234' as timestamp) is a valid
expression in SQL, as is
timestamp '07.02.2005 12:47:15.1234'

although
timestamp '07.02.2005' || ' ' || '12:47:15.1234', while it won't except,
will store/return a timestamp with the entire time part zeroed.

./heLen