Commit 5622dfba authored by Leo Gordon's avatar Leo Gordon
Browse files

param_substitute() introduced into MySQLTransfer module

parent ada2cee9
......@@ -79,13 +79,13 @@ use base ('Bio::EnsEMBL::Hive::Process');
# The following 4 parameters are mutually exclusive and define the source of ids for the jobs:
param('inputlist'); The list is explicitly given in the parameters, can be abbreviated: 'inputlist' => ['a'..'z']
param('inputlist'); [param_substituted] The list is explicitly given in the parameters, can be abbreviated: 'inputlist' => ['a'..'z']
param('inputfile'); The list is contained in a file whose name is supplied as parameter: 'inputfile' => 'myfile.txt'
param('inputfile'); [param_substituted] The list is contained in a file whose name is supplied as parameter: 'inputfile' => 'myfile.txt'
param('inputquery'); The list is generated by an SQL query (against the production database by default) : 'inputquery' => 'SELECT object_id FROM object WHERE x=y'
param('inputquery'); [param_substituted] The list is generated by an SQL query (against the production database by default) : 'inputquery' => 'SELECT object_id FROM object WHERE x=y'
param('inputcmd'); The list is generated by running a system command: 'inputcmd' => 'find /tmp/big_directory -type f'
param('inputcmd'); [param_substituted] The list is generated by running a system command: 'inputcmd' => 'find /tmp/big_directory -type f'
=cut
......
......@@ -46,9 +46,9 @@ use base ('Bio::EnsEMBL::Hive::Process');
param('mode'): 'overwrite' (default), 'topup' or 'insertignore'
param('where'): filter for rows to be copied/merged
param('where'): filter for rows to be copied/merged. [ param_substituted ]
param('table'): table name to be copied/merged
param('table'): table name to be copied/merged. [ param_substituted ]
=cut
......@@ -67,6 +67,8 @@ sub fetch_input {
my $table = $self->param('table') or die "Please specify 'table' parameter\n";
$self->input_job->transient_error(1);
$table = $self->param('table', $self->param_substitute($table) );
# Use connection parameters to source database if supplied, otherwise use the current database as default:
#
my ($src_dbh, $src_mysql_conn) = $src_db_conn
......@@ -90,7 +92,11 @@ sub fetch_input {
my $mode = $self->param('mode') || 'overwrite';
$self->param('mode', $self->param('mode'));
my $where = $self->param('where') || '';
my $where = $self->param('where');
if(defined($where)) {
$where = $self->param( 'where', $self->param_substitute($where) );
}
$self->param('src_before', $self->get_row_count($src_dbh, $table, $where) );
......@@ -116,12 +122,12 @@ sub run {
my $mode = $self->param('mode') || 'overwrite';
my $table = $self->param('table');
my $where = $self->param('where') || '';
my $where = $self->param('where');
my $cmd = 'mysqldump '
. { 'overwrite' => '', 'topup' => '--no-create-info ', 'insertignore' => '--no-create-info --insert-ignore ' }->{$mode}
. "$src_mysql_conn $table "
. ($where ? "--where '$where' " : '')
. (defined($where) ? "--where '$where' " : '')
. '| '
. ($filter_cmd ? "$filter_cmd | " : '')
. "mysql $dest_mysql_conn";
......@@ -144,7 +150,7 @@ sub write_output {
my $mode = $self->param('mode');
my $table = $self->param('table');
my $where = $self->param('where') || '';
my $where = $self->param('where');
my $dest_dbh = $self->param('dest_dbh');
......@@ -182,7 +188,7 @@ sub write_output {
sub get_row_count {
my ($self, $dbh, $table, $where) = @_;
my $sql = "SELECT count(*) FROM $table" . ($where ? "WHERE $where" : '');
my $sql = "SELECT count(*) FROM $table" . (defined($where) ? " WHERE $where" : '');
my $sth = $dbh->prepare($sql);
$sth->execute();
......
......@@ -61,7 +61,7 @@ sub strict_hash_format {
Here it deals with finding the sql command(s), doing parameter substitution, storing the result in a predefined place
and optionally connecting to another database (see param('db_conn')).
param('sql'): The recommended way of passing in the sql command(s).
param('sql'): The recommended way of passing in the sql command(s). [param_substituted]
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.
......
......@@ -56,7 +56,7 @@ sub strict_hash_format {
Description : Implements fetch_input() interface method of Bio::EnsEMBL::Hive::Process that is used to read in parameters and load data.
Here it deals with finding the command line, doing parameter substitution and storing the result in a predefined place.
param('cmd'): The recommended way of passing in the command line.
param('cmd'): The recommended way of passing in the command line. [param_substituted]
param('*'): Any other parameters can be freely used for parameter substitution.
......
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