Re: primary column in select query

From: Bryan Lewis (brya..aine.rr.com)
Date: Fri Nov 25 2005 - 11:02:04 EST

  • Next message: Mike Kienenberger: "Re: primary column in select query"

    Ah, I was answering a different question. I'm not sure that db: expressions
    can resolve multi-part paths.

    Why not use relationships rather than specify the columns? I would think it
    would be something like this in your model:

    Person --(address relationship)-> Address --(country relationship)->
    Country

    The code would do:

        Expression exp =
    ExpressionFactory.matchExp("address.country.countryCode", "uk");
        SelectQuery query = new SelectQuery("Person", exp);

    There might still be a problem with countryCode not being mapped as an
    object attribute, but that could be resolved by defining a read-only getter
    method getCountryCode() in Country.java. Or adding it as an attribute as
    you said.

    ----- Original Message -----
    From: "Lothar Krenzien" <lkrenzie..eb.de>
    To: <cayenne-use..bjectstyle.org>
    Sent: Friday, November 25, 2005 10:16 AM
    Subject: Re: primary column in select query

    >
    > Hi Bryan ,
    >
    > I'm not sure if I understood you right.
    >
    > I want to query a table called 'tblPerson' and have to walk over a table
    called 'tblAddress' (column addressId) to table 'tblCountry' (column
    countryCode). When I try it like in manual you said I get always an error
    that the path can't be resolved.
    >
    > -- db names
    > -- 1. try
    > expr.andExp(Expression.fromString("db:addressId.tblCountry.countryCode ==
    '" + searchCriteria.getCountry() + "'"));
    >
    > -- 2. try
    > expr.andExp(Expression.fromString("db:tblAddress.tblCountry.countryCode ==
    '" + searchCriteria.getCountry() + "'"));
    >
    > -- 3.try
    > expr = expr.andExp(Expression.fromString("db:addressId =
    tblAddress.addressId"));
    > expr = expr.andExp(Expression.fromString("db:tblAddress.countryCode =
    tblCountry.countryCode"));
    > expr = expr.andExp(Expression.fromString("db:tblCountry.countryCode = '" +
    searchCriteria.getCountry() + "'"));
    >
    > -- 4.try
    > expr = expr.andExp(Expression.fromString("db:tblPerson.addressId =
    tblAddress.addressId"));
    > expr = expr.andExp(Expression.fromString("db:tblAddress.countryCode =
    tblCountry.countryCode"));
    > expr = expr.andExp(Expression.fromString("db:tblCountry.countryCode = '" +
    searchCriteria.getCountry() + "'"));
    >
    >
    > -- objectNames
    > expr.andExp(Expression.fromString("toTblAddress.toTblCountry.countryCode
    == '" + searchCriteria.getCountry() + "'"));
    >
    >
    > The generated sql command should look like
    >
    > select ...
    > from tblPerson, tblAddress, tblCountry
    > where tblPerson.addressId = tblAddress.address.id
    > and tblAddress.countryCode = tblCountry.countryCode
    > and tblCountry.countrycode = 'uk'
    >
    > Thnaks again
    > Lothar
    >
    > cayenne-use..bjectstyle.org schrieb am 25.11.05 15:02:15:
    > >
    > > Take a look at the "db:" prefix.
    > > http://objectstyle.org/cayenne/userguide/expressions/common.html
    > >
    > >
    > >
    > > ----- Original Message -----
    > > From: "Lothar Krenzien" <lkrenzie..eb.de>
    > > To: <cayenne-use..bjectstyle.org>
    > > Sent: Friday, November 25, 2005 8:20 AM
    > > Subject: primary column in select query
    > >
    > >
    > > >
    > > > Hi there,
    > > >
    > > > I have a table which uses a character column with country codes as
    primary
    > > key. Now I want to use this column in a select query. First I tried it
    this
    > > way:
    > > >
    > > > ExpressionFactory.matchExp("toTblAddress.toTblCountry.countryCode",
    > > searchCriteria.getCountry())
    > > >
    > > > This didn't worked because the column is a primary key and not defined
    in
    > > the mapping file. Of course I can define a new (integer) column as
    primary
    > > key, but I would like to know is there a way to use the existing column
    in a
    > > query.
    > > >
    > > > Thanks, Lothar
    > > > ______________________________________________________________
    > > > Verschicken Sie romantische, coole und witzige Bilder per SMS!
    > > > Jetzt bei WEB.DE FreeMail: http://f.web.de/?mc=021193
    > > >
    > >
    >
    >
    > ______________________________________________________________
    > Verschicken Sie romantische, coole und witzige Bilder per SMS!
    > Jetzt bei WEB.DE FreeMail: http://f.web.de/?mc=021193
    >



    This archive was generated by hypermail 2.0.0 : Fri Nov 25 2005 - 11:02:07 EST