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';  # Short for: $row->value('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_object);
DBIx::DBO::Row->new($dbo, $query_object);

Create and return a new Row object.

tables

Return a list of DBIx::DBO::Table objects for this row.

column

$query->column($column_name);
$query->column($column_or_alias_name, 1);

Returns a reference to a column for use with other methods.

value

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

Return the value in the $column field. The ** method is a shortcut for the value method. $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.

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.

Common Methods

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

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.

do

$row->do($statement)         or die $row->dbh->errstr;
$row->do($statement, \%attr) or die $row->dbh->errstr;
$row->do($statement, \%attr, @bind_values) or die ...

This provides access to the DBI->do method. It defaults to using 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

When subclassing DBIx::DBO::Row, please note that Row objects created with the "new" method are blessed into a DBD driver specific module. For example, if using MySQL, a new Row object will be blessed into DBIx::DBO::Row::DBD::mysql which inherits from DBIx::DBO::Row. However if objects are created from a subclass called MySubClass the new object will be blessed into MySubClass::DBD::mysql which will inherit from both MySubClass and DBIx::DBO::Row::DBD::mysql.

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;
use base 'DBIx::DBO::Row';

sub new {
    my $class = shift;
    my $dbo = shift;
    
    $class->SUPER::new($dbo, 'Users'); # Create the Row for the "Users" table only
}

SEE ALSO

DBIx::DBO