Re: Problems to execute(SELECT MAX).

From: Reinaldo Coelho Sartorelli (reinaldo_sartorell..ahoo.com.br)
Date: Sun Aug 01 2004 - 22:53:58 EDT

  • Next message: Todd O'Bryan: "testing on alternate database"

    Tks for all.

    My code finish in this :

                            //Query da Seleção.
                            String sql = "SELECT MAX(generos.COD_GENERO) AS codigo FROM generos";
                            SQLTemplate query = new SQLTemplate(Generos.class, sql, true);
                            query.setFetchingDataRows(true);
                            List lst = conexao.performQuery(query);
                            if(!lst.isEmpty()) {
                              //Gera mapa de retorno.
                              Map a = (Map) lst.get(0);
                              //Verifica se existe algum registro atualmente.
                              if (a.get("codigo") == null) {
                                      return 1;
                              }
                              else{
                                      int i = Integer.parseInt(a.get("codigo").toString());
                                      return ++i;
                              }
                            }
                            else{
                                    return 1;
                            }
                    }
                    catch(Exception e){
                            System.out.println("Erro:" + e.getMessage());
                            //Em caso de erro, retorna 0.
                            return 0;
                    }

    On Friday 30 July 2004 12:07, Tore Halset wrote:
    > Hello
    >
    > String q = "select max(field) as max from table";
    > SQLTemplate query = new SQLTemplate(Table.class, q, true);
    > query.setFetchingDataRows(true);
    > List result = dc.performQuery(query);
    > Map row = (Map)result.get(0);
    > log.info("max: " + row.get("max"));
    >
    > Take a look at aggregate-functions in cayenne examples as well:
    > http://objectstyle.org/cayenne/examples/aggregate-functions/index.html
    >
    > Regards,
    > - Tore.
    >
    > On Jul 30, 2004, at 15:52, Reinaldo Coelho Sartorelli wrote:
    > > Regards, you have a example?
    > >
    > > I can't execute SELECT MAX with the SqlTemplate option and neither with
    > > Expression as was suggested in the other email.
    > >
    > > Tks,
    > > Reinaldo.
    > >
    > > On Friday 30 July 2004 03:08, Tore Halset wrote:
    > >> On Jul 30, 2004, at 3:22, Reinaldo Coelho Sartorelli wrote:
    > >>> All, who i can execute SELECT MAX from column, if "SqlSelectQuery" is
    > >>> deprecated, and don't have MAX option ???
    > >>
    > >> Take a look at SQLTemplate. It has replaced SqlSelectQuery and has
    > >> some
    > >> nice features.
    > >> http://www.objectstyle.org/cayenne/userguide/fetch/sqltemplate.html
    > >>
    > >> Does cayenne support using a attribute based on a function like min,
    > >> max, sum, count and avg in the model? The attribute needs to be read
    > >> only and should not be included when the table are created. I think
    > >> this is supported by EOF. The argument to the function could be a
    > >> path.
    > >> E.g: The Company ObjEntity could have a attribute named maxSallery
    > >> defined as max(employe.sallery).
    > >>
    > >> Regards,
    > >> - Tore.



    This archive was generated by hypermail 2.0.0 : Sun Aug 01 2004 - 22:53:58 EDT