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: "Dennis R dot Sherman" <sherman at trln dot lib dot unc dot edu>
Subject: Re: tool search: one row in column-name: value format?
Date: Nov 8 1995 1:42PM

I posted asking if anyone had a tool that would:

> > * take as input username, password, database, tablename, where-clause
> > * produce as output a listing of all rows in the named table that meet
> >   the criteria of the where-clause, in a form similar to
> >   
> > ========== (row separator) ======
> > column-name1: value1
> > column-name2: value2
> > column-name3: value3
> > etc.

And Michael Peppler posted a solution, "from the top of my head:".

Which, after I fixed a minor syntax error or two (missing close quote)
served my needs exactly!  Thank you!  (It'll be a while yet before I'm
familiar enough with SybPerl to whip this out off the top of my head, but
I'll get there, I hope...)

I fiddled with the output a little bit, added a check of the command line
parameters, and include it below for anyone interested.

> Michael
> 
> PS. Now I am truly leaving for my holidays... see you all in December :-)

Have a good time!  And thanks again.
--
  Dennis R. Sherman  	         Triangle Research Libraries Network
  dennis_sherman@unc.edu       Univ. of North Carolina - Chapel Hill
               http://www.unc.edu/~sherman/

#!/usr/local/bin/sybperl
# dumprow -- report row(s) in table in col: val format
# 
# 1995-11-07 D.Sherman 
#		fiddled with aesthetics, added usage()
# 1995-11-07 M.Peppler 
#		original coding, untested

require 'sybperl.pl';
require 'getopts.pl';

&Getopts('P:U:D:T:W:');

# $opt_P is password, $opt_U is user, $opt_D is db_name, 
# $opt_T is table_name, and $opt_W is where clause...

&usage() unless (defined($opt_P) && defined($opt_U) && defined($opt_D)
  && defined($opt_T) && defined($opt_W));

$d = &dblogin($opt_U, $opt_P);
&dbuse($d, $opt_D);
&dbcmd("select * from $opt_T where $opt_W");
&dbsqlexec($d); &dbresults($d);
while(%dat = &dbnextrow($d, 1))
{
    print "================\n";
    foreach $col (sort keys(%dat))
    {
         print "$col: $dat{$col}\n";
    }
}

###### Subroutines #####

sub usage
{
print < -P -D -T -W""
where
       is the Sybase username 
   is the Sybase password
     is the name of the database to use
  
is the name of the table to report is the where-clause identifying the row or rows to report Note: enclose in quotes if using embedded spaces Print one or more rows from one table, in col: val format. EOF exit; } # end usage() __END__;