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

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

Open
lestcape opened this issue Apr 13, 2020 · 8 comments

Comments

@lestcape
Copy link

If we are loading as values a set of table.columns values from a database like occurs in: #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:

if (typeof v == 'string') {
v = '\'' + v + '\'';
}

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?

@mistic100
Copy link
Owner

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
Copy link
Owner

mistic100 commented Apr 13, 2020

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.

@lestcape
Copy link
Author

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: #221 (comment)

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.

@mistic100
Copy link
Owner

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

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

@lestcape
Copy link
Author

Lot of Thanks.

@lestcape
Copy link
Author

Unfortunately the sqlStatements are filtered and then only the default Statements are allowed:

function getStmtConfig(stmt) {
var config = stmt.match(/(question_mark|numbered|named)(?:\((.)\))?/);
if (!config) config = [null, 'question_mark', undefined];
return config;
}

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 lestcape reopened this Apr 13, 2020
@mistic100
Copy link
Owner

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

@lestcape
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants