Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm just trying out Perl with the DBD::Sybase module nad cannot figure out whether it's possible or how to do this. I am a perl newcomer so forgive me if this is a trivial question.

I want to be able to put this statement into the prepare but don't know how to get DBD::Sybase to handle the delare bits ?
declare @name char(30)
declare @uid int
select @name=name, @uid=uid from $database..sysusers where suid = $suid
if (@name != null) exec $database..sp_dropuser @name else if exists (select 1 from $database..sysalternates where suid = $suid)
exec $database..sp_dropalias $loginname

Just sticking the whole select in a prepare doesn't work e.g.

$database="testdb"; $suid=1234; $loginname="joe"; $sth=$dbh->prepare("declare \@name char(30) declare \@uid int selec +t \@name=name, \@uid=uid from $database..sysusers where suid = $suid if (\@name != null) exec $database..sp_dropuser \@name else +if exists (select 1 from $database..sysal ternates where suid = $suid) exec $database..sp_dropalias $loginname") +; $sth->execute;
Any help appreciated

Replies are listed 'Best First'.
Re: DBD Sybase and declare
by derby (Abbot) on Jan 18, 2006 at 13:40 UTC

    In what way doesn't it work? What are the error messages? I would normally use do for something like this (and I'd also set an error handler - ala DBD::Sybase docs):

    $dbh = DBI->connect(...); $dbh->{syb_err_handler} = \&err_handler; $dbh->do($sql); $dbh->disconnect;

    -derby
Re: DBD Sybase and declare
by mpeppler (Vicar) on Jan 18, 2006 at 19:03 UTC
    As derby says that should work. However, without any error information it's really hard to figure out what you are doing wrong...

    Michael