DBD-Sybase
view release on metacpan or search on metacpan
$dbh=DBI->connect("dbi:Sybase:tdsLevel=CS_TDS_42", $user, $password);
B<NOTE>: Setting the tdsLevel below CS_TDS_495 will disable a number of
features, ?-style placeholders and CHAINED non-AutoCommit mode, in particular.
=item encryptPassword
Specify the use of the client password encryption supported by CT-Lib.
Specify a value of 1 to use encrypted passwords. Set to a value > 1 to also
enable asymetric password encryption.
$dbh=DBI->connect("dbi:Sybase:encryptPassword=1", $user, $password);
=item kerberos
Note: Requires OpenClient 11.1.1 or later.
Sybase and OpenClient can use Kerberos to perform network-based login.
If you use Kerberos for authentication you can use this feature and pass
a kerberos serverprincipal using the C<kerberos=value> parameter:
$dbh = DBI->connect("dbi:Sybase:kerberos=$serverprincipal", '', '');
In addition, if you have a system for retrieving Kerberos serverprincipals at
run-time you can tell DBD::Sybase to call a perl subroutine to get
the serverprincipal from connect():
sub sybGetPrinc {
my $srv = shift;
return the serverprincipal...
}
$dbh = DBI->connect('dbi:Sybase:server=troll', '', '', { syb_kerberos_serverprincipal => \&sybGetPrinc });
The subroutine will be called with one argument (the server that we will
connect to, using the normal Sybase behavior of checking the DSQUERY
environment variable if no server is specified in the connect()) and is
expected to return a string (the Kerberos serverprincipal) to the caller.
=item sslCAFile
Specify the location of an alternate I<trusted.txt> file for SSL
connection negotiation:
$dbh->DBI->connect("dbi:Sybase:sslCAFile=/usr/local/sybase/trusted.txt.ENGINEERING", $user, $password);
=item bulkLogin
Set this to 1 if the connection is going to be used for a bulk-load
operation (see I<Experimental Bulk-Load functionality> elsewhere in this
document.)
$dbh->DBI->connect("dbi:Sybase:bulkLogin=1", $user, $password);
=item serverType
Tell DBD::Sybase what the server type is. Defaults to ASE. Setting it to
something else will prevent certain actions (such as setting options,
fetching the ASE version via @@version, etc.) and avoid spurious errors.
=item tds_keepalive
Set this to 1 to tell OpenClient to enable the KEEP_ALIVE attribute on the
connection. Default 1.
=back
These different parameters (as well as the server name) can be strung
together by separating each entry with a semi-colon:
$dbh = DBI->connect("dbi:Sybase:server=ENGINEERING;packetSize=8192;language=us_english;charset=iso_1",
$user, $pwd);
=head1 Handling Multiple Result Sets
Sybase's Transact SQL has the ability to return multiple result sets
from a single SQL statement. For example the query:
select b.title, b.author, s.amount
from books b, sales s
where s.authorID = b.authorID
order by b.author, b.title
compute sum(s.amount) by b.author
which lists sales by author and title and also computes the total sales
by author returns two types of rows. The DBI spec doesn't really
handle this situation, nor the more hairy
exec my_proc @p1='this', @p2='that', @p3 out
where C<my_proc> could return any number of result sets (ie it could
perform an unknown number of C<select> statements.
I've decided to handle this by returning an empty row at the end
of each result set, and by setting a special Sybase attribute in $sth
which you can check to see if there is more data to be fetched. The
attribute is B<syb_more_results> which you should check to see if you
need to re-start the C<fetch()> loop.
To make sure all results are fetched, the basic C<fetch> loop can be
written like this:
{
while($d = $sth->fetch) {
... do something with the data
}
redo if $sth->{syb_more_results};
}
You can get the type of the current result set with
$sth->{syb_result_type}. This returns a numerical value, as defined in
$SYBASE/$SYBASE_OCS/include/cspublic.h:
#define CS_ROW_RESULT (CS_INT)4040
#define CS_CURSOR_RESULT (CS_INT)4041
#define CS_PARAM_RESULT (CS_INT)4042
#define CS_STATUS_RESULT (CS_INT)4043
#define CS_MSG_RESULT (CS_INT)4044
#define CS_COMPUTE_RESULT (CS_INT)4045
( run in 0.941 second using v1.01-cache-2.11-cpan-39bf76dae61 )