http://www.perlmonks.org?node_id=870185

perl@1983 has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am using DBI and DBD::Sybase to connect to Sybase database. I have seen that to execute a SQL statement or make a stored proc call, some of the programmers use syb_nsql ($SQL,"HASH") like method while some use prepare($SQL), $sth->execute() syntax. I was wondering what is the difference between those two? Which one is better? Thanks

Replies are listed 'Best First'.
Re: difference between syb_nsql and prepare/execute call
by TomDLux (Vicar) on Nov 08, 2010 at 21:03 UTC

    I always use prepare(), execute(), or at least selectall_hashref().

    What does the DBD-Sybase documentation say?

    As Occam said: Entia non sunt multiplicanda praeter necessitatem.

Re: difference between syb_nsql and prepare/execute call
by sundialsvc4 (Abbot) on Nov 09, 2010 at 03:57 UTC

    I would guess that the former is some kind of low-level call that is specific to Sybase, whereas the second is “ordinary DBI syntax.”   As others have suggested, look at the DBD driver documentation.   If the programmers that you speak of are available, go and ask them.

      Thanks for the reply. Unfortunately, the programmers I asked didn't have much clarity on this as well. :(
Re: difference between syb_nsql and prepare/execute call
by elwarren (Priest) on Nov 09, 2010 at 16:57 UTC

    If you prepare() then execute(), you have the option of executing the same statement multiple times without preparing again. A simple optimization that can add up when updating many records.

    The syb_nsql combines these steps into one, as well as offering additional functionality with callbacks. Docs cover this better than I can explain it.

      I already checked the documentation at cpan, but could not understand clearly. So, do you mean to say that syb_nsql is better?
        I don't know about you, but I read that as saying there are trade-offs.
Re: difference between syb_nsql and prepare/execute call
by mpeppler (Vicar) on Nov 10, 2010 at 14:58 UTC
    syb_nsql() was added to provide a compatible call with Sybase::CTlib and Sybase::DBlib, and to simplify porting perl code between the two. The call was added at the request of a rather large organization that uses a lot of perl/Sybase :-)

    Personally I use prepare/execute/fetch...

    Michael