Subject Re: Dialect 3 Time Field Query
Author Adam
--- In firebird-support@yahoogroups.com, "ra8009" <ra8009@...> wrote:
>
> > Date and time formatting is extremely variable because it often
depends
> > on the way the OS is configured, although dates are worse than
times
> > because a valid date could potentially be incorrectly
interpreted.
> > Paramatised queries can be used to take away this headache
entirely.
> > What development environment and connection components are you
working
> > with?
> >
> > Adam
> >
>
> I'm using Delphi 7 and IB Objects 4.3. My queries are coming up
empty,
> even when I know there are results. I've tried using both asTime and
> asDateTime with paramByName, but still can't get results. What else
> should I try?

Use a colon to indicate a string in the query is a parameter. It
should look something like this (This is IBX code but I don't imagine
that it would be much different with IBO)

qry.sql.text := 'insert into sometable (somefield) values (:mytime);
qry.ParamByName('mytime').AsTime := DateTimePicker1.Time;
qry.ExecSQL;

Using parameters also gives the following benefits:

* Immunity from SQL injection hacks through your edit boxes.
* Prepare the query a single time and you can just substitute the
parameters. If you are running a query inside a loop, then this is a
huge performance benefit.
* Easier to read and maintain code
* No messing around with m/d/yyyy or d/m/yyyy or 12/24 hr time or
trying to insert O'Conner into a surname field, or was
that 'O''Conner'?? (you get the drift)
* Separation of UI from query, allowing different interfaces using
the same business rules.

Adam