| Test-Database documentation | Contained in the Test-Database distribution. |
Test::Database::Driver::mysql - A Test::Database driver for mysql
use Test::Database;
my @handles = Test::Database->handles( 'mysql' );
This module is the Test::Database driver for DBD::mysql.
Philippe Bruhat (BooK), <book@cpan.org>
Many thanks to Kristian Köhntopp who helped me while writing a
previous version of this module (before Test::Database 0.03).
Copyright 2008-2010 Philippe Bruhat (BooK), all rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Test-Database documentation | Contained in the Test-Database distribution. |
package Test::Database::Driver::mysql; use strict; use warnings; use DBI; use Test::Database::Driver; our @ISA = qw( Test::Database::Driver ); sub _version { return DBI->connect( $_[0]->connection_info() ) ->selectcol_arrayref('SELECT VERSION()')->[0]; } sub create_database { my ( $self ) = @_; my $dbname = $self->available_dbname(); DBI->connect_cached( $self->connection_info() ) ->do("CREATE DATABASE $dbname"); # return the handle return Test::Database::Handle->new( dsn => $self->dsn($dbname), name => $dbname, username => $self->username(), password => $self->password(), driver => $self, ); } sub drop_database { my ( $self, $dbname ) = @_; DBI->connect_cached( $self->connection_info() ) ->do("DROP DATABASE $dbname") if grep { $_ eq $dbname } $self->databases(); } sub databases { my ($self) = @_; my $basename = qr/^@{[$self->_basename()]}/; my $databases = eval { DBI->connect_cached( $self->connection_info(), { PrintError => 0 } ) ->selectall_arrayref('SHOW DATABASES'); }; return grep {/$basename/} map {@$_} @$databases; } 'mysql'; __END__