PDA

View Full Version : dynamically transforming conditional statements to SQL


Sandro Psaila
11-24-02, 11:14
hi all

I am building an application where the user enters a conditional statement and then i want to perform some action.

Eg

user input > if customer.name = sandro then send email

My program will read the user input and then dynamically constructs an sql statement to retrieve the required info... if the sql returns data i.e. the condition succeeds, then a separate method is invoked.

My problem is to transform this statement into the appropriate SQL...since this need to be constructed at run time and for any type of user input..

The language i am using is java, however i dont expect any code...I was only wondering if someone has any ideas of how this can be done..

Thank you in anticipation.

aman
12-03-02, 09:38
Hi,

JDBC is right for your requirement. You'll find documentation such as tutorials in java.sun.com or even by oracle.com.

br

aman

Originally posted by Sandro Psaila
hi all

I am building an application where the user enters a conditional statement and then i want to perform some action.

Eg

user input > if customer.name = sandro then send email

My program will read the user input and then dynamically constructs an sql statement to retrieve the required info... if the sql returns data i.e. the condition succeeds, then a separate method is invoked.

My problem is to transform this statement into the appropriate SQL...since this need to be constructed at run time and for any type of user input..

The language i am using is java, however i dont expect any code...I was only wondering if someone has any ideas of how this can be done..

Thank you in anticipation.

Sandro Psaila
12-03-02, 09:51
Originally posted by aman
Hi,

JDBC is right for your requirement. You'll find documentation such as tutorials in java.sun.com or even by oracle.com.

br

aman


Hi aman

..thanks


However my problem is not what to use....... my concern is how to generate sql statments dynamically... i.e. acording to the user input.

Regards

WWebster
12-03-02, 11:16
JDBC will allow you to either pass our sql statement as a string which you can dynamically create after recieving your user input, or you may use a PrepearedStatement object for repetative querries. Here's an example of using a string.

String userInput = request.getParameter("userInput");

String sql = "Select " + userInput + "from myTable";


Originally posted by Sandro Psaila
Hi aman

..thanks


However my problem is not what to use....... my concern is how to generate sql statments dynamically... i.e. acording to the user input.

Regards

Sandro Psaila
12-03-02, 11:47
hi ..

unfortunately my problem is not that simple....

the user input i need to transform in sql is a sort of a rule..


typical user input

If users.name = "sandro" and prefs.category="gold" then send mail

from this user input i need to costruct an sql statement to verify if the rule condition part succeeds

WWebster
12-03-02, 11:59
You can handle this logic in your sql statement or through your java code
once you recieve the user input. To explain further, you would need to supply more details about your difficulty.

Originally posted by Sandro Psaila
hi ..

unfortunately my problem is not that simple....

the user input i need to transform in sql is a sort of a rule..


typical user input

If users.name = "sandro" and prefs.category="gold" then send mail

from this user input i need to costruct an sql statement to verify if the rule condition part succeeds

Sandro Psaila
12-03-02, 12:12
The problem is exactly how to handle the logic to construct the required sql... i need an algorithm which will transform the conditional statements which i am calling rules,

like

If users.name = "sandro" and prefs.category="gold" then send mail

into sql


One is to note that user can enter any number of conjuctives (AND,OR,NOT) in the rule supplied. The same is for the operators(= > < etc)



Thanks for your attention