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

problem with search in Type INT for NumberColumn #349

Closed
Chris53897 opened this issue Jul 8, 2024 · 6 comments
Closed

problem with search in Type INT for NumberColumn #349

Chris53897 opened this issue Jul 8, 2024 · 6 comments

Comments

@Chris53897
Copy link
Contributor

Chris53897 commented Jul 8, 2024

The NumberColumn does a check it it is valid for search. It checks with is_numeric.
https://github.com/omines/datatables-bundle/blob/master/src/Column/NumberColumn.php#L53

If the field is of type int, there is an error if you search for partial dates like 30.05 this is valid for is_numeric().
But that will raise an error.

An exception occurred while executing a query: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for type integer: "30." LINE 1: ...ce_name) LIKE '%30.%'

Possible solution.
Check if type is int and change the check.
Or a new ColumnType?

<?php 
namespace App\DataTable\Column;

use Omines\DataTablesBundle\Column\NumberColumn;

class IntColumn extends NumberColumn
{
    public function isValidForSearch(mixed $value): bool
    {
        # Filter out "." like in dates d.m.Y
        if(str_contains($value, '.'))
        {return false;}

        return is_numeric(trim($value));
    }
}
Copy link

Stale issue message

@Chris53897
Copy link
Contributor Author

Still relevant. But there are more cases to handle like. +12123 or -1231313 or over/under max INT_VALUES

@curry684
Copy link
Member

I believe the correct course of action would be to override leftExpr and rightExpr for NumberColumn as the real problem is that one shouldn't just call LIKE on numeric fields.

@curry684 curry684 added the bug label Oct 27, 2024
@mice6
Copy link

mice6 commented Oct 31, 2024

I believe the correct course of action would be to override leftExpr and rightExpr for NumberColumn as the real problem is that one shouldn't just call LIKE on numeric fields.

why do you think so? for numeric fields we should be able to do range, same for DateTime fields.

@curry684
Copy link
Member

Fair enough, but point remains that LIKE is flat out wrong.

Copy link

Stale issue message

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants