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