From: Matt S Trout Date: Fri, 10 Feb 2006 18:21:37 +0000 (+0000) Subject: Made PK::Auto::* shells since the functionality is now elsewhere X-Git-Tag: v0.06000~61^2~48 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0a8462d4fedc5392edec025bae67abd9c044d69e;p=dbsrgits%2FDBIx-Class.git Made PK::Auto::* shells since the functionality is now elsewhere --- diff --git a/lib/DBIx/Class/PK/Auto/DB2.pm b/lib/DBIx/Class/PK/Auto/DB2.pm index f05f781..29ecf78 100644 --- a/lib/DBIx/Class/PK/Auto/DB2.pm +++ b/lib/DBIx/Class/PK/Auto/DB2.pm @@ -7,39 +7,19 @@ use base qw/DBIx::Class/; __PACKAGE__->load_components(qw/PK::Auto/); -sub last_insert_id -{ - my ($self) = @_; - - my $dbh = $self->result_source->storage->dbh; - my $sth = $dbh->prepare_cached("VALUES(IDENTITY_VAL_LOCAL())", {}, 3); - $sth->execute(); - - my @res = $sth->fetchrow_array(); - - return @res ? $res[0] : undef; - -} - 1; =head1 NAME -DBIx::Class::PK::Auto::DB2 - Automatic primary key class for DB2 +DBIx::Class::PK::Auto::DB2 - (DEPRECATED) Automatic primary key class for DB2 =head1 SYNOPSIS - # In your table classes - __PACKAGE__->load_components(qw/PK::Auto::DB2 Core/); - __PACKAGE__->set_primary_key('id'); - -=head1 DESCRIPTION - -This class implements autoincrements for DB2. +Just load PK::Auto instead; auto-inc is now handled by Storage. =head1 AUTHORS -Jess Robinson +Matt S Trout =head1 LICENSE diff --git a/lib/DBIx/Class/PK/Auto/MSSQL.pm b/lib/DBIx/Class/PK/Auto/MSSQL.pm index a3c4329..8ac2778 100644 --- a/lib/DBIx/Class/PK/Auto/MSSQL.pm +++ b/lib/DBIx/Class/PK/Auto/MSSQL.pm @@ -1,40 +1,28 @@ -package DBIx::Class::PK::Auto::MSSQL; - -use strict; -use warnings; - -use base qw/DBIx::Class/; - -__PACKAGE__->load_components(qw/PK::Auto/); - -sub last_insert_id { - my( $id ) = $_[0]->result_source->storage->dbh->selectrow_array( - 'SELECT @@IDENTITY' ); - return $id; -} - -1; - -=head1 NAME - -DBIx::Class::PK::Auto::MSSQL - Automatic primary key class for MSSQL - -=head1 SYNOPSIS - - # In your table classes - __PACKAGE__->load_components(qw/PK::Auto::MSSQL Core/); - __PACKAGE__->set_primary_key('id'); - -=head1 DESCRIPTION - -This class implements autoincrements for MSSQL. - -=head1 AUTHORS - -Brian Cassidy - -=head1 LICENSE - -You may distribute this code under the same terms as Perl itself. - -=cut +package DBIx::Class::PK::Auto::MSSQL; + +use strict; +use warnings; + +use base qw/DBIx::Class/; + +__PACKAGE__->load_components(qw/PK::Auto/); + +1; + +=head1 NAME + +DBIx::Class::PK::Auto::MSSQL - (DEPRECATED) Automatic primary key class for MSSQL + +=head1 SYNOPSIS + +Just load PK::Auto instead; auto-inc is now handled by Storage. + +=head1 AUTHORS + +Matt S Trout + +=head1 LICENSE + +You may distribute this code under the same terms as Perl itself. + +=cut diff --git a/lib/DBIx/Class/PK/Auto/MySQL.pm b/lib/DBIx/Class/PK/Auto/MySQL.pm index e65bd39..7a1f78e 100644 --- a/lib/DBIx/Class/PK/Auto/MySQL.pm +++ b/lib/DBIx/Class/PK/Auto/MySQL.pm @@ -7,29 +7,19 @@ use base qw/DBIx::Class/; __PACKAGE__->load_components(qw/PK::Auto/); -sub last_insert_id { - return $_[0]->result_source->storage->dbh->{mysql_insertid}; -} - 1; =head1 NAME -DBIx::Class::PK::Auto::MySQL - Automatic primary key class for MySQL +DBIx::Class::PK::Auto::MySQL - (DEPRECATED) Automatic primary key class for MySQL =head1 SYNOPSIS - # In your table classes - __PACKAGE__->load_components(qw/PK::Auto::MySQL Core/); - __PACKAGE__->set_primary_key('id'); - -=head1 DESCRIPTION - -This class implements autoincrements for MySQL. +Just load PK::Auto instead; auto-inc is now handled by Storage. =head1 AUTHORS -Matt S. Trout +Matt S Trout =head1 LICENSE diff --git a/lib/DBIx/Class/PK/Auto/Oracle.pm b/lib/DBIx/Class/PK/Auto/Oracle.pm index 7455408..437246b 100644 --- a/lib/DBIx/Class/PK/Auto/Oracle.pm +++ b/lib/DBIx/Class/PK/Auto/Oracle.pm @@ -3,71 +3,23 @@ package DBIx::Class::PK::Auto::Oracle; use strict; use warnings; -use Carp qw/croak/; - use base qw/DBIx::Class/; __PACKAGE__->load_components(qw/PK::Auto/); -sub last_insert_id { - my $self = shift; - $self->get_autoinc_seq unless $self->{_autoinc_seq}; - my $sql = "SELECT " . $self->{_autoinc_seq} . ".currval FROM DUAL"; - my ($id) = $self->result_source->storage->dbh->selectrow_array($sql); - return $id; -} - -sub get_autoinc_seq { - my $self = shift; - - # return the user-defined sequence if known - if ($self->sequence) { - return $self->{_autoinc_seq} = $self->sequence; - } - - # look up the correct sequence automatically - my $dbh = $self->result_source->storage->dbh; - my $sql = qq{ - SELECT trigger_body FROM ALL_TRIGGERS t - WHERE t.table_name = ? - AND t.triggering_event = 'INSERT' - AND t.status = 'ENABLED' - }; - # trigger_body is a LONG - $dbh->{LongReadLen} = 64 * 1024 if ($dbh->{LongReadLen} < 64 * 1024); - my $sth = $dbh->prepare($sql); - $sth->execute( uc($self->result_source->name) ); - while (my ($insert_trigger) = $sth->fetchrow_array) { - if ($insert_trigger =~ m!(\w+)\.nextval!i ) { - $self->{_autoinc_seq} = uc($1); - } - } - unless ($self->{_autoinc_seq}) { - croak "Unable to find a sequence INSERT trigger on table '" . $self->_table_name . "'."; - } -} - 1; =head1 NAME -DBIx::Class::PK::Auto::Oracle - Automatic primary key class for Oracle +DBIx::Class::PK::Auto::Oracle - (DEPRECATED) Automatic primary key class for Oracle =head1 SYNOPSIS - # In your table classes - __PACKAGE__->load_components(qw/PK::Auto::Oracle Core/); - __PACKAGE__->set_primary_key('id'); - -=head1 DESCRIPTION - -This class implements autoincrements for Oracle. +Just load PK::Auto instead; auto-inc is now handled by Storage. =head1 AUTHORS -Andy Grundman - -Scott Connelly +Matt S Trout =head1 LICENSE diff --git a/lib/DBIx/Class/PK/Auto/Pg.pm b/lib/DBIx/Class/PK/Auto/Pg.pm index ad12dfa..00cd24f 100644 --- a/lib/DBIx/Class/PK/Auto/Pg.pm +++ b/lib/DBIx/Class/PK/Auto/Pg.pm @@ -7,54 +7,19 @@ use base qw/DBIx::Class/; __PACKAGE__->load_components(qw/PK::Auto/); -sub last_insert_id { - my $self = shift; - $self->get_autoinc_seq unless $self->{_autoinc_seq}; - $self->result_source->storage->dbh->last_insert_id(undef,undef,undef,undef, - {sequence=>$self->{_autoinc_seq}}); -} - -sub get_autoinc_seq { - my $self = shift; - - # return the user-defined sequence if known - if ($self->sequence) { - return $self->{_autoinc_seq} = $self->sequence; - } - - my @pri = $self->primary_columns; - my $dbh = $self->result_source->storage->dbh; - my ($schema,$table) = $self->table =~ /^(.+)\.(.+)$/ ? ($1,$2) : (undef,$self->table); - while (my $col = shift @pri) { - my $info = $dbh->column_info(undef,$schema,$table,$col)->fetchrow_arrayref; - if (defined $info->[12] and $info->[12] =~ - /^nextval\('"?([^"']+)"?'::(?:text|regclass)\)/) - { - $self->{_autoinc_seq} = $1; - last; - } - } -} - 1; =head1 NAME -DBIx::Class::PK::Auto::Pg - Automatic primary key class for PostgreSQL +DBIx::Class::PK::Auto::Pg - (DEPRECATED) Automatic primary key class for Pg =head1 SYNOPSIS - # In your table classes - __PACKAGE__->load_components(qw/PK::Auto::Pg Core/); - __PACKAGE__->set_primary_key('id'); - -=head1 DESCRIPTION - -This class implements autoincrements for PostgreSQL. +Just load PK::Auto instead; auto-inc is now handled by Storage. =head1 AUTHORS -Marcus Ramberg +Matt S Trout =head1 LICENSE diff --git a/lib/DBIx/Class/PK/Auto/SQLite.pm b/lib/DBIx/Class/PK/Auto/SQLite.pm index e405eac..de42922 100644 --- a/lib/DBIx/Class/PK/Auto/SQLite.pm +++ b/lib/DBIx/Class/PK/Auto/SQLite.pm @@ -7,29 +7,19 @@ use base qw/DBIx::Class/; __PACKAGE__->load_components(qw/PK::Auto/); -sub last_insert_id { - return $_[0]->result_source->storage->dbh->func('last_insert_rowid'); -} - 1; =head1 NAME -DBIx::Class::PK::Auto::SQLite - Automatic primary key class for SQLite +DBIx::Class::PK::Auto::SQLite - (DEPRECATED) Automatic primary key class for SQLite =head1 SYNOPSIS - # In your table classes - __PACKAGE__->load_components(qw/PK::Auto::SQLite Core/); - __PACKAGE__->set_primary_key('id'); - -=head1 DESCRIPTION - -This class implements autoincrements for SQLite. +Just load PK::Auto instead; auto-inc is now handled by Storage. =head1 AUTHORS -Matt S. Trout +Matt S Trout =head1 LICENSE diff --git a/t/run/10auto.tl b/t/run/10auto.tl index 3d2a038..7c795f4 100644 --- a/t/run/10auto.tl +++ b/t/run/10auto.tl @@ -3,7 +3,8 @@ my $schema = shift; plan tests => 2; -$schema->class("Artist")->load_components(qw/PK::Auto/); +$schema->class("Artist")->load_components(qw/PK::Auto::SQLite/); + # Should just be PK::Auto but this ensures the compat shim works # add an artist without primary key to test Auto my $artist = $schema->resultset("Artist")->create( { name => 'Auto' } );