Re: AW: query problem

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Fri Mar 12 2004 - 20:10:42 EST

  • Next message: Jorge Sopena: "CayenneRunTimeException when it's sent several requests quickly"

    Eric was referring to the new 1.1 feature, which is not a part of 1.0.
    On 1.0 you will have to do some manual expression assembly. In
    particular the part that I suspect causes confusion (least_decrease *
    capacitySU) can be created like that (unless you have these columns
    named differently as object properties):

    Expression left = ExpressionFactory.unaryExpression(Expression.DB_PATH,
    "least_decrease");
    Expression right =
    ExpressionFactory.unaryExpression(Expression.DB_PATH, "capacitySU");

    Expression multiply = new BinaryExpression(Expression.MULTIPLY);
    multiply.setOperand(0, left);
    multiply.setOperand(1, right);

    ... definitely not as easy as "Expression.fromString()" :-)

    Andrus

    On Mar 12, 2004, at 5:52 PM, Michael Schuldt wrote:

    > Sorry, but I can't find a method like "fromString"? Where can I find
    > it?
    >
    >> -----Ursprüngliche Nachricht-----
    >> Von: Eric Schneider [mailto:eri..entralparksoftware.com]
    >> Gesendet: Freitag, 12. März 2004 16:02
    >> An: cayenne-use..bjectstyle.org
    >> Betreff: Re: query problem
    >>
    >>
    >> Michael,
    >>
    >> I would think you could use the string expression API.
    >>
    >> Expression.fromString("status = $param1 and current_stock <
    >> (least_decrease
    >> * capacitySU)").
    >>
    >> Hope that helps,
    >> Eric
    >>
    >> ----- Original Message -----
    >> From: "Michael Schuldt" <m..scensys.de>
    >> To: <cayenne-use..bjectstyle.org>
    >> Sent: Friday, March 12, 2004 9:46 AM
    >> Subject: query problem
    >>
    >>
    >>> Hi,
    >>>
    >>> situation as follwos:
    >>>
    >>> I've got a table "tb_offer" with the follwoing fields:
    >>> - id (int)
    >>> - name (varchar)
    >>> - status (varchar)
    >>> - current_stock (double)
    >>> - least_decrease (double)
    >>> - capacitySU (int)
    >>>
    >>> Now I want to create the following SQL-Statement:
    >>> SELECT * FROM tb_offer WHERE status = 'on' AND current_stock <
    >>> (least_decrease * capacitySU);
    >>>
    >>> You see, in SQL this isn't a problem. But if I want to create this
    >>> Expression with Cayenne, I have to give up.
    >>>
    >>> A solution would be to use raw-sql but I have to use the
    >> resulting Objects
    >>> (TbOffer) for update. By using raw-sql I have to reread the
    >> Objects after
    >>> the first query.
    >>>
    >>> Any suggestions?
    >>>
    >>> Thx
    >>
    >
    >



    This archive was generated by hypermail 2.0.0 : Fri Mar 12 2004 - 20:10:47 EST