Massively optimize ->cursor->next while fixing some bugs along the way
[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;
5use base 'DBIx::Class::Storage::DBI::Cursor';
6use mro 'c3';
7use DBIx::Class::Storage::DBI::ADO::CursorUtils qw/_normalize_guids _strip_trailing_binary_nulls/;
8use namespace::clean;
9
10=head1 NAME
11
12DBIx::Class::Storage::DBI::ADO::Microsoft_SQL_Server::Cursor - Remove trailing
13NULLs in binary data and normalize GUIDs for MSSQL over ADO
14
15=head1 DESCRIPTION
16
17This class is for removing trailing C<NULL>s from binary data and removing braces
18from GUIDs retrieved from Microsoft SQL Server over ADO.
19
20You probably don't want to be here, see
21L<DBIx::Class::Storage::DBI::ADO::Microsoft_SQL_Server> for information on the
22Microsoft SQL Server driver for ADO and L<DBIx::Class::Storage::DBI::MSSQL> for
23the Microsoft SQL Server driver base class.
24
25Unfortunately when using L<DBD::ADO>, binary data comes back padded with
26trailing C<NULL>s and GUIDs come back wrapped in braces, the purpose of this
27class is to remove the C<NULL>s and braces.
28L<DBIx::Class::Storage::DBI::ADO::Microsoft_SQL_Server> sets
29L<cursor_class|DBIx::Class::Storage::DBI/cursor_class> to this class by
30default. It is overridable via your
31L<connect_info|DBIx::Class::Storage::DBI/connect_info>.
32
33You can use L<DBIx::Class::Cursor::Cached> safely with this class and not lose
34the binary data normalizing functionality,
35L<::Cursor::Cached|DBIx::Class::Cursor::Cached> uses the underlying class data
36for the inner cursor class.
37
38=cut
39
a2f22854 40sub next {
41 my $self = shift;
2edf3352 42
a2f22854 43 my @row = $self->next::method(@_);
2edf3352 44
a2f22854 45 $self->{_colinfos} ||= $self->storage->_resolve_column_info($self->args->[0]);
2edf3352 46
a2f22854 47 _normalize_guids(
48 $self->args->[1],
49 $self->{_colinfos},
50 \@row,
51 $self->storage
52 );
2edf3352 53
a2f22854 54 _strip_trailing_binary_nulls(
55 $self->args->[1],
56 $self->{_colinfos},
57 \@row,
58 $self->storage
59 );
2edf3352 60
61 return @row;
62}
63
a2f22854 64sub all {
65 my $self = shift;
2edf3352 66
a2f22854 67 my @rows = $self->next::method(@_);
2edf3352 68
a2f22854 69 $self->{_colinfos} ||= $self->storage->_resolve_column_info($self->args->[0]);
2edf3352 70
71 for (@rows) {
a2f22854 72 _normalize_guids(
73 $self->args->[1],
74 $self->{_colinfos},
75 $_,
76 $self->storage
77 );
78
79 _strip_trailing_binary_nulls(
80 $self->args->[1],
81 $self->{_colinfos},
82 $_,
83 $self->storage
84 );
2edf3352 85 }
86
87 return @rows;
88}
89
901;
91
92=head1 AUTHOR
93
94See L<DBIx::Class/AUTHOR> and L<DBIx::Class/CONTRIBUTORS>.
95
96=head1 LICENSE
97
98You may distribute this code under the same terms as Perl itself.
99
100=cut
101
102# vim:sts=2 sw=2: