jQuery-QueryBuilder icon indicating copy to clipboard operation
jQuery-QueryBuilder copied to clipboard

Feature request: plugins.sql-support avoid quote the string on user demand.

Open lestcape opened this issue 4 years ago • 8 comments

If we are loading as values a set of table.columns values from a database like occurs in: https://github.com/mistic100/jQuery-QueryBuilder/issues/221, our values are string, but we want get it without quotes, because are columns not statistic values.

This is current impossible to handled in the getSql method because it just check for the value type: https://github.com/mistic100/jQuery-QueryBuilder/blob/73cb350b57610d2632e1eda4bb52c27195a303af/src/plugins/sql-support/plugin.js#L321-L323

One idea is add a new sqlStatements that check for a variable in the current rule and with base on that disable the quote for that rule or not. Then the user can set that value in the rule on demand. But we can not add by our self an sqlStatements on demand. Also the usage of an sqlStatements in a standard sql have not semantic sense.

So, a solution, a workaround, an idea?

lestcape avatar Apr 13 '20 18:04 lestcape

Why could't you add a sqlStatement ?

$element.queryBuilder({
  filters: ...,
  sqlStatements: {
    custom: function() {
        return {
            add: function(rule, value) {
                escape or passthru
            },
            run: function() {
                return null;
            }
        };
    }
  }
});


$element.queryBuilder('getSQL', 'custom');

mistic100 avatar Apr 13 '20 18:04 mistic100

Also the usage of an sqlStatements in a standard sql have not semantic sense.

I don't understand this sentence. SQL statements should be mandary in any database communication, especially when dealing whith user inputs.

mistic100 avatar Apr 13 '20 18:04 mistic100

Why could't you add a sqlStatement ?

I'm creating a plugin to do it so how can i modify/add the sqlStatements from a plugin? See: https://github.com/mistic100/jQuery-QueryBuilder/issues/221#issuecomment-604249285

I don't understand this sentence. SQL statements should be mandary in any database communication, especially when dealing whith user inputs.

I try to said that we don' t need an statement when we have not parameters :) but probably i said something different, sorry i need to sleep a little, but childrens in house = chaos.

It will work as you suggest, but i was searching for a solution from inside a plugin. Thanks.

lestcape avatar Apr 13 '20 18:04 lestcape

QueryBuilder.defaults({
  sqlStatements: {
    custom: ...
  },
});

exactly like the SQL plugin is adding it's own configuration.

mistic100 avatar Apr 13 '20 18:04 mistic100

Lot of Thanks.

lestcape avatar Apr 13 '20 18:04 lestcape

Unfortunately the sqlStatements are filtered and then only the default Statements are allowed: https://github.com/mistic100/jQuery-QueryBuilder/blob/73cb350b57610d2632e1eda4bb52c27195a303af/src/plugins/sql-support/plugin.js#L655-L659

if i add the 'custom' to the regular expression it work, but that required modify the code. Probably that function can search for custom defined statemens and allow them if they are defined instead of only allow the default values?

lestcape avatar Apr 13 '20 19:04 lestcape

Do you plan to publish this plugin ? If not you override an existing statement function.

mistic100 avatar Apr 13 '20 20:04 mistic100

I have not an specific plan to published the plugin, but i have not problem to published it if needed by someone else. What it try to solve It's an open issue here anyway.

The inconvenient i see is just break the compatibility with upstream. It's really hard bifurcate a lot of jquery plugins and maintain then in also a lot of sites at same time (sure you know). If I change the plugin when i need to update it, I will lose the changes I made on it years before and it's hard remember what specific thing are needed by all of them. So, i always try to avoid divergence and not modify the upstream code as opposite. I always try to build a wrapper of the plugin.

This are examples: selectize: https://encuestas.insp.mx/includes/plugins/selectize/override/js/selectize.js or this for jQuery-QueryBuilder: https://encuestas.insp.mx/includes/plugins/query-builder/override/js/query-builder.js awesome-bootstrap-checkbox: https://encuestas.insp.mx/includes/plugins/awesome-bootstrap-checkbox/override/js/awesome-bootstrap-checkbox.js dataTables.jquery: https://encuestas.insp.mx/includes/plugins/dataTables.jquery/override/js/dataTables.jquery.js

So, yes is a lot of work i made trying to avoid an override. I understand your point anyway, but if you have a chance, please support it.

Have a good day and really thanks a lot.

lestcape avatar Apr 13 '20 20:04 lestcape