PEPPLER.ORG
Michael Peppler
Sybase Consulting
Menu
Home
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
Freeware
Sybperl
Sybase::Simple
DBD::Sybase
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
FAQs
Sybase on Linux FAQ
Sybperl FAQ
Personal
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: jander at lehman dot com (Jim Anderson)
Subject: Re: tool search: one row in column-name: value format?
Date: Nov 7 1995 5:11PM

Here's part of it. I used to have the whole thing, but somehow
misplaced it :-(

...
require 'getcols.pl';
...
@tablename_colname = &getcols('table*name*goes*here');
%tablename_type    = %coltypes;
%tablename_order   = %colorder;
%tablename_leng    = %colleng;
...


#!/usr/local/bin/sybperl
#
# getcols.pl

sub getcols {
    local($ut) = shift;
    return () if !$ut;
    local($ord) = 0;

    local($sql) = "
select name,usertype,length from syscolumns
 where id = object_id('$ut')
 order by colid
";
    local(@d,@colname,$colname,$coltype,$colleng);

    %colorder = %colleng = %coltype = ();

    &gettypes if !%USERTYPE_TO_NAME;

    &dbcmd($dbproc,$sql) || die "dbcmd failed: $!\n";
    &dbsqlexec($dbproc)  || die "dbsqlexec failed: $!\n";
    while (&dbresults($dbproc) != $NO_MORE_RESULTS) {
	while ((@d = &dbnextrow($dbproc))) {
	    ($colname,$coltype,$colleng) = @d;
	    push(@colname,$colname);
	    $colorder{$ord++}  = $colname;
	    $colleng{$colname} = $colleng;
	    $coltype{$colname} = $USERTYPE_TO_NAME{$coltype};
	}
    }
    return @colname;
}

sub gettypes {
    return if %USERTYPE_TO_NAME;

    local($sql) = "select usertype,name from systypes";
    local(@d);

    &dbcmd($dbproc,$sql) || die "dbcmd failed: $!\n";
    &dbsqlexec($dbproc)  || die "dbsqlexec failed: $!\n";
    
    while (&dbresults($dbproc) != $NO_MORE_RESULTS) {
	while ((@d = &dbnextrow($dbproc))) {
	    $USERTYPE_TO_NAME{$d[0]} = $d[1];
	}
    }
    return;
}

1;