我正在基于一个基本查询动态地构建查询。
base_query
是DB中的字符串列。
例如,用户将输入一个基本查询select * from users
。
在这个查询中,我将在后端添加一个where
子句,类似于这个select * from users where user id=1
。
在UI中,我们将使用id=1
返回与用户相关的所有细节。
基本查询不能有where
,因为我在后端追加它。如果有两个where
子句,它将中断查询。但是它应该接受带有where
的subquery
。
如何验证基本查询字符串?
它可以有subquery
与where
,但不能在最后,因为它会在后端崩溃。
例如,
有效查询:
select count(*) from users;
select count(*) from (select * from users where id > 2) as u
无效:
select * from users where id=1;
发布于 2022-04-05 08:56:32
服务器将以字符串的形式接收用户输入,因此您只需使用字符串库来检查您的字符串是否有子字符串where
。
有点像
str.scan(/#{where}/i)
应该做到这一点,而且会忽略案件
https://stackoverflow.com/questions/71752981
复制相似问题