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<connect_info|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 # user might have an identity PK without is_auto_increment
47 if (not $identity_col) {
48 foreach my $pk_col ($source->primary_columns) {
49 if (not exists $to_insert->{$pk_col}) {
50 $identity_col = $pk_col;
56 if ($identity_col && (not exists $to_insert->{$identity_col})) {
57 my $dbh = $self->_get_dbh;
58 my $table_name = $source->from;
59 $table_name = $$table_name if ref $table_name;
61 my ($identity) = $dbh->selectrow_array("SELECT GET_IDENTITY('$table_name')");
63 $to_insert->{$identity_col} = $identity;
65 $self->_identity($identity);
68 return $self->next::method(@_);
71 # this sub stolen from DB2
74 my ( $self, $opts ) = @_;
77 $self->{_sql_maker_opts} = { %$opts };
80 return { limit_dialect => 'RowNumberOver', %{$self->{_sql_maker_opts}||{}} };
83 # this sub stolen from MSSQL
85 sub build_datetime_parser {
87 my $type = "DateTime::Format::Strptime";
89 $self->throw_exception("Couldn't load ${type}: $@") if $@;
90 return $type->new( pattern => '%Y-%m-%d %H:%M:%S.%6N' );
93 =head2 connect_call_datetime_setup
97 on_connect_call => 'datetime_setup'
99 In L<connect_info|DBIx::Class::Storage::DBI/connect_info> to set the date and
100 timestamp formats (as temporary options for the session) for use with
101 L<DBIx::Class::InflateColumn::DateTime>.
103 The C<TIMESTAMP> data type supports up to 6 digits after the decimal point for
104 second precision. The full precision is used.
106 The C<DATE> data type supposedly stores hours and minutes too, according to the
107 documentation, but I could not get that to work. It seems to only store the
110 You will need the L<DateTime::Format::Strptime> module for inflation to work.
114 sub connect_call_datetime_setup {
118 "set temporary option timestamp_format = 'yyyy-mm-dd hh:mm:ss.ssssss'"
121 "set temporary option date_format = 'yyyy-mm-dd hh:mm:ss.ssssss'"
126 my ($self, $name) = @_;
128 $self->_get_dbh->do("SAVEPOINT $name");
131 # can't release savepoints that have been rolled back
132 sub _svp_release { 1 }
135 my ($self, $name) = @_;
137 $self->_get_dbh->do("ROLLBACK TO SAVEPOINT $name")
142 =head1 MAXIMUM CURSORS
144 A L<DBIx::Class> application can use a lot of cursors, due to the usage of
145 L<prepare_cached|DBI/prepare_cached>.
147 The default cursor maximum is C<50>, which can be a bit too low. This limit can
148 be turned off (or increased) by the DBA by executing:
150 set option max_statement_count = 0
151 set option max_cursor_count = 0
157 See L<DBIx::Class/AUTHOR> and L<DBIx::Class/CONTRIBUTORS>.
161 You may distribute this code under the same terms as Perl itself.