Re: Problems to execute(SELECT MAX).

From: Mike Kienenberger (mkienen..laska.net)
Date: Mon Aug 02 2004 - 10:56:08 EDT

  • Next message: Gentry, Michael: "RE: Oh, yeah..."

    "Gentry, Michael" <michael_gentr..anniemae.com> wrote:
    > Even if you setFetchingDataRows(true), you are still essentially
    > specifying the table name twice. For example:
    >
    > template = new SQLTemplate(MyTable.class, "select max(myColumn) from
    > MyTable", true);
    >
    > Instead of just:
    >
    > template = new SQLTemplate(MyTable.class, "select max(myColumn)", true);
    >
    > It seems to me that MyTable.class is already specifying the table, but
    > you have to specify it in the query, anyway. (I tried it in a little
    > testbed I have and it blows up if you leave the table name out of the
    > string.) I can understand the need to use MyTable.class (you need to
    > know which DB connection to use/etc, especially if accessing multiple
    > DBs simultaneously, etc), but I don't see why we'd need to specify the
    > table, since that information already exists.

    I haven't looked at the source, but my guess is that SQLTemplate can execute
    arbitrary SQL.

    For example "select table1.field9, table2.field4 from table1, table2"

    Also, sql is not standard. It's not reasonable to expect cayenne to be able
    to parse or generate arbitrary sql -- in fact, the reason SqlTemplate exists
    is so that you can specify SQL that Cayenne couldn't handle in the first
    place!

    My take on the first parameter is that it's the "expected" (but not
    required") DataObject format of the data returned by the query. Since you
    don't have to convert the results into DataObjects, there's no need to
    require it.

    Since I see the following as a constructor, there's no guarantee that it
    maps to any particular DataObject.

            SQLTemplate(DataMap rootMap, java.lang.String defaultTemplate, boolean
    selecting)

    -Mike



    This archive was generated by hypermail 2.0.0 : Mon Aug 02 2004 - 10:55:35 EDT