Query returns another user’s value

Asked

Viewed 37 times

1

I am not able to compare the code (from the logged in professional) with the hired code (which should be the same as the logged professional) in sql query and this makes the query return a value of another professional.

Below is the excerpt of the code:

FacesContext context = FacesContext.getCurrentInstance();
ELResolver resolver = context.getApplication().getELResolver();
LoginControllerOnline controller = new LoginControllerOnline();
controller = (LoginControllerOnline) 
resolver.getValue(context.getELContext(), null, "loginControllerOnline");
pessoa = controller.getPessoa();

if(pessoa instanceof Profissional) {
    Profissional profissional = (Profissional) pessoa;
    Map<String, Object> params = new HashMap<String, Object>();
    String queryArtWeb = "SELECT aw.numeroart, aw.dataElaboracao, p.nome as nomeprofissional, pe.nome as nomeempresa, "
                + "(SELECT nome FROM IdentificacaoContratoArtWeb contrato WHERE contrato.numeroart=aw.numeroart and sequencialcontrato = 1 and sequencialidentificacao = 1) as nomecontratante, "
                + "t.idTipoArt, t.descricao as tipoArt, st.idSubtipoArt, st.descricao as subtipoArt, "
                + "aw.nomeProfissionalContratado, aw.nomeEmpresaContratada "
                + "FROM ArtWeb aw "
                + "LEFT JOIN pessoa p ON p.codigo = aw.codigoprofissionalcontratado "
                + "LEFT JOIN pessoa pe ON pe.codigo = aw.codigoempresacontratada "
                + "LEFT JOIN empresa e ON e.codigo = pe.codigo "
                + "LEFT JOIN TipoArt t ON t.idTipoArt = aw.tipoArt_idTipoArt "
                + "LEFT JOIN SubtipoArt st ON st.idSubtipoArt = aw.subtipoArt_idSubtipoArt "
                + "WHERE aw.codigoprofissionalcontratado = :codigo AND aw.databaixa IS NULL AND datapagamento IS NOT NULL OR valortaxa = 0";


    params.put("codigo", profissional.getCodigo());

    List<Object[]> registrosArtWeb = objectDao.listPesqQuery(queryArtWeb, params);

1 answer

0


In the where probably missing parentheses around clause OR.

WHERE   aw.codigoprofissionalcontratado = :codigo AND 
        aw.databaixa IS NULL AND 
        (datapagamento IS NOT NULL OR valortaxa = 0)
  • 1

    That’s right, pure lack of attention. Thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.