Not Null Moose

Its yet another operator day here in the Moos Pen

Hmm I could just copy and past yesterday's postette here and and in 'NOT' in the correct places to get today's 'Is Not Null' operator postette but I an not going to take the schlock path today.

As I implied it is the turn of the 'Is Not Null' operator today another very easy one for a postette ad I start with the same test as yesterday and just add Not where needed, no need for that here.

As for the Driver::DBI code I could just add in another 'else if' into that _predicate_sql' sub but I think I will take a little different approach and have one 'elsif' that covers both. Here is the patch


}
elsif (uc($predicate->operator) eq Database::Accessor::Driver::DBI::SQL::IS_NULL
++ or uc($predicate->operator) eq Database::Accessor::Driver::DBI::SQL::IS_NOT_NULL) {

$clause .= join(" ",$self->_field_sql($predicate->left,1)
,Database::Accessor::Driver::DBI::SQL::IS
++ ,uc($predicate->operator) eq
Database::Accessor::Driver::DBI::SQL::IS_NOT_NULL
++ ? Database::Accessor::Driver::DBI::SQL::NOT
++ : undef
,Database::Accessor::Driver::DBI::SQL::NULL
);
}

Unfortunately this cased an error in the 'Is Null' as now I have an extra space in the SQL between the 'IS' and 'NULL'. Of well how about this;

elsif (uc($predicate->operator) eq Database::Accessor::Driver::DBI::SQL::IS_NULL
or uc($predicate->operator) eq
Database::Accessor::Driver::DBI::SQL::IS_NOT_NULL) {
my $is = Database::Accessor::Driver::DBI::SQL::IS;
$is .= " "
.Database::Accessor::Driver::DBI::SQL::NOT
if(uc($predicate->operator) eq
Database::Accessor::Driver::DBI::SQL::IS_NOT_NULL );

$clause .= join(" ",$self->_field_sql($predicate->left,1)
,$is
,Database::Accessor::Driver::DBI::SQL::NULL
);
}

and that works but!

It think I am just complicating my code and not really gaining anything though if I do write it the anti-pattern way like this;


}
elsif ( uc($predicate->operator) eq
Database::Accessor::Driver::DBI::SQL::IS_NOT_NULL) {

$clause .= join(" ",$self->_field_sql($predicate->left,1)
,Database::Accessor::Driver::DBI::SQL::IS
,Database::Accessor::Driver::DBI::SQL::IS_NOT_NULL
,Database::Accessor::Driver::DBI::SQL::NULL
);
}

I do get rid on an extra 'and' case and the '$is' var and it is a little easier to read so maybe I should of just done a cut, paste and edit for my postette today?

img5720a.jpg

Leave a comment

About byterock

user-pic Long time Perl guy, a few CPAN mods allot of work on DBD::Oracle and a few YAPC presentations