Subject | More Params info |
---|---|
Author | Ryan Nilsson-Harding |
Post date | 2003-07-17T06:03:40Z |
Hello again,
I'm having some issues with setting/clearing params and I'm sure
that what I'm doing worked until today...
I allow my users to select one of three fields to use in where
clauses, and because of this, I have found using OnPrepareSQL a
little annoying to set my SQLWhereItems, as I can't be too sure of
which param field to set, so generic code in OnPrepareSQL is not
suitable.
(My queries only ever have one field in the where clause, but there
are three different ones which can be used)
So instead, I was manually clearing the SQLWhere list, then setting
the new where clause by adding 'WHERE XX = :yy' into the SQLWhere
This was working fine until today, and now I am getting AV's.
Example code:
<User hits a button which sets a where clause>
qry.SQLWhere.Clear;
qry.SQLWhere.Add('WHERE ID = :id');
if not qry.Prepared then
qry.Prepare;
{..Here I save a file with the qry.SQL.Text}
{..Here I popup a message with qry.Params.ColumnCount}
qryQuote.Params[0].AsInteger = someInt; <--- AV!
I'm aware that an AV occurs if you try to access a parameter without
the dataset being prepared, but I have the Prepared check in the
line above, but it is obviously evaluating to false, as the Prepare
never gets called.
The saved file contains the correct query (contains Where clause),
but the qry.Params.ColumnCount returns 0, hence the AV.
I thought that when the qry.SQLWhere was changed, IBO automatically
did an unprepare. Has this changed?
Is what I'm doing fundamentally wrong? (i.e. should I only be using
SQLWhereItems?)
Sorry for the windy description, but params/preparing is something
that I really should be understanding now, but it's still a little
arcane...
Rgds,
-Ryan
I'm having some issues with setting/clearing params and I'm sure
that what I'm doing worked until today...
I allow my users to select one of three fields to use in where
clauses, and because of this, I have found using OnPrepareSQL a
little annoying to set my SQLWhereItems, as I can't be too sure of
which param field to set, so generic code in OnPrepareSQL is not
suitable.
(My queries only ever have one field in the where clause, but there
are three different ones which can be used)
So instead, I was manually clearing the SQLWhere list, then setting
the new where clause by adding 'WHERE XX = :yy' into the SQLWhere
This was working fine until today, and now I am getting AV's.
Example code:
<User hits a button which sets a where clause>
qry.SQLWhere.Clear;
qry.SQLWhere.Add('WHERE ID = :id');
if not qry.Prepared then
qry.Prepare;
{..Here I save a file with the qry.SQL.Text}
{..Here I popup a message with qry.Params.ColumnCount}
qryQuote.Params[0].AsInteger = someInt; <--- AV!
I'm aware that an AV occurs if you try to access a parameter without
the dataset being prepared, but I have the Prepared check in the
line above, but it is obviously evaluating to false, as the Prepare
never gets called.
The saved file contains the correct query (contains Where clause),
but the qry.Params.ColumnCount returns 0, hence the AV.
I thought that when the qry.SQLWhere was changed, IBO automatically
did an unprepare. Has this changed?
Is what I'm doing fundamentally wrong? (i.e. should I only be using
SQLWhereItems?)
Sorry for the windy description, but params/preparing is something
that I really should be understanding now, but it's still a little
arcane...
Rgds,
-Ryan