X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage%2FDBI%2FOracle%2FGeneric.pm;h=5ed31a049e61137a07a3ec91519a56bac105f391;hb=af0edca1cb4cc086f70fb81e9c1955230346691a;hp=a9da2c77b7632165249148adabf8b2a3e2ec11cd;hpb=0d1207e89fdfd78830e1ac236a4ac5d1fd72cda2;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm b/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm index a9da2c7..5ed31a0 100644 --- a/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm +++ b/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm @@ -9,15 +9,17 @@ DBIx::Class::Storage::DBI::Oracle::Generic - Oracle Support for DBIx::Class =head1 SYNOPSIS - # In your table classes - __PACKAGE__->load_components(qw/PK::Auto Core/); + # In your result (table) classes + use base 'DBIx::Class::Core'; __PACKAGE__->add_columns({ id => { sequence => 'mysequence', auto_nextval => 1 } }); __PACKAGE__->set_primary_key('id'); __PACKAGE__->sequence('mysequence'); =head1 DESCRIPTION -This class implements autoincrements for Oracle. +This class implements base Oracle support. The subclass +L is for C<(+)> joins in Oracle +versions before 9. =head1 METHODS @@ -53,8 +55,16 @@ sub _dbh_get_autoinc_seq { my $sth; + my $source_name; + if ( ref $source->name ne 'SCALAR' ) { + $source_name = $source->name; + } + else { + $source_name = ${$source->name}; + } + # check for fully-qualified name (eg. SCHEMA.TABLENAME) - if ( my ( $schema, $table ) = $source->name =~ /(\w+)\.(\w+)/ ) { + if ( my ( $schema, $table ) = $source_name =~ /(\w+)\.(\w+)/ ) { $sql = q{ SELECT trigger_body FROM ALL_TRIGGERS t WHERE t.owner = ? AND t.table_name = ? @@ -66,7 +76,7 @@ sub _dbh_get_autoinc_seq { } else { $sth = $dbh->prepare($sql); - $sth->execute( uc( $source->name ) ); + $sth->execute( uc( $source_name ) ); } while (my ($insert_trigger) = $sth->fetchrow_array) { return uc($1) if $insert_trigger =~ m!(\w+)\.nextval!i; # col name goes here??? @@ -76,7 +86,7 @@ sub _dbh_get_autoinc_seq { sub _sequence_fetch { my ( $self, $type, $seq ) = @_; - my ($id) = $self->dbh->selectrow_array("SELECT ${seq}.${type} FROM DUAL"); + my ($id) = $self->_get_dbh->selectrow_array("SELECT ${seq}.${type} FROM DUAL"); return $id; } @@ -206,12 +216,6 @@ sub connect_call_datetime_setup { "alter session set nls_timestamp_tz_format='$timestamp_tz_format'"); } -sub _svp_begin { - my ($self, $name) = @_; - - $self->dbh->do("SAVEPOINT $name"); -} - =head2 source_bind_attributes Handle LOB types in Oracle. Under a certain size (4k?), you can get away @@ -229,8 +233,9 @@ table with more than one LOB column. =cut -sub source_bind_attributes +sub source_bind_attributes { + require DBD::Oracle; my $self = shift; my($source) = @_; @@ -255,6 +260,12 @@ sub source_bind_attributes return \%bind_attributes; } +sub _svp_begin { + my ($self, $name) = @_; + + $self->_get_dbh->do("SAVEPOINT $name"); +} + # Oracle automatically releases a savepoint when you start another one with the # same name. sub _svp_release { 1 } @@ -262,7 +273,41 @@ sub _svp_release { 1 } sub _svp_rollback { my ($self, $name) = @_; - $self->dbh->do("ROLLBACK TO SAVEPOINT $name") + $self->_get_dbh->do("ROLLBACK TO SAVEPOINT $name") +} + +=head2 relname_to_table_alias + +L uses L names as table aliases in +queries. + +Unfortunately, Oracle doesn't support identifiers over 30 chars in length, so +the L name is shortened and appended with half of an +MD5 hash. + +See L. + +=cut + +sub relname_to_table_alias { + my $self = shift; + my ($relname, $join_count) = @_; + + my $alias = $self->next::method(@_); + + return $alias if length($alias) <= 30; + + # get a base64 md5 of the alias with join_count + require Digest::MD5; + my $ctx = Digest::MD5->new; + $ctx->add($alias); + my $md5 = $ctx->b64digest; + + # truncate and prepend to truncated relname without vowels + (my $devoweled = $relname) =~ s/[aeiou]//g; + my $res = substr($devoweled, 0, 18) . '_' . substr($md5, 0, 11); + + return $res; } =head1 AUTHOR