Skip to Content.
Sympa Menu

freetds - [freetds] RE: Stored Procedures with DBD::Sybase and FreeTDS

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: RWilbert AT exchange.webmd.net
  • To: mpeppler AT peppler.org, dbi-users AT perl.org, freetds AT lists.ibiblio.org
  • Subject: [freetds] RE: Stored Procedures with DBD::Sybase and FreeTDS
  • Date: Mon, 23 Dec 2002 11:16:06 -0500

Thanks

I will also ask on the FreeTDS mailing list. Here is a log of what happens
when I execute the stored procedure. I just do a select and insert and
select to so that I can insert into the database. I was not sure if it was
an issue with freetds or DBD::Sybase. I should also note the procedure works
it inserts the data. but throw the error. It segs with trace->(3). Also I
get the same error with a $dbh->do();

Here is the trace using the typical prepare, execute, fetch method
[rwilbert@bender dev]$ ./sp.pl snow NSADB "select * from test1" sa null
[rwilbert@bender dev]$ ./sp.pl snow NSADB "insert into test1 (text1, text2)
values (\"test\", \"1\")" sa null
[rwilbert@bender dev]$ ./sp.pl snow NSADB "select * from test1" sa null

test ,1
[rwilbert@bender dev]$ ./sp.pl snow NSADB "InsertMe \"test\", \"1\"" sa null

ct_res_info() returned 0 columns at
/usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi/DBD/Sybase.pm line
132.
dbih_setup_fbav: invalid number of fields: 0, NUM_OF_FIELDS attribute
probably not set right at /usr/lib/perl5/site_perl/5.8.0/i386-
linux-thread-multi/DBD/Sybase.pm line 137.
[rwilbert@bender dev]$ ./sp.pl snow NSADB "InsertMe \"test\", \"1\"" sa null
3
DBI::db=HASH(0x81a9da8) trace level set to 3 in DBI 1.32-ithread
Note: perl is running without the recommended perl -w option
-> do for DBD::Sybase::db (DBI::db=HASH(0x81a9e68)~0x81a9da8 'InsertMe
"test", "1"') thr#804b3c0
1 -> prepare for DBD::Sybase::db (DBI::db=HASH(0x81a9da8)~INNER 'InsertMe
"test", "1"' undef) thr#804b3c0
dbih_setup_handle(DBI::st=HASH(0x81aa624)=>DBI::st=HASH(0x81aa684),
DBD::Sybase::st, 81aa630, Null!)
dbih_make_com(DBI::db=HASH(0x81a9da8), DBD::Sybase::st, 396) thr#804b3c0
1 <- prepare= DBI::st=HASH(0x81aa624) at Sybase.pm line 131 via ./sp.pl
line 60
-> execute for DBD::Sybase::st (DBI::st=HASH(0x81aa624)~0x81aa684)
thr#804b3c0
syb_st_execute() -> ct_command() OK
syb_st_execute() -> ct_send() OK
st_next_result() -> ct_results(12) == 1
st_next_result() -> ct_results(12) == 1
st_next_result() -> ct_results(4043) == 1
ct_res_info() returns 25933 columns
Segmentation fault

Here is the trace of the do:

[rwilbert@bender dev]$ ./sp.pl snow NSADB "InsertMe \"test\", \"1\"" sa null
3
DBI::db=HASH(0x81a97c0) trace level set to 3 in DBI 1.32-ithread
Note: perl is running without the recommended perl -w option
-> do for DBD::Sybase::db (DBI::db=HASH(0x81a9880)~0x81a97c0 'InsertMe
"test", "1"') thr#804b3c0
1 -> prepare for DBD::Sybase::db (DBI::db=HASH(0x81a97c0)~INNER 'InsertMe
"test", "1"' undef) thr#804b3c0
dbih_setup_handle(DBI::st=HASH(0x81a9940)=>DBI::st=HASH(0x81bd3b4),
DBD::Sybase::st, 81a994c, Null!)
dbih_make_com(DBI::db=HASH(0x81a97c0), DBD::Sybase::st, 396) thr#804b3c0
1 <- prepare= DBI::st=HASH(0x81a9940) at Sybase.pm line 131 via ./sp.pl
line 60
-> execute for DBD::Sybase::st (DBI::st=HASH(0x81a9940)~0x81bd3b4)
thr#804b3c0
syb_st_execute() -> ct_command() OK
syb_st_execute() -> ct_send() OK
st_next_result() -> ct_results(12) == 1
st_next_result() -> ct_results(12) == 1
st_next_result() -> ct_results(4043) == 1
ct_res_info() returned 0 columns at
/usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi/DBD/Sybase.pm line
132.
describe() retcode = 1
st_next_result() -> lasterr = 0, lastsev = 0
<- execute= 1074912608 at Sybase.pm line 132 via ./sp.pl line 60
-> err in DBD::_::common for DBD::Sybase::st
(DBI::st=HASH(0x81a9940)~0x81bd3b4) thr#804b3c0
<- err= undef at Sybase.pm line 133 via ./sp.pl line 60
-> rows for DBD::Sybase::st (DBI::st=HASH(0x81a9940)~0x81bd3b4)
thr#804b3c0
<- rows= 1074912608 at Sybase.pm line 134 via ./sp.pl line 60
-> FETCH for DBD::Sybase::st (DBI::st=HASH(0x81bd3b4)~INNER
'syb_more_results') thr#804b3c0
<- FETCH= 0 at Sybase.pm line 135 via ./sp.pl line 60
-> fetch for DBD::Sybase::st (DBI::st=HASH(0x81a9940)~0x81bd3b4)
thr#804b3c0
dbih_setup_fbav: invalid number of fields: 0, NUM_OF_FIELDS attribute
probably not set right at /usr/lib/perl5/site_perl/5.8.0/i386-
linux-thread-multi/DBD/Sybase.pm line 137.
<> DESTROY ignored for outer handle DBI::st=HASH(0x81a9940) (inner
DBI::st=HASH(0x81bd3b4))
-> DESTROY for DBD::Sybase::st (DBI::st=HASH(0x81bd3b4)~INNER)
thr#804b3c0
syb_st_finish() -> ct_cancel(CS_CANCEL_ALL)
syb_st_finish() -> resetting ACTIVE, moreResults, dyn_execed
syb_st_destroy: called on 81bd890...
syb_st_destroy(): freeing imp_sth->statement
syb_st_destroy(): cmd dropped: 1
<- DESTROY= undef
-> DESTROY for DBD::Sybase::db (DBI::db=HASH(0x81a97c0)~INNER)
thr#804b3c0
syb_db_disconnect() -> ct_close()
<- DESTROY= undef



Here is the script that I am using:

#!/usr/bin/perl

use DBI;


sub usage(){
print<<EOF;

$0: Machine_Name DBName "SQL Statement"

The SQL Statement must be quoted .

example:

$0 server database "select * from dbo.syscolumns" [username] [password]
[trace_level]

EOF

exit 1
}

if (@ARGV <= 2){
usage();
}

### define the the required vars
my $sv = shift;
my $db = shift;
my $qs = shift;


### set up our optional username and password
my $user = shift || "username";
my $passwd = shift || "password" ;
if ($passwd =~ /null/ ){
undef $passwd;
}
my $trace = shift;

## connect to the database
my $dbh = DBI->connect("DBI:Sybase:server=$sv;port=1433:database=$db",
$user, $passwd)||die $!;
if ( $trace ne '' ) {
$dbh->trace($trace);
}

#different $dbi call for inserts or updates
if ($qs =~ /^insert|^update|^delete/i){
$dbh->do ($qs) || die "$dbh->errstr";
}else{

### deals with selects
my $sth = $dbh->prepare($qs)|| die "$dbh->errstr";
# $dbh->do ($qs) || die "$dbh->errstr";
$sth ->execute() || die "$dbh->errstr";
while (my @tmp = $sth->fetchrow_array()){
print join ",", @tmp;
print "\n";
}
}

## disconnects from server
$dbh ->disconnect;


Here is the stored procedure:

CREATE PROCEDURE InsertMe
@Text1 AS char(10),
@Text2 AS char(10)

AS

INSERT INTO test1 (
text1,
text2
)
VALUES (
@Text1,
@Text2


);
RETURN 0
GO





-----Original Message-----
From: Michael Peppler [mailto:mpeppler AT peppler.org]
Sent: Friday, December 20, 2002 11:06 AM
To: dbi-users AT perl.org
Subject: Re: Stored Procedures with DBD::Sybase and FreeTDS


On Thu, 2002-12-19 at 13:35, RWilbert AT exchange.webmd.net wrote:
> Has anyone had a problem calling to a stored procedure that performs an
> insert and returns no data ?
>
> I am currently having that and the error that I am getting is:
> dbih_setup_fbav: invalid number of fields: 0, NUM_OF_FIELDS attribute
> probably not set right at
> /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi/DBD/Sybase.pm line
> 445.
>
> The sql statement works from the MSSql client and if I call a stored
> procedure that returns data it works.

Try asking on the FreeTDS list.

Alternatively send me (but not the list) a trace (DBI->trace(3)) from
running your script.

Thanks

Michael
--
Michael Peppler Data Migrations, Inc.
mpeppler AT peppler.org http://www.mbay.net/~mpeppler
Sybase T-SQL/OpenClient/OpenServer/C/Perl developer available for short or
long term contract positions - http://www.mbay.net/~mpeppler/resume.html



  • [freetds] RE: Stored Procedures with DBD::Sybase and FreeTDS, RWilbert, 12/23/2002

Archive powered by MHonArc 2.6.24.

Top of Page