2011-05-16 Juan Manuel Ramon <juanmanuel.ramon@artica.es>

include/functions_graph.php
	include/db/oracle.php
	include/functions_modules.php
	include/functions_network_components.php
	operation/agentes/estado_monitores.php: Several corrections over
	sql queries for Oracle DBMS.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4359 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
juanmanuelr 2011-05-16 16:56:14 +00:00
parent be995bedee
commit c1de8a9dea
6 changed files with 153 additions and 36 deletions

View File

@ -1,3 +1,12 @@
2011-05-16 Juan Manuel Ramon <juanmanuel.ramon@artica.es>
include/functions_graph.php
include/db/oracle.php
include/functions_modules.php
include/functions_network_components.php
operation/agentes/estado_monitores.php: Several corrections over
sql queries for Oracle DBMS.
2011-05-16 Juan Manuel Ramon <juanmanuel.ramon@artica.es>
* include/config_process.php

View File

@ -67,15 +67,15 @@ function oracle_connect_db($host = null, $db = null, $user = null, $pass = null)
function oracle_db_get_value ($field, $table, $field_search = 1, $condition = 1, $search_history_db = false) {
if (is_int ($condition)) {
$sql = sprintf ("SELECT %s FROM %s WHERE %s = %d AND rownum < 2",
$sql = sprintf ("SELECT * FROM (SELECT %s FROM %s WHERE %s = %d) WHERE rownum < 2",
$field, $table, $field_search, $condition);
}
else if (is_float ($condition) || is_double ($condition)) {
$sql = sprintf ("SELECT %s FROM %s WHERE %s = %f AND rownum < 2",
$sql = sprintf ("SELECT * FROM (SELECT %s FROM %s WHERE %s = %f) WHERE rownum < 2",
$field, $table, $field_search, $condition);
}
else {
$sql = sprintf ("SELECT %s FROM %s WHERE %s = '%s' AND rownum < 2",
$sql = sprintf ("SELECT * FROM (SELECT %s FROM %s WHERE %s = '%s') WHERE rownum < 2",
$field, $table, $field_search, $condition);
}
@ -120,15 +120,15 @@ function oracle_db_get_row ($table, $field_search, $condition, $fields = false)
}
if (is_int ($condition)) {
$sql = sprintf ('SELECT %s FROM %s WHERE %s = %d AND rownum < 2',
$sql = sprintf ('SELECT * FROM (SELECT %s FROM %s WHERE %s = %d) WHERE rownum < 2',
$fields, $table, $field_search, $condition);
}
else if (is_float ($condition) || is_double ($condition)) {
$sql = sprintf ("SELECT %s FROM %s WHERE \"%s\" = %f AND rownum < 2",
$sql = sprintf ("SELECT * FROM (SELECT %s FROM %s WHERE \"%s\" = %f) WHERE rownum < 2",
$fields, $table, $field_search, $condition);
}
else {
$sql = sprintf ("SELECT %s FROM %s WHERE %s = '%s' AND rownum < 2",
$sql = sprintf ("SELECT * FROM (SELECT %s FROM %s WHERE %s = '%s') WHERE rownum < 2",
$fields, $table, $field_search, $condition);
}
$result = db_get_all_rows_sql ($sql);
@ -396,6 +396,9 @@ function oracle_db_process_sql_insert($table, $values, $autocommit = true) {
else if (is_float ($value) || is_double ($value)) {
$values_str .= sprintf("%f", $value);
}
else if (substr($value,0,1) == '#'){
$values_str .= sprintf("%s", substr($value,1));
}
else {
$values_str .= sprintf("'%s'", $value);
}
@ -462,7 +465,7 @@ function oracle_db_get_value_filter ($field, $table, $filter, $where_join = 'AND
unset ($filter['limit']);
unset ($filter['offset']);
$sql = sprintf ("SELECT %s FROM %s WHERE %s AND rownum < 2",
$sql = sprintf ("SELECT * FROM (SELECT %s FROM %s WHERE %s) WHERE rownum < 2",
$field, $table,
db_format_array_where_clause_sql ($filter, $where_join));
@ -1348,4 +1351,42 @@ function oracle_db_get_type_field_table($table, $field) {
return $type;
}
/**
* Get all field names of a table and recode fields
* for clob datatype as "dbms_lob.substr(<field>, 4000 ,1) as <field>".
*
* @param string $table The table to retrieve all column names.
* @param integer $return_mode Whether to return as array (by default) or as comma separated string.
*
* @return mixed Return an array/string of table fields or false if something goes wrong.
*/
function oracle_list_all_field_table($table_name, $return_mode = 'array'){
if (empty($table_name)){
return false;
}
$fields_info = db_get_all_rows_field_filter('user_tab_columns', 'table_name', strtoupper($table_name));
if (empty($fields_info)){
return false;
}
$field_list = array();
foreach ($fields_info as $field){
if ($field['data_type'] == 'CLOB'){
$new_field = 'dbms_lob.substr(' . $field['table_name'] . '.' . $field['column_name'] . ', 4000, 1) as ' . strtolower($field['column_name']);
$field_list[] = $new_field;
}
else{
$field_list[] = strtolower($field['table_name'] . '.' . $field['column_name']);
}
}
// Return as comma separated string
if ($return_mode == 'string'){
return implode(',', $field_list);
}
// Return as array
else{
return $field_list;
}
}
?>

View File

@ -707,11 +707,23 @@ function graphic_agentaccess2 ($id_agent, $width, $height, $period = 0) {
}
$top = $datelimit + ($periodtime * ($i + 1));
$data[$name]['data'] = (int) db_get_value_filter ('COUNT(*)',
'tagent_access',
array ('id_agent' => $id_agent,
'utimestamp > '.$bottom,
'utimestamp < '.$top));
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
$data[$name]['data'] = (int) db_get_value_filter ('COUNT(*)',
'tagent_access',
array ('id_agent' => $id_agent,
'utimestamp > '.$bottom,
'utimestamp < '.$top));
break;
case "oracle":
$data[$name]['data'] = (int) db_get_value_filter ('count(*)',
'tagent_access',
array ('id_agent' => $id_agent,
'utimestamp > '.$bottom,
'utimestamp < '.$top));
break;
}
}
echo area_graph($config['flash_charts'], $data, $width, $height,
@ -733,12 +745,24 @@ function graph_event_module2 ($width = 300, $height = 200, $id_agent) {
$data = array ();
$max_items = 6;
$sql = sprintf ('SELECT COUNT(id_evento) as count_number, nombre
FROM tevento, tagente_modulo
WHERE id_agentmodule = id_agente_modulo
AND disabled = 0 AND tevento.id_agente = %d
GROUP BY id_agentmodule, nombre LIMIT %d', $id_agent, $max_items);
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
$sql = sprintf ('SELECT COUNT(id_evento) as count_number, nombre
FROM tevento, tagente_modulo
WHERE id_agentmodule = id_agente_modulo
AND disabled = 0 AND tevento.id_agente = %d
GROUP BY id_agentmodule, nombre LIMIT %d', $id_agent, $max_items);
break;
case "oracle":
$sql = sprintf ('SELECT COUNT(id_evento) as count_number, dbms_lob.substr(nombre,4000,1) as nombre
FROM tevento, tagente_modulo
WHERE (id_agentmodule = id_agente_modulo
AND disabled = 0 AND tevento.id_agente = %d) AND rownum <= %d
GROUP BY id_agentmodule, dbms_lob.substr(nombre,4000,1)', $id_agent, $max_items);
break;
}
$events = db_get_all_rows_sql ($sql);
if ($events === false) {
if (! $graphic_type) {

View File

@ -253,7 +253,7 @@ function modules_create_agent_module ($id_agent, $name, $values = false, $disabl
$result = db_process_sql_insert ('tagente_estado',
array ('id_agente_modulo' => $id_agent_module,
'datos' => 0,
'timestamp' => 'to_date(01-01-1970 00:00:00, \'YYYY-MM-DD HH24:MI:SS\')',
'timestamp' => '#to_date(\'1970-01-01 00:00:00\', \'YYYY-MM-DD HH24:MI:SS\')',
'estado' => 0,
'id_agente' => (int) $id_agent,
'utimestamp' => 0,

View File

@ -131,6 +131,7 @@ function network_components_get_groups ($id_module_components = 0, $localCompone
/* Special vars to keep track of indentation level */
static $level = 0;
static $id_parent = 0;
global $config;
$groups = db_get_all_rows_filter ('tnetwork_component_group',
array ('parent' => $id_parent),
@ -155,9 +156,17 @@ function network_components_get_groups ($id_module_components = 0, $localCompone
$retval = $retval + $childs;
}
else {
$count = db_get_value_filter ('COUNT(*)', 'tlocal_component',
array ('id_network_component_group' => (int) $group['id_sg']));
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
$count = db_get_value_filter ('COUNT(*)', 'tlocal_component',
array ('id_network_component_group' => (int) $group['id_sg']));
break;
case "oracle":
$count = db_get_value_filter ('count(*)', 'tlocal_component',
array ('id_network_component_group' => (int) $group['id_sg']));
break;
}
if ($count > 0)
$retval[$group['id_sg']] = $prefix.$group['name'];
}
@ -172,9 +181,19 @@ function network_components_get_groups ($id_module_components = 0, $localCompone
/* If components id module is provided, only groups with components
that belongs to this id module are returned */
if ($id_module_components) {
$count = db_get_value_filter ('COUNT(*)', 'tnetwork_component',
array ('id_group' => (int) $group['id_sg'],
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
$count = db_get_value_filter ('COUNT(*)', 'tnetwork_component',
array ('id_group' => (int) $group['id_sg'],
'id_modulo' => $id_module_components));
break;
case "oracle":
$count = db_get_value_filter ('count(*)', 'tnetwork_component',
array ('id_group' => (int) $group['id_sg'],
'id_modulo' => $id_module_components));
break;
}
if ($count > 0)
$retval[$group['id_sg']] = $prefix.$group['name'];
}

View File

@ -130,18 +130,42 @@ switch ($config["dbtype"]) {
// Get all module from agent
$sql = sprintf ("
SELECT *
FROM tagente_estado, tagente_modulo
LEFT JOIN tmodule_group
ON tmodule_group.id_mg = tagente_modulo.id_module_group
WHERE tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
AND tagente_modulo.id_agente = %d
AND tagente_modulo.disabled = 0
AND tagente_modulo.delete_pending = 0
AND tagente_estado.utimestamp != 0
ORDER BY tagente_modulo.id_module_group , %s %s
", $id_agente, $order['field'], $order['order']);
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
$sql = sprintf ("
SELECT *
FROM tagente_estado, tagente_modulo
LEFT JOIN tmodule_group
ON tmodule_group.id_mg = tagente_modulo.id_module_group
WHERE tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
AND tagente_modulo.id_agente = %d
AND tagente_modulo.disabled = 0
AND tagente_modulo.delete_pending = 0
AND tagente_estado.utimestamp != 0
ORDER BY tagente_modulo.id_module_group , %s %s
", $id_agente, $order['field'], $order['order']);
break;
// If Dbms is Oracle then field_list in sql statement has to be recoded. See oracle_list_all_field_table()
case "oracle":
$fields_tagente_estado = oracle_list_all_field_table('tagente_estado', 'string');
$fields_tagente_modulo = oracle_list_all_field_table('tagente_modulo', 'string');
$fields_tmodule_group = oracle_list_all_field_table('tmodule_group', 'string');
$sql = sprintf ("
SELECT " . $fields_tagente_estado . ', ' . $fields_tagente_modulo . ', ' . $fields_tmodule_group .
" FROM tagente_estado, tagente_modulo
LEFT JOIN tmodule_group
ON tmodule_group.id_mg = tagente_modulo.id_module_group
WHERE tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
AND tagente_modulo.id_agente = %d
AND tagente_modulo.disabled = 0
AND tagente_modulo.delete_pending = 0
AND tagente_estado.utimestamp != 0
ORDER BY tagente_modulo.id_module_group , %s %s
", $id_agente, $order['field'], $order['order']);
break;
}
$modules = db_get_all_rows_sql ($sql);
if (empty ($modules)) {