[Rt-commit] r2563 - in DBIx-SearchBuilder/trunk: . SearchBuilder
jesse at bestpractical.com
jesse at bestpractical.com
Sun Apr 3 05:11:14 EDT 2005
Author: jesse
Date: Sun Apr 3 05:11:14 2005
New Revision: 2563
Added:
DBIx-SearchBuilder/trunk/SearchBuilder/Unique.pm
Modified:
DBIx-SearchBuilder/trunk/ (props changed)
DBIx-SearchBuilder/trunk/Changes
DBIx-SearchBuilder/trunk/MANIFEST
Log:
r11660 at hualien: jesse | 2005-04-03 17:09:15 +0800
* Added a SearchBuilder::Unique subclass
Modified: DBIx-SearchBuilder/trunk/Changes
==============================================================================
--- DBIx-SearchBuilder/trunk/Changes (original)
+++ DBIx-SearchBuilder/trunk/Changes Sun Apr 3 05:11:14 2005
@@ -1,5 +1,7 @@
Revision history for Perl extension DBIx::SearchBuilder.
+ - Added a new "SearchBuilder::Unique module for uniquifying search results
+
1.23
- Now use DBI->quote_identifier to quote column and table names (Ruslan)
Modified: DBIx-SearchBuilder/trunk/MANIFEST
==============================================================================
--- DBIx-SearchBuilder/trunk/MANIFEST (original)
+++ DBIx-SearchBuilder/trunk/MANIFEST Sun Apr 3 05:11:14 2005
@@ -19,6 +19,7 @@
SearchBuilder/Record.pm
SearchBuilder/Record/Cachable.pm
SearchBuilder/Union.pm
+SearchBuilder/Unique.pm
t/00.load.t
t/01records.t
t/02records_object.t
Added: DBIx-SearchBuilder/trunk/SearchBuilder/Unique.pm
==============================================================================
--- (empty file)
+++ DBIx-SearchBuilder/trunk/SearchBuilder/Unique.pm Sun Apr 3 05:11:14 2005
@@ -0,0 +1,66 @@
+package DBIx::SearchBuilder::Unique;
+use base 'Exporter';
+our @EXPORT = qw(AddRecord);
+our $VERSION = "0.01";
+use strict;
+use warnings;
+
+
+
+sub AddRecord {
+ my $self = shift;
+ my $record = shift;
+
+ # We're a mixin, so we can't override _CleanSlate, but if an object
+ # gets reused, we need to clean ourselves out. If there are no items,
+ # we're clearly doing a new search
+ $self->{"dbix_sb_unique_cache"} = {} unless (@{$self->{'items'}}[0]);
+ return if $self->{"dbix_sb_unique_cache"}->{$record->id}++;
+ push @{$self->{'items'}}, $record;
+ $self->{'rows'}++;
+}
+
+1;
+
+=head1 NAME
+
+DBIx::SearchBuilder::Unique - Ensure uniqueness of records in a collection
+
+=head1 SYNOPSIS
+
+ package Foo::Collection;
+ use base 'DBIx::SearchBuilder';
+
+ use DBIx::SearchBuilder::Unique; # mixin
+
+ my $collection = Foo::Collection->New();
+ $collection->SetupComplicatedJoins;
+ $collection->OrderByMagic;
+
+ while (my $thing = $collection->Next) {
+ # $thing is going to be distinct
+ }
+
+=head1 DESCRIPTION
+
+Currently, DBIx::SearchBuilder makes exceptions for databases which
+cannot handle both C<SELECT DISTINCT> and ordering in the same
+statement; it drops the C<DISTINCT> requirement. This, of course, means
+that you can get the same row twice, which you might not want. If that's
+the case, use this module as a mix-in, and it will provide you with an
+C<AddRecord> method which ensures that a record will not appear twice in
+the same search.
+
+=head1 AUTHOR
+
+Simon Cozens.
+
+=head1 COPYRIGHT
+
+Copyright 2005 Best Practical Solutions, LLC
+
+This library is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+=cut
+
More information about the Rt-commit
mailing list