NAME
DBIx::SQLEngine::Record::Set - Array of Record Objects
SYNOPSIS
use DBIx::SQLEngine::Record::Set;
$record_set = DBIx::SQLEngine::Record::Set->new( @records );
$record_set = $record_class->fetch_select( criteria => { status => 2 } );
print "Found " . $record_set->count() . " records";
$record_set->filter( { 'status' => 'New' } );
$record_set->sort( 'creation_date' );
foreach ( 0 .. $record_set->count() ) {
print $record_set->record( $_ )->name();
}
foreach ( $record_set->range_records( 11, 20 ) ) {
print $_->name();
}
DESCRIPTION
This package is not yet complete.
The base implementation of RecordSet is an array of Record references.
Constructor
Contents
- init()
-
$recordset->init ( @records )
Array content setter.
- records()
-
$rs->records() : @records
Array content accessor.
Positional Access
$count = $rs->count();
$record = $rs->record( $position );
Return the record in the indicated position in the array.
Indexes start with zero. Negative indexes are counted back from the end, with -1 being the last, -2 being the one before that, and so forth.
$record = $rs->last_record();
Return the last record in the array.
Positional Subsets
$clone = $rs->range_set( $start_pos, $stop_pos );
Return a copy of the current set containing only those records at or between the start and stop positions.
@records = $rs->range_records( $start_pos, $stop_pos );
Return the records at or between the start and stop positions.
Sorting
Use of these methods requires the Data::Sorting module from CPAN.
See Data::Sorting for more information.
$rs->sort( @fieldnames );
Sort the contents of the set.
$clone = $rs->sorted_set( @fieldnames );
Return a sorted copy of the current set.
@records = $rs->sorted_records( @fieldnames );
Return the records from the current set, in sorted order.
Criteria Matching
Caution: This set of methods is currently not working.
$rs->filter( $criteria );
Remove non-matching records from the set.
$clone = $rs->filtered_set( $criteria );
Return a set containing only the matching records from the current set.
@records = $rs->filtered_records( $criteria );
Return the matching records from the current set.
SEE ALSO
See DBIx::SQLEngine for the overall interface and developer documentation.
See DBIx::SQLEngine::Docs::ReadMe for general information about this distribution, including installation and license information.
CHANGES
2001-06-29 Moved to DBIx::DBO2 namespace.
2001-04-10 Added last_record.
2000-12-13 Simon: Substantial revisions. Moved to EBiz::Database namespace.
2000-12-01 Ed: Created.
Class and IDs
$rs = DBIx::SQLEngine::Record::Set->new_class_ids( $class, @ids );
$rs->init_class_ids( $class, @ids );
( $class, @ids ) = $rs->class_ids();
Conversions
Each of the below returns a RecordSet blessed into a particular subclass. Returns the original object if it is already of that subclass, or returns a cloned and converted copy.
@data = $rs->raw();
Returns the contents of the RecordSet as stored internally within the object. Results are dependent on which subclass is in use.
$rs = $rs->as_RecordArray;
INCOMPLETE
$clone = $rs->as_IDArray;
INCOMPLETE
$clone = $rs->as_IDString;
INCOMPLETE
# $rs = DBIx::SQLEngine::Record::Set->new_class_ids( $class, @ids ); sub new_ids { my $callee = shift; my $package = ref $callee || $callee;
my $self = [];
bless $self, $package;
$self->init_class_ids( @_ );
return $self;
}
# $rs->init_ids( $class, @ids ); sub init_ids { my $self = shift; my $class = shift;
@$self = map { $class->fetch_id( $_ ) } @_;
}
# @records = $rs->class_ids(); sub class_ids { my $self = shift; my $class = ref( $self->[0] ); return $class, map { $_->{id} } @$self; }
###
sub raw { my $self = shift; if ( scalar @_ ) { @$self = @_; } else { @$self; } } # # sub as_RecordArray { # my $self = shift; # } # # sub as_IDArray { # my $self = shift; # EBiz::Database::RecordSet::IDArray->new( $self->records ); # } # # sub as_IDString { # my $self = shift; # EBiz::Database::RecordSet::IDString->new( $self->records ); # }