Apache-iNcom

 view release on metacpan or  search on metacpan

lib/DBIx/SearchProfiles.pm  view on Meta::CPAN

=pod

=head2 template_delete ( $name, params )

This method will delete records according to the template $name and
using regular template's placeholders substitutions semantics.

Return value is the number of records deleted.

=cut

sub template_delete {
    my $self = shift;
    my $name = shift;

    my ( $fdat, @params );

    # Params is either an hash ref in which we will look
    # for named base params or it can be an array (or array ref)
    # of which the elements will be used for substitutions in
    # the SQL query
    if ( ref $_[0] eq "HASH" ) {
	$fdat = shift;
    } elsif ( ref $_[0] eq "ARRAY" ) {
	@params = @{$_[0]};
    } else {
	@params = @_;
    }
    $fdat ||= {};

    $self->load_profiles;

    my $profile = $self->{profiles}{$name};
    die "No such profile: $name\n" unless $profile;

    my $statement_spec  = $profile->{query};
    die "Query doesn't start with DELETE"
      unless  $statement_spec =~ /^\s*DELETE /;

    my $params_spec = $profile->{params} || [];

    # Fetch the param from the query
    if ( @params ) {
	die "Number of params doesn't match the number of specs\n"
	  unless @params == @$params_spec;
    } else {
	@params = map { 
	    defined $fdat->{$_} ? $fdat->{$_} : $profile->{defaults}{$_}
	} @$params_spec;
    }

    $self->sql_do( $statement_spec, @params );
}

1;

__END__

=pod

=head1 BUGS AND LIMITATIONS

Please report bugs, suggestions, patches and thanks to
<bugs@iNsu.COM>.

The search limitations and offset SQL generation is probably not completely
portable. It uses LIMIT and OFFSET which are maybe not supported across SQL92
implementation. (PostgreSQL supports it so...)

To find the number of records that will be returned by a query (in
*_search) we use C<count(*)>. This could cause a number of problems.

=head1 AUTHOR

Copyright (c) 1999 Francis J. Lacoste and iNsu Innovations Inc.
All rights reserved.

This program is free software; you can redistribute it and/or modify
it under the terms as perl itself.

=head1 SEE ALSO

DBIx::Recordset(3) DBI(3) DBIx::UserDB(3)

=cut



( run in 1.147 second using v1.01-cache-2.11-cpan-99c4e6809bf )