Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#30 Allow empty string and NULL queries using Criteria objects

XOOPS_2.2
open
Skalpa Keo
None
5
2012-09-25
2004-05-03
chapichapo
No

The Criteria::render() function currently returns an
empty string (without any statement) if you build a
query to search for an empty string, e.g. doing:
$criteria = new Criteria('text1', '');
and calling
$criteria->renderWhere();
it will not render any WHERE statement but will return
an empty string.

To allow this, modify the function Criteria::render()
(file class/criteria.php) replacing the lines:
if ( '' === ($value = trim($this->value)) ) {
return '';
}
with
$value = trim($this->value);

Furthermore, the Criteria::render() function does not
allow to make queries looking for columns that are
NULL. To allow this, modify the beginning of the
Criteria::render() function adding:
if (is_null($this->value)) {
$value = 'NULL';
} else
before the first line of the function which is:
if ( is_numeric($this->value) ||
strtoupper($this->operator) == 'IN') {

Then you can do:
$criteria = new Criteria('length', null, '<=>');
and retrieves the rows with NULL value.

All this works on XOOPS 2.0.6 running a MySQL database
(I am not sure it will work with other database
engine... Will it?)

I hope it can help anybody, and that it will be
included in future releases of XOOPS.

Discussion

  • Skalpa Keo
    Skalpa Keo
    2004-05-12

    Logged In: YES
    user_id=882380

    OK for that one. Am keeping this one for 2.2 as this should
    go to beta before release (some modules might rely on this
    misbehavior).