Skip to content

Commit 5770b20

Browse files
committed
Adding parameter type information for SQL log, that allow to detect issues with parameter types and length
SVN: trunk@4914
1 parent 20f35ac commit 5770b20

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/NHibernate.Test/SqlTest/Identity/MsSQL/MSSQLIdentityInsertWithStoredProcsTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ protected override bool AppliesTo(Dialect.Dialect dialect)
1414

1515
protected override string GetExpectedInsertOrgLogStatement(string orgName)
1616
{
17-
return string.Format("exec nh_organization_native_id_insert @p0;@p0 = '{0}'", orgName);
17+
return string.Format("exec nh_organization_native_id_insert @p0;@p0 = '{0}' [Type: String ({1})]", orgName, orgName.Length);
1818
}
1919

2020
protected override IList Mappings

src/NHibernate/AdoNet/Util/SqlStatementLogger.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,23 @@ public string GetCommandLineWithParameters(IDbCommand command)
9393
}
9494
appendComma = true;
9595
p = (IDataParameter)command.Parameters[i];
96-
output.Append(string.Format("{0} = {1}", p.ParameterName, GetParameterLogableValue(p)));
96+
output.Append(string.Format("{0} = {1} [Type: {2}]", p.ParameterName, GetParameterLogableValue(p), GetParameterLogableType(p)));
9797
}
9898
outputText = output.ToString();
9999
}
100100
return outputText;
101101
}
102102

103-
public string GetParameterLogableValue(IDataParameter parameter)
103+
private static string GetParameterLogableType(IDataParameter dataParameter)
104+
{
105+
var p = dataParameter as IDbDataParameter;
106+
if (p != null)
107+
return p.DbType + " (" + p.Size + ")";
108+
return p.DbType.ToString();
109+
110+
}
111+
112+
public string GetParameterLogableValue(IDataParameter parameter)
104113
{
105114
if (parameter.Value == null || DBNull.Value.Equals(parameter.Value))
106115
{

0 commit comments

Comments
 (0)