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 UPDATE
s 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 DELETE
s 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
$dbo->do($statement) or die $dbo->dbh->errstr;
$dbo->do($statement, \%attr) or die $dbo->dbh->errstr;
$dbo->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 = $dbo->config($option);
$dbo->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.