Privatize _sth
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / ODBC / ACCESS.pm
CommitLineData
65c2b042 1package DBIx::Class::Storage::DBI::ODBC::ACCESS;
2use strict;
3use warnings;
4
65c2b042 5use base qw/DBIx::Class::Storage::DBI/;
2ad62d97 6use mro 'c3';
7
8use DBI;
65c2b042 9
10my $ERR_MSG_START = __PACKAGE__ . ' failed: ';
11
6a247f33 12__PACKAGE__->sql_limit_dialect ('Top');
2b8cc2f2 13__PACKAGE__->sql_quote_char ([qw/[ ]/]);
6a247f33 14
65c2b042 15sub insert {
16 my $self = shift;
17 my ( $source, $to_insert ) = @_;
18
19 my $bind_attributes = $self->source_bind_attributes( $source );
20 my ( undef, $sth ) = $self->_execute( 'insert' => [], $source, $bind_attributes, $to_insert );
21
22 #store the identity here since @@IDENTITY is connection global and this prevents
23 #possibility that another insert to a different table overwrites it for this resultsource
24 my $identity = 'SELECT @@IDENTITY';
25 my $max_sth = $self->{ _dbh }->prepare( $identity )
26 or $self->throw_exception( $ERR_MSG_START . $self->{ _dbh }->errstr() );
27 $max_sth->execute() or $self->throw_exception( $ERR_MSG_START . $max_sth->errstr );
28
29 my $row = $max_sth->fetchrow_arrayref()
30 or $self->throw_exception( $ERR_MSG_START . "$identity did not return any result." );
31
32 $self->{ last_pk }->{ $source->name() } = $row;
33
34 return $to_insert;
35}
36
37sub last_insert_id {
38 my $self = shift;
39 my ( $result_source ) = @_;
40
41 return @{ $self->{ last_pk }->{ $result_source->name() } };
42}
43
44sub bind_attribute_by_data_type {
45 my $self = shift;
d4daee7b 46
65c2b042 47 my ( $data_type ) = @_;
d4daee7b 48
65c2b042 49 return { TYPE => $data_type } if $data_type == DBI::SQL_LONGVARCHAR;
d4daee7b 50
65c2b042 51 return;
52}
53
54sub sqlt_type { 'ACCESS' }
55
561;
57
58=head1 NAME
59
60DBIx::Class::Storage::DBI::ODBC::ACCESS - Support specific to MS Access over ODBC
61
62=head1 WARNING
63
64I am not a DBI, DBIx::Class or MS Access guru. Use this module with that in
65mind.
66
67This module is currently considered alpha software and can change without notice.
68
69=head1 DESCRIPTION
70
71This class implements support specific to Microsoft Access over ODBC.
72
73It is loaded automatically by by DBIx::Class::Storage::DBI::ODBC when it
74detects a MS Access back-end.
75
76=head1 SUPPORTED VERSIONS
77
78This module have currently only been tested on MS Access 2003 using the Jet 4.0 engine.
79
80As far as my knowledge it should work on MS Access 2000 or later, but that have not been tested.
81Information about support for different version of MS Access is welcome.
82
83=head1 IMPLEMENTATION NOTES
84
48580715 85MS Access supports the @@IDENTITY function for retrieving the id of the latest inserted row.
65c2b042 86@@IDENTITY is global to the connection, so to support the possibility of getting the last inserted
87id for different tables, the insert() function stores the inserted id on a per table basis.
88last_insert_id() then just returns the stored value.
89
90=head1 KNOWN ACCESS PROBLEMS
91
92=over
93
94=item Invalid precision value
95
96This error message is received when trying to store more than 255 characters in a MEMO field.
97The problem is (to my knowledge) an error in the MS Access ODBC driver. The problem is fixed
98by setting the C<data_type> of the column to C<SQL_LONGVARCHAR> in C<add_columns>.
99C<SQL_LONGVARCHAR> is a constant in the C<DBI> module.
100
101=back
102
103=head1 IMPLEMENTED FUNCTIONS
104
105=head2 bind_attribute_by_data_type
106
107This function currently supports the SQL_LONGVARCHAR column type.
108
109=head2 insert
110
111=head2 last_insert_id
112
113=head2 sqlt_type
114
115=head1 BUGS
116
117Most likely. Bug reports are welcome.
118
119=head1 AUTHORS
120
121Øystein Torget C<< <oystein.torget@dnv.com> >>
122
123=head1 COPYRIGHT
124
125You may distribute this code under the same terms as Perl itself.
126
127Det Norske Veritas AS (DNV)
128
129http://www.dnv.com
130
131=cut
132