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