Warm tip: This article is reproduced from serverfault.com, please click

Query with variable inside throws an error in Code Analysis

发布于 2020-11-27 10:45:23

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?

enter image description here

Questioner
Juan García
Viewed
0
Juan García 2020-11-30 06:14:14

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.

akina_solution