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:

le="color: #000000"><?php $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:

le="color: #000000"><?php WHERE AND text2='sample text'


instead of:

le="color: #000000"><?php 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:

le="color: #000000"><?php $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:

le="color: #000000"><?php 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:

le="color: #000000"><?php 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:

le="color: #000000"><?php SELECT * FROM `xoops_mytable` WHERE length <=> 'NULL' LIMIT 0 , 30


nothing is returned, but if I do:

le="color: #000000"><?php SELECT * FROM `xoops_mytable` WHERE 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

Donat-O-Meter

Stats
Goal: $15.00
Due Date: Jul 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $15.00
Make donations with PayPal!

Latest GitHub Commits