|
|
sybperl-l Archive
Up Prev Next
From: =?iso-8859-1?Q?Pochet_Fr=E9d=E9ric?=
<Frederic dot Pochet at cockerill-sambre dot com>
Subject: RE: Sybperl Examples
Date: Feb 1 1999 8:58AM
Hello,
here are two samples using CTLib:
List your database:
use Sybase::CTlib;
$dbh= new Sybase::CTlib 'sa', 'foobar',
'AL1FLM';
$dbh->ct_execute("select dbid, name from
sysdatabases");
while ($dbh->ct_results($restype) == CS_SUCCEED)
{
next unless
$dbh->ct_fetchable($restype);
while (($dbid, $dbname) =
$dbh->ct_fetch) {
print "dbid: $dbid - dbname:
$dbname\n";
}
}
exit
Using an aka:
use Sybase::CTlib;
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], "\n" if ($ARGV
[3] ne $ARGV [4]);
$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) {
}
$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
";
print $cSql, "\n";
($rc = $dbh->ct_execute("$cSql")) == CS_SUCCEED
or print "KO - $rc = execute $cSql\n"
;
## Copy the aka
## %r= ct_fetch(1)
## ...$r{} ...
$res_type = 0;
$tSql='select ';
while ($dbh->ct_results($restype) == CS_SUCCEED)
{
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"
;
## the aka address
## $r=ct_fetch(1,1)
## ...$$r{} ...
$res_type = 0;
$tSql='select ';
while ($dbh->ct_results($restype) == CS_SUCCEED)
{
next unless
$dbh->ct_fetchable($restype);
while ($row = $dbh->ct_fetch(1,1)) {
print $$row{ID}, '-',
$$row{INDID}, '-',$$row{NAME},"\n";
}
}
exit
have fun
best regards
F.Pochet
==========================================
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: illo[SMTP:illo@cn2000.net]
> Reply To: SYBPERL-L@listproc.net
> Sent: lundi 1 février 1999 2:37
> To: SybPerl Discussion List
>
> This message uses a character set that is not supported by the
> Internet Mail Service. To view the original message content, open
> the attached message. If the text doesn't display correctly, save the
> attachment to disk, and then open it using a viewer that can display
> the original character set.<>
>
|