dbish:

@mysql--> /desc gender_codes
                     NAME               TYPE NULLABLE
------------------------- ------------------ --------
                    id_pk       decimal  (2)        N
                 iso_code       decimal  (2)        N
                   gender          char  (1)        N
              description       varchar (15)        N
[4 rows of 3 fields returned]


sub do_describe {
    my ($sh, $tab, @argv) = @_;
        $sh->log( "Describe: $tab" );
        my $dbh = $sh->{dbh};
        my $sql = qq{select * from $tab where 1 = 0};
        my $sth = $dbh->prepare( $sql );
        $sth->execute;
        my $cnt = $#{$sth->{NAME}};  #
        my @names = qw{NAME TYPE NULLABLE};
        my @ti;
        for ( my $c = 0; $c <= $cnt; $c++ ) {
                push( my @j, $sth->{NAME}->[$c] || 0 );
                my $m = $dbh->type_info($sth->{TYPE}->[$c]);
                my $s;
                if (ref $m eq 'HASH') {
                        $s = $m->{TYPE_NAME} . q{ } . $sth->{TYPE}->[$c];
                } elsif (not defined $m) {
                         $s = q{undef } . $sth->{TYPE}->[$c];
                } else {
                        warn "describe:  not good.  Not good at all!";
                }

                if (defined $sth->{PRECISION}->[$c]) {
                        $s .= "(" . $sth->{PRECISION}->[$c] || '';
                        $s .= "," . $sth->{SCALE}->[$c] 
                        if ( defined $sth->{SCALE}->[$c] 
                                and $sth->{SCALE}->[$c] ne 0);
                        $s .= ")";
                }
                push(@j, $s,
                         $sth->{NULLABLE}->[$c] ne 1? qq{N}: qq{Y} );
                push(@ti,\@j);
        }
        $sth->finish;
        $sth = $sh->prepare_from_data("describe", \@ti, \@names);
        return $sh->sth_go($sth, 0);
}




On Tue, Aug 28, 2001 at 05:22:55PM +0100, Koen Gogne wrote:

> to select something from the database I do
> $qw = "select * from table";
> $sth = $dbh->prepare(qq ($qw));
> $sth->execute();
> to perform delete's, update's and insert's I use
> $qw = "delete from table";
> $dbh->do(qq ($qw));
> 
> BUT WHAT DO I NEED TO USE TO GET
> "describe table"
> both $h->execute() and $h->do() fail when I try them.
> What's the solution ?
> 
> btw, I'm trying this on an oracle db.

-- 
Thomas A. Lowery
See DBI/FAQ http://tlowery.hypermart.net

_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

Reply via email to