从MySqlCommand获取生成的SQL语句 [英] Get generated SQL statement from MySqlCommand

查看:465
本文介绍了从MySqlCommand获取生成的SQL语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MySqlCommand绑定参数,因此可以正确地转义和清理事物,但是我没有在生成它的机器上直接执行命令.我需要将其作为原始SQL发送到执行它的另一台计算机上.

现在,我正在手动循环遍历参数并替换CommandText,但这并没有进行任何区分.任何人都知道如何生成在.ExecuteNonQuery()上发送的SQL吗?

解决方案

这是因为它不仅仅像在查询中调用String.Replace()一样.

参数化查询实际上由RDBMS处理的方式与普通查询不同,因此它不是具有某种"RawQuery"属性很简单.唯一的方法是使用此答案中的信息自己滚动".. >

I am using MySqlCommand to bind parameters so things are properly escaped and sanitized but I'm not directly executing the command on the machine that generates it. I need to send it as raw SQL to another machine that executes it.

Right now I'm manually looping through parameters and replacing the CommandText but this doesn't do any of the sensitization. Anyone have any idea how to generate the SQL that is sent on .ExecuteNonQuery() ?

解决方案

It's because it's not just like calling String.Replace() on the query.

Parameterized queries are actually handled differently by the RDBMS than plain queries, so it's not as simple as having some sort of "RawQuery" property. The only way to do this is to "roll your own", using info from this answer.

这篇关于从MySqlCommand获取生成的SQL语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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