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

Multi row statement should fail if no values are replaced #551

Open
lasher23 opened this issue Apr 30, 2024 · 4 comments
Open

Multi row statement should fail if no values are replaced #551

lasher23 opened this issue Apr 30, 2024 · 4 comments

Comments

@lasher23
Copy link

Is your feature request related to a problem? Please describe.
Currently it is not easy visible if you make a mistake while using the multi row statements.

Describe the solution you'd like
If nothing is replaced with the regex i would like that an error is thrown.
Replace the following:
image
With something like this:

    public String replacePlaceholders(String stmt, String sqlBuilder) {
        return replaceWithCheck(stmt, "(?i)VALUES \\((\\?(?:,\\s*\\?\\s*)*)\\)",  "VALUES " + sqlBuilder)
    }

    public static String replaceWithCheck(String input, String regex, String replacement) throws Exception {
        String newString = input.replaceAll(regex, replacement);
        if (input.equals(newString)) {
            throw new Exception("No values found to replace for multi row statements");
        }
        return newString;
    }

@lasher23 lasher23 changed the title Should multi row statement not fail if no values are replaced Multi row statement should fail if no values are replaced Apr 30, 2024
@jepiqueau
Copy link
Collaborator

@lasher23 not really it is for the case where you have "INSERT INTO TABLE (name, email) VALUES ('Jeep','jeep@example.com') " this should pass through

@lasher23
Copy link
Author

@jepiqueau but then you dont provide a two dimensional array as parameter. The logic is only triggered if the array is a two dimensional array.

@jepiqueau
Copy link
Collaborator

@lasher23 i will have an other look give me an example of statements that you want me to add to my test program thanks

@lasher23
Copy link
Author

lasher23 commented May 7, 2024

@jepiqueau
If i call executeSet with a two dimensional array. I always want to get into the multi statement logic.
A simple example is i dont get it that i have to pass ? as parameter. What you are doing now is just execute the statement with an empty array as args which makes it replace it with null.

For example the following code raises no error:
executeSet("insert into table", [['a'],['b']])

This for sure is an error in my statement. But it would be very nice if the Plugin tells me that i am not allowed to execute this.
For example it was very hard to spot the bugs with the case insensitive 'VALUES' because there was never an error from the plugin, it just did not replace the values.

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