[Jifty-commit] r884 - in Jifty-DBI/trunk: lib/Jifty/DBI
lib/Jifty/DBI/Filter
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Fri Apr 21 01:08:20 EDT 2006
Author: alexmv
Date: Fri Apr 21 01:08:19 2006
New Revision: 884
Modified:
Jifty-DBI/trunk/ (props changed)
Jifty-DBI/trunk/lib/Jifty/DBI/Filter/DateTime.pm
Jifty-DBI/trunk/lib/Jifty/DBI/Handle.pm
Jifty-DBI/trunk/lib/Jifty/DBI/Record.pm
Log:
r12459 at zoq-fot-pik: chmrr | 2006-04-21 01:05:42 -0400
* Allow set_* methods to work on objects with no id
* Jifty::DBI::Filter::DateTime uses ISO8601 dates
Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Filter/DateTime.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Filter/DateTime.pm (original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Filter/DateTime.pm Fri Apr 21 01:08:19 2006
@@ -3,9 +3,9 @@
use warnings;
use strict;
-use base qw(Jifty::DBI::Filter);
-use DateTime ();
-use DateTime::Format::Strptime ();
+use base qw|Jifty::DBI::Filter|;
+use DateTime ();
+use DateTime::Format::ISO8601 ();
=head1 NAME
@@ -13,14 +13,14 @@
=head1 DESCRIPTION
-This filter allow you to work with DateTime objects instead of
-plain text dates.
+This filter allow you to work with DateTime objects instead of plain
+text dates.
=head2 encode
If value is DateTime object then converts it into ISO format
-C<YYYY-MM-DD hh:mm:ss>. Does nothing if value is not defined
-or string.
+C<YYYY-MM-DD hh:mm:ss>. Does nothing if value is not defined or
+string.
=cut
@@ -39,8 +39,8 @@
=head2 decode
-If value is defined then converts it into DateTime object otherwise
-do nothing.
+If value is defined then converts it into DateTime object otherwise do
+nothing.
=cut
@@ -56,9 +56,7 @@
# server time_zone, by default ISO
# other DBs may have own formats(Interbase for example can be forced to use special format)
# but we need Jifty::DBI::Handle here to get DB type
- my $parser
- = DateTime::Format::Strptime->new( pattern => '%Y-%m-%d %H:%M:%S', );
- my $dt = $parser->parse_datetime($$value_ref);
+ my $dt = DateTime::Format::ISO8601->parse_datetime($$value_ref);
if ($dt) {
$$value_ref = $dt;
} else {
Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Handle.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Handle.pm (original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Handle.pm Fri Apr 21 01:08:19 2006
@@ -356,6 +356,8 @@
@_
);
+ return 1 unless grep {defined} values %{$args{primary_keys}};
+
my @bind = ();
my $query = 'UPDATE ' . $args{'table'} . ' ';
$query .= 'SET ' . $args{'column'} . '=';
Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Record.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Record.pm (original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Record.pm Fri Apr 21 01:08:19 2006
@@ -492,9 +492,7 @@
$self->{'values'}{ $column->name } = $value;
$self->{'fetched'}{ $column->name } = 1;
}
- if ( $self->{'fetched'}{ $column->name }
- && !$self->{'decoded'}{ $column->name } )
- {
+ unless ( $self->{'decoded'}{ $column->name } ) {
$self->_apply_output_filters(
column => $column,
value_ref => \$self->{'values'}{ $column->name },
@@ -572,9 +570,13 @@
)
|| ( defined $args{'value'}
&& defined $self->{'values'}{ $column->name }
- # XXX: This is a bloody hack to stringify DateTime
- # and other objects for compares
- && $args{value}."" eq "".$self->{'values'}{ $column->name } )
+
+ # XXX: This is a bloody hack to stringify DateTime
+ # and other objects for compares
+ && $args{value}
+ . "" eq ""
+ . $self->{'values'}{ $column->name }
+ )
)
{
$ret->as_array( 1, "That is already the current value" );
@@ -582,19 +584,18 @@
}
}
-
+ my $method = "validate_" . $column->name;
+ my ( $ok, $msg ) = $self->$method( $args{'value'} );
+ unless ($ok) {
+ $ret->as_array( 0, 'Illegal value for ' . $column->name );
+ $ret->as_error(
+ errno => 3,
+ do_backtrace => 0,
+ message => "Illegal value for " . $column->name
+ );
+ return ( $ret->return_value );
+ }
- my $method = "validate_" . $column->name;
- my ( $ok, $msg ) = $self->$method( $args{'value'} );
- unless ($ok) {
- $ret->as_array( 0, 'Illegal value for ' . $column->name );
- $ret->as_error(
- errno => 3,
- do_backtrace => 0,
- message => "Illegal value for " . $column->name
- );
- return ( $ret->return_value );
- }
# The blob handling will destroy $args{'Value'}. But we assign
# that back to the object at the end. this works around that
my $unmunged_value = $args{'value'};
@@ -614,8 +615,8 @@
%args,
table => $self->table(),
primary_keys => { $self->primary_keys() }
-
);
+
unless ($val) {
my $message
= $column->name . " could not be set to " . $args{'value'} . ".";
More information about the Jifty-commit
mailing list