1 package DBIx::Class::Storage::DBI::SQLAnywhere;
5 use base qw/DBIx::Class::Storage::DBI::UniqueIdentifier/;
7 use List::Util 'first';
11 __PACKAGE__->mk_group_accessors(simple => qw/_identity/);
12 __PACKAGE__->sql_limit_dialect ('RowNumberOver');
16 DBIx::Class::Storage::DBI::SQLAnywhere - Driver for Sybase SQL Anywhere
20 This class implements autoincrements for Sybase SQL Anywhere 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 }
38 sub _new_uuid { 'UUIDTOSTR(NEWID())' }
42 my ($source, $to_insert) = @_;
45 first { $source->column_info($_)->{is_auto_increment} } $source->columns;
47 # user might have an identity PK without is_auto_increment
48 if (not $identity_col) {
49 foreach my $pk_col ($source->primary_columns) {
50 if (not exists $to_insert->{$pk_col} &&
51 $source->column_info($pk_col)->{data_type} !~ /^uniqueidentifier/i)
53 $identity_col = $pk_col;
59 if ($identity_col && (not exists $to_insert->{$identity_col})) {
60 my $dbh = $self->_get_dbh;
61 my $table_name = $source->from;
62 $table_name = $$table_name if ref $table_name;
64 my ($identity) = try {
65 $dbh->selectrow_array("SELECT GET_IDENTITY('$table_name')")
68 if (defined $identity) {
69 $to_insert->{$identity_col} = $identity;
70 $self->_identity($identity);
74 return $self->next::method(@_);
77 # convert UUIDs to strings in selects
80 my ($ident, $select) = @_;
82 my $col_info = $self->_resolve_column_info($ident);
84 for my $select_idx (0..$#$select) {
85 my $selected = $select->[$select_idx];
87 next if ref $selected;
89 my $data_type = $col_info->{$selected}{data_type};
91 if ($data_type && lc($data_type) eq 'uniqueidentifier') {
92 $select->[$select_idx] = { UUIDTOSTR => $selected };
96 return $self->next::method(@_);
99 # this sub stolen from MSSQL
101 sub build_datetime_parser {
103 my $type = "DateTime::Format::Strptime";
105 eval "require ${type}"
108 $self->throw_exception("Couldn't load ${type}: $_");
111 return $type->new( pattern => '%Y-%m-%d %H:%M:%S.%6N' );
114 =head2 connect_call_datetime_setup
118 on_connect_call => 'datetime_setup'
120 In L<connect_info|DBIx::Class::Storage::DBI/connect_info> to set the date and
121 timestamp formats (as temporary options for the session) for use with
122 L<DBIx::Class::InflateColumn::DateTime>.
124 The C<TIMESTAMP> data type supports up to 6 digits after the decimal point for
125 second precision. The full precision is used.
127 The C<DATE> data type supposedly stores hours and minutes too, according to the
128 documentation, but I could not get that to work. It seems to only store the
131 You will need the L<DateTime::Format::Strptime> module for inflation to work.
135 sub connect_call_datetime_setup {
139 "set temporary option timestamp_format = 'yyyy-mm-dd hh:mm:ss.ssssss'"
142 "set temporary option date_format = 'yyyy-mm-dd hh:mm:ss.ssssss'"
147 my ($self, $name) = @_;
149 $self->_get_dbh->do("SAVEPOINT $name");
152 # can't release savepoints that have been rolled back
153 sub _svp_release { 1 }
156 my ($self, $name) = @_;
158 $self->_get_dbh->do("ROLLBACK TO SAVEPOINT $name")
163 =head1 MAXIMUM CURSORS
165 A L<DBIx::Class> application can use a lot of cursors, due to the usage of
166 L<prepare_cached|DBI/prepare_cached>.
168 The default cursor maximum is C<50>, which can be a bit too low. This limit can
169 be turned off (or increased) by the DBA by executing:
171 set option max_statement_count = 0
172 set option max_cursor_count = 0
178 See L<DBIx::Class/AUTHOR> and L<DBIx::Class/CONTRIBUTORS>.
182 You may distribute this code under the same terms as Perl itself.