1
Hi there.
I'm trying to use the Criteria class to construct a "is not null" condition in SQL but with little luck.
i.e
select * from xoops_users where uid is not null
Doing the above using Criteria
$crit =& new Criteria('uid','0','','%s is not null');
produces
select * from xoops_users where uid is not null 0
While
$crit =& new Criteria('uid','','','%s is not null');
produces
select * from xoops_users where
because no value is specified in the Criteria constructor.
The only way I have managed to do this is by hacking the criteria.php XOOPS class to the following:
function render() {
if ( is_numeric($this->value) || strtoupper($this->operator) == 'IN') {
$value = $this->value;
} else {
if ( '' === ($value = trim($this->value)) ) {
$value = null;
}
if ( (substr($value, 0, 1) != '`') && (substr($value, -1) != '`') ) {
$value = "'$value'";
}
}
$clause = (!empty($this->prefix) ? "{$this->prefix}." : "") . $this->column;
if ( !empty($this->function) ) {
$clause = sprintf($this->function, $clause);
} else {
$clause .= " {$this->operator} $value";
}
return $clause;
}
Is this the only way of doing this? Am I missing something obvious? If not, can the above changes be incorporated into the core?
Cheers.
McNaz.