DBX
view release on metacpan or search on metacpan
DBX/Recordset.pm view on Meta::CPAN
$self->fetch;
}
sub fetch
{
my ($self) = @_;
$self->clear;
$self->{cur_rec} = $self->{sth}->fetchrow_hashref;
if(!$self->{cur_rec})
{
$self->{eof} = 1;
}
}
sub move_prev
{
my ($self) = @_;
$self->clear;
die "Selected cursor cannot move_prev" if $self->{how} != DBX_CURSOR_RANDOM;
}
sub eof
{
my ($self) = @_;
$self->{eof};
}
sub clear
{
my ($self) = @_;
$self->{dirty} = 0;
$self->{changed} = {};
}
sub field
{
my ($self, $field, $value) = @_;
if(not defined $value)
{
my $value = $self->{cur_rec}->{$field};
die "No such field" unless $value;
return $value;
}
else
{
$self->{dirty} = 1;
$self->{changed}->{$field} = $value;
return $value;
}
}
sub as_num
{
my ($self) = @_;
return !$self->{eof};
}
sub update
{
my ($self) = @_;
return unless $self->{dirty};
my %changed = %{$self->{changed}};
my %old = %{$self->{cur_rec}};
my $sql = "UPDATE $self->{table} SET ";
for(keys(%changed))
{
$sql .= "$_ = '$changed{$_}', ";
}
$sql =~ s/, $//;
$sql .= "WHERE ";
for(keys(%old))
{
$sql .= "$_ = '$old{$_}' AND ";
}
$sql =~ s/ AND $/\;/;
$self->{dbh}->do($sql) or die $!;
}
1;
__END__
=head1 NAME
DBX::Recordset - abstracts a DBX query result
=head1 SYNOPSIS
use DBX;
$conn = DBX->mysql("database=test;host=localhost;", "", "");
$rs = $conn->query("SELECT * FROM test");
while($rs)
{
print $rs->field("client") . "\n";
$rs->field("client", "test");
$rs->move_next;
}
=head1 DESCRIPTION
DBX::Recordset is the heart of the DBX and provides most of its additional functionality. Recordsets are
returned by the query method of a L<DBX::Connection> object.
Recordsets support simple forward-only cursors (at the moment) and allow you to easily retrieve and/or modify
fields.
=over 4
( run in 2.008 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )