Subject Re: [IBO] Type conversion
Author Helen Borrie
At 01:44 PM 29-01-01 +1100, you wrote:
>I tried this but the problem is that the cast to Timestamp requires a string
>(I think) and not a double.

Yes, yer right. It's discussed in Chap. 7 of the EmbedSQL manual - you can
*only* cast Timestamp from one of the valid InterBase date literals. :(


>The SQL statement contains:
>
>cast(cast (item.startdate as float) + cast(log.offset as float) * 2.0 as
>timestamp)
>
>This will produce an error like:
> Overflow error during type conversion. Conversion error from string
>"9.9999999999 ."

Yup, that's consistent with the documentation.


>Using a TDBChart gets around the problem because it has a flag to indicate
>the field is a date and so the graph actually displays the dates. The
>TDBGrid is the issue where I see the floating point values and not the date.
>I have used the SetFieldType command but it has had no impact. As far as I
>can tell there is no means to specify the field type within the TDBGrid, it
>is set by IB or IBObjects.
>
>I call the SetFieldType after I make the query active. If I do it before
>then the field name does not exist. I don't know if this impacts upon
>anything.
>
>Also the above SQL will not operate on my PC because the time/date format
>results in an overflow error. In my code I actually convert the startdate in
>Delphi and dynamically create the SQL.

If you're converting to a date literal string, this looks like a way to do
it. Not pretty though.

Another idea:
Could you bring in item.startdate as a ftDateTime and log.offset as an
integer calculated by multiplying the stored value by the precision, and
use a ftCalculatedField type for your output field by putting code into
OnCalcFields to
1) subtract log.offset from item.startdate (you can do this with a TDateTime)
2) divide the result by the precision
3) multiply that by 2
4) cast the result into a DateTime which you assign to a client-side
calculated field (i.e. traditional Delphi-style calc field)

H.


All for Open and Open for All
InterBase Developer Initiative ยท http://www.interbase2000.org
_______________________________________________________