How to addInCondition with floats?
I tried a lot.
This works ok:
$criteria=new CDbCriteria();
$criteria->addInCondition('order_id',array(36907));
$tasks=OrderTask::model()->findAll($criteria);
In my case it returns 4 models:
But if I try
$criteria=new CDbCriteria();
$criteria->addInCondition('order_id',array(36907));
$criteria->addInCondition('step',array(3.20));
$tasks=OrderTask::model()->findAll($criteria);
Or
$criteria=new CDbCriteria();
$criteria->addInCondition('step',array("3.20"));
$tasks=OrderTask::model()->findAll($criteria);
Or
$criteria=new CDbCriteria();
$criteria->addInCondition('step',array('3.2'));
$tasks=OrderTask::model()->findAll($criteria);
Results are empty.
According to log, the query is:
system.db.CDbCommand.query(SELECT * FROM
orders_tasks
t
WHERE step=:ycp1. Bound with :ycp1=3.2)
This query in phpmyadmin returns 5360 rows
SELECT * FROM `orders_tasks` `t` WHERE step = 3.20
This queries in phpmyadmin returns 0 rows
SELECT * FROM `orders_tasks` `t` WHERE step = '3.20'
SELECT * FROM `orders_tasks` `t` WHERE step = '3.2'
SELECT * FROM `orders_tasks` `t` WHERE step = "3.20"
This try
$criteria=new CDbCriteria();
$criteria->addInCondition('step',array("3,20"));
$tasks=OrderTask::model()->findAll($criteria);
returns Models with step=3 OR 20
This query in phpmyadmin returns rows with step=3 OR 20
SELECT * FROM `orders_tasks` `t` WHERE step = '3,20'
So, how to addInCondition
with floats?
Details, for instance
step
field is float(8,2)
Sql table dump:
CREATE TABLE IF NOT EXISTS `orders_tasks` (
`task_id` int(11) NOT NULL AUTO_INCREMENT,
`order_id` int(11) NOT NULL,
`step` float(6,2) NOT NULL,
`done` int(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`task_id`),
KEY `order_id` (`order_id`),
KEY `step` (`step`),
KEY `orderstep` (`order_id`,`step`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;
Yii version: 1.1.10
Query in Yii logs
Real query in MySql logs
This will fix you problem
After that your query returns