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');
13 __PACKAGE__->sql_quote_char ('"');
15 __PACKAGE__->new_guid('UUIDTOSTR(NEWID())');
19 DBIx::Class::Storage::DBI::SQLAnywhere - Driver for Sybase SQL Anywhere
23 This class implements autoincrements for Sybase SQL Anywhere and provides
24 L<DBIx::Class::InflateColumn::DateTime> support.
26 You need the C<DBD::SQLAnywhere> driver that comes with the SQL Anywhere
27 distribution, B<NOT> the one on CPAN. It is usually under a path such as:
29 /opt/sqlanywhere11/sdk/perl
31 Recommended L<connect_info|DBIx::Class::Storage::DBI/connect_info> settings:
33 on_connect_call => 'datetime_setup'
39 sub last_insert_id { shift->_identity }
41 sub _prefetch_autovalues {
43 my ($source, $to_insert) = @_;
45 my $values = $self->next::method(@_);
47 my $colinfo = $source->columns_info;
50 first { $colinfo->{$_}{is_auto_increment} } keys %$colinfo;
52 # user might have an identity PK without is_auto_increment
53 if (not $identity_col) {
54 foreach my $pk_col ($source->primary_columns) {
56 ! exists $to_insert->{$pk_col}
58 $colinfo->{$pk_col}{data_type}
60 $colinfo->{$pk_col}{data_type} !~ /^uniqueidentifier/i
62 $identity_col = $pk_col;
68 if ($identity_col && (not exists $to_insert->{$identity_col})) {
69 my $dbh = $self->_get_dbh;
70 my $table_name = $source->from;
71 $table_name = $$table_name if ref $table_name;
73 my ($identity) = try {
74 $dbh->selectrow_array("SELECT GET_IDENTITY('$table_name')")
77 if (defined $identity) {
78 $values->{$identity_col} = $identity;
79 $self->_identity($identity);
86 # convert UUIDs to strings in selects
89 my ($ident, $select) = @_;
91 my $col_info = $self->_resolve_column_info($ident);
93 for my $select_idx (0..$#$select) {
94 my $selected = $select->[$select_idx];
96 next if ref $selected;
98 my $data_type = $col_info->{$selected}{data_type};
100 if ($data_type && lc($data_type) eq 'uniqueidentifier') {
101 $select->[$select_idx] = { UUIDTOSTR => $selected };
105 return $self->next::method(@_);
108 # this sub stolen from MSSQL
110 sub build_datetime_parser {
112 my $type = "DateTime::Format::Strptime";
114 eval "require ${type}"
117 $self->throw_exception("Couldn't load ${type}: $_");
120 return $type->new( pattern => '%Y-%m-%d %H:%M:%S.%6N' );
123 =head2 connect_call_datetime_setup
127 on_connect_call => 'datetime_setup'
129 In L<connect_info|DBIx::Class::Storage::DBI/connect_info> to set the date and
130 timestamp formats (as temporary options for the session) for use with
131 L<DBIx::Class::InflateColumn::DateTime>.
133 The C<TIMESTAMP> data type supports up to 6 digits after the decimal point for
134 second precision. The full precision is used.
136 The C<DATE> data type supposedly stores hours and minutes too, according to the
137 documentation, but I could not get that to work. It seems to only store the
140 You will need the L<DateTime::Format::Strptime> module for inflation to work.
144 sub connect_call_datetime_setup {
148 "set temporary option timestamp_format = 'yyyy-mm-dd hh:mm:ss.ssssss'"
151 "set temporary option date_format = 'yyyy-mm-dd hh:mm:ss.ssssss'"
156 my ($self, $name) = @_;
158 $self->_get_dbh->do("SAVEPOINT $name");
161 # can't release savepoints that have been rolled back
162 sub _svp_release { 1 }
165 my ($self, $name) = @_;
167 $self->_get_dbh->do("ROLLBACK TO SAVEPOINT $name")
172 =head1 MAXIMUM CURSORS
174 A L<DBIx::Class> application can use a lot of cursors, due to the usage of
175 L<prepare_cached|DBI/prepare_cached>.
177 The default cursor maximum is C<50>, which can be a bit too low. This limit can
178 be turned off (or increased) by the DBA by executing:
180 set option max_statement_count = 0
181 set option max_cursor_count = 0
187 See L<DBIx::Class/AUTHOR> and L<DBIx::Class/CONTRIBUTORS>.
191 You may distribute this code under the same terms as Perl itself.