From a27cac4bd002f178c5db01cfa2af207a4e55fa5d Mon Sep 17 00:00:00 2001 From: Leo Gordon <lg4@ebi.ac.uk> Date: Mon, 14 Jun 2010 23:06:46 +0000 Subject: [PATCH] track insert_ids of separate commands and make them available for dataflow --- modules/Bio/EnsEMBL/Hive/RunnableDB/SqlCmd.pm | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/modules/Bio/EnsEMBL/Hive/RunnableDB/SqlCmd.pm b/modules/Bio/EnsEMBL/Hive/RunnableDB/SqlCmd.pm index 8fcc1000c..b19ef1439 100755 --- a/modules/Bio/EnsEMBL/Hive/RunnableDB/SqlCmd.pm +++ b/modules/Bio/EnsEMBL/Hive/RunnableDB/SqlCmd.pm @@ -91,16 +91,9 @@ sub fetch_input { ? $self->db->get_AnalysisDataAdaptor->fetch_by_dbID( $self->param('did') ) : die "Could not find the command defined in input_id(), param('sql') or param('did')"; - # Perform parameter substitution: + # Store the sql command array: # - my @substituted_sqls = (); - foreach my $unsubst ((ref($sql) eq 'ARRAY') ? @$sql : ($sql) ) { - push @substituted_sqls, $self->param_substitute($unsubst); - } - - # Store the substituted sql command array - # - $self->param('sqls', \@substituted_sqls); + $self->param('sqls', (ref($sql) eq 'ARRAY') ? $sql : [$sql] ); # Use connection parameters to another database if supplied, otherwise use the current database as default: # @@ -126,20 +119,37 @@ sub run { my $dbc = $self->param('dbc'); my $sqls = $self->param('sqls'); + my %output_id; + # What would be a generic way of indicating an error in (My)SQL statement, that percolates through PerlDBI? - foreach my $sql (@$sqls) { + my $counter = 0; + foreach my $unsubst_sql (@$sqls) { + + # Perform parameter substitution: + my $sql = $self->param_substitute($unsubst_sql); + $dbc->do( $sql ); + + my $insert_id_name = '_insert_id_'.$counter++; + my $insert_id_value = $dbc->db_handle->{'mysql_insertid'}; + $output_id{$insert_id_name} = $insert_id_value; + $self->param($insert_id_name, $insert_id_value); # for templates } + + $self->param('output_id', \%output_id); } =head2 write_output Description : Implements write_output() interface method of Bio::EnsEMBL::Hive::Process that is used to deal with job's output after the execution. - Here we have nothing to do, as the wrapper is very generic. + Here we only flow out the insert_ids. =cut sub write_output { + my $self = shift; + + $self->dataflow_output_id( $self->param('output_id'), 2); } 1; -- GitLab