Introduce GOVERNANCE document and empty RESOLUTIONS file.
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Sybase / FreeTDS.pm
CommitLineData
c1e5a9ac 1package DBIx::Class::Storage::DBI::Sybase::FreeTDS;
2
3use strict;
4use warnings;
5use base qw/DBIx::Class::Storage::DBI::Sybase/;
6use mro 'c3';
ddcc02d1 7use DBIx::Class::_Util 'dbic_internal_try';
c1e5a9ac 8use namespace::clean;
9
10=head1 NAME
11
6cefa7ab 12DBIx::Class::Storage::DBI::Sybase::FreeTDS - Base class for drivers using
13DBD::Sybase over FreeTDS.
c1e5a9ac 14
15=head1 DESCRIPTION
16
17This is the base class for Storages designed to work with L<DBD::Sybase> over
18FreeTDS.
19
20It is a subclass of L<DBIx::Class::Storage::DBI::Sybase>.
21
22=head1 METHODS
23
24=cut
25
26# The subclass storage driver defines _set_autocommit_stmt
27# for MsSQL it is SET IMPLICIT_TRANSACTIONS ON/OFF
28# for proper Sybase it's SET CHAINED ON/OFF
29sub _set_autocommit {
30 my $self = shift;
31
32 if ($self->_dbh_autocommit) {
33 $self->_dbh->do($self->_set_autocommit_stmt(1));
34 } else {
35 $self->_dbh->do($self->_set_autocommit_stmt(0));
36 }
37}
38
39# Handle AutoCommit and SET TEXTSIZE because LongReadLen doesn't work.
40#
41sub _run_connection_actions {
42 my $self = shift;
43
44 # based on LongReadLen in connect_info
45 $self->set_textsize;
46
47 $self->_set_autocommit;
48
49 $self->next::method(@_);
50}
51
52=head2 set_textsize
53
54When using DBD::Sybase with FreeTDS, C<< $dbh->{LongReadLen} >> is not available,
55use this function instead. It does:
56
57 $dbh->do("SET TEXTSIZE $bytes");
58
59Takes the number of bytes, or uses the C<LongReadLen> value from your
60L<connect_info|DBIx::Class::Storage::DBI/connect_info> if omitted, lastly falls
61back to the C<32768> which is the L<DBD::Sybase> default.
62
63=cut
64
65sub set_textsize {
66 my $self = shift;
67 my $text_size =
68 shift
69 ||
ddcc02d1 70 dbic_internal_try { $self->_dbic_connect_attributes->{LongReadLen} }
c1e5a9ac 71 ||
72 32768; # the DBD::Sybase default
73
74 $self->_dbh->do("SET TEXTSIZE $text_size");
75}
76
90d7422f 77sub _exec_txn_begin {
c1e5a9ac 78 my $self = shift;
79
90d7422f 80 if ($self->{_in_do_block}) {
c1e5a9ac 81 $self->_dbh->do('BEGIN TRAN');
82 }
83 else {
84 $self->dbh_do(sub { $_[1]->do('BEGIN TRAN') });
85 }
86}
87
90d7422f 88sub _exec_txn_commit {
c1e5a9ac 89 my $self = shift;
90
91 my $dbh = $self->_dbh
92 or $self->throw_exception('cannot COMMIT on a disconnected handle');
93
94 $dbh->do('COMMIT');
95}
96
90d7422f 97sub _exec_txn_rollback {
c1e5a9ac 98 my $self = shift;
99
100 my $dbh = $self->_dbh
101 or $self->throw_exception('cannot ROLLBACK on a disconnected handle');
102
103 $dbh->do('ROLLBACK');
104}
105
a2bd3796 106=head1 FURTHER QUESTIONS?
c1e5a9ac 107
a2bd3796 108Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
c1e5a9ac 109
a2bd3796 110=head1 COPYRIGHT AND LICENSE
c1e5a9ac 111
a2bd3796 112This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
113by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
114redistribute it and/or modify it under the same terms as the
115L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.
c1e5a9ac 116
117=cut
a2bd3796 118
1191;