02 Apr 2012 10:10:51 UTC
- Distribution: DBD-Simulated
- Module version: 0.01
- Source (raw)
- Browse (raw)
- How to Contribute
- Testers (362 / 0 / 5)
- KwaliteeBus factor: 0
- 45.11% Coverage
- License: perl_5
- Perl: v5.10.0
- Activity24 month
- Download (27.17KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest versionSEWI Sebastian Willingand 1 contributors
- Copyright 2012 Sebastian Willing, eGENTIC Systems L<http://egentic-systems.com/karriere/>
DBD::Simulated - Fake DBI database driver simulating a database for testing error checks
Do not use this directly without DBI. See DBI::DBD for more information about using a DBD module.
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.
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.
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');
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;
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 like do and prepare_cached fall back to the default methods shown above. All error strings may be used when calling them.
No support is available
Copyright 2012 Sebastian Willing, eGENTIC Systems http://egentic-systems.com/karriere/
Module Install Instructions
To install DBD::Simulated, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell install DBD::Simulated
For more information on module installation, please visit the detailed CPAN module installation guide.