spotorm / spot2

Spot v2.x DataMapper built on top of Doctrine's Database Abstraction Layer
http://phpdatamapper.com
BSD 3-Clause "New" or "Revised" License
601 stars 101 forks source link

Whitespace in operators #216

Open marcelloh opened 7 years ago

marcelloh commented 7 years ago

I have this code:

$aFilter['appdeletedby_id'] = NULL;
$dataRecords = $this->select('distinct myField)
            ->where($aFilter)
            ->order([$field => 'ASC']);

and it works but when I add another filter:

$aFilter['myField  != ' ] = '';

It doesn't work. I get a: Unsupported operator '' in WHERE clause. If you want to use a custom operator, you can add one with \Spot\Query::addWhereOperator('', function (QueryBuilder $builder, $column, $value) { ... });

willemwollebrants commented 7 years ago

There's a trailing space in the array key:

$aFilter['myField  != '  ];

If you remove the space, it should work:

$aFilter['myField  !=' ];
marcelloh commented 7 years ago

Happy to see, that there is somehow a solution. I have to test this, but if it is like this, I would say it is an issue

marcelloh commented 7 years ago

Just tested it. Nice workaround :-) and it will do for now, but I consider it a bug.

marcelloh commented 7 years ago

The solution: Query.php ->parseWhereToSQLFragments was:

            // Column name with comparison operator
            $colData = explode(' ', $column);

becomes:

            // Column name with comparison operator
            $colData = explode(' ', trim($column));
FlipEverything commented 7 years ago

I don't consider it a huge bug, but it doesn't hurt to create a PR with this modification.