如果用户提供传递给变量的值,或者如果有人找到一种方法来执行存储过程并传入特制的恶意代码,则您的过程可能会被注入。谷歌我的用户名,以获取基于此的有趣漫画。
由于您处于存储过程中,因此您可以检查变量,然后SELECT
根据提供的变量执行语句:
IF @featuretype = 'mobile'
BEGIN
select TOP 3 *
from featuredtypes_v
where featuredtypes_v.MobilePage=1
order by featuredtypes_v.priority desc
END
IF @featuretype = 'login'
BEGIN
select TOP 3 *
from featuredtypes_v
where featuredtypes_v.LoginPage=1
order by featuredtypes_v.priority desc
END
-- etc...
或者,您可以将WHERE
子句中的条件放在一个查询中:
select TOP 3 *
from featuredtypes_v
where (featuredtypes_v.MobilePage=1 AND @featuretype = 'Mobile') OR
(featuredtypes_v.LoginPage=1 AND @featuretype = 'Login') OR
(featuredtypes_v.IndexPage=1 AND @featuretype = 'Index')
order by featuredtypes_v.priority desc