Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 2002
    Posts
    21

    Unanswered: dynamically transforming conditional statements to SQL

    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.

  2. #2
    Join Date
    Sep 2002
    Posts
    3

    Re: dynamically transforming conditional statements to SQL

    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.

  3. #3
    Join Date
    Nov 2002
    Posts
    21

    Re: dynamically transforming conditional statements to SQL

    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

  4. #4
    Join Date
    Nov 2002
    Posts
    4

    Re: dynamically transforming conditional statements to SQL

    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

  5. #5
    Join Date
    Nov 2002
    Posts
    21
    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

  6. #6
    Join Date
    Nov 2002
    Posts
    4
    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

  7. #7
    Join Date
    Nov 2002
    Posts
    21
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •