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

oracle db returning * fixes #5598

Merged
merged 1 commit into from Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/dialects/oracledb/index.js
Expand Up @@ -254,10 +254,6 @@ class Client_Oracledb extends Client_Oracle {
});
}
}
if (connection.isTransaction) {
return obj;
}
await connection.commitAsync();
if (obj.returningSql) {
const response = await connection.executeAsync(
obj.returningSql(),
Expand All @@ -266,6 +262,10 @@ class Client_Oracledb extends Client_Oracle {
);
obj.response = response.rows;
}
if (connection.isTransaction) {
return obj;
}
await connection.commitAsync();
return obj;
});
}
Expand All @@ -287,7 +287,7 @@ class Client_Oracledb extends Client_Oracle {
case 'del':
case 'update':
case 'counter':
if (obj.returning && !isEmpty(obj.returning)) {
if ((obj.returning && !isEmpty(obj.returning)) || obj.returningSql) {
return response;
} else if (obj.rowsAffected !== undefined) {
return obj.rowsAffected;
Expand Down
155 changes: 154 additions & 1 deletion test/integration2/query/update/updates.spec.js
Expand Up @@ -341,7 +341,20 @@ describe('Updates', function () {
1,
(v) => v.toString() === '[object ReturningHelper:ROWID]',
],
1
[
{
id: accountId1,
first_name: 'UpdatedUser',
last_name: 'UpdatedTest',
email: 'test100@example.com',
logins: 1,
balance: 12.24,
about: 'Lorem ipsum Dolore labore incididunt enim.',
created_at: TEST_TIMESTAMP,
updated_at: TEST_TIMESTAMP,
phone: null,
},
]
);
tester(
'mssql',
Expand All @@ -365,6 +378,146 @@ describe('Updates', function () {
});
});

it('should allow returning for updates with specific transaction', async function () {
await knex('accounts').where('id', accountId1).update({
balance: 12.240000000000002,
});

await knex.transaction(function (tr) {
return knex('accounts')
.transacting(tr)
.where('id', accountId1)
.update(
{
email: 'test100@example.com',
first_name: 'UpdatedUser',
last_name: 'UpdatedTest',
},
'*'
)
.testSql(function (tester) {
tester(
'mysql',
'update `accounts` set `email` = ?, `first_name` = ?, `last_name` = ? where `id` = ?',
['test100@example.com', 'UpdatedUser', 'UpdatedTest', 1],
1
);
tester(
'pg',
'update "accounts" set "email" = ?, "first_name" = ?, "last_name" = ? where "id" = ? returning *',
['test100@example.com', 'UpdatedUser', 'UpdatedTest', '1'],
[
{
id: '1',
first_name: 'UpdatedUser',
last_name: 'UpdatedTest',
email: 'test100@example.com',
logins: 1,
balance: 12.24,
about: 'Lorem ipsum Dolore labore incididunt enim.',
created_at: TEST_TIMESTAMP,
updated_at: TEST_TIMESTAMP,
phone: null,
},
]
);
tester(
'cockroachdb',
'update "accounts" set "email" = ?, "first_name" = ?, "last_name" = ? where "id" = ? returning *',
[
'test100@example.com',
'UpdatedUser',
'UpdatedTest',
accountId1,
],
[
{
id: accountId1,
first_name: 'UpdatedUser',
last_name: 'UpdatedTest',
email: 'test100@example.com',
logins: '1',
balance: 12.24,
about: 'Lorem ipsum Dolore labore incididunt enim.',
created_at: TEST_TIMESTAMP,
updated_at: TEST_TIMESTAMP,
phone: null,
},
]
);
tester(
'pg-redshift',
'update "accounts" set "email" = ?, "first_name" = ?, "last_name" = ? where "id" = ?',
['test100@example.com', 'UpdatedUser', 'UpdatedTest', 1],
1
);
tester(
'sqlite3',
'update `accounts` set `email` = ?, `first_name` = ?, `last_name` = ? where `id` = ? returning *',
['test100@example.com', 'UpdatedUser', 'UpdatedTest', 1],
[
{
id: 1,
first_name: 'UpdatedUser',
last_name: 'UpdatedTest',
email: 'test100@example.com',
logins: 1,
balance: 12.240000000000002,
about: 'Lorem ipsum Dolore labore incididunt enim.',
created_at: TEST_TIMESTAMP,
updated_at: TEST_TIMESTAMP,
phone: null,
},
]
);
tester(
'oracledb',
'update "accounts" set "email" = ?, "first_name" = ?, "last_name" = ? where "id" = ? returning "ROWID" into ?',
[
'test100@example.com',
'UpdatedUser',
'UpdatedTest',
1,
(v) => v.toString() === '[object ReturningHelper:ROWID]',
],
[
{
id: accountId1,
first_name: 'UpdatedUser',
last_name: 'UpdatedTest',
email: 'test100@example.com',
logins: 1,
balance: 12.24,
about: 'Lorem ipsum Dolore labore incididunt enim.',
created_at: TEST_TIMESTAMP,
updated_at: TEST_TIMESTAMP,
phone: null,
},
]
);
tester(
'mssql',
'update [accounts] set [email] = ?, [first_name] = ?, [last_name] = ? output inserted.* where [id] = ?',
['test100@example.com', 'UpdatedUser', 'UpdatedTest', '1'],
[
{
id: '1',
first_name: 'UpdatedUser',
last_name: 'UpdatedTest',
email: 'test100@example.com',
logins: 1,
balance: 12.240000000000002,
about: 'Lorem ipsum Dolore labore incididunt enim.',
created_at: TEST_TIMESTAMP,
updated_at: TEST_TIMESTAMP,
phone: null,
},
]
);
});
});
});

it('with update query', async function () {
await knex
.with('withClause', function () {
Expand Down