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: Dave dot Cross at gb dot swissbank dot com
Subject: Re: Help using sybperl Sybase::DBLib sql routine
Date: Sep 24 1997 7:46AM

     
     Bob,
     
     The function is acting exactly as described in the docs. Calling sql 
     in the way you tried at first, it returns an array. Each element of 
     the array is a reference to another array. Each of these referenced 
     arrays is a row in your result set and contains one element for each 
     column.
     
     To convert that into useful code...
     
     my ($row, $col, @data);
     @data = $db->sql("select field1, field2 from tablename");
     
     foreach $row (@data)
     {
        foreach $col (@{$row})
        {
                print "$col\t";
        }
        print "\n";
     }
     
     ... will print out the contents of your result set.
     
     As for the second way of calling sql, you were getting very close. The 
     second parameter to sql is the name of a function to call for each 
     row. To not pass this value but pass a value in the third parameter 
     (in order to get a hash rather than an array) you need to pass the 
     special perl value 'undef'. The two attempts you made were both read 
     as function names (and of course the functions were undefined).
     
     To convert this into useful code...
     
     my ($row, $col, @data);
     @data = $db->sql("select field1, field2 from tablename", undef, 1);
     
     foreach $row (@data)
     {
        foreach $col (keys %{$row})
        {
                print "$col:$rows->{$col}\t";
        }
        print "\n";
     }
     
     Apologies for any typos - I've typed this straight into the mailer!
     
     You should get hold of the SybPerl documentation. It explains all this 
     quite clearly.
     
     Hope this helps,
     
     Dave...
     
     
______________________________ Reply Separator _________________________________
Subject: Help using sybperl Sybase::DBLib sql routine
Author:  bbrown2 (bbrown2@lindy.stanford.edu) at unix,mime 
Date:    23/09/97 19:05
     
     
I'm using the Sybase::DBLib routines.
     
I've called sql with
     
        $db->sql("select field1, field2 from tablename");
     
It returns something like:
     
>>>> ARRAY(0x330f14)
>>>> ARRAY(0x330f38)
>>>> ARRAY(0x334928)
>>>> ARRAY(0x33497c)
>>>> ARRAY(0x3349ac)
>>>> ARRAY(0x3349f4)
>>>> ARRAY(0x334a24)
>>>> ARRAY(0x334a54)
>>>> ARRAY(0x334a84)
>>>> ARRAY(0x334ab4)
>>>> ARRAY(0x334ae4)
>>>> ARRAY(0x334b14)
>>>> ARRAY(0x334b44)
>>>> ARRAY(0x334b74)
>>>> ARRAY(0x334ba4)
>>>> ARRAY(0x334bd4)
>>>> ARRAY(0x334c20)
>>>> ARRAY(0x334c50)
>>>> ARRAY(0x334c80)
>>>> ARRAY(0x334cb0)
>>>> ARRAY(0x334ce0)
>>>> ARRAY(0x334d10)
>>>> ARRAY(0x334d40)
>>>> ARRAY(0x334d70)
>>>> ARRAY(0x334da0)
     
How do I get this into something useful?
     
I thought that sql had a flag in the third field that set the kind of 
results so I tried:
     
        $db->sql("select field1, field2 from tablename", "", 1);
     
I get this:
     
Call sql
Undefined subroutine &main:: called at 
/opt/perl5.003/lib/site_perl/auto/Sybase/DBlib/sql.al 
line 21,  chunk 5.
     
     
This:
     
        $db->sql("select field1, field2 from tablename", NULL, 1);
     
gives this result:
     
Call sql
Undefined subroutine &main::0 called at 
/opt/perl5.003/lib/site_perl/auto/Sybase/DBlib/sql.al 
line 21,  chunk 5.
     
     
Any ideas?!
     
Bob