summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Woodward2006-03-04 03:38:00 +0000
committerJason Woodward2006-03-04 03:38:00 +0000
commit752b5bb1bf750d72ce14034872e72c3a1abf2af1 (patch)
treea0feaba0b810939047a990c329f174362b3939c9
parent478d63cbd8adab2b26bf8c6f0e9802c98adb3901 (diff)
downloadJaos-DBI-752b5bb1bf750d72ce14034872e72c3a1abf2af1.tar.gz
fixed virtual_columns handling0.3.1
-rw-r--r--Changes13
-rw-r--r--lib/Jaos/DBI.pm22
-rw-r--r--t/04full.t13
-rw-r--r--t/lib/Foo.pm1
4 files changed, 36 insertions, 13 deletions
diff --git a/Changes b/Changes
index af44196..0236019 100644
--- a/Changes
+++ b/Changes
@@ -1,10 +1,13 @@
Revision history for Perl extension Jaos::DBI
+0.3.1
+ - fixed virtual_columns handling
+
0.3
- - added 04full.t
- - updated POD
- - added additional search methods
- - added is_changed
+ - added 04full.t
+ - updated POD
+ - added additional search methods
+ - added is_changed
0.2
- - initial release
+ - initial release
diff --git a/lib/Jaos/DBI.pm b/lib/Jaos/DBI.pm
index 49fa59e..3932e02 100644
--- a/lib/Jaos/DBI.pm
+++ b/lib/Jaos/DBI.pm
@@ -4,7 +4,7 @@ use warnings;
use base qw/Class::Data::Inheritable Class::Accessor/;
use DBI ();
-our $VERSION = 0.3;
+our $VERSION = 0.3.1;
our $if_active = ($DBI::VERSION >= '1.40') ? 3 : 0;
=head1 NAME
@@ -278,9 +278,9 @@ sub virtual_columns
{
my $self = shift;
if (@_) {
- $self->_virtual_columns(@_);
+ $self->_virtual_columns([@_]);
}
- $self->_virtual_columns();
+ @{$self->_virtual_columns() || [] };
}
=head2 manual_update
@@ -675,11 +675,18 @@ Set a column value. This updates the column in the table row represented by the
sub set
{
my ($self, $key) = splice(@_, 0, 2);
+
$self->SUPER::set($key, @_);
- if ($self->manual_update) {
- $self->is_changed(1);
- } else {
- $self->_update($key)
+
+ # only actual columns get updated, not virtual_columns
+ if ($self->_columns && grep { /$key/ } @{$self->_columns} ) {
+
+ if ($self->manual_update) {
+ $self->is_changed(1);
+ } else {
+ $self->_update($key)
+ }
+
}
}
@@ -705,6 +712,7 @@ sub _update
my @values = ();
return undef unless ref $self;
return undef unless $primary_column;
+ return undef unless $self->_columns; # don't update virtual_columns only
if ($key) {
$sql = "update $table set $key = ? where $primary_column = ?";
diff --git a/t/04full.t b/t/04full.t
index 1b5c735..cd468b9 100644
--- a/t/04full.t
+++ b/t/04full.t
@@ -13,7 +13,7 @@ BEGIN
or plan skip_all =>
"DBD::CSV is needed for this test";
- plan tests => 25;
+ plan tests => 28;
unlink('foo_table') if ( -e 'foo_table' );
my $dbh = DBI->connect('DBI:CSV:f_dir=./') or die $DBI::errstr;
@@ -35,12 +35,16 @@ my @base_class_methods = qw/
/;
can_ok('Foo',@base_class_methods);
+can_ok('Foo',qw/foo bar/);
+
ok(Foo->table eq 'foo_table','checking table class method');
ok(Foo->columns == 3,'checking columns class method');
+
my $obj = Foo->find_or_create( id => 1, name => 'jason', password => 'pass', email => 'woodwardj@jaos.org' );
isa_ok($obj,'Foo');
isa_ok(Foo->retrieve(1),'Foo');
isa_ok(Foo->find_or_create( id => 2, name => 'jason', password => 'pass', email => 'woodwardj@jaos.org' ),'Foo');
+
ok(Foo->search(name => 'jason') > 0,'search returns array');
ok(Foo->search(name => 'jason',{ order_by => 'id'}) > 0,'search with order_by returns array');
ok(Foo->search_where("name = 'jason'") > 0,'search returns array');
@@ -51,9 +55,16 @@ ok(Foo->search_or_ilike() > 0,'search_or_ilike returns array');
ok(Foo->retrieve_all() > 0,'search_or_ilike returns array');
ok($obj->id == 1,'testing generated method');
ok($obj->name eq 'jason','testing generated method');
+
+$obj->foo('test me');
+$obj->bar('test me');
+ok($obj->foo eq 'test me','testing virtual_method');
+ok($obj->bar eq 'test me','testing virtual_method');
+
eval{$obj->begin_work;};
$obj->name('j');
$obj->commit;
+
ok($obj->manual_update(1),'setting manual update');
ok($obj->name eq 'j','testing generated method');
ok($obj->password eq 'pass','testing generated method');
diff --git a/t/lib/Foo.pm b/t/lib/Foo.pm
index 3810736..14ec130 100644
--- a/t/lib/Foo.pm
+++ b/t/lib/Foo.pm
@@ -4,6 +4,7 @@ use base qw/ Jaos::DBI /;
__PACKAGE__->db_dsn('DBI:CSV:f_dir=');
__PACKAGE__->table('foo_table');
__PACKAGE__->columns(qw/name password email/);
+__PACKAGE__->virtual_columns(qw/foo bar/);
__PACKAGE__->primary_column('id');
__PACKAGE__->setup();