您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

参数化查询(C#,Oracle):如何产生更具可读性的表示形式?

参数化查询(C#,Oracle):如何产生更具可读性的表示形式?

也许值得在NHibernate源代码中查看其完成方式。

找到名为“ GetCommandLogString(IDbCommand command)”的函数,几乎可以复制/粘贴该函数:p

protected string GetCommandLogString(IDbCommand command)
{
    string outputText;

    if (command.Parameters.Count == 0)
    {
        outputText = command.CommandText;
    }
    else
    {
        StringBuilder output = new StringBuilder();
        output.Append(command.CommandText);
        output.Append("; ");

        IDataParameter p;
        int count = command.Parameters.Count;
        for (int i = 0; i < count; i++)
        {
            p = (IDataParameter) command.Parameters[i];
            output.Append(string.Format("{0} = '{1}'", p.ParameterName, p.Value));

            if (i + 1 < count)
            {
                output.Append(", ");
            }
        }
        outputText = output.ToString();
    }
    return outputText;
}
c# 2022/1/1 18:44:16 有360人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶