NAME

DBD::Simulated - Fake DBI database driver simulating a database for testing error checks

SYNOPSIS

Do not use this directly without DBI. See DBI::DBD for more information about using a DBD module.

DESCRIPTION

Every major project has it's own database access module, I never saw one directly using DBI all the time.

Custom source must be tested but it isn't easy to create predefined error cases using real databases for testing your own database error handling source.

This fake database driver simulates a real database usable via DBI. It can neither store nor fetch data or run any kind of real SQL queries but it could return any error state you want.

connect

Use DBI->connect as usual.

  my $dbh = DBI->connect('DBI:Simulated:database=success;simulated_error=256');

Only one dsn named argument is supported right now: simulated_error expects a positive or negative number which is returned as connect error code and no connection object is returned. All other arguments are simply ignored.

You may pass any real-life DSN string to get a simulated database handle and simply add the simulated_error to get a simulated error code.

prepare

Any query will be accepted by prepare, all arguments are ignored.

Add simulated_prepare_error=XXX to your query to trigger a prepare-error. XXX must be a number.

  my $dbh = DBI->connect('DBI:Simulated:database=success');
  $dbh->prepare('SELECT * FROM MyTable WHERE simulated_prepare_error=1024');

execute

Prepare any statement containing simulated_execute_error=XXX and execute it to trigger error code XXX (must be a number - as always).

  my $dbh = DBI->connect('DBI:Simulated:database=success');
  my $sth = $dbh->prepare('SELECT * FROM MyTable WHERE simulated_execute_error=1024');
  $sth->execute;

fetch*

Prepare any statement containing simulated_fetch_error=XXX and to trigger error code XXX (must be a number - as always).

  my $dbh = DBI->connect('DBI:Simulated:database=success');
  my $sth = $dbh->prepare('SELECT * FROM MyTable WHERE simulated_fetch_error=65535');
  $sth->execute;
  $sth->fetchall_arrayref;

Notice that fetch always returns undef (looks like to data returned by the query) but also sets the error code if requested.

Other DBI methods

Other DBI methods like do and prepare_cached fall back to the default methods shown above. All error strings may be used when calling them.

SUPPORT

No support is available

AUTHOR

Copyright 2012 Sebastian Willing, eGENTIC Systems http://egentic-systems.com/karriere/