__PACKAGE__->mk_group_accessors('simple' =>
qw/_connect_info _dbi_connect_info _dbh _sql_maker _sql_maker_opts
_conn_pid _conn_tid transaction_depth _dbh_autocommit _on_connect_do
- _on_disconnect_do savepoints/
+ _on_disconnect_do _on_connect_do_store _on_disconnect_do_store
+ savepoints/
);
# the values for these accessors are picked out (and deleted) from
Executes a SQL string or a code reference that returns a SQL string. This is
what L</on_connect_do> and L</on_disconnect_do> use.
-=item set_datetime_format
+It can take:
+
+=over
+
+=item a scalar
+
+Will execute the scalar as SQL.
+
+=item an arrayref
+
+Taken to be arguments to L<DBI/do>, the SQL string optionally followed by the
+attributes hashref and bind values.
+
+=item a code reference
+
+Will execute C<< $code->($storage) >> and execute the return array refs as
+above.
+
+=back
+
+=item datetime_setup
Execute any statements necessary to initialize the database session to return
and accept datetime/timestamp values used with
L<DBIx::Class::InflateColumn::DateTime>.
+Only necessary for some databases, see your specific storage driver for
+implementation details.
+
=back
=item on_disconnect_call
my ($self, $opt) = (shift, shift);
my $accessor = "_$opt";
+ my $store = "_${opt}_store";
return $self->$accessor if not @_;
my $val = shift;
- (my $call = $opt) =~ s/_do\z/_call/;
-
- if (ref($self->$call) ne 'ARRAY') {
- $self->$call([
- defined $self->$call ? $self->$call : ()
- ]);
+ if (not defined $val) {
+ $self->$accessor(undef);
+ $self->$store(undef);
+ return;
}
+ my @store;
+
if (not ref($val)) {
- push @{ $self->$call }, [ 'do_sql', $val ];
+ push @store, [ 'do_sql', $val ];
} elsif (ref($val) eq 'CODE') {
- push @{ $self->$call }, $val;
+ push @store, $val;
} elsif (ref($val) eq 'ARRAY') {
- push @{ $self->$call },
- map [ 'do_sql', $_ ], @$val;
+ push @store, map [ 'do_sql', $_ ], @$val;
} else {
$self->throw_exception("Invalid type for $opt ".ref($val));
}
+ $self->$store(\@store);
$self->$accessor($val);
}
my ($self) = @_;
if( $self->connected ) {
- my $connection_call = $self->on_disconnect_call;
- $self->_do_connection_actions(disconnect_call_ => $connection_call)
- if $connection_call;
+ if (my $connection_call = $self->on_disconnect_call) {
+ $self->_do_connection_actions(disconnect_call_ => $connection_call)
+ }
+ if (my $connection_do = $self->_on_disconnect_do_store) {
+ $self->_do_connection_actions(disconnect_call_ => $connection_do)
+ }
$self->_dbh->rollback unless $self->_dbh_autocommit;
$self->_dbh->disconnect;
# there is no transaction in progress by definition
$self->{transaction_depth} = $self->_dbh_autocommit ? 0 : 1;
- my $connection_call = $self->on_connect_call;
- $self->_do_connection_actions(connect_call_ => $connection_call)
- if $connection_call;
+ if (my $connection_call = $self->on_connect_call) {
+ $self->_do_connection_actions(connect_call_ => $connection_call)
+ }
+ if (my $connection_do = $self->_on_connect_do_store) {
+ $self->_do_connection_actions(connect_call_ => $connection_do)
+ }
}
sub _determine_driver {
}
# override in db-specific backend when necessary
-sub connect_call_set_datetime_format { 1 }
+sub connect_call_datetime_setup { 1 }
sub _do_query {
my ($self, $action) = @_;
return ($sql, \@bind);
}
-=head2 as_query
-
-=over 4
-
-=item Arguments: $rs_attrs
-
-=item Return Value: \[ $sql, @bind ]
-
-=back
-
-Returns the SQL statement and bind vars that would result from the given
-ResultSet attributes (does not actually run a query)
-
-=cut
-
-sub as_query {
- my ($self, $rs_attr) = @_;
-
- my $sql_maker = $self->sql_maker;
- local $sql_maker->{for};
-
- # my ($op, $bind, $ident, $bind_attrs, $select, $cond, $order, $rows, $offset) = $self->_select_args(...);
- my @args = $self->_select_args($rs_attr->{from}, $rs_attr->{select}, $rs_attr->{where}, $rs_attr);
-
- # my ($sql, $bind) = $self->_prep_for_execute($op, $bind, $ident, [ $select, $cond, $order, $rows, $offset ]);
- my ($sql, $bind) = $self->_prep_for_execute(
- @args[0 .. 2],
- [ @args[4 .. $#args] ],
- );
- return \[ "($sql)", @{ $bind || [] }];
-}
sub _fix_bind_params {
my ($self, @bind) = @_;
return $self->_execute($self->_select_args(@_));
}
+sub _select_args_to_query {
+ my $self = shift;
+
+ my $sql_maker = $self->sql_maker;
+ local $sql_maker->{for};
+
+ # my ($op, $bind, $ident, $bind_attrs, $select, $cond, $order, $rows, $offset)
+ # = $self->_select_args($ident, $select, $cond, $attrs);
+ my ($op, $bind, $ident, $bind_attrs, @args) =
+ $self->_select_args(@_);
+
+ # my ($sql, $bind) = $self->_prep_for_execute($op, $bind, $ident, [ $select, $cond, $order, $rows, $offset ]);
+ my ($sql, $prepared_bind) = $self->_prep_for_execute($op, $bind, $ident, \@args);
+
+ return \[ "($sql)", @{ $prepared_bind || [] }];
+}
+
sub _select_args {
my ($self, $ident, $select, $condition, $attrs) = @_;
return;
}
+=head2 is_datatype_numeric
+
+Given a datatype from column_info, returns a boolean value indicating if
+the current RDBMS considers it a numeric value. This controls how
+L<DBIx::Class::Row/set_column> decides whether to mark the column as
+dirty - when the datatype is deemed numeric a C<< != >> comparison will
+be performed instead of the usual C<eq>.
+
+=cut
+
+sub is_datatype_numeric {
+ my ($self, $dt) = @_;
+
+ return 0 unless $dt;
+
+ return $dt =~ /^ (?:
+ numeric | int(?:eger)? | (?:tiny|small|medium|big)int | dec(?:imal)? | real | float | double (?: \s+ precision)? | (?:big)?serial
+ ) $/ix;
+}
+
+
=head2 create_ddl_dir (EXPERIMENTAL)
=over 4