Oryx::DBI::Util::mysql - Oryx DBI utilities for MySQL connections


Oryx documentation Contained in the Oryx distribution.

Index


Code Index:

NAME

Top

Oryx::DBI::Util::mysql - Oryx DBI utilities for MySQL connections

DESCRIPTION

Top

This provides an Oryx DBI utility class for use with DBD::mysql.

BUGS

Top

The lastval() method is implemented using the "mysql_insertid" field of the database handler. This will only be able to return the insert ID of the last inserted row. This is, to my knowledge at the time of this writing, the only way to do this as the standard last_insert_id() method of DBI has not yet been implemented.

SEE ALSO

Top

Oryx::DBI::Util, DBD::mysql

AUTHORS

Top

Richard Hundt <richard NO SPAM AT protea-systems.com>

Andrew Sterling Hanenkamp <hanenkamp@cpan.org>

COPYRIGHT AND LICENSE

Top


Oryx documentation Contained in the Oryx distribution.

package Oryx::DBI::Util::mysql;

use base qw(Oryx::DBI::Util);

our %SQL_TYPES = (
    'Oid'       => 'bigint PRIMARY KEY auto_increment',
    'Integer'   => 'bigint',
    'String'    => 'varchar',
    'Text'      => 'text',
    'Binary'    => 'blob',
    'Float'     => 'float',
    'Boolean'   => 'tinyint',
    'DateTime'  => 'datetime',
);

sub type2sql {
    my ($self, $type, $size) = @_;
    my $sql_type = $SQL_TYPES{$type};
    if ($type eq 'String') {
	$size ||= '255';
	$sql_type .= "($size)";
    } elsif ($type eq 'Integer' and defined $size) {
	$sql_type .= "($size)";
    }
    return $sql_type;
}

sub table_exists {
    my ($self, $dbh, $table) = @_;
    my $sth = $dbh->table_info('%', '%', $table);
    $sth->execute();
    my @rv = @{$sth->fetchall_arrayref};
    $sth->finish;
    return grep { $_->[2] eq $table } @rv;
}

# DBD::mysql is gimpy here...
sub lastval {
    my ($self, $dbh, $table) = @_;
    return $dbh->{mysql_insertid};
}

1;

__END__