The variable $extra_query
breaks the logic of the Code Analysis feature and throws an error:
SELECT *, so.`Location` as so_loc
FROM vw_dispatch
left join sales_orders so on vw_dispatch.customerOrderNo = so.External_Document_No
left join customer_data cd on so.Customer_ID = cd.no
where 1 = 1
and archived = 0
and processed = 0 $extra_query
order by vw_dispatch_id desc
limit 0,200
Should I stop the inspection for error cases like this? Should I use a different way to inject that variable?
The answer of @Akina has been the closest to solve this issue.
Try to move 1st logical operator from the variable to the query pattern, like ... and processed = 0 AND ($extra_query) .... The variable itself will contain 1=1 @additional_conditions.