search regex sub expression error

search regex sub expression error

loukinglouking Posts: 259Questions: 52Answers: 0
edited March 2016 in DataTables 1.10

I am trying to use serverSide=true, search: {regex: true} with sqlalchemy-datatables python on the server side.

I am trying to update sqlalchemy-datatables to support regex. I have successfully added regex on the server side with mysql to handle OR regex on a column (as provided by yadcf select2 multiselect function).

I am also trying to support regex (again with mysql) for the table search, but when I type the OR bar ("|") into the search, the database side raises an exception because there is an empty regex subexpression received.

OperationalError: (OperationalError) (1139, "Got error 'empty (sub)expression' from regexp")

Is there any way to have datatables wait for the user to make the search box contain a valid regex expression before sending it to the server?

(It turns out that sqlalchemy, which is an sql framework for python, only provides mechanisms to support regex with a couple of database engines, and each of these are handled differently. yuck)

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 61,890Questions: 1Answers: 10,143 Site admin

    The built in global search currently will do search as you type (also considering the searchDelay option). There is no built in option to submit only when complete - for that you could simply built the input yourself and only call the search() method when the search input is done.

    Allan

  • loukinglouking Posts: 259Questions: 52Answers: 0
    edited March 2016

    Thanks

    Is there any way for the server to respond that the input isn't complete, which doesn't cause an error popup?

    Or maybe a new feature would be to inhibit the transmission of characters which cause errored regex.

    Or maybe a hook so the javascript which is using datatables can detect the error and inhibit the transmission or filter what is sent (e.g., leave out the characters which cause the error). (Maybe you are saying above that this hook exists to process the search box?)

    I thought about catching the exception on the server, but it happens too late in the processing.

  • allanallan Posts: 61,890Questions: 1Answers: 10,143 Site admin
    Answer ✓

    Is there any way for the server to respond that the input isn't complete, which doesn't cause an error popup?

    Yes, don't return invalid JSON and don't return an error property in the JSON. Just return an empty data array.

    Allan

  • loukinglouking Posts: 259Questions: 52Answers: 0

    Will this cause the table view to be unchanged? or to show no rows? I assume the latter, which isn't optimal, but maybe the best for the purpose.

    I expect is someone is actually using global search with regex they would know what they were doing and understand invalid intermediate results.

    I wonder how often this use case occurs, especially with more complex regex's.

    Thanks again.

  • allanallan Posts: 61,890Questions: 1Answers: 10,143 Site admin
    Answer ✓

    It will show no rows. If you want it to so the same data as before you'd need to have it return that.

    I think very few deployments actually accept regex input in the search. The next major version will likely see the regex flag removed (or at least obsoleted) and allow regular expressions to be passed in directly. For server-side processing it would then be up to the server if it treats it as regex or not.

    Allan

This discussion has been closed.