Home » Community » Newbie corner » SQL query generator
SQL query generator [message #32948] |
Fri, 24 June 2011 14:07 |
|
jibe
Messages: 294 Registered: February 2007 Location: France
|
Experienced Member |
|
|
Hi,
I want to make a kind of query generator. I'm trying this :
In a dialog box, I have :
- a dropdown list with the fields of my table,
- another dropdown list with possible relations (==, !=, <, <= etc.)
- an EditString where to type the desired value.
This will generate SQL queries like :
SELECT * from MYTABLE where (field) (relation) (value)
ie : SELECT * FROM CLIENTS WHERE NAME == TOTO
I tried this :
void MyApp::Query()
{
String field, cond, val;
SqlBool where;
field = dialog.dl_field.GetValue();
cond = dialog.dl_cond.GetValue();
val = dialog.ed_cond.GetData();
where = NAME == ~val;
mytable.Query(where);
}
This is working well
But when I change to this
Or this
It's no more working...
I tried many other things, ie grouping field, cond and val in a single String, but I cannot find a way to have it working.
How can I do ? I want to find a way to choose at runtime the complete "where" condition...
[Updated on: Fri, 24 June 2011 14:12] Report message to a moderator
|
|
|
|
|
|
|
|
Re: SQL query generator [message #32990 is a reply to message #32988] |
Tue, 28 June 2011 08:32 |
|
jibe
Messages: 294 Registered: February 2007 Location: France
|
Experienced Member |
|
|
Hi,
BioBytes wrote on Mon, 27 June 2011 21:49 | Switch/case seems to be heavy but I think the application is not really slowed going this way.
|
Yes, it's a good solution ! I was just telling that there could be some "more beautifull" way to code that.
In fact, it's not sure that there is really another solution, as some statements (Like, IsNull) have another syntax...
For me, I'm satisfied with the switch/cas solution, more especially because I need Like, IsNull and there contraries.
Anyway, if somebody has other(s) solution(s), or usefull links to documentation, I'll be happy to know
Thanks again to BioBytes, and good luck for your research !
|
|
|
Goto Forum:
Current Time: Sun Apr 28 14:21:52 CEST 2024
Total time taken to generate the page: 0.07438 seconds
|