0

I'm using RedQueryBuilder to implement a table filter on a web application. When the user clicks an Apply Filter button the current sql and params are sent to a backend application, and the page refreshes. I read in the sql and params back into RQB so it displays the filter applied.

In some cases the user can specify a filter that RQB isn't happy reading back in - for example if they included an empty param for an Integer field. Now I can do some client-side validation as well, but I really want as a first step to be able to recover gracefully if there is a problem. However, the following doesn't actually trap the error:

    try {
       RedQueryBuilderFactory.create(rq, filter.initial_query, filter.initial_params);
    } catch(err) {
       //
       // There is a problem with the filter. Replace it with default values.
       //
       filter.initial_query = "SELECT * FROM \"<%=cleanTableName%>\" WHERE (\""+default_column+"\" = ?)";
       filter.initial_params = [];
       RedQueryBuilderFactory.create(rq, filter.initial_query, filter.initial_params);
       //
       // Explain the error to the user
       //
       $("#filter-message").innerText("There was a problem interpreting your filter; this is usually caused by using an empty value or text for filtering a number field. Click Clear Filter to reset the view and try again.")
    }

Instead, I'm seeing "Uncaught java.lang.ClassCastException" in the console when the page loads when using a malformed query.

However If I try this in console I do trap an exception as expected.

NB My RQB code above is wrapped in a function executed using Deferred.

Any idea how I can trap these kind of errors?

Scott Wilson
  • 1,650
  • 1
  • 17
  • 14
  • Sounds like a bug. What do you mean by "empty param"? "foo=" ? Does totally spurious SQL give you an exception you can work with? e.g. "SELECTY foo FRO bar"? – salk31 Apr 11 '15 at 09:06
  • So things like SELECT * FROM foo WHERE bar = ?" where params are empty or NULL and "bar" is an integer field. – Scott Wilson Apr 12 '15 at 10:05

1 Answers1

0

I think this is a simple bug. The error reporting is not great but it should be better than this.

Best if you raise a bug on github? https://github.com/salk31/RedQueryBuilder/issues

salk31
  • 995
  • 2
  • 8
  • 13