Vernon Lyon

NAME

DBIx::DBO::Row - An OO interface to SQL queries and results. Encapsulates a fetched row of data in an object.

SYNOPSIS

  # Create a Row object for the `users` table
  my $row = $dbo->row('users');
  
  # Load my record
  $row->load(login => 'vlyon') or die "Where am I?";
  
  # Double my salary :)
  $row->update(salary => {FUNC => '? * 2', COL => 'salary'});
  
  # Print my email address
  print $row->{email};
  
  # Delete my boss
  $row->load(id => $row->{boss_id})->delete or die "Can't kill the boss";

METHODS

new

  DBIx::DBO::Row->new($dbo, $table);
  DBIx::DBO::Row->new($dbo, $query_object);

Create and return a new Row object. The object returned represents rows in the given table/query. Can take the same arguments as "new" in DBIx::DBO::Table or a Query object can be used.

tables

Return a list of Table objects for this row.

columns

Return a list of column names.

column

  $row->column($column_name);

Returns a column reference from the name or alias.

value

  $value = $row->value($column);

Return the value in the $column field. $column can be a column name or a Column object.

Values in the Row can also be obtained by using the object as an array/hash reference.

  $value = $row->[2];
  $value = $row->{some_column};

load

  $row->load(id => 123);
  $row->load(name => 'Bob', status => 'Employed');

Fetch a new row using the where definition specified. Returns the Row object if the row is found and loaded successfully. Returns an empty list if there is no row or an error occurs.

update

  $row->update(id => 123);
  $row->update(name => 'Bob', status => 'Employed');

Updates the current row with the new values specified. Returns the number of rows updated or '0E0' for no rows to ensure the value is true, and returns false if there was an error.

Note: If LIMIT is supported on UPDATEs then only the first matching row will be updated otherwise ALL rows matching the current row will be updated.

delete

  $row->delete;

Deletes the current row. Returns the number of rows deleted or '0E0' for no rows to ensure the value is true, and returns false if there was an error. The Row object will then be empty.

Note: If LIMIT is supported on DELETEs then only the first matching row will be deleted otherwise ALL rows matching the current row will be deleted.

is_empty

  return $row->{id} unless $row->is_empty;

Checks to see if it's an empty Row, and returns true or false.

Common Methods

These methods are accessible from all DBIx::DBO* objects.

dbo

The DBO object.

dbh

The read-write DBI handle.

rdbh

The read-only DBI handle, or if there is no read-only connection, the read-write DBI handle.

config

  $row_setting = $row->config($option);
  $row->config($option => $row_setting);

Get or set the Row config settings. When setting an option, the previous value is returned. When getting an option's value, if the value is undefined, the Query object (If the the Row belongs to one) or DBIx::DBO's value is returned.

See "Available_config_options" in DBIx::DBO.

SUBCLASSING

Classes can easily be created for tables in your database. Assume you want to create a simple Row class for a "Users" table:

  package My::User;
  our @ISA = qw(DBIx::DBO::Row);
  
  sub new {
      my($class, $dbo) = @_;
      
      $class->SUPER::new($dbo, 'Users'); # Create the Row for the "Users" table
  }

SEE ALSO

DBIx::DBO