Skip to content

Commit

Permalink
handle case when table name is invalid in on query
Browse files Browse the repository at this point in the history
ujjwalguptaofficial committed Nov 26, 2024
1 parent 7d9b871 commit 1888649
Showing 2 changed files with 41 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/worker/executors/select/join.ts
Original file line number Diff line number Diff line change
@@ -344,6 +344,12 @@ class Join {
const table2 = jointblInfo.table2;
const tableSchemaOf1stTable = this.getTable(table1.table);
const tableSchemaOf2ndTable = this.getTable(table2.table);
if (tableSchemaOf1stTable == null || tableSchemaOf2ndTable == null) {
return new LogHelper(ERROR_TYPE.InvalidJoinQuery,
`The 'on' condition references tables or columns ('${table1.table}.${table1.column}', '${table2.table}.${table2.column}') that do not exist or are not part of the join. Ensure that the tables and columns used in the 'on' condition match those specified in the 'from' and 'with' clauses.`
);
}

let err: LogHelper;
// check on info & with info
if (qry.with !== table2.table) {
35 changes: 35 additions & 0 deletions test/cases/select/join.js
Original file line number Diff line number Diff line change
@@ -915,4 +915,39 @@ describe('Test join', function () {
}).catch(done);
})

it('on query invalid table in left side', function (done) {
con.select({
from: "Orders",
join: {
with: "Customers",
type: "left",
on: "Orders_invalid.customerId=Customers.customerId"
}
}).catch(function (err) {
const error = {
"message": "The 'on' condition references tables or columns ('Orders_invalid.customerId', 'Customers.customerId') that do not exist or are not part of the join. Ensure that the tables and columns used in the 'on' condition match those specified in the 'from' and 'with' clauses.",
"type": "invalid_join_query"
};
expect(err).to.eql(error);
done();
})
});

it('on query invalid table in right side', function (done) {
con.select({
from: "Orders",
join: {
with: "Customers",
type: "left",
on: "Orders.customerId=Customers_invalid.customerId"
}
}).catch(function (err) {
const error = {
"message": "The 'on' condition references tables or columns ('Orders.customerId', 'Customers_invalid.customerId') that do not exist or are not part of the join. Ensure that the tables and columns used in the 'on' condition match those specified in the 'from' and 'with' clauses.",
"type": "invalid_join_query"
};
expect(err).to.eql(error);
done();
})
});
});

0 comments on commit 1888649

Please sign in to comment.