办法看到查询应用参数后? [英] A way to see query after parameters are applied?

查看:123
本文介绍了办法看到查询应用参数后?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#应用程序,我建立一个查询,通过创建一个带参数的查询字符串,然后在命令添加参数和它们的值。例如:

In a C# application, I'm building a query by creating a query string with parameters, then to the command adding the parameters and their values. For example:

string query = "UPDATE USERS u SET u.username = @PARM_USERNAME " +
               "WHERE u.id = @PARM_USERID ";

command.Parameters.AddWithValue("@PARM_USERNAME", user.username);
command.Parameters.AddWithValue("@PARM_USERID", user.id);

command.Connection.Open();
int res = command.ExecuteNonQuery();

有将是有益的看到参数用的查询,这是可行的在C#/ Visual Studio中?我可以检查command.CommandText,但它只是显示了我同样的内容,上面的查询,使用参数占位符存在。如果有帮助,这是对MySQL的。

It would be beneficial to see the query with parameters applied, is this doable in C#/Visual Studio? I can check the command.CommandText, but it's only showing me the same content as the query above, with the parameter placeholders there. If it helps, this is against MySQL.

推荐答案

有没有保证,还有的的这样的事,查询与应用的参数。我会的希望的一个驱动程序会简单地以适当的形式发下来的命令,SQL和参数重新present每个值。为什么要去打扰转义值等,仅在查询处理器反向转义它们,分析它们在另一边?这是更有效的的风险较小,只是传递数据的一些描述二进制格式。

There's no guarantee that there is such a thing as "the query with the parameters applied". I would hope that a driver would simply send down the command as SQL and the parameters in an appropriate form to represent each value. Why go to the bother of escaping values etc, only for the query processor to unescape them and parse them at the other side? It's more efficient and less risky to just pass the data in a binary format of some description.

您应该把它当成一些code(的SQL),它使用的一些数据(参数),并保持这两个概念非常独立的在你的心中。如果您需要登录这是怎么回事,我会记录它的的参数化的SQL和单独的参数值。

You should regard it as some code (the SQL) which uses some data (the parameters) and keep the two concepts very separate in your mind. If you need to log what's going on, I would log it as the parameterized SQL and the parameter values separately.

这篇关于办法看到查询应用参数后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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