Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SELECT DISTINCT tb.* FROM (
  2.             SELECT DISTINCT usuario.nome, sistema.* FROM usuario
  3.             INNER JOIN usuario_unidade ON usuario_unidade.cpf_usuario = usuario.cpf
  4.             INNER JOIN unidade ON unidade.id = usuario_unidade.id_unidade AND unidade.ativo = 'A'
  5.             INNER JOIN unidade_sistema ON unidade_sistema.id_unidade = unidade.id
  6.             INNER JOIN sistema ON sistema.id = unidade_sistema.id_sistema
  7.             INNER JOIN sistema_menu_associacao ON sistema_menu_associacao.sistema_id = sistema.id AND sistema_menu_associacao.unidade_id = unidade.id
  8.             INNER JOIN sistema_menu ON sistema_menu.id = sistema_menu_associacao.menu_id AND sistema_menu.ativo = TRUE
  9.             WHERE usuario.cpf = '$cpf' AND usuario.senha = '$senha' AND NOT sistema.id IN (1, 6, 10, 16)
  10.  
  11.             AND EXISTS ( SELECT tb.* FROM
  12.                DBLINK
  13.                  (  'dbname='||sistema.banco_dados||'
  14.                    hostaddr=127.0.0.1
  15.                    user=postgres
  16.                    password=postgres
  17.                    port=5555'::text,
  18.                   'SELECT cpf_usuario, id_empresa, id_menu FROM usuario_liberacao
  19.                  WHERE id_empresa = '||unidade.id::text
  20.                  ) AS tb ( cpf_usuario character varying(11),
  21.                            id_empresa integer,
  22.                            id_menu integer
  23.                          )
  24.                 INNER JOIN sistema_menu ON sistema_menu.id = tb.id_menu
  25.                 WHERE sistema_menu.sistema_id = sistema.id
  26.                 AND sistema.cliente <> 'S'
  27.                 AND tb.cpf_usuario = '$cpf'
  28.             )
  29.  
  30.           UNION ALL
  31.  
  32.             SELECT usuario.nome, sistema.* FROM sistema
  33.             INNER JOIN  DBLINK
  34.                   ('dbname='||sistema.banco_dados||'
  35.                     hostaddr=127.0.0.1
  36.                     user=postgres
  37.                     password=postgres
  38.                     port=5555'::text,
  39.                    'SELECT cpf, senha, nome FROM usuario_cliente'::text
  40.                   ) AS usuario ( cpf character varying(11),
  41.                             senha character varying(50),
  42.                             nome character varying(200))
  43.               ON usuario.cpf = '06353864965' AND usuario.senha = 'Bud5029'
  44.             WHERE (sistema.cliente = 'S' OR sistema.id IN (15)) AND NOT sistema.id IN (1, 6, 10, 16)
  45.           ) AS tb
  46.           ORDER BY tb.id ASC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement