我有以下 MySqlCommand:
Dim cmd As New MySqlCommand
cmd.CommandText = "REPLACE INTO `customer` VALUES( ?customerID, ?firstName, ?lastName)"
With cmd.Parameters
.AddWithValue("?customerID", m_CustomerID)
.AddWithValue("?firstName", m_FirstName)
.AddWithValue("?lastName", m_LastName)
End With
我有一个处理 MySqlCommands 执行的类,我想让它把每个查询记录到一个文件中。我可以检索正在执行的查询/命令:
cmd.CommandText
但这只是返回带有参数(?customerID、?firstName 等)的原始 CommandText,而不是 AddWithValue 函数添加的实际替换值。我如何找出执行的实际“最终”查询?
最佳答案
我做了以下事情:
dim tmpstring as string = MySqlCommand.CommandText
For each p as MySqlParameter in MySqlCommand.parameters
tmpstring = tmpstring.replace(p.ParameterName, p.Value)
Next
这似乎输出了你需要的一切
关于mysql - 从 MySqlCommand 获取 "final"准备好的语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1355047/