Merge the relationship resolution rework
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / ADO / Microsoft_SQL_Server / Cursor.pm
CommitLineData
2edf3352 1package DBIx::Class::Storage::DBI::ADO::Microsoft_SQL_Server::Cursor;
2
3use strict;
4use warnings;
616ca57f 5
2edf3352 6use base 'DBIx::Class::Storage::DBI::Cursor';
7use mro 'c3';
616ca57f 8
2edf3352 9use DBIx::Class::Storage::DBI::ADO::CursorUtils qw/_normalize_guids _strip_trailing_binary_nulls/;
616ca57f 10use DBIx::Class::ResultSource::FromSpec::Util 'fromspec_columns_info';
2edf3352 11use namespace::clean;
12
13=head1 NAME
14
15DBIx::Class::Storage::DBI::ADO::Microsoft_SQL_Server::Cursor - Remove trailing
16NULLs in binary data and normalize GUIDs for MSSQL over ADO
17
18=head1 DESCRIPTION
19
20This class is for removing trailing C<NULL>s from binary data and removing braces
21from GUIDs retrieved from Microsoft SQL Server over ADO.
22
23You probably don't want to be here, see
24L<DBIx::Class::Storage::DBI::ADO::Microsoft_SQL_Server> for information on the
25Microsoft SQL Server driver for ADO and L<DBIx::Class::Storage::DBI::MSSQL> for
26the Microsoft SQL Server driver base class.
27
28Unfortunately when using L<DBD::ADO>, binary data comes back padded with
29trailing C<NULL>s and GUIDs come back wrapped in braces, the purpose of this
30class is to remove the C<NULL>s and braces.
31L<DBIx::Class::Storage::DBI::ADO::Microsoft_SQL_Server> sets
32L<cursor_class|DBIx::Class::Storage::DBI/cursor_class> to this class by
33default. It is overridable via your
34L<connect_info|DBIx::Class::Storage::DBI/connect_info>.
35
36You can use L<DBIx::Class::Cursor::Cached> safely with this class and not lose
37the binary data normalizing functionality,
38L<::Cursor::Cached|DBIx::Class::Cursor::Cached> uses the underlying class data
39for the inner cursor class.
40
41=cut
42
a2f22854 43sub next {
44 my $self = shift;
2edf3352 45
a2f22854 46 my @row = $self->next::method(@_);
2edf3352 47
616ca57f 48 $self->{_colinfos} ||= fromspec_columns_info($self->args->[0]);
2edf3352 49
a2f22854 50 _normalize_guids(
51 $self->args->[1],
52 $self->{_colinfos},
53 \@row,
54 $self->storage
55 );
2edf3352 56
a2f22854 57 _strip_trailing_binary_nulls(
58 $self->args->[1],
59 $self->{_colinfos},
60 \@row,
61 $self->storage
62 );
2edf3352 63
64 return @row;
65}
66
a2f22854 67sub all {
68 my $self = shift;
2edf3352 69
a2f22854 70 my @rows = $self->next::method(@_);
2edf3352 71
616ca57f 72 $self->{_colinfos} ||= fromspec_columns_info($self->args->[0]);
2edf3352 73
74 for (@rows) {
a2f22854 75 _normalize_guids(
76 $self->args->[1],
77 $self->{_colinfos},
78 $_,
79 $self->storage
80 );
81
82 _strip_trailing_binary_nulls(
83 $self->args->[1],
84 $self->{_colinfos},
85 $_,
86 $self->storage
87 );
2edf3352 88 }
89
90 return @rows;
91}
92
a2bd3796 93=head1 FURTHER QUESTIONS?
2edf3352 94
a2bd3796 95Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
2edf3352 96
a2bd3796 97=head1 COPYRIGHT AND LICENSE
2edf3352 98
a2bd3796 99This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
100by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
101redistribute it and/or modify it under the same terms as the
102L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.
2edf3352 103
104=cut
105
a2bd3796 1061;
107
2edf3352 108# vim:sts=2 sw=2: