From: Justin Hunter Date: Sun, 12 Jul 2009 07:48:21 +0000 (-0700) Subject: add index parsing X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=92403c5e5dfb6c78714d3e097f4a44070e03b5f9;p=dbsrgits%2FSQL-Translator-2.0-ish.git add index parsing --- diff --git a/lib/SQL/Translator/Parser/DBI.pm b/lib/SQL/Translator/Parser/DBI.pm index 73607b5..4b26606 100644 --- a/lib/SQL/Translator/Parser/DBI.pm +++ b/lib/SQL/Translator/Parser/DBI.pm @@ -7,6 +7,7 @@ use DBI::Const::GetInfo::ANSI; use DBI::Const::GetInfoReturn; use aliased 'SQL::Translator::Object::Column'; use aliased 'SQL::Translator::Object::ForeignKey'; +use aliased 'SQL::Translator::Object::Index'; use aliased 'SQL::Translator::Object::PrimaryKey'; use aliased 'SQL::Translator::Object::Table'; use aliased 'SQL::Translator::Object::View'; @@ -69,6 +70,7 @@ sub _add_tables { $schema->add_table($table); $self->_add_columns($table); $self->_add_primary_key($table); + $self->_add_indexes($table); } elsif ($table_info->{TABLE_TYPE} eq 'VIEW') { my $sql = $self->_get_view_sql($table_info->{TABLE_NAME}); @@ -136,4 +138,21 @@ sub _add_foreign_keys { } } +sub _add_indexes { + my $self = shift; + my $table = shift; + + my $index_info = $self->dbh->statistics_info($self->catalog_name, $self->schema_name, $table->name, 1, 0); + + my ($index_name, $index_type, @index_cols); + while (my $index_col = $index_info->fetchrow_hashref) { + $index_name = $index_col->{INDEX_NAME}; + $index_type = $index_col->{NON_UNIQUE} ? 'NON_UNIQUE' : 'UNIQUE'; + push @index_cols, $index_col->{COLUMN_NAME}; + } + my $index = Index->new({ name => $index_name, type => $index_type }); + $index->add_column($table->get_column($_)) for @index_cols; + $table->add_index($index); +} + 1;