2010-09-23 Sergio Martin <sergio.martin@artica.es>
* lib/PandoraFMS/DB.pm: Added a function db_process_insert to insert a generic query receiving a hash reference with the parameters (columns in index and value in values) git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@3280 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
1610883d02
commit
9935209777
|
@ -1,3 +1,9 @@
|
|||
2010-09-23 Sergio Martin <sergio.martin@artica.es>
|
||||
|
||||
* lib/PandoraFMS/DB.pm: Added a function db_process_insert
|
||||
to insert a generic query receiving a hash reference with
|
||||
the parameters (columns in index and value in values)
|
||||
|
||||
2010-09-22 Sancho Lerena <slerena@artica.es>
|
||||
|
||||
* pandora_server/pandora_server.spec: Updated spec with some
|
||||
|
|
|
@ -30,6 +30,7 @@ our @EXPORT = qw(
|
|||
db_connect
|
||||
db_disconnect
|
||||
db_do
|
||||
db_process_insert
|
||||
db_insert
|
||||
get_action_id
|
||||
get_agent_id
|
||||
|
@ -305,6 +306,29 @@ sub db_insert ($$;@) {
|
|||
return $dbh->{'mysql_insertid'};
|
||||
}
|
||||
|
||||
##########################################################################
|
||||
## SQL insert. Returns the ID of the inserted row.
|
||||
##########################################################################
|
||||
sub db_process_insert($$$;@) {
|
||||
my ($dbh, $table, $parameters, @values) = @_;
|
||||
|
||||
my @columns_array = keys %$parameters;
|
||||
my @values_array = values %$parameters;
|
||||
|
||||
if(!defined($table) || $#columns_array == -1) {
|
||||
return -1;
|
||||
exit;
|
||||
}
|
||||
|
||||
my $columns_string = join(',',@columns_array);
|
||||
my $values_string = "'".join("','",@values_array)."'";
|
||||
|
||||
my $query = "INSERT INTO $table ($columns_string) VALUES ($values_string)";
|
||||
|
||||
$dbh->do($query, undef, @values);
|
||||
return $dbh->{'mysql_insertid'};
|
||||
}
|
||||
|
||||
##########################################################################
|
||||
## Generic SQL sentence.
|
||||
##########################################################################
|
||||
|
|
Loading…
Reference in New Issue