EPrints Technical Mailing List Archive

Message: #00800


< Previous (by date) | Next (by date) > | < Previous (in thread) | Next (in thread) > | Messages - Most Recent First | Threads - Most Recent First

[EP-tech] Patch: handle NULL values in EPrints::Search::Condition::Comparison


Hi!

The attached patch changes SQL output to use "IS" instead of "=" when
comparing for equality against undefined values.

This fixes a problem (at least with Oracle databases) when using views
to browse by creators that have an empty givenname. (The SQL that was
created contained something like
"EPRINT_CREATORS_NAME"."CREATORS_NAME_GIVEN" = NULL
... which will never match.

I believe it could also correct several other problems concerning empty
fields, however, I did only stumble across the browse view issue yet.

Cheers,
--leo
-- 
e-mail   ::: Leo.Bergolth (at) wu.ac.at
fax      ::: +43-1-31336-906050
location ::: IT-Services | Vienna University of Economics | Austria

Index: perl_lib/EPrints/Search/Condition/Comparison.pm
===================================================================
--- perl_lib/EPrints/Search/Condition/Comparison.pm	(revision 5890)
+++ perl_lib/EPrints/Search/Condition/Comparison.pm	(working copy)
@@ -174,9 +174,10 @@
 		my @logic;
 		for(qw( given family ))
 		{
+			my $op = ( $self->{op} eq '=' and !defined $self->{params}->[0]->{$_} ) ? 'IS' : $self->{op};
 			push @logic, sprintf("%s %s %s",
 				$db->quote_identifier( $table, "$sql_name\_$_" ),
-				$self->{op},
+				$op,
 				$db->quote_value( $self->{params}->[0]->{$_} ) );
 		}
 		return "(".join(") AND (", @logic).")";
@@ -187,16 +188,18 @@
 	}
 	elsif( $field->isa( "EPrints::MetaField::Int" ) )
 	{
+		my $op = ( $self->{op} eq '=' and !defined $self->{params}->[0] ) ? 'IS' : $self->{op};
 		return sprintf("%s %s %s",
 			$db->quote_identifier( $table, $sql_name ),
-			$self->{op},
+			$op,
 			EPrints::Database::prep_int( $self->{params}->[0] ) );
 	}
 	else
 	{
+		my $op = ( $self->{op} eq '=' and !defined $self->{params}->[0] ) ? 'IS' : $self->{op};
 		return sprintf("%s %s %s",
 			$db->quote_identifier( $table, $sql_name ),
-			$self->{op},
+			$op,
 			$db->quote_value( $self->{params}->[0] ) );
 	}
 }