1 package DBIx::Class::Storage::DBI::SQLAnywhere;
5 use base qw/DBIx::Class::Storage::DBI::UniqueIdentifier/;
8 __PACKAGE__->mk_group_accessors(simple => qw/_identity/);
9 __PACKAGE__->sql_limit_dialect ('RowNumberOver');
10 __PACKAGE__->sql_quote_char ('"');
12 __PACKAGE__->new_guid('UUIDTOSTR(NEWID())');
14 # default to the UUID decoding cursor, overridable by the user
15 __PACKAGE__->cursor_class('DBIx::Class::Storage::DBI::SQLAnywhere::Cursor');
19 DBIx::Class::Storage::DBI::SQLAnywhere - Driver for SQL Anywhere
23 This class implements autoincrements for SQL Anywhere and provides
24 L<DBIx::Class::InflateColumn::DateTime> support and support for the
25 C<uniqueidentifier> type (via
26 L<DBIx::Class::Storage::DBI::SQLAnywhere::Cursor>.)
28 You need the C<DBD::SQLAnywhere> driver that comes with the SQL Anywhere
29 distribution, B<NOT> the one on CPAN. It is usually under a path such as:
31 /opt/sqlanywhere11/sdk/perl
33 Recommended L<connect_info|DBIx::Class::Storage::DBI/connect_info> settings:
35 on_connect_call => 'datetime_setup'
41 sub last_insert_id { shift->_identity }
43 sub _prefetch_autovalues {
45 my ($source, $colinfo, $to_insert) = @_;
47 my $values = $self->next::method(@_);
50 grep { $colinfo->{$_}{is_auto_increment} } keys %$colinfo;
52 # user might have an identity PK without is_auto_increment
54 # FIXME we probably should not have supported the above, see what
55 # does it take to move away from it
56 if (not $identity_col) {
57 foreach my $pk_col ($source->primary_columns) {
59 ! exists $to_insert->{$pk_col}
61 $colinfo->{$pk_col}{data_type}
63 $colinfo->{$pk_col}{data_type} !~ /^uniqueidentifier/i
65 $identity_col = $pk_col;
71 if ($identity_col && (not exists $to_insert->{$identity_col})) {
72 my $dbh = $self->_get_dbh;
73 my $table_name = $source->from;
74 $table_name = $$table_name if ref $table_name;
76 my ($identity) = dbic_internal_try {
77 $dbh->selectrow_array("SELECT GET_IDENTITY('$table_name')")
80 if (defined $identity) {
81 $values->{$identity_col} = $identity;
82 $self->_identity($identity);
90 my ($self, $data) = @_;
92 $data = unpack 'H*', $data;
94 for my $pos (8, 13, 18, 23) {
95 substr($data, $pos, 0) = '-';
101 # select_single does not invoke a cursor object at all, hence UUID decoding happens
102 # here if the proper cursor class is set
106 my @row = $self->next::method(@_);
109 unless $self->cursor_class->isa('DBIx::Class::Storage::DBI::SQLAnywhere::Cursor');
111 my ($ident, $select) = @_;
113 my $col_info = $self->_resolve_column_info($ident);
115 for my $select_idx (0..$#$select) {
116 my $selected = $select->[$select_idx];
118 next if ref $selected;
120 my $data_type = $col_info->{$selected}{data_type}
123 if ($self->_is_guid_type($data_type)) {
124 my $returned = $row[$select_idx];
126 if (length $returned == 16) {
127 $row[$select_idx] = $self->_uuid_to_str($returned);
135 sub build_datetime_parser {
137 require DateTime::Format::Strptime;
139 DateTime::Format::Strptime->new( pattern => '%Y-%m-%d %H:%M:%S.%6N' );
142 =head2 connect_call_datetime_setup
146 on_connect_call => 'datetime_setup'
148 In L<connect_info|DBIx::Class::Storage::DBI/connect_info> to set the date and
149 timestamp formats (as temporary options for the session) for use with
150 L<DBIx::Class::InflateColumn::DateTime>.
152 The C<TIMESTAMP> data type supports up to 6 digits after the decimal point for
153 second precision. The full precision is used.
155 The C<DATE> data type supposedly stores hours and minutes too, according to the
156 documentation, but I could not get that to work. It seems to only store the
159 You will need the L<DateTime::Format::Strptime> module for inflation to work.
163 sub connect_call_datetime_setup {
167 "set temporary option timestamp_format = 'yyyy-mm-dd hh:mm:ss.ssssss'"
170 "set temporary option date_format = 'yyyy-mm-dd hh:mm:ss.ssssss'"
174 sub _exec_svp_begin {
175 my ($self, $name) = @_;
177 $self->_dbh->do("SAVEPOINT $name");
180 # can't release savepoints that have been rolled back
181 sub _exec_svp_release { 1 }
183 sub _exec_svp_rollback {
184 my ($self, $name) = @_;
186 $self->_dbh->do("ROLLBACK TO SAVEPOINT $name")
191 =head1 MAXIMUM CURSORS
193 A L<DBIx::Class> application can use a lot of cursors, due to the usage of
194 L<prepare_cached|DBI/prepare_cached>.
196 The default cursor maximum is C<50>, which can be a bit too low. This limit can
197 be turned off (or increased) by the DBA by executing:
199 set option max_statement_count = 0
200 set option max_cursor_count = 0
204 =head1 FURTHER QUESTIONS?
206 Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
208 =head1 COPYRIGHT AND LICENSE
210 This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
211 by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
212 redistribute it and/or modify it under the same terms as the
213 L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.