From: <fab...@us...> - 2009-10-27 00:43:08
|
Revision: 4803 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4803&view=rev Author: fabiomaulo Date: 2009-10-26 23:58:32 +0000 (Mon, 26 Oct 2009) Log Message: ----------- Fix NH-1997 Modified Paths: -------------- branches/2.1.x/nhibernate/src/NHibernate/Exceptions/ADOExceptionHelper.cs branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- branches/2.1.x/nhibernate/src/NHibernate.Test/ExceptionsTest/NullQueryTest.cs Modified: branches/2.1.x/nhibernate/src/NHibernate/Exceptions/ADOExceptionHelper.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate/Exceptions/ADOExceptionHelper.cs 2009-10-26 11:02:27 UTC (rev 4802) +++ branches/2.1.x/nhibernate/src/NHibernate/Exceptions/ADOExceptionHelper.cs 2009-10-26 23:58:32 UTC (rev 4803) @@ -36,7 +36,9 @@ public static Exception Convert(ISQLExceptionConverter converter, Exception sqlException, string message, SqlString sql) { - return Convert(converter, new AdoExceptionContextInfo {SqlException = sqlException, Message = message, Sql = sql.ToString()}); + return Convert(converter, + new AdoExceptionContextInfo + {SqlException = sqlException, Message = message, Sql = sql != null ? sql.ToString() : null}); } /// <summary> @@ -57,9 +59,9 @@ object[] parameterValues, IDictionary<string, TypedValue> namedParameters) { sql = TryGetActualSqlQuery(sqle, sql); - string extendMessage = ExtendMessage(message, sql.ToString(), parameterValues, namedParameters); + string extendMessage = ExtendMessage(message, sql != null ? sql.ToString() : null, parameterValues, namedParameters); ADOExceptionReporter.LogExceptions(sqle, extendMessage); - return new ADOException(extendMessage, sqle, sql.ToString()); + return new ADOException(extendMessage, sqle, sql != null ? sql.ToString() : SQLNotAvailable); } /// <summary> For the given <see cref="Exception"/>, locates the <see cref="System.Data.Common.DbException"/>. </summary> @@ -81,7 +83,7 @@ IDictionary<string, TypedValue> namedParameters) { var sb = new StringBuilder(); - sb.Append(message).Append(Environment.NewLine).Append("[ ").Append(sql).Append(" ]"); + sb.Append(message).Append(Environment.NewLine).Append("[ ").Append(sql ?? SQLNotAvailable).Append(" ]"); if (parameterValues != null && parameterValues.Length > 0) { sb.Append(Environment.NewLine).Append("Positional parameters: "); Added: branches/2.1.x/nhibernate/src/NHibernate.Test/ExceptionsTest/NullQueryTest.cs =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/ExceptionsTest/NullQueryTest.cs (rev 0) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/ExceptionsTest/NullQueryTest.cs 2009-10-26 23:58:32 UTC (rev 4803) @@ -0,0 +1,46 @@ +using System; +using System.Collections; +using System.Data; +using NHibernate.Exceptions; +using NUnit.Framework; + +namespace NHibernate.Test.ExceptionsTest +{ + /// <summary> + /// NH-1997 + /// </summary> + [TestFixture] + public class NullQueryTest : TestCase + { + #region Overrides of TestCase + + protected override IList Mappings + { + get { return new string[0]; } + } + + #endregion + [Test] + public void BadGrammar() + { + ISession session = OpenSession(); + IDbConnection connection = session.Connection; + try + { + IDbCommand ps = connection.CreateCommand(); + ps.CommandType = CommandType.Text; + ps.CommandText = "whatever"; + ps.ExecuteNonQuery(); + } + catch (Exception sqle) + { + Assert.DoesNotThrow( + () => ADOExceptionHelper.Convert(sessions.SQLExceptionConverter, sqle, "could not get or update next value", null)); + } + finally + { + session.Close(); + } + } + } +} \ No newline at end of file Modified: branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-10-26 11:02:27 UTC (rev 4802) +++ branches/2.1.x/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-10-26 23:58:32 UTC (rev 4803) @@ -110,6 +110,7 @@ <Compile Include="EngineTest\NativeSQLQueryNonScalarReturnTest.cs" /> <Compile Include="EngineTest\NativeSQLQueryScalarReturnTest.cs" /> <Compile Include="EngineTest\NativeSQLQuerySpecificationTest.cs" /> + <Compile Include="ExceptionsTest\NullQueryTest.cs" /> <Compile Include="FilterTest\ConfigFixture.cs" /> <Compile Include="FilterTest\FilterSecondPassArgsFixture.cs" /> <Compile Include="CfgTest\HbmBinderFixture.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |