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

mysql-内部带有变量的查询在代码分析中引发错误

(mysql - Query with variable inside throws an error in Code Analysis)

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

该变量$extra_query破坏了代码分析功能的逻辑并引发错误:

 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

我应该停止检查这种错误情况吗?我应该使用其他方式来注入该变量吗?

在此处输入图片说明

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

@Akina的答案最接近解决此问题的方法。

尝试将第1个逻辑运算符从变量移至查询模式,例如...,并且已处理= 0 AND($ extra_query)...。变量本身将包含1 = 1 @additional_conditions。

akina_solution