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=88cf72d2dd857cc13e32a1488a13c421d2e17b4c;hpb=e33b954c9a8c955f72f302255aad685cdd9a8cd4;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 88cf72d..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??? @@ -223,7 +233,7 @@ table with more than one LOB column. =cut -sub source_bind_attributes +sub source_bind_attributes { require DBD::Oracle; my $self = shift; @@ -266,6 +276,40 @@ sub _svp_rollback { $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 See L.