From e8cc3ccbf93485242900d0d39f0f5f93d82b7a85 Mon Sep 17 00:00:00 2001 From: Arturo Gonzalez Diaz Date: Wed, 21 Oct 2015 13:57:05 +0200 Subject: [PATCH] Fixed sql problemas in incidents section (oracle). Ticket#2902 --- .../godmode/agentes/agent_incidents.php | 17 ++++++-- pandora_console/include/functions_graph.php | 41 +++++++++++++++---- .../operation/incidents/incident.php | 8 +++- 3 files changed, 51 insertions(+), 15 deletions(-) diff --git a/pandora_console/godmode/agentes/agent_incidents.php b/pandora_console/godmode/agentes/agent_incidents.php index b4f889e808..e81d213dc0 100644 --- a/pandora_console/godmode/agentes/agent_incidents.php +++ b/pandora_console/godmode/agentes/agent_incidents.php @@ -40,10 +40,19 @@ $url = "index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=inciden //Select incidencts where the user has access to ($groups from //get_user_groups), array_keys for the id, implode to pass to SQL -$sql = "SELECT * FROM tincidencia WHERE - id_grupo IN (".implode (",",array_keys ($groups)).")".$filter." - ORDER BY actualizacion DESC LIMIT ".$offset.",".$config["block_size"]; - +switch ($config["dbtype"]) { + case 'mysql': + $sql = "SELECT * FROM tincidencia WHERE + id_grupo IN (".implode (",",array_keys ($groups)).")".$filter." + ORDER BY actualizacion DESC LIMIT ".$offset.",".$config["block_size"]; + break; + case 'oracle': + $sql = "SELECT * FROM tincidencia WHERE + id_grupo IN (".implode (",",array_keys ($groups)).")".$filter." + AND rownum <= " . $offset.",".$config["block_size"] . " + ORDER BY actualizacion DESC"; + break; +} $result = db_get_all_rows_sql ($sql); $count_sql = "SELECT count(*) FROM tincidencia WHERE diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index 0518087ac2..c1616837a2 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -2233,11 +2233,23 @@ function graphic_incident_group () { $data = array (); $max_items = 5; - $sql = sprintf ('SELECT COUNT(id_incidencia) n_incidents, nombre - FROM tincidencia,tgrupo - WHERE tgrupo.id_grupo = tincidencia.id_grupo - GROUP BY tgrupo.id_grupo, nombre ORDER BY 1 DESC LIMIT %d', - $max_items); + switch ($config["dbtype"]) { + case 'mysql': + $sql = sprintf ('SELECT COUNT(id_incidencia) n_incidents, nombre + FROM tincidencia,tgrupo + WHERE tgrupo.id_grupo = tincidencia.id_grupo + GROUP BY tgrupo.id_grupo, nombre ORDER BY 1 DESC LIMIT %d', + $max_items); + break; + case 'oracle': + $sql = sprintf ('SELECT COUNT(id_incidencia) n_incidents, nombre + FROM tincidencia,tgrupo + WHERE tgrupo.id_grupo = tincidencia.id_grupo + AND rownum <= %d + GROUP BY tgrupo.id_grupo, nombre ORDER BY 1 DESC', + $max_items); + break; + } $incidents = db_get_all_rows_sql ($sql); $sql = sprintf ('SELECT COUNT(id_incidencia) n_incidents @@ -2279,10 +2291,21 @@ function graphic_incident_user () { $data = array (); $max_items = 5; - $sql = sprintf ('SELECT COUNT(id_incidencia) n_incidents, id_usuario - FROM tincidencia - GROUP BY id_usuario - ORDER BY 1 DESC LIMIT %d', $max_items); + switch ($config["dbtype"]) { + case 'mysql': + $sql = sprintf ('SELECT COUNT(id_incidencia) n_incidents, id_usuario + FROM tincidencia + GROUP BY id_usuario + ORDER BY 1 DESC LIMIT %d', $max_items); + break; + case 'oracle': + $sql = sprintf ('SELECT COUNT(id_incidencia) n_incidents, id_usuario + FROM tincidencia + WHERE rownum <= %d + GROUP BY id_usuario + ORDER BY 1 DESC', $max_items); + break; + } $incidents = db_get_all_rows_sql ($sql); if ($incidents == false) { diff --git a/pandora_console/operation/incidents/incident.php b/pandora_console/operation/incidents/incident.php index 5b9c7116b2..871b2e8836 100755 --- a/pandora_console/operation/incidents/incident.php +++ b/pandora_console/operation/incidents/incident.php @@ -196,9 +196,13 @@ switch ($config["dbtype"]) { break; case "postgresql": case "oracle": - $sql = "SELECT * FROM tincidencia WHERE + $set = array(); + $set['limit'] = $config["block_size"]; + $set['offset'] = $offset; + $sql = "SELECT * FROM tincidencia WHERE id_grupo IN (".implode (",",array_keys ($groups)).")".$filter." - ORDER BY actualizacion DESC OFFSET ".$offset." LIMIT ".$config["block_size"]; + ORDER BY actualizacion DESC"; + $sql = oracle_recode_query ($sql, $set); $count_sql = "SELECT count(*) FROM tincidencia WHERE id_grupo IN (".implode (",",array_keys ($groups)).")".$filter; $total_sql = "SELECT count(*) FROM tincidencia WHERE