DBIx-Class
view release on metacpan or search on metacpan
lib/DBIx/Class/Storage/DBI/ADO/Microsoft_SQL_Server.pm view on Meta::CPAN
});
=head1 NAME
DBIx::Class::Storage::DBI::ADO::Microsoft_SQL_Server - Support for Microsoft
SQL Server via DBD::ADO
=head1 SYNOPSIS
This subclass supports MSSQL server connections via L<DBD::ADO>.
=head1 DESCRIPTION
The MSSQL specific functionality is provided by
L<DBIx::Class::Storage::DBI::MSSQL>.
=head1 EXAMPLE DSN
dbi:ADO:provider=sqlncli10;server=EEEBOX\SQLEXPRESS
=head1 CAVEATS
=head2 identities
C<_identity_method> is set to C<@@identity>, as C<SCOPE_IDENTITY()> doesn't work
with L<DBD::ADO>. See L<DBIx::Class::Storage::DBI::MSSQL/IMPLEMENTATION NOTES>
for caveats regarding this.
=head2 truncation bug
There is a bug with MSSQL ADO providers where data gets truncated based on the
size of the bind sizes in the first prepare call:
L<https://rt.cpan.org/Ticket/Display.html?id=52048>
The C<ado_size> workaround is used (see L<DBD::ADO/ADO providers>) with the
approximate maximum size of the data_type of the bound column, or 8000 (maximum
VARCHAR size) if the data_type is not available.
Please report problems with this driver and send patches.
=head2 LongReadLen
C<LongReadLen> is set to C<LongReadLen * 2 + 1> on connection as it is necessary
for some LOB types. Be aware of this if you localize this value on the C<$dbh>
directly.
=head2 binary data
Due perhaps to the ado_size workaround we use, and/or other reasons, binary data
such as C<varbinary> column data comes back padded with trailing C<NULL> chars.
The Cursor class for this driver
(L<DBIx::Class::Storage::DBI::ADO::Microsoft_SQL_Server::Cursor>) removes them,
of course if your binary data is actually C<NULL> padded that may be an issue to
keep in mind when using this driver.
=head2 uniqueidentifier columns
uniqueidentifier columns come back from ADO wrapped in braces and must be
submitted to the MSSQL ADO driver wrapped in braces. We take care of this
transparently in this driver and the associated Cursor class
(L<DBIx::Class::Storage::DBI::ADO::Microsoft_SQL_Server::Cursor>) so that you
don't have to use braces in most cases (except in literal SQL, in those cases
you will have to add the braces yourself.)
=head2 fractional seconds
Fractional seconds with L<DBIx::Class::InflateColumn::DateTime> are not
currently supported, datetimes are truncated at the second.
=cut
sub _init {
my $self = shift;
# SCOPE_IDENTITY() doesn't work
$self->_identity_method('@@identity');
$self->_no_scope_identity_query(1);
return $self->next::method(@_);
}
sub _run_connection_actions {
my $self = shift;
# make transactions work
require DBD::ADO::Const;
$self->_dbh->{ado_conn}{CursorLocation} =
DBD::ADO::Const->Enums->{CursorLocationEnum}{adUseClient};
# set LongReadLen = LongReadLen * 2 + 1
# this may need to be in ADO.pm, being conservative for now...
my $long_read_len = $self->_dbh->{LongReadLen};
# This is the DBD::ADO default.
if ($long_read_len != 2147483647) {
$self->_dbh->{LongReadLen} = $long_read_len * 2 + 1;
}
return $self->next::method(@_);
}
# Fix up binary data and GUIDs for ->find, for cursors see the cursor_class
# above.
sub select_single {
my $self = shift;
my ($ident, $select) = @_;
my @row = $self->next::method(@_);
return @row unless $self->cursor_class->isa(
'DBIx::Class::Storage::DBI::ADO::Microsoft_SQL_Server::Cursor'
);
my $col_infos = $self->_resolve_column_info($ident);
_normalize_guids($select, $col_infos, \@row, $self);
_strip_trailing_binary_nulls($select, $col_infos, \@row, $self);
( run in 1.320 second using v1.01-cache-2.11-cpan-39bf76dae61 )