Fixes for the Oracl€.

This commit is contained in:
mdtrooper 2015-06-02 19:10:11 +02:00
parent f2539395c3
commit 11d2b66b30
8 changed files with 315 additions and 97 deletions

View File

@ -1302,9 +1302,29 @@ function print_SLA_list($width, $action, $idItem = null) {
echo '<td class="sla_list_service_col">' . printSmallFont($nameService) . '</th>'; echo '<td class="sla_list_service_col">' . printSmallFont($nameService) . '</th>';
} }
echo '<td class="sla_list_sla_min_col">' . $item['sla_min'] . '</td>'; switch ($config['dbtype']) {
echo '<td class="sla_list_sla_max_col">' . $item['sla_max'] . '</td>'; case "mysql":
echo '<td class="sla_list_sla_limit_col">' . $item['sla_limit'] . '</td>'; case "postgresql":
$item_sla_min = $item['sla_min'];
$item_sla_max = $item['sla_max'];
$item_sla_limit = $item['sla_limit'];
break;
case "oracle":
$item_sla_min =
oracle_format_float_to_php($item['sla_min']);
$item_sla_max =
oracle_format_float_to_php($item['sla_max']);
$item_sla_limit =
oracle_format_float_to_php($item['sla_limit']);
break;
}
echo '<td class="sla_list_sla_min_col">' .
$item_sla_min . '</td>';
echo '<td class="sla_list_sla_max_col">' .
$item_sla_max . '</td>';
echo '<td class="sla_list_sla_limit_col">' .
$item_sla_limit . '</td>';
echo '<td class="sla_list_action_col" style="text-align: center;"> echo '<td class="sla_list_action_col" style="text-align: center;">
<a href="javascript: deleteSLARow(' . $item['id'] . ');">' . html_print_image("images/cross.png", true) . '</a> <a href="javascript: deleteSLARow(' . $item['id'] . ');">' . html_print_image("images/cross.png", true) . '</a>
</td>'; </td>';

View File

@ -944,8 +944,17 @@ switch ($action) {
$values['friday'] = get_parameter('friday', 0); $values['friday'] = get_parameter('friday', 0);
$values['saturday'] = get_parameter('saturday', 0); $values['saturday'] = get_parameter('saturday', 0);
$values['sunday'] = get_parameter('sunday', 0); $values['sunday'] = get_parameter('sunday', 0);
switch ($config['dbtype']) {
case "mysql":
case "postgresql":
$values['time_from'] = get_parameter('time_from'); $values['time_from'] = get_parameter('time_from');
$values['time_to'] = get_parameter('time_to'); $values['time_to'] = get_parameter('time_to');
break;
case "oracle":
$values['time_from'] = '#to_date(\'' . get_parameter('time_from') . '\',\'hh24:mi:ss\')';
$values['time_to'] = '#to_date(\'' . get_parameter('time_to') . '\', \'hh24:mi:ss\')';
break;
}
$values['group_by_agent'] = get_parameter ('checkbox_row_group_by_agent'); $values['group_by_agent'] = get_parameter ('checkbox_row_group_by_agent');
$values['show_resume'] = get_parameter ('checkbox_show_resume'); $values['show_resume'] = get_parameter ('checkbox_show_resume');
$values['order_uptodown'] = get_parameter ('radiobutton_order_uptodown'); $values['order_uptodown'] = get_parameter ('radiobutton_order_uptodown');
@ -1062,6 +1071,18 @@ switch ($action) {
$values['style'] = io_safe_input(json_encode($style)); $values['style'] = io_safe_input(json_encode($style));
if ($good_format) { if ($good_format) {
switch ($config["dbtype"]) {
case "oracle":
if (isset($values['type'])) {
$values[
db_encapsule_fields_with_same_name_to_instructions(
"type")] = $values['type'];
unset($values['type']);
}
break;
}
$resultOperationDB = db_process_sql_update( $resultOperationDB = db_process_sql_update(
'treport_content', 'treport_content',
$values, $values,
@ -1351,11 +1372,15 @@ switch ($action) {
} }
switch ($config["dbtype"]) { switch ($config["dbtype"]) {
case "mysql": case "mysql":
db_process_sql_update('treport_content', array('`order`' => $max + 1), array('id_rc' => $idItem)); db_process_sql_update('treport_content',
array('`order`' => $max + 1),
array('id_rc' => $idItem));
break; break;
case "postgresql": case "postgresql":
case "oracle": case "oracle":
db_process_sql_update('treport_content', array('"order"' => $max + 1), array('id_rc' => $idItem)); db_process_sql_update('treport_content',
array('"order"' => $max + 1),
array('id_rc' => $idItem));
break; break;
} }
$resultOperationDB = true; $resultOperationDB = true;

0
pandora_console/include/ajax/reporting.ajax.php Normal file → Executable file
View File

View File

@ -429,6 +429,9 @@ function oracle_db_process_sql_insert($table, $values, $autocommit = true) {
$query .= ' VALUES (' . $values_str . ')'; $query .= ' VALUES (' . $values_str . ')';
$status = ''; $status = '';
return db_process_sql($query, 'insert_id', '', true, $status, $autocommit); return db_process_sql($query, 'insert_id', '', true, $status, $autocommit);
} }
@ -1189,6 +1192,10 @@ function oracle_db_process_sql_update($table, $values, $where = false, $where_jo
} }
$status = ''; $status = '';
return db_process_sql ($query, "affected_rows", '', true, $status, $autocommit); return db_process_sql ($query, "affected_rows", '', true, $status, $autocommit);
} }
@ -1582,4 +1589,8 @@ function oracle_db_process_file ($path, $handle_error = true) {
return false; return false;
} }
} }
function oracle_format_float_to_php($val) {
return floatval(str_replace(',', '.', $val));
}
?> ?>

View File

@ -2662,6 +2662,17 @@ function graph_custom_sql_graph ($id, $width, $height,
} }
} }
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
break;
case "oracle":
$sql = str_replace(";", "", $sql);
break;
}
$data_result = db_get_all_rows_sql ($sql); $data_result = db_get_all_rows_sql ($sql);
if (($config['metaconsole'] == 1) && defined('METACONSOLE')) if (($config['metaconsole'] == 1) && defined('METACONSOLE'))

View File

@ -481,6 +481,8 @@ function reporting_SLA($report, $content, $type = 'dinamic',
'treport_content_sla_combined', 'treport_content_sla_combined',
'id_report_content', $content['id_rc']); 'id_report_content', $content['id_rc']);
if (empty($slas)) { if (empty($slas)) {
$return['failed'] = __('There are no SLAs defined'); $return['failed'] = __('There are no SLAs defined');
} }
@ -501,6 +503,8 @@ function reporting_SLA($report, $content, $type = 'dinamic',
$return['planned_downtimes'] = array(); $return['planned_downtimes'] = array();
if ($metaconsole_on) { if ($metaconsole_on) {
$id_agent_modules_by_server = array(); $id_agent_modules_by_server = array();
@ -618,6 +622,9 @@ function reporting_SLA($report, $content, $type = 'dinamic',
} }
} }
else { else {
$id_agent_modules = array(); $id_agent_modules = array();
foreach ($slas as $sla) { foreach ($slas as $sla) {
if (!empty($sla['id_agent_module'])) if (!empty($sla['id_agent_module']))
@ -625,8 +632,13 @@ function reporting_SLA($report, $content, $type = 'dinamic',
} }
$planned_downtimes = reporting_get_planned_downtimes(($report['datetime']-$content['period']), $report['datetime'], $id_agent_modules); $planned_downtimes = reporting_get_planned_downtimes(($report['datetime']-$content['period']), $report['datetime'], $id_agent_modules);
$malformed_planned_downtimes = planned_downtimes_get_malformed(); $malformed_planned_downtimes = planned_downtimes_get_malformed();
if (!empty($planned_downtimes)) if (!empty($planned_downtimes))
$planned_downtimes_empty = false; $planned_downtimes_empty = false;
if (!empty($malformed_planned_downtimes)) if (!empty($malformed_planned_downtimes))
@ -721,6 +733,8 @@ function reporting_SLA($report, $content, $type = 'dinamic',
$sla_showed = array(); $sla_showed = array();
$sla_showed_values = array(); $sla_showed_values = array();
foreach ($slas as $sla) { foreach ($slas as $sla) {
$server_name = $sla ['server_name']; $server_name = $sla ['server_name'];
//Metaconsole connection //Metaconsole connection
@ -736,12 +750,18 @@ function reporting_SLA($report, $content, $type = 'dinamic',
continue; continue;
} }
//Get the sla_value in % and store it on $sla_value //Get the sla_value in % and store it on $sla_value
$sla_value = reporting_get_agentmodule_sla( $sla_value = reporting_get_agentmodule_sla(
$sla['id_agent_module'], $content['period'], $sla['id_agent_module'],
$sla['sla_min'], $sla['sla_max'], $content['period'],
$report["datetime"], $content, $sla['sla_min'],
$content['time_from'], $content['time_to']); $sla['sla_max'],
$report["datetime"],
$content,
$content['time_from'],
$content['time_to']);
if (($config ['metaconsole'] == 1) && defined('METACONSOLE')) { if (($config ['metaconsole'] == 1) && defined('METACONSOLE')) {
//Restore db connection //Restore db connection
@ -770,6 +790,8 @@ function reporting_SLA($report, $content, $type = 'dinamic',
} }
} }
$return['data'] = array(); $return['data'] = array();
$return['charts'] = null; $return['charts'] = null;
@ -793,9 +815,21 @@ function reporting_SLA($report, $content, $type = 'dinamic',
$sla['id_agent_module']); $sla['id_agent_module']);
$data['module'] = modules_get_agentmodule_name( $data['module'] = modules_get_agentmodule_name(
$sla['id_agent_module']); $sla['id_agent_module']);
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
$data['max'] = $sla['sla_max']; $data['max'] = $sla['sla_max'];
$data['min'] = $sla['sla_min']; $data['min'] = $sla['sla_min'];
$data['sla_limit'] = $sla['sla_limit']; $data['sla_limit'] = $sla['sla_limit'];
break;
case "oracle":
$data['max'] = oracle_format_float_to_php($sla['sla_max']);
$data['min'] = oracle_format_float_to_php($sla['sla_min']);
$data['sla_limit'] = oracle_format_float_to_php($sla['sla_limit']);
break;
}
$data['sla_value_unknown'] = 0; $data['sla_value_unknown'] = 0;
$data['sla_status'] = 0; $data['sla_status'] = 0;
@ -834,12 +868,15 @@ function reporting_SLA($report, $content, $type = 'dinamic',
} }
// Slice graphs calculation // Slice graphs calculation
if ($show_graphs) { if ($show_graphs) {
$dataslice = array(); $dataslice = array();
$dataslice['agent'] = modules_get_agentmodule_agent_name ($sla['id_agent_module']); $dataslice['agent'] = modules_get_agentmodule_agent_name ($sla['id_agent_module']);
$dataslice['module'] = modules_get_agentmodule_name ($sla['id_agent_module']); $dataslice['module'] = modules_get_agentmodule_name ($sla['id_agent_module']);
$dataslice['chart'] = graph_sla_slicebar( $dataslice['chart'] = graph_sla_slicebar(
$sla['id_agent_module'], $sla['id_agent_module'],
$content['period'], $content['period'],
@ -859,6 +896,8 @@ function reporting_SLA($report, $content, $type = 'dinamic',
$return['charts'][] = $dataslice; $return['charts'][] = $dataslice;
} }
if ($config ['metaconsole'] == 1 && defined('METACONSOLE')) { if ($config ['metaconsole'] == 1 && defined('METACONSOLE')) {
//Restore db connection //Restore db connection
metaconsole_restore_db(); metaconsole_restore_db();
@ -868,6 +907,7 @@ function reporting_SLA($report, $content, $type = 'dinamic',
} }
return reporting_check_structure_content($return); return reporting_check_structure_content($return);
} }
@ -6443,6 +6483,8 @@ function reporting_get_agentmodule_sla ($id_agent_module, $period = 0,
$timeTo); $timeTo);
} }
else { else {
// Extract the data each day // Extract the data each day
$sla = 0; $sla = 0;
@ -6494,7 +6536,41 @@ function reporting_get_planned_downtimes_intervals ($id_agent_module, $start_dat
if (empty($malformed_planned_downtimes)) if (empty($malformed_planned_downtimes))
$malformed_planned_downtimes = array(); $malformed_planned_downtimes = array();
$sql_downtime = "SELECT DISTINCT(tpdr.id), tpdr.* switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
$tpdr_description = "tpdr.description";
break;
case "oracle":
$tpdr_description = "to_char(tpdr.description)";
break;
}
$sql_downtime = "
SELECT DISTINCT(tpdr.id),
tpdr.name,
" . $tpdr_description . ",
tpdr.date_from,
tpdr.date_to,
tpdr.executed,
tpdr.id_group,
tpdr.only_alerts,
tpdr.monday,
tpdr.tuesday,
tpdr.wednesday,
tpdr.thursday,
tpdr.friday,
tpdr.saturday,
tpdr.sunday,
tpdr.periodically_time_from,
tpdr.periodically_time_to,
tpdr.periodically_day_from,
tpdr.periodically_day_to,
tpdr.type_downtime,
tpdr.type_execution,
tpdr.type_periodicity,
tpdr.id_user
FROM ( FROM (
SELECT tpd.* SELECT tpd.*
FROM tplanned_downtime tpd, tplanned_downtime_agents tpda, tagente_modulo tam FROM tplanned_downtime tpd, tplanned_downtime_agents tpda, tagente_modulo tam
@ -6510,6 +6586,8 @@ function reporting_get_planned_downtimes_intervals ($id_agent_module, $start_dat
) tpdr ) tpdr
ORDER BY tpdr.id"; ORDER BY tpdr.id";
$downtimes = db_get_all_rows_sql($sql_downtime); $downtimes = db_get_all_rows_sql($sql_downtime);
if ($downtimes == false) { if ($downtimes == false) {
@ -6994,6 +7072,8 @@ function reporting_get_agentmodule_data_sum ($id_agent_module,
* agent modules selected. * agent modules selected.
*/ */
function reporting_get_planned_downtimes ($start_date, $end_date, $id_agent_modules = false) { function reporting_get_planned_downtimes ($start_date, $end_date, $id_agent_modules = false) {
global $config;
$start_time = date("H:i:s", $start_date); $start_time = date("H:i:s", $start_date);
$end_time = date("H:i:s", $end_date); $end_time = date("H:i:s", $end_date);
@ -7097,7 +7177,41 @@ function reporting_get_planned_downtimes ($start_date, $end_date, $id_agent_modu
$id_agent_modules_str = implode(",", $id_agent_modules); $id_agent_modules_str = implode(",", $id_agent_modules);
$sql_downtime = "SELECT DISTINCT(tpdr.id), tpdr.* switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
$tpdr_description = "tpdr.description";
break;
case "oracle":
$tpdr_description = "to_char(tpdr.description)";
break;
}
$sql_downtime = "
SELECT
DISTINCT(tpdr.id),
tpdr.name,
" . $tpdr_description . ",
tpdr.date_from,
tpdr.date_to,
tpdr.executed,
tpdr.id_group,
tpdr.only_alerts,
tpdr.monday,
tpdr.tuesday,
tpdr.wednesday,
tpdr.thursday,
tpdr.friday,
tpdr.saturday,
tpdr.sunday,
tpdr.periodically_time_from,
tpdr.periodically_time_to,
tpdr.periodically_day_from,
tpdr.periodically_day_to,
tpdr.type_downtime,
tpdr.type_execution,
tpdr.type_periodicity,
tpdr.id_user
FROM ( FROM (
SELECT tpd.* SELECT tpd.*
FROM tplanned_downtime tpd, tplanned_downtime_agents tpda, tagente_modulo tam FROM tplanned_downtime tpd, tplanned_downtime_agents tpda, tagente_modulo tam
@ -7188,6 +7302,8 @@ function reporting_get_agentmodule_sla_day ($id_agent_module, $period = 0, $min_
AND utimestamp > %d AND utimestamp <= %d', AND utimestamp > %d AND utimestamp <= %d',
$id_agent_module, $datelimit, $date); $id_agent_module, $datelimit, $date);
//Add the working times (mon - tue - wed ...) and from time to time //Add the working times (mon - tue - wed ...) and from time to time
$days = array(); $days = array();
//Translate to mysql week days //Translate to mysql week days
@ -7219,26 +7335,42 @@ function reporting_get_agentmodule_sla_day ($id_agent_module, $period = 0, $min_
} }
} }
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
if (count($days) > 0) { if (count($days) > 0) {
$sql .= ' AND DAYOFWEEK(FROM_UNIXTIME(utimestamp)) NOT IN (' . implode(',', $days) . ')'; $sql .= ' AND DAYOFWEEK(FROM_UNIXTIME(utimestamp)) NOT IN (' . implode(',', $days) . ')';
} }
if ($timeFrom < $timeTo) { if ($timeFrom < $timeTo) {
$sql .= ' AND (TIME(FROM_UNIXTIME(utimestamp)) >= "' . $timeFrom . '" AND TIME(FROM_UNIXTIME(utimestamp)) <= "'. $timeTo . '")'; $sql .= ' AND (TIME(FROM_UNIXTIME(utimestamp)) >= "' . $timeFrom . '" AND TIME(FROM_UNIXTIME(utimestamp)) <= "'. $timeTo . '")';
} }
elseif ($timeFrom > $timeTo) { elseif ($timeFrom > $timeTo) {
$sql .= ' AND (TIME(FROM_UNIXTIME(utimestamp)) >= "' . $timeFrom . '" OR TIME(FROM_UNIXTIME(utimestamp)) <= "'. $timeTo . '")'; $sql .= ' AND (TIME(FROM_UNIXTIME(utimestamp)) >= "' . $timeFrom . '" OR TIME(FROM_UNIXTIME(utimestamp)) <= "'. $timeTo . '")';
} }
break;
case "oracle":
break;
}
$sql .= ' ORDER BY utimestamp ASC'; $sql .= ' ORDER BY utimestamp ASC';
$interval_data = db_get_all_rows_sql ($sql, $search_in_history_db); $interval_data = db_get_all_rows_sql ($sql, $search_in_history_db);
if ($interval_data === false) { if ($interval_data === false) {
$interval_data = array (); $interval_data = array ();
} }
// Calculate planned downtime dates // Calculate planned downtime dates
$downtime_dates = reporting_get_planned_downtimes_intervals($id_agent_module, $datelimit, $date); $downtime_dates = reporting_get_planned_downtimes_intervals($id_agent_module, $datelimit, $date);
// Get previous data // Get previous data
$previous_data = modules_get_previous_data ($id_agent_module, $datelimit); $previous_data = modules_get_previous_data ($id_agent_module, $datelimit);
@ -7262,6 +7394,8 @@ function reporting_get_agentmodule_sla_day ($id_agent_module, $period = 0, $min_
array_push ($interval_data, $next_data); array_push ($interval_data, $next_data);
} }
if (count ($interval_data) < 2) { if (count ($interval_data) < 2) {
return false; return false;
} }
@ -7365,6 +7499,8 @@ function reporting_get_agentmodule_sla_array ($id_agent_module, $period = 0, $mi
AND utimestamp > %d AND utimestamp <= %d', AND utimestamp > %d AND utimestamp <= %d',
$id_agent_module, $datelimit, $date); $id_agent_module, $datelimit, $date);
//Add the working times (mon - tue - wed ...) and from time to time //Add the working times (mon - tue - wed ...) and from time to time
$days = array(); $days = array();
//Translate to mysql week days //Translate to mysql week days
@ -7403,16 +7539,24 @@ function reporting_get_agentmodule_sla_array ($id_agent_module, $period = 0, $mi
if ($timeFrom != $timeTo) { if ($timeFrom != $timeTo) {
if ($timeFrom < $timeTo) { if ($timeFrom < $timeTo) {
$sql .= ' AND (TIME(FROM_UNIXTIME(utimestamp)) >= "' . $timeFrom . '" AND TIME(FROM_UNIXTIME(utimestamp)) <= "'. $timeTo . '")'; $sql .= ' AND (TIME(FROM_UNIXTIME(utimestamp)) >= \'' .
$timeFrom . '\'
AND TIME(FROM_UNIXTIME(utimestamp)) <= \'' .
$timeTo . '\')';
} }
elseif ($timeFrom > $timeTo) { elseif ($timeFrom > $timeTo) {
$sql .= ' AND (TIME(FROM_UNIXTIME(utimestamp)) >= "' . $timeFrom . '" OR TIME(FROM_UNIXTIME(utimestamp)) <= "'. $timeTo . '")'; $sql .= ' AND (TIME(FROM_UNIXTIME(utimestamp)) >= \'' .
$timeFrom . '\'
OR TIME(FROM_UNIXTIME(utimestamp)) <= \''.
$timeTo . '\')';
} }
} }
$sql .= ' ORDER BY utimestamp ASC'; $sql .= ' ORDER BY utimestamp ASC';
$interval_data = db_get_all_rows_sql ($sql, $search_in_history_db); $interval_data = db_get_all_rows_sql ($sql, $search_in_history_db);
if ($interval_data === false) { if ($interval_data === false) {
$interval_data = array (); $interval_data = array ();
} }

View File

@ -325,6 +325,7 @@ function reporting_html_SLA($table, $item, $mini) {
$table->data['planned_downtime']['cell'] = html_print_table($table1, true); $table->data['planned_downtime']['cell'] = html_print_table($table1, true);
} }
$table1 = new stdClass();
$table1->width = '99%'; $table1->width = '99%';
$table1->align = array(); $table1->align = array();
@ -380,7 +381,7 @@ function reporting_html_SLA($table, $item, $mini) {
$table->data['sla']['cell'] = html_print_table($table1, true); $table->data['sla']['cell'] = html_print_table($table1, true);
if (!empty($item['charts'])) { if (!empty($item['charts'])) {
$table1 = null; $table1 = new stdClass();
$table1->width = '99%'; $table1->width = '99%';
$table1->data = array (); $table1->data = array ();

View File

@ -26,6 +26,12 @@
CREATE OR REPLACE FUNCTION UNIX_TIMESTAMP (oracletime IN DATE DEFAULT NULL ) RETURN INTEGER AS utcdate DATE; unixtime INTEGER; BEGIN IF (oracletime IS NULL) THEN utcdate := SYS_EXTRACT_UTC(SYSTIMESTAMP); ELSE utcdate := oracletime; END IF; unixtime := (utcdate - to_date('19700101','YYYYMMDD')) * 86400; RETURN unixtime; END;; CREATE OR REPLACE FUNCTION UNIX_TIMESTAMP (oracletime IN DATE DEFAULT NULL ) RETURN INTEGER AS utcdate DATE; unixtime INTEGER; BEGIN IF (oracletime IS NULL) THEN utcdate := SYS_EXTRACT_UTC(SYSTIMESTAMP); ELSE utcdate := oracletime; END IF; unixtime := (utcdate - to_date('19700101','YYYYMMDD')) * 86400; RETURN unixtime; END;;
CREATE OR REPLACE FUNCTION NOW RETURN TIMESTAMP AS t_now TIMESTAMP; BEGIN SELECT LOCALTIMESTAMP INTO t_now FROM dual; RETURN t_now; END;; CREATE OR REPLACE FUNCTION NOW RETURN TIMESTAMP AS t_now TIMESTAMP; BEGIN SELECT LOCALTIMESTAMP INTO t_now FROM dual; RETURN t_now; END;;
CREATE OR REPLACE FUNCTION FROM_UNIXTIME (p_unix_ts IN NUMBER) RETURN TIMESTAMP IS l_date TIMESTAMP; BEGIN l_date := date '1970-01-01' + p_unix_ts/60/60/24; RETURN l_date; END;;
CREATE OR REPLACE FUNCTION DAYOFWEEK (p_date IN TIMESTAMP) RETURN NUMBER IS l_number_week NUMBER; BEGIN l_number_week := to_char(p_date, 'd'); RETURN l_number_week; END;;
CREATE OR REPLACE FUNCTION TIME (p_date IN TIMESTAMP) RETURN VARCHAR2 IS l_time VARCHAR2(20); BEGIN l_time := TO_CHAR(p_date,'hh24:mi:ss'); RETURN l_time; END;;
-- Procedure for retrieve PK information after an insert statement -- Procedure for retrieve PK information after an insert statement
CREATE OR REPLACE PROCEDURE insert_id (table_name IN VARCHAR2, sql_insert IN VARCHAR2, id OUT NUMBER ) IS v_count NUMBER; BEGIN EXECUTE IMMEDIATE sql_insert; EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM user_sequences WHERE sequence_name = UPPER(''' || table_name || '_s'')' INTO v_count; IF v_count >= 1 THEN EXECUTE IMMEDIATE 'SELECT ' || table_name || '_s.currval FROM DUAL' INTO id; ELSE id := 0; END IF; EXCEPTION WHEN others THEN RAISE_APPLICATION_ERROR(-20001, 'ERROR on insert_id procedure, please check input parameters or procedure logic.'); END insert_id;; CREATE OR REPLACE PROCEDURE insert_id (table_name IN VARCHAR2, sql_insert IN VARCHAR2, id OUT NUMBER ) IS v_count NUMBER; BEGIN EXECUTE IMMEDIATE sql_insert; EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM user_sequences WHERE sequence_name = UPPER(''' || table_name || '_s'')' INTO v_count; IF v_count >= 1 THEN EXECUTE IMMEDIATE 'SELECT ' || table_name || '_s.currval FROM DUAL' INTO id; ELSE id := 0; END IF; EXCEPTION WHEN others THEN RAISE_APPLICATION_ERROR(-20001, 'ERROR on insert_id procedure, please check input parameters or procedure logic.'); END insert_id;;
@ -1278,10 +1284,10 @@ CREATE TABLE treport_content_sla_combined (
-- This sequence will not work with the 'insert_id' procedure -- This sequence will not work with the 'insert_id' procedure
CREATE SEQUENCE treport_cont_sla_c_s INCREMENT BY 1 START WITH 1; CREATE SEQUENCE treport_cont_sla_c_s INCREMENT BY 1 START WITH 1;
CREATE OR REPLACE TRIGGER treport_content_sla_comb_inc BEFORE INSERT ON treport_content REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT treport_cont_sla_c_s.nextval INTO :NEW.id_rc FROM dual; END treport_content_sla_comb_inc;; CREATE OR REPLACE TRIGGER treport_content_sla_comb_inc BEFORE INSERT ON treport_content_sla_combined REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT treport_cont_sla_c_s.nextval INTO :NEW.id FROM dual; END treport_content_sla_comb_inc;;
-- on update trigger -- on update trigger
CREATE OR REPLACE TRIGGER treport_cont_sla_comb_update AFTER UPDATE OF id_rc on treport_content FOR EACH ROW BEGIN UPDATE treport_content_sla_combined SET id_report_content = :NEW.id_rc WHERE id_report_content = :OLD.id_rc; END;; CREATE OR REPLACE TRIGGER treport_cont_sla_comb_update AFTER UPDATE OF id on treport_content_sla_combined FOR EACH ROW BEGIN UPDATE treport_content_sla_combined SET id = :NEW.id WHERE id = :OLD.id; END;;
-- ----------------------------------------------------- -- -----------------------------------------------------
-- Table `treport_content_item` -- Table `treport_content_item`