NAME

SqlBatch::InstructionBase

DESCRIPTION

Base class for a sqlbatch instruction

METHODS

address

Returns address number of instruction in the execution plan

argument($argname)

Returns the value of a given instruction argument

content

Returns the value of the instruction's content area

databasehandle

Returns a valid DBI database-handle.

Transaction commit is either done by DBI or sqlbatch on that handle and it's session.

show_warning($text)

Shows a warning text.

show_error($text)

Shows a error text.

state_dump

Returns a HASH-ref to HASH containing the (public) state of the instruction

configuration

Reference to given SqlBatch::Configuration object

run

Abstract method to be overridden in a PERL-instruction

run_if_tags

HASH-ref to tags required for execution of this instruction.

run_not_if_tags

HASH-ref to tags required for preventing execution of this instruction.

runstate

Reference to a SqlBatch::RunState-object

The runstate information are imported from an earlier instruction. After finishing this instruction the public values of that object will be copied to the next instructions runstate.

EXAMPLE OF USAGE

In this is example we execute a PERL-instruction:

--PERL-- -class=MyPerlInstruction -special="Special value"
My content
--END--

The code for an PERL-instruction can look like:

    package MyPerlInstruction;

    use v5.16;
    use strict;
    use warnings;
    use utf8;

    use Carp;
    use parent 'SqlBatch::InstructionBase';

    sub new {
        my ($class,$config,$content,%args) = @_;

        my $self = SqlBatch::InstructionBase->new($config,$content,%args);

        $self = bless $self, $class;
        return $self;    
    }

    sub run {
        my $self = shift;

        my $verbosity = $self->configuration->verbosity;
        my $content   = $self->content;
        my $self->databasehandle    

        say "Running Perl instruction module SqlBatch::MyPerlInstruction" if $verbosity > 1;

        # Get a given instruction argumment
        my $special = $self->argument('special');

        # Time for some action
        eval {
            say "The special argument: ".$special;
            say "Instruction content: ".$content;

	    # Run something againt the database
	    my $rv = $dbh->...

	    # And store the returnvalue
	    $self->runstate->_returnvalue($rv);
            ...
        };
        if($@) {
            # Handle errors
	    $self->runstate->_error($@);
	    self->show_error("Failed running instruction: ".Dumper($self->state_dump));

            # Continue dying
	    croak($@);
        }
    }

AUTHOR

Sascha Dibbern (sascha at dibbern.info)

LICENCE

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.