From 96e37e142f828f684bb24c78764864bf1c06b2c2 Mon Sep 17 00:00:00 2001 From: m-lopez-f Date: Mon, 18 Jan 2016 17:01:37 +0100 Subject: [PATCH] Fixed problems with use CLI with Oracle DB, Tiquet: #3089 --- pandora_server/lib/PandoraFMS/DB.pm | 10 +++++++++- pandora_server/util/pandora_manage.pl | 23 ++++++++++++++--------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/DB.pm b/pandora_server/lib/PandoraFMS/DB.pm index 65e23caeba..0f37da1b53 100644 --- a/pandora_server/lib/PandoraFMS/DB.pm +++ b/pandora_server/lib/PandoraFMS/DB.pm @@ -477,7 +477,15 @@ sub get_agent_module_id ($$$) { sub get_template_id ($$) { my ($dbh, $template_name) = @_; - my $rc = get_db_value ($dbh, "SELECT id FROM talert_templates WHERE name = ?", safe_input($template_name)); + my $field; + if ($RDBMS eq 'oracle') { + $field = "to_char(name)"; + } + else { + $field = "name"; + } + + my $rc = get_db_value ($dbh, "SELECT id FROM talert_templates WHERE $field = ?", safe_input($template_name)); return defined ($rc) ? $rc : -1; } diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index bfa91c1c46..701b1fa1b4 100644 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -333,7 +333,7 @@ sub pandora_add_profile_to_user ($$$;$) { $group_id = 0 unless defined($group_id); - db_do ($dbh, 'INSERT INTO tusuario_perfil (`id_usuario`, `id_perfil`, `id_grupo`) + db_do ($dbh, 'INSERT INTO tusuario_perfil (id_usuario, id_perfil, id_grupo) VALUES (?, ?, ?)', safe_input($user_id), $profile_id, $group_id); } @@ -681,19 +681,19 @@ sub pandora_get_planned_downtime_id ($$) { ########################################################################## sub pandora_get_all_planned_downtime ($$$$$$) { my ($dbh, $downtime_name, $id_group, $type_downtime, $type_execution, $type_periodicity) = @_; - my $sql = "SELECT * FROM tplanned_downtime WHERE name LIKE '%".safe_input($downtime_name)."%' ?"; + my $sql = "SELECT * FROM tplanned_downtime WHERE name LIKE '%".safe_input($downtime_name)."%' "; my $text_sql = ''; - if (defined($id_group) && $id_group != '') { + if (defined($id_group) && $id_group ne '') { $text_sql .= " id_group = $id_group "; } - if ( defined($type_downtime) && $type_downtime != '' ) { + if ( defined($type_downtime) && $type_downtime ne '' ) { $text_sql .= " type_downtime = $type_downtime "; } - if (defined($type_execution) && $type_execution != '') { + if (defined($type_execution) && $type_execution ne '') { $text_sql .= " type_execution = $type_execution "; } - if (defined($type_periodicity) && $type_periodicity != '') { + if (defined($type_periodicity) && $type_periodicity ne '') { $text_sql .= " type_periodicity = $type_periodicity "; } @@ -701,7 +701,8 @@ sub pandora_get_all_planned_downtime ($$$$$$) { $text_sql = ''; } - my @downtimes = get_db_rows ($dbh, $sql, $text_sql); + $sql .= $text_sql; + my @downtimes = get_db_rows ($dbh, $sql); return @downtimes; } @@ -770,7 +771,7 @@ sub pandora_update_special_day_from_hash ($$$$) { sub pandora_get_special_day_id ($$) { my ($dbh, $special_day) = @_; - my $special_day_id = get_db_value ($dbh, "SELECT id FROM talert_special_days WHERE date = ?", safe_input($special_day)); + my $special_day_id = get_db_value ($dbh, "SELECT id FROM talert_special_days WHERE ${RDBMS_QUOTE}date${RDBMS_QUOTE} = ?", safe_input($special_day)); return defined ($special_day_id) ? $special_day_id : -1; } @@ -1732,7 +1733,11 @@ sub cli_create_plugin_module($) { print "[ERROR] Error to create module\n\n"; help_screen(); } - + + if (${RDBMS} eq 'oracle') { + $plug_params =~ s/\\//g; + } + my $decode_params = decode_json($plug_params); my $user_params_size = scalar(@user_params);