Alzabo
view release on metacpan or search on metacpan
lib/Alzabo/Driver/MySQL.pm view on Meta::CPAN
package Alzabo::Driver::MySQL;
use strict;
use vars qw($VERSION);
use Alzabo::Driver;
use Alzabo::Utils;
use DBD::mysql;
use DBI;
use Params::Validate qw( :all );
Params::Validate::validation_options( on_fail => sub { Alzabo::Exception::Params->throw( error => join '', @_ ) } );
$VERSION = 2.0;
use base qw(Alzabo::Driver);
sub new
{
my $proto = shift;
my $class = ref $proto || $proto;
my $self = bless {}, $class;
return $self;
}
sub connect
{
my $self = shift;
$self->disconnect if $self->{dbh};
$self->{dbh} = $self->_make_dbh( @_,
name => $self->{schema}->db_schema_name
);
foreach ( $self->rows( sql => 'SHOW VARIABLES' ) )
{
if ( $_->[0] eq 'sql_mode' )
{
# some versions of mysql may return '' for sql_mode
$self->{mysql_ansi_mode} = ( $_->[1] ? $_->[1] : 0 ) & 4;
last;
}
}
}
sub quote_identifier
{
my $self = shift;
my @ids = @_;
my $quote = $self->{mysql_ansi_mode} ? '"' : '`';
foreach (@ids)
{
next unless defined;
s/$quote/$quote$quote/g;
$_ = "$quote$_$quote";
}
return join '.', @ids;
}
sub supports_referential_integrity
{
my $self = shift;
my ($maj, $min, $p) = $self->_version_components;
if ( $maj == 3 )
{
return 0 if $min < 23;
# 3.23.50 && 4.0.2 are the first versions where InnoDB
# actually honored CASCADE, SET NULL, and SET DEFAULT
return 0 if $p < 50;
}
# same deal
return 0 if $maj == 4 && $min == 0 && $p < 2;
foreach my $row ( $self->rows_hashref( sql => 'SHOW TABLE STATUS' ) )
( run in 1.889 second using v1.01-cache-2.11-cpan-39bf76dae61 )