Board index » delphi » Problem with DataSet.CommandText and *two* parameters

Problem with DataSet.CommandText and *two* parameters


2004-08-24 08:24:10 PM
delphi190
Hi,
my problem is, in short:
I have two input-fields. Their values are passed to a
DataSet.CommandText via parameters (:sucha and :suchb) and the
query should look for combinations of the two values in the
mysql-database.
In general the query should look for
:sucha in all fields of the database ('OR' combination)
AND
:suchb in all fields of the same database (again 'OR' combination)
The query works OK when I restrict it to the first field, so it
seems to me, that the parameters are set correct and have been
assigned a correct value:
<snip>
ClientDataSet1.CommandText :='select * from `biblio` '+
'where autor like :sucha '+
'AND autor like :suchb';
<snip>
Now, when I extend the query over two fields I will get the message
that the value for the second parameter is missing and the program
stops executing:
<snip>
ClientDataSet1.CommandText :='select * from biblio '+
'where (autor like :sucha '
'OR titel like :sucha) '+
'AND (autor like :suchb'+
'OR titel like :suchb)';
<snip>
I tried all kinds of bracketing, all with the same result.
What am I doing wrong?
Thanks in advance,
Roland
Delphi6 (Update 2), MySQL 4.017
 
 

Re:Problem with DataSet.CommandText and *two* parameters

Hi,
I posted this already in b.p.d.d.dbexpress, but didn't receive any
answer, so this group might be more appropriate
my problem is, in short:
I have two input-fields. Their values are passed to a
DataSet.CommandText via parameters (:sucha and :suchb) and the
query should look for combinations of the two values in the
mysql-database.
In general the query should look for
:sucha in all fields of the database (with an 'OR' combination)
AND
:suchb in all fields of the same database (again with an 'OR' combination)
The query works OK when I restrict it to the first field, so it
seems to me, that both parameters are set correct and have been
assigned a correct value:
<snip>
ClientDataSet1.CommandText :='select * from `biblio` '+
'where autor like :sucha '+
'AND autor like :suchb';
<snip>
Now, when I extend the query over two fields (with AND and OR)
I'll get the message that the value for the second parameter is
missing and the program stops executing:
<snip>
ClientDataSet1.CommandText :='select * from biblio '+
'where (autor like :sucha '
'OR titel like :sucha) '+
'AND (autor like :suchb '+
'OR titel like :suchb)';
<snip>
I tried all kinds of bracketing to make the logical hierarchy of
the query unambiguous (incl. double-bracketing), all with the same
result.
What am I doing wrong?
Thanks in advance,
Roland
Delphi6 (Update 2), MySQL 4.017
 

Re:Problem with DataSet.CommandText and *two* parameters

Roland Reuss writes:
Quote
Hi,


I have two input-fields. Their values are passed to a
DataSet.CommandText via parameters (:sucha and :suchb) and the
query should look for combinations of the two values in the
mysql-database.

ClientDataSet1.CommandText :='select * from biblio '+
'where (autor like :sucha '
'OR titel like :sucha) '+
'AND (autor like :suchb '+
'OR titel like :suchb)';
<snip>

I tried all kinds of bracketing to make the logical hierarchy of
the query unambiguous (incl. double-bracketing), all with the same
result.

What am I doing wrong?

Thanks in advance,
Roland

Delphi6 (Update 2), MySQL 4.017
It depends on the "database access engine", but often you have to have
all the parameter names different, for your case
'where (autor like :sucha '
'OR titel like :sucha2) '+
'AND (autor like :suchb '+
'OR titel like :suchb2)';
Don't know about MySQL and the access components you are using but you
could at least give it a try.
Alex
 

Re:Problem with DataSet.CommandText and *two* parameters

Alex Ehrlich <XXXX@XXXXX.COM>schrieb:
Quote
It depends on the "database access engine", but often you have to have
all the parameter names different
Thanks, Alex. That worked.
Roland