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

Ensure that semicolon is not appended to statements that already end with a semicolon #4052

Merged
merged 2 commits into from
Oct 5, 2020
Merged

Ensure that semicolon is not appended to statements that already end with a semicolon #4052

merged 2 commits into from
Oct 5, 2020

Conversation

guilhermedalleprane
Copy link
Contributor

@guilhermedalleprane guilhermedalleprane commented Sep 29, 2020

This solves #4045:

toQuery() & toSql() are returning duplicate semicolons for queries that pass through the method wrapSqlWithCatch()

Example:

var knex = require('knex')({
    client: 'oracledb',
    connection: {
        host: '127.0.0.1',
        user: 'your_database_user',
        password: 'your_database_password',
        database: 'myapp_test'
    }
});

var builder = knex.schema.dropTableIfExists('book');

console.log(builder.toQuery())

outputs:

begin execute immediate 'drop table "book"'; exception when others then if sqlcode != -942 then raise; end if; end;;
begin execute immediate 'drop sequence "book_seq"'; exception when others then if sqlcode != -2289 then raise; end if; end;

@kibertoad
Copy link
Collaborator

Thanks! Could you please add test for this? Also CI seems to be failing.

@guilhermedalleprane guilhermedalleprane marked this pull request as draft September 29, 2020 13:22
@guilhermedalleprane
Copy link
Contributor Author

Of course, in reality this does not seem to be the solution, I will take a closer look.

@guilhermedalleprane guilhermedalleprane changed the title Oracle: remove trailing semicolons on wrapSqlWithCatch Ensure that semicolon is not appended to statements that already end with a semicolon Sep 29, 2020
@guilhermedalleprane guilhermedalleprane marked this pull request as ready for review September 30, 2020 11:40
@guilhermedalleprane
Copy link
Contributor Author

Well, I believe it will now work as expected. But I don't know where to put the tests.

This specific case would be testing whether converting a set of queries, some ending with semicolons, would work as expected, with all of them ending with just one semicolon, except the last, where nothing would be appended.

The query builder already has tests to verify that most queries are converted correctly, the schema builder does not and that would require refactoring a lot for such a small adjustment I think.

It is not something strongly related to a dialect, nor to the query builder, nor to the schema builder and nor a specific statement.

What do you think?

@kibertoad
Copy link
Collaborator

kibertoad commented Sep 30, 2020

@guicovred Is it possible to write an integration test that would have been failing prior to this change, but no longer does after it?

@guilhermedalleprane
Copy link
Contributor Author

Ok, this is possible. I was thinking about something more generic before. I added the test. Thanks!

@guilhermedalleprane
Copy link
Contributor Author

guilhermedalleprane commented Sep 30, 2020

It seems that these new failed CI tests was introduced by nodejs v14.13 (20 hours ago).

esm-interop.spec.js#L164 and esm-interop.spec.js#L179

Apparently the exception is from here: lexer.js#L892

@kibertoad
Copy link
Collaborator

kibertoad commented Sep 30, 2020

#4054

@kibertoad
Copy link
Collaborator

@guicovred Please pull from master, that should fix it.

@guilhermedalleprane
Copy link
Contributor Author

@guicovred Please pull from master, that should fix it.

Done. Thanks!

@guilhermedalleprane
Copy link
Contributor Author

guilhermedalleprane commented Oct 5, 2020

@kibertoad Is there still anything I can do to get it merged?

@kibertoad
Copy link
Collaborator

Thanks a lot!

@kibertoad kibertoad merged commit 975b5a9 into knex:master Oct 5, 2020
@guilhermedalleprane
Copy link
Contributor Author

I thank you!

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

Successfully merging this pull request may close these issues.

None yet

2 participants