Home » Databases » Sybase » ASE » SQL::Translator::Parser::DBI::Sybase bug (35380) causes script to fail when sp_helpindex doesn’t return a result set

SQL::Translator::Parser::DBI::Sybase bug (35380) causes script to fail when sp_helpindex doesn’t return a result set

35380: 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.

diff Sybase_orig.pm Sybase_new.pm
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);
>                           }
>                      }
>                  }
>               }
Share Button

2 thoughts on “SQL::Translator::Parser::DBI::Sybase bug (35380) causes script to fail when sp_helpindex doesn’t return a result set

  1. Pingback: i386
  2. itay says:

    nice post
    would you consider link exchange
    email my at :
    fit.blog1@gmail.com

    visit me at my blog
    http://sql-insights.blogspot.com/

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Facebook login by WP-FB-AutoConnect