Yii 1.1.16 - cdbcriteria with string check

Hi,

Not sure if it’s a bug but it seems so. When trying to add a condition on a string (varchar 5000) field it simply doesn’t work. Please see below:

Table item_desc:

id : int 13

ean : varchar 20

desc : varchar 5000

idb: int 15

input some data with some "desc" empty and other with some text.

Code not working:




		$eant = "test";

		$idbt = "test";

		$criteria_desc = new CDbCriteria();

		$criteria_desc->addInCondition('ean',array($eant), 'AND');

		$criteria_desc->addNotInCondition('idb',array($idbt), 'AND');

		$criteria_desc->addNotInCondition('desc',array(''), 'AND');

		$descs_item = ItemDesc::model()->findAll($criteria_desc);



Error:

Same if we use array(null), the "IS NOT NULL" is not working also.

Do you have an idea?

Yii: latest 1.1.16 / OSX Yosemite / Apache / PHP 5.5 / MySQL

Thanks and regards,

Jinsa.

Condition for ‘desc’ field should be:




$criteria_desc->addCondition('desc <> ""');



and not addNotInCondiition

Hi, thanks for your reply but I also tried it and it doesn’t work neither:

Any idea?

DESC is a reserved word. You should not and may not use reserved words for your database fields.

my friend you on the wrong track first of all you using VARCHAR for pretty long string I would recommend you use text field for that as far as your following query is concerned




SELECT * FROM `item_desc` `t` WHERE ((ean=:ycp0) AND (idboutique!=:ycp1)) AND (desc!=:ycp2)


desc != ''

// I would recommend you replace it with following

LENGTH(desc) > 1

My bad! Thank you so much Ronald I just didn’t realized that I used “desc”… omg I’m so stupid >.< I just changed “desc” to “descitem” and then it works!

I also use your recommendation alirz23 using LENGTH(descitem) to prevent SQL injection I suppose.

Thanks both of you guys, sorry for that stupid post ^^