leikind / wice_grid

A Rails grid plugin to create grids with sorting, pagination, and (automatically generated) filters
MIT License
535 stars 215 forks source link

PostgreSQL PG::InvalidTextRepresentation error when using decimals in range filter #338

Closed kreintjes closed 7 years ago

kreintjes commented 7 years ago

When using a range filter for an integer field, I get an SQL error when someone (accidentally) tries to enter a value with decimals:

PG::InvalidTextRepresentation: ERROR:  invalid input syntax for integer: "2017.5"
LINE 1: ..._id" = $1 AND ( models.year >= '2017.5' )...
                                                             ^
: SELECT COUNT(count_column) FROM (SELECT  1 AS count_column FROM "models" WHERE ( models.year >= '2017.5' ) LIMIT $2 OFFSET $3) subquery_for_count

vendor/bundle/ruby/2.4.0/bundler/gems/wice_grid-2fcb600bb7f7/lib/wice/helpers/wice_grid_view_helpers.rb:121:in `define_grid'
vendor/bundle/ruby/2.4.0/bundler/gems/wice_grid-2fcb600bb7f7/lib/wice/helpers/wice_grid_view_helpers.rb:74:in `grid'

The same occurs when using a range filter for a float field and using a comma as decimal separator (as is usual in my locale):

PG::InvalidTextRepresentation: ERROR:  invalid input syntax for type numeric: "0,5"
LINE 1: ...es" WHERE ( models.float_value >= '0,5' ) LI...
                                                             ^
: SELECT COUNT(count_column) FROM (SELECT  1 AS count_column FROM "models" WHERE ( models.float_value >= '0,5' ) LIMIT $1 OFFSET $2) subquery_for_count

It does work when entering a decimal using a point as separator, but the users of my application don't tend to do this (values are displayed with a comma as separator as well).

Are there any solutions for these problems?