Alzabo

 view release on metacpan or  search on metacpan

lib/Alzabo/Driver/MySQL.pm  view on Meta::CPAN

    my $self = shift;

    my $db = $self->{schema}->db_schema_name;

    my $dbh = $self->_make_dbh( name => '',
                                @_ );

    $dbh->func( 'dropdb', $db, 'admin' );
    Alzabo::Exception::Driver->throw( error => $dbh->errstr )
        if $dbh->errstr;

    $dbh->disconnect;
}

sub _connect_params
{
    my $self = shift;

    my %p = @_;

    %p = validate( @_, { name => { type => SCALAR },
                         user => { type => SCALAR | UNDEF,
                                   optional => 1 },
                         password => { type => SCALAR | UNDEF,
                                       optional => 1 },
                         host => { type => SCALAR | UNDEF,
                                   optional => 1 },
                         port => { type => SCALAR | UNDEF,
                                   optional => 1 },
                         map { $_ => 0 } grep { /^mysql_/ } keys %p,
                       } );

    my $dsn = "DBI:mysql:$p{name}";
    $dsn .= ";host=$p{host}" if $p{host};
    $dsn .= ";port=$p{port}" if $p{port};

    foreach my $k ( grep { /^mysql_/ } keys %p )
    {
        $dsn .= ";$k=$p{$k}";
    }

    return [ $dsn, $p{user}, $p{password},
             { RaiseError => 1,
               AutoCommit => 1,
               PrintError => 0,
             }
           ];
}

sub next_sequence_number
{
    # This will cause an auto_increment column to go up (because we're
    # inserting a NULL into it).
    return undef;
}

sub rollback
{
    my $self = shift;

    eval { $self->SUPER::rollback };

    if ( my $e = $@ )
    {
        unless ( $e->error =~ /Some non-transactional changed tables/ )
        {
            if ( Alzabo::Utils::safe_can( $e, 'rethrow' ) )
            {
                $e->rethrow;
            }
            else
            {
                Alzabo::Exception->throw( error => $e );
            }
        }
    }
}

sub get_last_id
{
     my $self = shift;

     return $self->{dbh}->{mysql_insertid};
}

sub driver_id
{
    return 'MySQL';
}

sub dbi_driver_name
{
    return 'mysql';
}

1;

__END__

=head1 NAME

Alzabo::Driver::MySQL - MySQL specific Alzabo driver subclass

=head1 SYNOPSIS

  use Alzabo::Driver::MySQL;

=head1 DESCRIPTION

This provides some MySQL specific implementations for the virtual
methods in Alzabo::Driver.

=head1 METHODS

=head2 connect, create_database, drop_database

Besides the parameters listed in L<the Alzabo::Driver
docs|Alzabo::Driver/Parameters for connect(),
create_database(), and drop_database()>, these methods will also
include any parameter starting with C<mysql_> in the DSN used to
connect to the database.  This allows you to pass parameters such as



( run in 0.533 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )