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