diff --git a/src/worker/executors/select/join.ts b/src/worker/executors/select/join.ts index ece6d73c..b3ab3821 100644 --- a/src/worker/executors/select/join.ts +++ b/src/worker/executors/select/join.ts @@ -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) { diff --git a/test/cases/select/join.js b/test/cases/select/join.js index 547e6122..4f677bfe 100644 --- a/test/cases/select/join.js +++ b/test/cases/select/join.js @@ -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(); + }) + }); });