Re: Getting complex queries in cayenne

From: Dhruti Ramani (dhrutiraman..ahoo.com)
Date: Fri May 06 2005 - 11:24:03 EDT

  • Next message: Cris Daniluk: "Re: Getting complex queries in cayenne"

    Here is the code that I am trying,
     
    SQLTemplate query=new SQLTemplate(CashFlow.class,"select * from cashflow",true);
    String str="select c.paydate from cashflow c,quote q where c.quote_id=q.quote_id AND q.isacceptedQuote='t' ";
    query.setTemplate(DbAdapter.POSTGRES,str);
    List results=dataContext.performQuery(query);
     
    It returns 5 rows which is true but if i try to print those values it returns null for all rows.
    Am I doing something wrong?
     
    Thanks,
    Denna

    Cris Daniluk <cris.danilu..mail.com> wrote:
    >
    > You said this in you email.
    > If you tried creating SQLTemplates in the Modeler, you may have noticed
    > that each such query allows alternative SQL syntax to be stored under
    > different adapter
    > keys. So each target database can have its own SQL "flavor" without any
    > dependencies in the Java code.
    >
    > Can you tell me how I can create SQLTemplate in modeler? Or anybody has some
    > example for SQLTemaplate?
    >

    The docs are pretty good on SQLTemplates. Check out:

    http://objectstyle.org/cayenne/userguide/fetch/sqltemplate.html

    and...

    http://objectstyle.org/cayenne/userguide/fetch/sqltemplate-scripting.html

    You really have a lot of flexibility to "generate" SQL. For example,
    you may have a set of criteria that changes at runtime. The scripting
    gives you a lot of flexibility in how you 'bind' these criteria.

    I'd start by building your SQLTemplates in code to get the hang of it,
    then move them to the modeler. To add a SQLTEmplate to the modeler,
    create a new Query and select "Raw SQL" as the type. Note that you
    have the option to fetch into DataObjects, or return as a DataRow.

    Under the "SQL Scripts" tab, you can paste your SQL, including any
    bindings or other directives. You can even specify alternate SQL for
    different JDBC drivers if necessary.

    Accessing this query via the application is the same as accessing any
    other named query. See:

    http://objectstyle.org/cayenne/userguide/fetch/datamap-queries.html

    > I am really sorry if I am being annoying here.
    >
    This list is for questions, and this question is as good as any... :)

    Cris

                    
    ---------------------------------
    Discover Yahoo!
     Stay in touch with email, IM, photo sharing & more. Check it out!



    This archive was generated by hypermail 2.0.0 : Fri May 06 2005 - 11:24:05 EDT