Skip to content
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

Open
intersel opened this issue Oct 24, 2017 · 3 comments
Open

Comments

@intersel
Copy link

intersel commented Oct 24, 2017

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

Summary

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

Step to reproduce

create an XPDO query calling andCondtion as this following exemple

$query->andCondition(
	 array(
		  'location_latitude:>=' => 48.858201356788,
		  'AND:location_latitude:<=' => 48.861798643212,
	 )			
);

Observed behavior

result is like this one :

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

Expected behavior

SELECT `id` FROM `match_request` AS `MatchRequest` 
WHERE ( 
  `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
                break;

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...

@Mark-H
Copy link
Collaborator

Mark-H commented Oct 24, 2017

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

@intersel
Copy link
Author

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" />
......
......
        </object>
</model>

@wshawn
Copy link

wshawn commented Sep 27, 2022

Having the exact same issue using xPDO included with MODX 3.01 , where parsing a schema to create Model files:

Deprecated: Implicit conversion from float 2.5 to int loses precision in D:\wamp64\www\modx3\core\vendor\xpdo\xpdo\src\xPDO\Om\xPDOGenerator.php on line 129

Deprecated: Implicit conversion from float 1.5 to int loses precision in D:\wamp64\www\modx3\core\vendor\xpdo\xpdo\src\xPDO\Om\xPDOGenerator.php on line 129

Deprecated: Implicit conversion from float 0.5 to int loses precision in D:\wamp64\www\modx3\core\vendor\xpdo\xpdo\src\xPDO\Om\xPDOGenerator.php on line 129

I get dozens of lines of these errors on two geo-location fields:

        <field key="latitude" dbtype="float" precision="8,6" phptype="float" null="true" />
        <field key="longitude" dbtype="float" precision="9,6" phptype="float" null="true" />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants