Re: primary column in select query

From: Lothar Krenzien (lkrenzie..eb.de)
Date: Fri Nov 25 2005 - 10:16:26 EST

  • Next message: Bryan Lewis: "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 - 10:16:29 EST