Fixed sql problemas in incidents section (oracle). Ticket#2902

This commit is contained in:
Arturo Gonzalez Diaz 2015-10-21 13:57:05 +02:00
parent 7aed427a7a
commit e8cc3ccbf9
3 changed files with 51 additions and 15 deletions

View File

@ -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

View File

@ -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) {

View File

@ -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