Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Maybe Bug: Sql Power Function Breaks Cdbcriteria ->With Parsing

$
0
0
Hi, I think this may be a bug in parsing the POWER function for MySQL in a criteria->with statement when doing a select as (it works in ->having when select as not present) - also the workaround works fine - just manually performing the power function 2x:
$criteria = new CDbCriteria;
/* this works - manually workaround repeating args */
$criteria->with = array('place_geometry'=>array('select'=>'place_id,center,'.new CDbExpression('(3956 * 2 * ASIN(SQRT( (SIN(('.$lat.' - Y(center)) * pi()/180 / 2)* SIN(('.$lat.' - Y(center)) * pi()/180 / 2)) + COS('.$lat.' * pi()/180 ) * COS( Y(center) * pi()/180) * (SIN(('.$lon.' - X(center)) * pi()/180 / 2)*SIN(('.$lon.' - X(center)) * pi()/180 / 2)) ))) as distance')));
/* this fails using POWER */
$criteria->with = array('place_geometry'=>array('select'=>'place_id,center,'.new CDbExpression('(3956 * 2 * ASIN(SQRT( (POWER( SIN(('.$lat.' - Y(center)) * pi()/180 / 2),2) + COS('.$lat.' * pi()/180 ) * COS( Y(center) * pi()/180) * (SIN(('.$lon.' - X(center)) * pi()/180 / 2)*SIN(('.$lon.' - X(center)) * pi()/180 / 2)) ))) as distance')));
$criteria->having= "distance <3";
$criteria->order = "distance ASC";

$dataProvider = new CActiveDataProvider('Place',
array('criteria' => $criteria,
'pagination' => array(
'pageSize' => 10,
),
));

- Mac OS X 10.7
- MAMP Apache/2.2.23 (Unix)
- Safari/Chrome
- Yii version v1.1.13

Viewing all articles
Browse latest Browse all 18717

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>