NAME

Persist::Table - Represents a persistent table object

SYNOPSIS

  use Persist::Source;

  $source = new Persist::Source(...);

  $table = $source->folks;

  print "Table name: ", $source->table_name, "\n";
  while ($table->next) {
	  print "Name: ", $table->name, "\n";
	  print "Age: ", $table->age, "\n";
  }

  $table->insert;
  $table->name('Bob');
  $table->age(45);
  $table->save;

  $table->insert({
      name => 'George',
      age => 50});
  $table->save;

  my $fid = $table->last_fid; # last autonumber inserted

  $table->first;
  $table->delete;

DESCRIPTION

Provides simplified access to a persistent table. This object may be used to insert, update, delete, and access records in a table. Some functionality is inherited from Source::Tabular. See that documentation for more information.

$table = $source->table($table, $filter)

The alternative to the table constructor is to use the table's name as the constructor name directly. As in:

$table = $source->folks($filter);

See Persist::Source for details.

$name = $table->table_name;

Returns the schema name for the table.

$table->cancel

Cancels any changes that have been made to the current record. If the current record is new, the set values are returned to undef. Changes are automatically saved by default, so an explicit call to this function should be made whenever saving should be prevented.

$value = $table->value($column [, $set ] )

Either gets/sets a column value.

$value = $table->last_value($column)

Retrieves the last sequence value assigned to the given column during an insert operation. This call is only valid upon columns of type AUTONUMBER. Using this method on any other column type will result in an exception.

$table->save

Saves any changes that have been made to the current record. If the current record is new then it is inserted. If it is an existing record it is updated.

This operation is performed automatically whenever a call to insert or first or next is made or whenever the table object is destroyed.

$table->insert( [ \%values ] )

Marks the current record as being a new record. If given, it will set the columns that are keys in %values to the given values. All values will default to undef if not specified by %values.

$table->insert_now(\%values)

Inserts a record immediately with the given %values. This is equivalent to

$table-E<gt>insert(\%values);
$table-E<gt>save;
$table->delete

Deletes the current record. If the current record is marked as new, then this call has the same effect as cancel.

$value = $table-><column>( [ $set ] )

Gets/sets a column value. This is a shorthand for value.

$value = $table->last_<column>;

Retrieves the last assigned sequence value to the given AUTONUMBER typed column. Given a non-autonumber column will result in an exception. This is a shorthand for last_seq.

SEE ALSO

Persist, Persist::Source, Persist::Tabular

AUTHOR

Andrew Sterling Hanenkamp, <hanenkamp@users.sourceforge.net>

COPYRIGHT AND LICENSE

Copyright (c) 2003, Andrew Sterling Hanenkamp
All rights reserved.

Redistribution and use in source and binary forms, with or without 
modification, are permitted provided that the following conditions 
are met:

  * Redistributions of source code must retain the above copyright 
    notice, this list of conditions and the following disclaimer.
  * Redistributions in binary form must reproduce the above copyright 
    notice, this list of conditions and the following disclaimer in 
    the documentation and/or other materials provided with the 
    distribution.
  * Neither the name of the Contentment nor the names of its 
    contributors may be used to endorse or promote products derived 
    from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
POSSIBILITY OF SUCH DAMAGE.