I am trying to query Sybase database using DBD::Sybase. Can someone please clarify what is the difference between using syb_nsql vs prepare(...) - execute(..) calls?
syb_nsql (as a direct port of Sybase::DBlib's nsql
which is a fairly high level wrapper) supports all of the nsql's advanced functionality which DBD::Sybase's prepare-execute does not (IIRC) have natively and for which you have to write the wrapper code yourself (basically, you pretty much have to re-implement your own version of nsql anyway):
MaxRows functionality to limit the # of returned rows to conserve memory usage
optional deadlock retry logic
error checking (using its companion error and message handlers - I don't recall DBD::Sybase having message handlers)
and several options for the format of the return values.
In addition, the data can either be returned to the caller in bulk (thus no need to write your own loop for fetch_arrayref etc...), or processes line by line via a callback subroutine passed as an argument (this functionality is similar to the r_sql() method).
Considering the fact that nsql is actually implemented using prepare/execute/fetchrow_arrayref; it will pretty much have no functional difference from any normal prepare-execute functionality you use directly. It seems to even support placeholders as per the code comments though it doesn't appear to be documented.
So the difference is that nsql allows you to avoid rolling your own wrapper code to support any of the advanced features like deadlock retry or MaxRows that are listed above.