markhoy has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I use FreeTDS to connect to SQL Server7. Can someone tell me the syntax to get the field size? In asp it is:
rs.fields(fld).definedsize
Is there a Perl equivalent (along the lines of
@$oXs[$j]->{field_size}
)?? Thanks, Mark

Replies are listed 'Best First'.
Re: Field Size using FreeTDS and SQL7
by derby (Abbot) on Feb 28, 2003 at 14:24 UTC
    I'm assuming you possibly mean the max size of a field and not the size of the data in the field (like finding out a column can contain a CHAR(255)). I'm not sure about FreeTDS or SQL Server 7 but under DBD::Sybase (they're closely relatated), you can find out this information by checking the PRECISION attribute of the statement handle - not quite as convenient as asp but ...

    #!/usr/bin/perl -w use DBI; use Data::Dumper; my $dbh = DBI->connect( 'dbi:Sybase:server=name', 'user', 'pass' ); $dbh->do( "use database" ); my $sql = "select * from alertquerystring order by alert_id"; my $sth = $dbh->prepare( $sql ); $sth->execute; print "The fields returned are of type: ", Dumper( $sth->{TYPE} ); print "The fields have the following precision ", Dumper( $sth->{PRECI +SION} ); $sth->finish; $dbh->disconnect;

    -derby

      I had thought it was field length but it was meant to be length of the returned data in each field. Thanks. Mark