rspec/rules/S3647/rule.adoc

39 lines
919 B
Plaintext
Raw Normal View History

Omitting a join condition is a subtle, yet classic blunder. Do so, and you're guaranteed not to get the results you intended.
2021-02-02 15:02:10 +01:00
2021-01-27 13:42:22 +01:00
This rule raises an issue when a table is included in the ``++FROM++`` list but not in the ``++WHERE++`` list in relation to other tables, and when only part of a compound key is used in the conditions.
== Noncompliant Code Example
----
SELECT p.name, f.name
FROM product p,
product_feature f -- Noncompliant
WHERE p.id=?
SELECT p.name, ck.date
FROM product p
JOIN compound_key_table ck
ON p.manufacturer_product_id=ck.manufacturer_product_id -- Noncompliant
WHERE ...
----
== Compliant Solution
----
SELECT p.name, f.name
FROM product p,
product_feature f
WHERE p.id=f.product_id AND p.id=?
SELECT p.name, ck.date
FROM product p
JOIN compound_key_table ck
ON p.manufacturer_product_id=ck.manufacturer_product_id AND p.manufacturer_id=ck.manufacturer_id
WHERE ...
----