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: "Sheree Hemphill" <sah18 at po dot cwru dot edu>
Subject: RE: very basic db connection question
Date: Feb 10 1999 12:53PM

frederick,
thank you for your example!
sheree

> -----Original Message-----
> From: owner-SYBPERL-L@listproc.net
> [mailto:owner-SYBPERL-L@listproc.net]On Behalf Of Pochet Frédéric
> Sent: Wednesday, February 10, 1999 4:42 AM
> To: SybPerl Discussion List
> Subject: RE: very basic db connection question
>
>
> here is how to use different db and how to use associative array
>
> use Sybase::CTlib;
>
> print "\n param count >", $#ARGV;  ## ko
> print "\n user   >", $ARGV [0];
> print "\n pwd    >", $ARGV [1];
> print "\n server >", $ARGV [2];
> print "\n db     >", $ARGV [3];
> print "\n table  >", $ARGV [4] if ($ARGV [3] ne $ARGV [4]);
> print "\n";
>
> $dbh= new Sybase::CTlib $ARGV[0],$ARGV[1],$ARGV[2];
>
> $cSql= "use $ARGV[3]";
> ($rc = $dbh->ct_execute($cSql)) == CS_SUCCEED
> 	or print "KO - $rc = execute '$cSql'\n"
> ;
>
> $res_type = 0;
> while(($rc = $dbh->ct_results($res_type)) == CS_SUCCEED) {
> 	print "1 - $res_type\n";
> }
>
> $cSql='
> 	select ID=i.id, INDID=i.indid, NAME=i.name
> 	from sysindexes i, sysobjects o
> 	where i.id = o.id and o.type=\'U\'
> ';
> if ($ARGV [3] ne $ARGV [4]) {
> $cSql="$cSql
> 	  and o.id = object_id(\'$ARGV[4]\')
> ";
> }
> $cSql="$cSql
> 	order by o.name
> ";
>
> ($rc = $dbh->ct_execute("$cSql")) == CS_SUCCEED
> 	or print "KO - $rc = execute $cSql\n"
> ;
>
> ## récupérer un Associative Array par recopie
> ## %r= ct_fetch(1)
> ## ...$r{} ...
>
> $res_type = 0;
> $tSql='select ';
> while ($dbh->ct_results($restype) == CS_SUCCEED) {
>    print "2 - $res_type\n";
> 	next unless $dbh->ct_fetchable($restype);
> 	while (%row = $dbh->ct_fetch(1)) {
> 		print $row{ID}, '-', $row{INDID}, '-',$row{NAME},"\n";
> 	}
> }
>
> ($rc = $dbh->ct_execute("$cSql")) == CS_SUCCEED
> 	or print "KO - $rc = execute $cSql\n"
> ;
>
> ## récupérer un Associative Array par adresse
> ## $r=ct_fetch(1,1)
> ## ...$$r{} ...
>
> $res_type = 0;
> $tSql='select ';
> while ($dbh->ct_results($restype) == CS_SUCCEED) {
>    print "2 - $res_type\n";
> 	next unless $dbh->ct_fetchable($restype);
> 	while ($row = $dbh->ct_fetch(1,1)) {
> 		print $$row{ID}, '-', $$row{INDID}, '-',$$row{NAME},"\n";
> 	}
> }
>
>
> exit
>
>
> ==========================================
> Frederic Pochet
> DBA DB Distribuees
>
> Cockerill Sambre
>
> *
> Rue Vieille Fosse
> B-4400 Flemalle
> Belgium
>
> *  +32 4 236 20 71
> *   +32 4 236 21 00
> *  frederic.pochet@cockerill-sambre.com
> ==========================================
>
> > ----------
> > From: 	Sheree Hemphill[SMTP:sah18@po.cwru.edu]
> > Reply To: 	SYBPERL-L@listproc.net
> > Sent: 	mardi 9 février 1999 22:06
> > To: 	SybPerl Discussion List
> > Subject: 	very basic db connection question
> >
> > Hello.  I am new to Sybperl, and I would like to use CTlib to
> connect to a
> > database.  I can only seem to find code examples which connect to the
> > Master
> > database, but none which show how to connect to a user-defined database.
> > Can someone give me an example of the syntax for this?
> >
> > Thank you in advance!
> > Sheree
> >
> > ps:  The main sample code that I am trying to model after is
> listed below.
> > It was taken from "Sybperl 2.0: Using the Sybase::CTlib module"
> by Michael
> > Peppler.  It worked perfectly for me.
> >
> > #!/usr/local/bin/perl
> >
> > # Load the Sybase::CTlib module:
> > use Sybase::CTlib;
> >
> > # Allocate a new Database 'handle';
> > $dbh = new Sybase::CTlib 'sa', 'oracle8', 'helix';
> >
> > # Send the query to the server:
> > $dbh->ct_execute("select uid, name from sysusers");
> >
> > # Retrieve the result sets
> > while($dbh->ct_results($restype) == CS_SUCCEED) {
> >
> > 	# Skip non-fetchable results:
> > 	next unless $dbh->ct_fetchable($restype);
> >
> > 	# Retrieve actual data rows:
> > 	while(($uid, $name) = $dbh->ct_fetch) {
> > 		print "$uid - $name\n";
> > 	}
> > }
> >
>
>