[jifty-devel] Re: [Jifty-commit] r1158 - in Jifty-DBI/trunk: lib/Jifty/DBI

Jesse Vincent jesse at bestpractical.com
Mon Jun 5 12:40:13 EDT 2006


Sean,

would it make sense to factor out this chunk of duplicated code to a
single function?

-Jesse

On Mon, Jun 05, 2006 at 11:49:46AM -0400, jifty-commit at lists.jifty.org wrote:
> Author: seanmil
> Date: Mon Jun  5 11:49:44 2006
> New Revision: 1158
> 
> Modified:
>    Jifty-DBI/trunk/   (props changed)
>    Jifty-DBI/trunk/lib/Jifty/DBI/Record.pm
>    Jifty-DBI/trunk/lib/Jifty/DBI/Schema.pm
> 
> Log:
>  r351 at pc102:  sean | 2006-06-05 11:49:28 -0400
>  * Implement support for 'distinct' column checks
> 
> 
> 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	Mon Jun  5 11:49:44 2006
> @@ -589,6 +589,23 @@
>          return ( $ret->return_value );
>      }
>  
> +    # Implement 'is distinct' checking
> +    if ( $column->distinct ) {
> +        my $new_record = $self->new( $self->_handle );
> +        $new_record->load_by_cols ( $column->name => $args{'value'} );
> +        if( $new_record->id ) {
> +            $ret->as_array( 0, 'Value already exists for distinct column ' . 
> +                $column->name );
> +            $ret->as_error(
> +                errno        => 3,
> +                do_backtrace => 0,
> +                message      => 'Value already exists for distinct column ' .
> +                    $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'};
> @@ -860,6 +877,24 @@
>              value_ref => \$attribs{$column_name},
>          );
>  
> +        # Implement 'is distinct' checking
> +        if ( $column->distinct ) {
> +            my $new_record = $self->new( $self->_handle );
> +            $new_record->load_by_cols ( $column_name => $attribs{$column_name} );
> +            if( $new_record->id ) {
> +                my $ret = Class::ReturnValue->new();
> +                $ret->as_array( 0, 'Value already exists for distinct column ' . 
> +                    $column->name );
> +                $ret->as_error(
> +                    errno        => 3,
> +                    do_backtrace => 0,
> +                    message      => 'Value already exists for distinct column ' .
> +                        $column->name,
> +                );
> +                return ( $ret->return_value );
> +            }
> +        }
> +
>          if ( $column->type =~ /^(text|longtext|clob|blob|lob|bytea)$/i ) {
>              my $bhash = $self->_handle->blob_params( $column_name, $column->type );
>              $bhash->{'value'} = $attribs{$column_name};
> 
> Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Schema.pm
> ==============================================================================
> --- Jifty-DBI/trunk/lib/Jifty/DBI/Schema.pm	(original)
> +++ Jifty-DBI/trunk/lib/Jifty/DBI/Schema.pm	Mon Jun  5 11:49:44 2006
> @@ -256,8 +256,11 @@
>  =head2 distinct
>  
>  Declares that a column should only have distinct values.  This
> -currently does nothing, due to not being implemented in
> -L<DBIx::DBSchema>.  Correct usage is C<is distinct>.
> +currently is implemented via database queries prior to updates
> +and creates instead of constraints on the database columns
> +themselves. This is because there is no support for distinct
> +columns implemented in L<DBIx::DBSchema> at this time.  
> +Correct usage is C<is distinct>.
>  
>  =cut
>  
> _______________________________________________
> Jifty-commit mailing list
> Jifty-commit at lists.jifty.org
> http://lists.jifty.org/cgi-bin/mailman/listinfo/jifty-commit
> 

-- 


More information about the jifty-devel mailing list