Expressions and arbitrary SQL?

From: Jim Menard (jim..o.com)
Date: Sat Jan 17 2004 - 19:47:46 EST

  • Next message: Mike Kienenberger: "Re: Expressions and arbitrary SQL?"

    My problem: I want to turn the text that a user types into a search box
    into part of a SQL statement's WHERE clause.

    Does anybody have any code I can use?

    My first solution: turn text like "bob or ted and not alice" into
    "column like '%bob%' or column like '%ted%' and column not like
    '%alice%'". There are a few problems with this approach. Some are in
    the translation to a WHERE clause, but I'll ignore those right now. I
    want to use Expressions since I need to further qualify the search
    and---most importantly---retrieve Data Objects. If I write

            String sql = "select * from photo where my_generated_clause";
            Photo photo = (Photo)context.objectFromDataRow("Photo",
    context.performQuery(sql);

    will I really get a Photo object?

    My other potential solution: turn the text into a parse tree and from
    that parse tree create the "tree" of expressions using
    Expression.andExp and Expression.orExp. I've started playing with this
    solution, but it ain't easy.

    Has anyone done this before? What did you do?

    Jim

    -- 
    Jim Menard, jim..o.com, http://www.io.com/~jimm/
    "How do you keep an Englishman entertained in his dotage? Tell him
    a joke when he's young." -- Charles-A. Rovira
    



    This archive was generated by hypermail 2.0.0 : Sat Jan 17 2004 - 19:47:51 EST