Commit 62add16dc4c907cb535b419d40daa10aeb36d17a

Authored by Guilherme Andrade Del Cantoni
1 parent 29a37c57

Alinhamento de compatibilidade de scripts entre Oracle e SQLServer

Showing 1 changed file with 12 additions and 5 deletions   Show diff stats
rn/ProcessoExpedidoRN.php
... ... @@ -15,9 +15,11 @@ class ProcessoExpedidoRN extends InfraRN {
15 15 public function listarProcessoExpedido(ProtocoloDTO &$objProtocoloDTO) {
16 16  
17 17 $bolSqlServer = $this->getObjInfraIBanco() instanceof InfraSqlServer;
  18 + $bolOracle = $this->getObjInfraIBanco() instanceof InfraOracle;
18 19 $numLimit = $objProtocoloDTO->getNumMaxRegistrosRetorno();
19 20 $numOffset = $objProtocoloDTO->getNumPaginaAtual() * $objProtocoloDTO->getNumMaxRegistrosRetorno();
20 21 $strInstrucaoPaginacao = (!$bolSqlServer) ? "LIMIT ".$numOffset.",".$numLimit : "OFFSET $numOffset ROWS FETCH NEXT $numLimit ROWS ONLY";
  22 + $strInstrucaoPaginacao = ($bolOracle) ? "" : $strInstrucaoPaginacao;
21 23  
22 24 $sql = "SELECT
23 25 p.id_protocolo,
... ... @@ -41,14 +43,20 @@ class ProcessoExpedidoRN extends InfraRN {
41 43 ptra.dth_registro = (SELECT MAX(pt.dth_registro) dth_registro FROM md_pen_tramite pt WHERE pt.numero_registro = pe.numero_registro)
42 44 AND
43 45 NOT EXISTS (
44   - SELECT at2.* FROM atividade as at2
  46 + SELECT at2.* FROM atividade at2
45 47 WHERE at2.id_protocolo = p.id_protocolo
46 48 AND at2.id_tarefa = ". ProcessoEletronicoRN::obterIdTarefaModulo(ProcessoEletronicoRN::$TI_PROCESSO_ELETRONICO_PROCESSO_RECEBIDO) ."
47 49 AND at2.dth_abertura > a.dth_abertura )
48 50 GROUP BY
49 51 p.id_protocolo, p.protocolo_formatado, a.id_unidade , atd.valor , us.id_usuario, us.nome, a.dth_abertura ORDER BY a.dth_abertura DESC ".$strInstrucaoPaginacao;
50 52  
51   - $sqlCount = "SELECT
  53 +
  54 + if ($this->getObjInfraIBanco() instanceof InfraOracle){
  55 + $qtd = $numLimit + $numLimit;
  56 + $sql = "select a.* from ($sql) a where rownum >= $numOffset and rownum <= $qtd";
  57 + }
  58 +
  59 + $sqlCount = "SELECT
52 60 count(*) total
53 61 FROM protocolo p
54 62 INNER JOIN atividade a ON a.id_protocolo = p.id_protocolo
... ... @@ -64,13 +72,12 @@ class ProcessoExpedidoRN extends InfraRN {
64 72 ptra.dth_registro = (SELECT MAX(pt.dth_registro) dth_registro FROM md_pen_tramite pt WHERE pt.numero_registro = pe.numero_registro)
65 73 AND
66 74 NOT EXISTS (
67   - SELECT at2.* FROM atividade as at2
  75 + SELECT at2.* FROM atividade at2
68 76 WHERE at2.id_protocolo = p.id_protocolo
69 77 AND at2.id_tarefa = ". ProcessoEletronicoRN::obterIdTarefaModulo(ProcessoEletronicoRN::$TI_PROCESSO_ELETRONICO_PROCESSO_RECEBIDO) ."
70 78 AND at2.dth_abertura > a.dth_abertura ) ";
71 79  
72   -
73   -
  80 +//die($sql);
74 81 $pag = $this->getObjInfraIBanco()->consultarSql($sql);
75 82 $count = $this->getObjInfraIBanco()->consultarSql($sqlCount);
76 83 $total = $count ? $count[0]['total'] : 0;
... ...