Commit c26b0907 authored by Leo Gordon's avatar Leo Gordon
Browse files

one PREPARE statement per dataflow-to-table call (so works for array of...

one PREPARE statement per dataflow-to-table call (so works for array of output_ids with identical structure)
parent 30a33144
......@@ -238,22 +238,25 @@ sub dataflow_output_id {
my @output_job_ids = ();
my $rules = $self->adaptor->db->get_DataflowRuleAdaptor->fetch_from_analysis_id_branch_code($self->analysis_id, $branch_code);
foreach my $rule (@{$rules}) {
foreach my $rule (@$rules) {
my $substituted_template;
my $output_ids_for_this_rule;
if(my $template = $rule->input_id_template()) {
$substituted_template = $self->param_substitute($template);
$output_ids_for_this_rule = [ $self->param_substitute($template) ];
} else {
$output_ids_for_this_rule = $output_ids;
}
my $target_analysis_or_table = $rule->to_analysis();
foreach my $output_id ($substituted_template ? ($substituted_template) : @$output_ids) {
if($target_analysis_or_table->can('dataflow')) {
if($target_analysis_or_table->can('dataflow')) {
my $insert_ids = $target_analysis_or_table->dataflow( $output_ids_for_this_rule );
my $insert_id = $target_analysis_or_table->dataflow( $output_id );
} else {
foreach my $output_id ( @$output_ids_for_this_rule ) {
} else {
if(my $job_id = $self->adaptor->CreateNewJob(
-input_id => $output_id,
-analysis => $target_analysis_or_table,
......
......@@ -37,27 +37,33 @@ sub create_new {
}
sub dataflow {
my ( $self, $naked_table, $data_hash ) = @_;
my ( $self, $naked_table, $output_ids ) = @_;
if(not ref($data_hash)) { # assume it was passed as a string
$data_hash = eval $data_hash;
}
return unless(@$output_ids);
my $table_name = $naked_table->table_name();
my $insertion_method = uc( $naked_table->insertion_method() ); # INSERT, INSERT_IGNORE or REPLACE
$insertion_method =~ s/_/ /g;
# NB: here we assume all hashes will have the same keys (and also the same order):
my @column_names = keys %{$output_ids->[0]};
# By using question marks you can insert true NULLs by setting corresponding values to undefs:
my $sql = "$insertion_method INTO $table_name (".join(', ', keys %$data_hash).') VALUES ('.join(',', (('?') x scalar(keys %$data_hash))).')';
my $sql = "$insertion_method INTO $table_name (".join(', ', @column_names).') VALUES ('.join(',', (('?') x scalar(@column_names))).')';
my $sth = $self->prepare( $sql );
$sth->execute( values %$data_hash ); # Perl manual promises that the order of "keys" will be the same as the order of "values", so no need to sort.
my $insert_id = $sth->{'mysql_insertid'}; # capture it just in case
my @insert_ids = ();
foreach my $data_hash (@$output_ids) {
$sth->execute( values %$data_hash ); # Perl manual promises that the order of "keys" will be the same as the order of "values", so no need to sort.
push @insert_ids, $sth->{'mysql_insertid'}; # capture it just in case
}
$sth->finish();
return $insert_id;
return \@insert_ids;
}
1;
......
......@@ -77,9 +77,9 @@ sub url {
}
sub dataflow {
my ( $self, $data_hash ) = @_;
my ( $self, $output_ids ) = @_;
return $self->adaptor->dataflow($self, $data_hash);
return $self->adaptor->dataflow($self, $output_ids);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment