fix stupid identity bug, test empty insert (works), test DTs (not working yet)
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Sybase / ASA.pm
CommitLineData
f200d74b 1package DBIx::Class::Storage::DBI::Sybase::ASA;
2
3use strict;
4use warnings;
5use base qw/DBIx::Class::Storage::DBI/;
6use mro 'c3';
7use List::Util ();
8
9__PACKAGE__->mk_group_accessors(simple => qw/
10 _identity
11/);
12
13=head1 NAME
14
15DBIx::Class::Storage::DBI::Sybase::ASA - Driver for Sybase SQL Anywhere
16
17=head1 DESCRIPTION
18
19This class implements autoincrements for Sybase SQL Anywhere and selects the
20RowNumberOver limit implementation.
21
22You need the C<DBD::SQLAnywhere> driver that comes with the SQL Anywhere
23distribution, B<NOT> the one on CPAN. It is usually under a path such as:
24
25 /opt/sqlanywhere11/sdk/perl
26
27=cut
28
29sub last_insert_id { shift->_identity }
30
31sub insert {
32 my $self = shift;
33 my ($source, $to_insert) = @_;
34
35 my $supplied_col_info = $self->_resolve_column_info($source, [keys %$to_insert]);
36
37 my $is_identity_insert = (List::Util::first { $_->{is_auto_increment} } (values %$supplied_col_info) )
38 ? 1
39 : 0;
40
ed720bc5 41 my $identity_col = List::Util::first {
42 $source->column_info($_)->{is_auto_increment}
43 } $source->columns;
44
45 if ((not $is_identity_insert) && $identity_col) {
f200d74b 46 my $dbh = $self->_get_dbh;
47 my $table_name = $source->from;
54e39a07 48 $table_name = $$table_name if ref $table_name;
f200d74b 49
50 my ($identity) = $dbh->selectrow_array("SELECT GET_IDENTITY('$table_name')");
51
52 $to_insert->{$identity_col} = $identity;
53
54 $self->_identity($identity);
55 }
56
57 return $self->next::method(@_);
58}
59
60# stolen from DB2
61
62sub _sql_maker_opts {
63 my ( $self, $opts ) = @_;
64
65 if ( $opts ) {
66 $self->{_sql_maker_opts} = { %$opts };
67 }
68
69 return { limit_dialect => 'RowNumberOver', %{$self->{_sql_maker_opts}||{}} };
70}
71
721;
73
74=head1 AUTHOR
75
76See L<DBIx::Class/AUTHOR> and L<DBIx::Class/CONTRIBUTORS>.
77
78=head1 LICENSE
79
80You may distribute this code under the same terms as Perl itself.
81
82=cut