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

This commit is contained in:
Guilherme Covre Dalleprane 2020-10-05 15:35:22 -03:00 committed by GitHub
parent 6f817a3b6e
commit 975b5a919e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 1 deletions

View File

@ -11,7 +11,7 @@ module.exports = function (Target) {
.map((statement) => {
return this.client._formatQuery(statement.sql, statement.bindings, tz);
})
.join(';\n');
.reduce((a, c) => a.concat(a.endsWith(';') ? '\n' : ';\n', c));
};
// Create a new instance of the `Runner`, passing in the current object.

View File

@ -963,4 +963,12 @@ describe('Oracle SchemaBuilder', function () {
expect(spy.thirdCall.args).to.deep.equal(['users', 'table context']);
});
});
it('test converting a sql wrapped with catch to string, #4045', function () {
tableSql = client.schemaBuilder().dropTableIfExists('book');
expect(tableSql.toQuery()).to.equal(
'begin execute immediate \'drop table "book"\'; exception when others then if sqlcode != -942 then raise; end if; end;\nbegin execute immediate \'drop sequence "book_seq"\'; exception when others then if sqlcode != -2289 then raise; end if; end;'
);
});
});

View File

@ -963,4 +963,12 @@ describe('OracleDb SchemaBuilder', function () {
expect(spy.thirdCall.args).to.deep.equal(['users', 'table context']);
});
});
it('test converting a sql wrapped with catch to string, #4045', function () {
tableSql = client.schemaBuilder().dropTableIfExists('book');
expect(tableSql.toQuery()).to.equal(
'begin execute immediate \'drop table "book"\'; exception when others then if sqlcode != -942 then raise; end if; end;\nbegin execute immediate \'drop sequence "book_seq"\'; exception when others then if sqlcode != -2289 then raise; end if; end;'
);
});
});