17 This RunnableDB module acts as a wrapper
for an SQL command
18 run against either the current hive database (
default) or against one specified by
'db_conn' parameter
19 (--db_conn becomes obligatory in standalone mode, because there is no hive_db).
21 The Sql command must be stored in the parameters() as the value corresponding to the 'sql' key.
22 It allows to pass in other parameters and use the parameter substitution mechanism in its full glory.
24 The Sql command(s) can be wrapped in a global transaction if the "wrap_in_transaction" flag is switched on (off by default)
28 Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
29 Copyright [2016-2022] EMBL-European Bioinformatics Institute
31 Licensed under the Apache License,
Version 2.0 (the "License"); you may not use this file except in compliance with the License.
32 You may obtain a copy of the License at
36 Unless required by applicable law or agreed to in writing, software distributed under the License
37 is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
38 See the License for the specific language governing permissions and limitations under the License.
42 Please subscribe to the
Hive mailing list: http:
56 'wrap_in_transaction' => 0,
63 Description : Implements run()
interface method of
Bio::EnsEMBL::Hive::Process that is used to perform the
main bulk of the job (minus input and output).
64 Here it is a simple decision step based on the "wrap_in_transaction" parameter. If the latter is set, call _exec_sql() in a transaction,
65 otherwise call it directly.
67 param('wrap_in_transaction'): Whether or not run the commands in a global transaction
74 if ($self->param(
'wrap_in_transaction')) {
75 $self->data_dbc()->run_in_transaction( sub {
86 Description : Actually run the sql command(s). If a list of commands is given, they are run in succession within the same session
87 (so you can create a temporary tables and use it in another command within the same sql command list).
89 param(
'sql'): Either a scalar SQL command or an array of SQL commands.
91 param(
'db_conn'): An optional hash to pass in connection parameters to the database upon which the sql command(s) will have to be run.
93 param(
'*'): Any other parameters can be freely used
for parameter substitution.
100 my $sqls = $self->param_required(
'sql');
101 $sqls = [$sqls]
if(ref($sqls) ne
'ARRAY');
103 my $data_dbc = $self->data_dbc();
108 foreach my $sql (@$sqls) {
110 $self->say_with_header(qq{sql =
"$sql"});
112 $data_dbc->do( $sql ) or die
"Could not run '$sql': ".$data_dbc->db_handle->errstr;
114 my $insert_id_name =
'_insert_id_'.$counter++;
115 # FIXME: does this work if the "MySQL server has gone away" ? 116 my $insert_id_value = $data_dbc->db_handle->last_insert_id(undef, undef, undef, undef);
118 $output_id{$insert_id_name} = $insert_id_value;
119 $self->param($insert_id_name, $insert_id_value); #
for templates
122 $self->param(
'output_id', \%output_id);
128 Description : Implements write_output()
interface method of Bio::EnsEMBL::Hive::Process that is used to deal with job's output after the execution.
129 Here we only flow out the insert_ids.
136 $self->dataflow_output_id( $self->param(
'output_id'), 2);