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) = @_;
44 my $colinfo = $source->columns_info;
47 first { $_->{is_auto_increment} } values %$colinfo;
49 # user might have an identity PK without is_auto_increment
50 if (not $identity_col) {
51 foreach my $pk_col ($source->primary_columns) {
53 ! exists $to_insert->{$pk_col}
55 $colinfo->{$pk_col}{data_type}
57 $colinfo->{$pk_col}{data_type} !~ /^uniqueidentifier/i
59 $identity_col = $pk_col;
65 if ($identity_col && (not exists $to_insert->{$identity_col})) {
66 my $dbh = $self->_get_dbh;
67 my $table_name = $source->from;
68 $table_name = $$table_name if ref $table_name;
70 my ($identity) = try {
71 $dbh->selectrow_array("SELECT GET_IDENTITY('$table_name')")
74 if (defined $identity) {
75 $to_insert->{$identity_col} = $identity;
76 $self->_identity($identity);
80 return $self->next::method(@_);
83 # convert UUIDs to strings in selects
86 my ($ident, $select) = @_;
88 my $col_info = $self->_resolve_column_info($ident);
90 for my $select_idx (0..$#$select) {
91 my $selected = $select->[$select_idx];
93 next if ref $selected;
95 my $data_type = $col_info->{$selected}{data_type};
97 if ($data_type && lc($data_type) eq 'uniqueidentifier') {
98 $select->[$select_idx] = { UUIDTOSTR => $selected };
102 return $self->next::method(@_);
105 # this sub stolen from MSSQL
107 sub build_datetime_parser {
109 my $type = "DateTime::Format::Strptime";
111 eval "require ${type}"
114 $self->throw_exception("Couldn't load ${type}: $_");
117 return $type->new( pattern => '%Y-%m-%d %H:%M:%S.%6N' );
120 =head2 connect_call_datetime_setup
124 on_connect_call => 'datetime_setup'
126 In L<connect_info|DBIx::Class::Storage::DBI/connect_info> to set the date and
127 timestamp formats (as temporary options for the session) for use with
128 L<DBIx::Class::InflateColumn::DateTime>.
130 The C<TIMESTAMP> data type supports up to 6 digits after the decimal point for
131 second precision. The full precision is used.
133 The C<DATE> data type supposedly stores hours and minutes too, according to the
134 documentation, but I could not get that to work. It seems to only store the
137 You will need the L<DateTime::Format::Strptime> module for inflation to work.
141 sub connect_call_datetime_setup {
145 "set temporary option timestamp_format = 'yyyy-mm-dd hh:mm:ss.ssssss'"
148 "set temporary option date_format = 'yyyy-mm-dd hh:mm:ss.ssssss'"
153 my ($self, $name) = @_;
155 $self->_get_dbh->do("SAVEPOINT $name");
158 # can't release savepoints that have been rolled back
159 sub _svp_release { 1 }
162 my ($self, $name) = @_;
164 $self->_get_dbh->do("ROLLBACK TO SAVEPOINT $name")
169 =head1 MAXIMUM CURSORS
171 A L<DBIx::Class> application can use a lot of cursors, due to the usage of
172 L<prepare_cached|DBI/prepare_cached>.
174 The default cursor maximum is C<50>, which can be a bit too low. This limit can
175 be turned off (or increased) by the DBA by executing:
177 set option max_statement_count = 0
178 set option max_cursor_count = 0
184 See L<DBIx::Class/AUTHOR> and L<DBIx::Class/CONTRIBUTORS>.
188 You may distribute this code under the same terms as Perl itself.