Re: Example: How to build a subquery

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Mon Jul 21 2003 - 10:30:59 EDT

  • Next message: Andrus Adamchik: "Cayenne 1.0 Release Candidate is out"

    Hi Andre Luiz,

    Though there is no direct subqueries support in expressions package,
    here is a solution to your problem:

        http://objectstyle.org/cayenne/faq/develop.html#not-query

    Andrus

    On Monday, July 21, 2003, at 09:46 AM, André Luiz N Sousa wrote:

    > Hello, Andrus,
    >  
    >  
    >         I'm having some doubts about how to build a query with a
    > subquery using the Cayenne. Let's see if someone could help me.
    >  
    >         Given the following scenario:
    >  
    > Entity: 
    >         Escotista        (DB Table: TB01_ESCOTISTA)
    >         =======
    >         ideEscotista           (PK) - it wasn't mapped by the Cayenne
    > Modeller
    >         nomEscotista        String
    >         dthNascimento     Date
    >         .... (a lot of another fields...)
    >         MembroPatrulhaArray        'To-Many' relationship to entity
    > "MembroPatrulha"
    >  
    > Entity:
    >         MembroPatrulha      (DB Table: TB36_MEMBRO_PATRULHA)
    >         =============
    >         idePatrulhaFk35        Integer    (PK)
    >         ideEscotistaFk01      Integer    (PK)
    >         dthAdmissao             Date
    >         dthDesligamento      Date
    >         indCargoAtual            String
    >         toEscotista                 'To-One' relationship to entity
    > "Escotista"
    >  
    >  
    >         Suppose that I have the "idePatrulhaFk35" value and I'd like
    > to list all the records of the "Escotista" entity that don't exist
    > yet in the "MembroPatrulha" for the given "idePatrulhaFk35" value.
    >  
    >         The pure SQL would be something like this:
    >             "select T01.*
    >                 from TB01_ESCOTISTA As T01
    >               where T01.IDE_ESCOTISTA not in (select
    > T02.IDE_ESCOTISTA_FK01
    >                                                                        
    >            from TB36_MEMBRO_PATRULHA As T02
    >                                                                        
    >         where T02.IDE_PATRULHA_FK35 = X);"
    >  
    >         The question is: How can I do that query using the Cayenne
    > syntax (Expression, ExpressionFactory, etc...) ???
    >  
    >  
    >         Thanks for the attention,
    >  
    >  
    > André Luiz do Nascimento Sousa
    > System Analist
    > Brasília - Brazil
    >  
    >  
    >  
    >  
    >  
    >  
    >  
    >  
    >  
    >  
    >  
    >  
    >            
    >  
    >  
    >



    This archive was generated by hypermail 2.0.0 : Mon Jul 21 2003 - 10:28:54 EDT