mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-12 04:45:45 +00:00
Bug 285713: Cross-DB bz_column_info and bz_index_info
Patch By Max Kanat-Alexander <mkanat@kerio.com> r=Tomas.Kopal, a=justdave
This commit is contained in:
parent
af16820a6e
commit
7674c809f6
@ -434,6 +434,19 @@ sub _bz_schema {
|
||||
return $self->{private_bz_schema};
|
||||
}
|
||||
|
||||
sub bz_column_info {
|
||||
my ($self, $table, $column) = @_;
|
||||
|
||||
return $self->_bz_real_schema->get_column_abstract($table, $column);
|
||||
}
|
||||
|
||||
sub bz_index_info {
|
||||
my ($self, $table, $index) = @_;
|
||||
|
||||
return $self->_bz_real_schema->get_index_abstract($table, $index);
|
||||
}
|
||||
|
||||
|
||||
# XXX - Needs to be made cross-db compatible.
|
||||
sub bz_get_field_def ($$) {
|
||||
my ($self, $table, $field) = @_;
|
||||
@ -709,6 +722,10 @@ Bugzilla::DB - Database access routines, using L<DBI>
|
||||
$dbh->bz_rename_field($table, $column, $newname);
|
||||
|
||||
# Schema Information
|
||||
my $column = $dbh->bz_column_info($table, $column);
|
||||
my $index = $dbh->bz_index_info($table, $index);
|
||||
|
||||
# Schema Information (DEPRECATED)
|
||||
my @fields = $dbh->bz_get_field_defs();
|
||||
my @fieldinfo = $dbh->bz_get_field_def($table, $column);
|
||||
my @indexinfo = $dbh->bz_get_index_def($table, $field);
|
||||
@ -1038,9 +1055,43 @@ These methods modify the current Bugzilla schema.
|
||||
$newname = the new name of the column
|
||||
Returns: none
|
||||
|
||||
=back
|
||||
|
||||
|
||||
=head2 Schema Information Methods
|
||||
|
||||
These methods return info about the current Bugzilla database schema.
|
||||
These methods return information about the current Bugzilla database
|
||||
schema, as it currently exists on the disk.
|
||||
|
||||
Where a parameter says "Abstract index/column definition", it returns/takes
|
||||
information in the formats defined for indexes and columns in
|
||||
C<Bugzilla::DB::Schema::ABSTRACT_SCHEMA>.
|
||||
|
||||
=over 4
|
||||
|
||||
=item C<bz_column_info($table, $column)>
|
||||
|
||||
Description: Get abstract column definition.
|
||||
Params: $table - The name of the table the column is in.
|
||||
$column - The name of the column.
|
||||
Returns: An abstract column definition for that column.
|
||||
If the table or column does not exist, we return undef.
|
||||
|
||||
=item C<bz_index_info($table, $index)>
|
||||
|
||||
Description: Get abstract index definition.
|
||||
Params: $table - The table the index is on.
|
||||
$index - The name of the index.
|
||||
Returns: An abstract index definition for that index.
|
||||
If the index does not exist, we return undef.
|
||||
|
||||
=back
|
||||
|
||||
|
||||
=head2 Deprecated Schema Information Methods
|
||||
|
||||
These methods return info about the current Bugzilla database, for
|
||||
MySQL only.
|
||||
|
||||
=over 4
|
||||
|
||||
|
@ -1167,9 +1167,9 @@ sub get_type_ddl {
|
||||
|
||||
} #eosub--get_type_ddl
|
||||
#--------------------------------------------------------------------------
|
||||
sub get_column_info {
|
||||
sub get_column_ddl {
|
||||
|
||||
=item C<get_column_info>
|
||||
=item C<get_column_ddl>
|
||||
|
||||
Description: Public method to generate a DDL segment of a "create table"
|
||||
SQL statement for a given table and field.
|
||||
@ -1192,7 +1192,7 @@ sub get_column_info {
|
||||
return() unless ($fields{$column});
|
||||
return %{ $fields{$column} };
|
||||
|
||||
} #eosub--get_column_info
|
||||
} #eosub--get_column_ddl
|
||||
#--------------------------------------------------------------------------
|
||||
sub get_table_list {
|
||||
|
||||
@ -1348,7 +1348,52 @@ sub _get_create_index_ddl {
|
||||
|
||||
} #eosub--_get_create_index_ddl
|
||||
#--------------------------------------------------------------------------
|
||||
sub get_column_abstract {
|
||||
|
||||
=item C<get_column_abstract($table, $column)>
|
||||
|
||||
Description: A column definition from the abstract internal schema.
|
||||
cross-database format.
|
||||
Params: $table - The name of the table
|
||||
$column - The name of the column that you want
|
||||
Returns: A hash reference. For the format, see the docs for
|
||||
C<ABSTRACT_SCHEMA>.
|
||||
Returns undef if the column or table does not exist.
|
||||
|
||||
=cut
|
||||
|
||||
my ($self, $table, $column) = @_;
|
||||
|
||||
# Prevent a possible dereferencing of an undef hash, if the
|
||||
# table doesn't exist.
|
||||
if (exists $self->{abstract_schema}->{$table}) {
|
||||
return $self->{abstract_schema}->{$table}{FIELDS}{$column};
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub get_index_abstract {
|
||||
|
||||
=item C<get_index_abstract($table, $index)
|
||||
|
||||
Description: Returns an index definition from the internal abstract schema.
|
||||
Params: $table - The table the index is on.
|
||||
$index - The name of the index.
|
||||
Returns: A hash reference representing an index definition.
|
||||
See the C<ABSTRACT_SCHEMA> docs for details.
|
||||
Returns undef if the index does not exist.
|
||||
|
||||
=cut
|
||||
|
||||
my ($self, $table, $index) = @_;
|
||||
|
||||
# Prevent a possible dereferencing of an undef hash, if the
|
||||
# table doesn't exist.
|
||||
if (exists $self->{abstract_schema}->{$table}) {
|
||||
return $self->{abstract_schema}->{$table}{INDEXES}{$index};
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
|
||||
=head1 SERIALIZATION/DESERIALIZATION
|
||||
|
Loading…
Reference in New Issue
Block a user