1
chapo
CriteriaElement problems
  • 2004/5/3 5:49

  • chapo

  • Just popping in

  • Posts: 3

  • Since: 2003/9/11


I am currently trying to develop a module for XOOPS, and found some strange behaviour in the CriteriaElement and related classes. Maybe somebody could help or let me know if I am using them in the wrong way.

First I found that when you do the following:

$criteria =& new CriteriaCompo();
$criteria->add(new Criteria('text1''');
$criteria->add(new Criteria('text2'$text2);


the render of the WHERE clause is not correctly formatted and it ends up with:

WHERE AND text2='sample text'


instead of:

WHERE text1 '' AND text2 'sample text'


It basically means that we cannot look for an empty string in a table.

Furthermore, I have try to use the CriteriaElement objects to look for NULL columns in the database, and it does not work too. If I do:

$criteria =& new CriteriaCompo();
$criteria->add(new Criteria('text1'null'<=>');
$criteria->add(new Criteria('text2'$text2);


the same happen.

It looks like the two problems are coming from the following lines in the Criteria::render() function:

if ( '' === ($value trim($this->value)) ) {
    return 
'';
    }


Is it intentional? How can I look for an empty column using the CriteriCompo object?

Same questions for the NULL columns? For this one, I had to add the following lines at the beginning of the Criteria::render() function:

if (is_null($this->value)) {
        
$value 'NULL';
    } else ...


Thanks for your help.

BTW congratulation to the XOOPS team! XOOPS is great, I love it.

2
Mithrandir
Re: CriteriaElement problems

would this work?
$criteria->add(new Criteria('text1', 'NULL');

3
chapo
Re: CriteriaElement problems
  • 2004/5/3 6:25

  • chapo

  • Just popping in

  • Posts: 3

  • Since: 2003/9/11


No, it did not.

If I have a column as type INT and perform the following querry:

SELECT FROM `xoops_mytableWHERE length <=> 'NULL' LIMIT 0 30


nothing is returned, but if I do:

SELECT FROM `xoops_mytableWHERE length <=> NULL LIMIT 0 30


It returns all the rows where I have this column set as NULL. The problem is that the Criteria class automatically adds the quotes.

For a varchar column it looks like you cannot look for a NULL value but you have to look for an empty string (but I cannot use it with XOOPS as explain before).

Thanks.

4
Mithrandir
Re: CriteriaElement problems

If your little hack works as it should, do submit it to the Patches Tracker

Sounds like it could be useful.

5
chapo
Re: CriteriaElement problems
  • 2004/5/3 6:47

  • chapo

  • Just popping in

  • Posts: 3

  • Since: 2003/9/11


I will.

Thanks.

Login

Who's Online

394 user(s) are online (288 user(s) are browsing Support Forums)


Members: 0


Guests: 394


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits