New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

floats are truncated (casted in integer) with andCondition function #125

intersel opened this Issue Oct 24, 2017 · 2 comments


None yet
2 participants
Copy link

intersel commented Oct 24, 2017

The issue was initially written in Modx Revolution modxcms/revolution#13657 (comment)


Using floats in a 'andCondition' call would transform them as integer

Step to reproduce

create an XPDO query calling andCondtion as this following exemple

		  'location_latitude:>=' => 48.858201356788,
		  'AND:location_latitude:<=' => 48.861798643212,

Observed behavior

result is like this one :

SELECT `id` FROM `match_request` AS `MatchRequest` 
  `MatchRequest`.`location_latitude` >= 48 AND 
  `MatchRequest`.`location_latitude` <= 48

Expected behavior

SELECT `id` FROM `match_request` AS `MatchRequest` 
  `MatchRequest`.`location_latitude` >= 48.858201356788 AND 
  `MatchRequest`.`location_latitude` <= 48.861798643212

Suggestion for solving the problem

Perhaps I missed something but...

The problem was detected in the parseBindings function using the 'quote' function... called line 2670 --2704 in modx revo 2.5.8-- in core/xpdo/xpdo.class.php

if ($type > 0) {
                    $v= $this->quote($v, $type);

Whatever type (int, float, ...) , you call 'quote'...

The problem sounds to be solved by changing line 2534 --2560 in modx revo-- in core/xpdo/xpdo.class.php in function quote

           case PDO::PARAM_INT:
                $quoted = trim($quoted);
                //$quoted = (integer) trim($quoted, "'");//removed
                $quoted = trim($quoted, "'");//added

Actually, it seems like float are seen like "param_int" (versus param_str) all along the processing...
so it should not be cast here as values in float could arrive here...


This comment has been minimized.

Copy link

Mark-H commented Oct 24, 2017

Could you show the relevant portion of your schema? What locale does your server use?


This comment has been minimized.

Copy link

intersel commented Oct 24, 2017

Hi Mark
Thanks to take care of my pb...

For the "locale" part, I'm not sure what the server uses... I let everything by default in modx
setlocale returns "C"...?

Here my schema:

<?xml version="1.0" encoding="UTF-8"?>
<model package="XXXX" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
        <object class="MatchRequest" table="match_request" extends="xPDOSimpleObject">
                <field key="location_latitude" dbtype="float" phptype="float" null="false" />
                <field key="location_longitude" dbtype="float" phptype="float" null="false" />
                <field key="location_altitude" dbtype="float" phptype="float" null="false" />
                <field key="location_radiusAccuracy" dbtype="float" phptype="float" null="false" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment