1 package DBIx::Class::Storage::DBI::SQLAnywhere;
5 use base qw/DBIx::Class::Storage::DBI/;
9 __PACKAGE__->mk_group_accessors(simple => qw/
15 DBIx::Class::Storage::DBI::SQLAnywhere - Driver for Sybase SQL Anywhere
19 This class implements autoincrements for Sybase SQL Anywhere, selects the
20 RowNumberOver limit implementation and provides
21 L<DBIx::Class::InflateColumn::DateTime> support.
23 You need the C<DBD::SQLAnywhere> driver that comes with the SQL Anywhere
24 distribution, B<NOT> the one on CPAN. It is usually under a path such as:
26 /opt/sqlanywhere11/sdk/perl
28 Recommended L<DBIx::Class::Storage::DBI/connect_info> settings:
30 on_connect_call => 'datetime_setup'
36 sub last_insert_id { shift->_identity }
40 my ($source, $to_insert) = @_;
42 my $identity_col = List::Util::first {
43 $source->column_info($_)->{is_auto_increment}
46 if ($identity_col && (not exists $to_insert->{$identity_col})) {
47 my $dbh = $self->_get_dbh;
48 my $table_name = $source->from;
49 $table_name = $$table_name if ref $table_name;
51 my ($identity) = $dbh->selectrow_array("SELECT GET_IDENTITY('$table_name')");
53 $to_insert->{$identity_col} = $identity;
55 $self->_identity($identity);
58 return $self->next::method(@_);
61 # this sub stolen from DB2
64 my ( $self, $opts ) = @_;
67 $self->{_sql_maker_opts} = { %$opts };
70 return { limit_dialect => 'RowNumberOver', %{$self->{_sql_maker_opts}||{}} };
73 # this sub stolen from MSSQL
75 sub build_datetime_parser {
77 my $type = "DateTime::Format::Strptime";
79 $self->throw_exception("Couldn't load ${type}: $@") if $@;
80 return $type->new( pattern => '%Y-%m-%d %H:%M:%S.%6N' );
83 =head2 connect_call_datetime_setup
87 on_connect_call => 'datetime_setup'
89 In L<DBIx::Class::Storage::DBI/connect_info> to set the date and timestamp
90 formats (as temporary options for the session) for use with
91 L<DBIx::Class::InflateColumn::DateTime>.
93 The C<TIMESTAMP> data type supports up to 6 digits after the decimal point for
94 second precision. The full precision is used.
96 The C<DATE> data type supposedly stores hours and minutes too, according to the
97 documentation, but I could not get that to work. It seems to only store the
100 You will need the L<DateTime::Format::Strptime> module for inflation to work.
104 sub connect_call_datetime_setup {
108 "set temporary option timestamp_format = 'yyyy-mm-dd hh:mm:ss.ssssss'"
111 "set temporary option date_format = 'yyyy-mm-dd hh:mm:ss.ssssss'"
119 See L<DBIx::Class/AUTHOR> and L<DBIx::Class/CONTRIBUTORS>.
123 You may distribute this code under the same terms as Perl itself.