SQL::Translator::Parser::DBI::Sybase bug (35380) causes script to fail when sp_helpindex doesn’t return a result set
ASE, DBI, Perl, Sybase Add comments35380: SQL::Translator::Parser::DBI::Sybase fails when sp_helpindex is empty
Centos 5
Linux dba-dev1 2.6.22.9-default #1 SMP Mon Oct 1 11:26:48 CDT 2007 i686
athlon i386 GNU/Linux
Perl v5.8.8 built for i386-linux-thread-multi
SQL::Translator::0.09000
Sybase ASE’s sp_helpindex will normally return a result set containing
the column “INDEX_NAME” which parse() requires. When no index exists,
sp_helpindex returns a error string similar to “Object does not have any
indexes.” but no result set.
The following workaround simply wraps the selectall_hash with an eval,
if the eval results in no error, then try to use the hash.
252,259c252,259
< my $h = $dbh->selectall_hashref("sp_helpindex
< $table_info->{TABLE_NAME}", ‘INDEX_NAME’);
< foreach (values %{$h}) {
< my $fields = $_->{‘INDEX_KEYS’};
< $fields =~ s/\s*//g;
< my $i = $table->add_index(
< name =>
< $_->{INDEX_NAME},
—
> my $h;
> eval { $h = $dbh->selectall_hashref("sp_helpindex $table_info->{TABLE_NAME}", ‘INDEX_NAME’) };
> unless ($@) {
> foreach (values %{$h}) {
> my $fields = $_->{‘INDEX_KEYS’};
> $fields =~ s/\s*//g;
> my $i = $table->add_index(
> name => $_->{INDEX_NAME},
262,263c262,263
< if ($_->{‘INDEX_DESCRIPTION’} =~ /unique/i) {
< $i->type(‘unique’);
—
> if ($_->{‘INDEX_DESCRIPTION’} =~ /unique/i) {
> $i->type(‘unique’);
265,276c265,277
< # we could make this a primary key if there
< # isn’t already one defined and if there
< # aren’t any nullable columns in thisindex.
<
< if (!defined($table->primary_key())) {
< $table->primary_key($fields)
< unless grep {
< $table->get_field($_)->is_nullable()
< } split(/,\s*/, $fields);
< }
< }
< }
—
> # we could make this a primary key if there
> # isn’t already one defined and if there
> # aren’t any nullable columns in thisindex.
>
> if (!defined($table->primary_key())) {
> $table->primary_key($fields)
> unless grep {
> $table->get_field($_)->is_nullable()
> } split(/,\s*/, $fields);
> }
> }
> }
> }
Listen to this podcast




April 28th, 2008 at 1:12 am
[...] i686 athlon i386 GNU/Linux Perl v5.8.8 built for i386-linux-thread-multi SQL::Translator::0.0900http://froebe.net/blog/2008/04/24/sqltranslatorparserdbisybase-bug-35380-causes-script-to-fail-when-…Recent Original Stories OS News”The Fedora Unity Project is proud to announce the release of new DVD [...]