仅当它是select语句时才执行查询.如何? [英] Execute query only if it is select statement. How?

查看:80
本文介绍了仅当它是select语句时才执行查询.如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅当它是select语句时才执行查询.怎么样?

如果该语句不是更新查询,我有继续sql分隔符的字符串.执行查询,否则以其他方式阻止执行

Execute query only if it is select statement. How?

i have string that contins sql selements if that statement is not update query execute the query other wise block the execution

推荐答案

听起来很危险!这些限制应在数据库级别设置.
不要这样做.
Sounds dangerous! These restrictions should be set at database level.
Don''t do it this way.


始终存在该语句包含DML从而影响数据库的风险.确保不造成损害的正确方法是仅将必要的特权授予执行该语句的用户.有关更多信息,请参见: GRANT [
There''s always a risk that the statement contains DML thus affecting the database. The proper way to ensure that no harm is done is to grant only necessary privileges to the user executing the statement. More info, see: GRANT[^].


if (yourquery.Trim().ToUpper().StartsWith("SELECT"))
{
    // execute the query
}


这篇关于仅当它是select语句时才执行查询.如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆