PDA

View Full Version : qsqlquery interactive?



lamera
6th September 2008, 22:20
Hi!
this time I'm struggling with queries in Qt.
The problem is that I'm doing a program where the data to be received from the DB varies depending on what the user decides he needs.
So I need to somehow make the SELECT-command interactive.
So the thing is that my basic query look sth like this:

SELECT ID FROM Table1 WHERE Name="bla1";

but then it might be so that the query should look sth like

SELECT ID FROM Table1 WHERE Name="bla1" INTERSECT
SELECT ID FROM Table1 WHERE Name="bla2";

or even like

SELECT ID FROM Table1 WHERE Name="bla1" INTERSECT
SELECT ID FROM Table1 WHERE Name="bla2" INTERSECT
SELECT ID FROM Table1 WHERE Name="bla3" ;

etc.

it depends on what the user decides, so he can say I'm interested on the answer depending on the name being bla1, bla2 and bla3 etc.

so is there a way to do this in Qt?
so I know that in query.exec() one must state a query in advance.

I hope I made myself somehow clear?
thanks for any help

haldrik
7th September 2008, 01:06
Use:


query.prepare("SELECT ID FROM Table1 WHERE Name=:name");
query.bindValue(":name", Widget->text());
query.exec();

where Widget->text() is the control you have the text you need, for example a comboBox or a LineEdit.

You must read the documentation.

lamera
7th September 2008, 10:09
right, I meant sth different still, but I'll just manipulate the query using a string.
I just thought there might be some kind of a function like

QSqlQuery::intersect (QList<QSqlQuery>)
anyway thanks for answering!
cheers