public static Exception Convert(ISQLExceptionConverter converter, AdoExceptionContextInfo exceptionContextInfo)
		{
			if(exceptionContextInfo == null)
			{
				throw new AssertionFailure("The argument exceptionContextInfo is null.");
			}
			var sql = TryGetActualSqlQuery(exceptionContextInfo.SqlException, exceptionContextInfo.Sql);
			ADOExceptionReporter.LogExceptions(exceptionContextInfo.SqlException,
			                                   ExtendMessage(exceptionContextInfo.Message, sql, null, null));
			return converter.Convert(exceptionContextInfo);
		}
Example #2
0
 public static Exception Convert(ISqlLog log, ISQLExceptionConverter converter, DbExceptionContextInfo exceptionContextInfo)
 {
     if (exceptionContextInfo == null)
     {
         throw new ArgumentNullException("The argument exceptionContextInfo is null.");
     }
     var sql = TryGetActualSqlQuery(exceptionContextInfo.SqlException, exceptionContextInfo.Sql);
     log.Error(exceptionContextInfo.SqlException,
                                        ExtendMessage(exceptionContextInfo.Message, sql));
     return converter.Convert(exceptionContextInfo);
 }
Example #3
0
        public static Exception Convert(ISQLExceptionConverter converter, AdoExceptionContextInfo exceptionContextInfo)
        {
            if (exceptionContextInfo == null)
            {
                throw new AssertionFailure("The argument exceptionContextInfo is null.");
            }
            var sql = TryGetActualSqlQuery(exceptionContextInfo.SqlException, exceptionContextInfo.Sql);

            ADOExceptionReporter.LogExceptions(exceptionContextInfo.SqlException,
                                               ExtendMessage(exceptionContextInfo.Message, sql, null, null));
            return(converter.Convert(exceptionContextInfo));
        }
Example #4
0
        public static Exception Convert(ISqlLog log, ISQLExceptionConverter converter, DbExceptionContextInfo exceptionContextInfo)
        {
            if (exceptionContextInfo == null)
            {
                throw new ArgumentNullException("The argument exceptionContextInfo is null.");
            }
            var sql = TryGetActualSqlQuery(exceptionContextInfo.SqlException, exceptionContextInfo.Sql);

            log.Error(exceptionContextInfo.SqlException,
                      ExtendMessage(exceptionContextInfo.Message, sql));
            return(converter.Convert(exceptionContextInfo));
        }
Example #5
0
        public static Exception Convert(ILogger log, ISQLExceptionConverter converter, DbExceptionContextInfo exceptionContextInfo)
        {
            //if (exceptionContextInfo == null)
            //{
            //    throw new ArgumentNullException("The argument exceptionContextInfo is null.");
            //}
            var sql = TryGetActualSqlQuery(exceptionContextInfo.SqlException, exceptionContextInfo.Sql);

            //log.Log(LogLevel.Error, exceptionContextInfo.SqlException,
            //                                   ExtendMessage(exceptionContextInfo.Message, sql));
            return(converter.Convert(exceptionContextInfo));
        }
Example #6
0
        public void BadGrammar()
        {
            if (Dialect is SQLiteDialect)
            {
                Assert.Ignore("Example exception converter not implemented.");
            }

            //ISQLExceptionConverter converter = Dialect.BuildSQLExceptionConverter();
            ISQLExceptionConverter converter = sessions.Settings.SqlExceptionConverter;

            ISession      session    = OpenSession();
            IDbConnection connection = session.Connection;

            // prepare/execute a query against a non-existent table
            IDbCommand ps = null;

            try
            {
                ps             = connection.CreateCommand();
                ps.CommandType = CommandType.Text;
                ps.CommandText = "SELECT user_id, user_name FROM tbl_no_there";
                ps.ExecuteNonQuery();

                Assert.Fail("SQL compilation should have failed");
            }
            catch (Exception sqle)
            {
                Assert.AreEqual(typeof(SQLGrammarException),
                                converter.Convert(new AdoExceptionContextInfo {
                    SqlException = sqle
                }).GetType(),
                                "Bad conversion [" + sqle.Message + "]");
            }
            finally
            {
                if (ps != null)
                {
                    try
                    {
                        ps.Dispose();
                    }
                    catch (Exception)
                    {
                        // ignore...
                    }
                }
            }

            session.Close();
        }
Example #7
0
        public static Exception Convert(ISqlLog log, ISQLExceptionConverter converter,DbExceptionContextInfo exceptionContextInfo,
                                           object[] parameterValues, NamedParameter[] namedParameters)
        {
            var sql = TryGetActualSqlQuery(exceptionContextInfo.SqlException, exceptionContextInfo.Sql);
            string extendMessage = ExtendMessage(
                exceptionContextInfo.Message,
                sql != null ? sql.ToString() : null,
                exceptionContextInfo.Entity,
                parameterValues,
                namedParameters);
            log.Error(exceptionContextInfo.SqlException, extendMessage);

            return converter.Convert(exceptionContextInfo);
        }
Example #8
0
        public static Exception Convert(ISqlLog log, ISQLExceptionConverter converter, DbExceptionContextInfo exceptionContextInfo,
                                        object[] parameterValues, NamedParameter[] namedParameters)
        {
            var    sql           = TryGetActualSqlQuery(exceptionContextInfo.SqlException, exceptionContextInfo.Sql);
            string extendMessage = ExtendMessage(
                exceptionContextInfo.Message,
                sql != null ? sql.ToString() : null,
                exceptionContextInfo.Entity,
                parameterValues,
                namedParameters);

            log.Error(exceptionContextInfo.SqlException, extendMessage);

            return(converter.Convert(exceptionContextInfo));
        }
Example #9
0
        public void IntegrityViolation()
        {
            //ISQLExceptionConverter converter = Dialect.BuildSQLExceptionConverter();
            ISQLExceptionConverter converter = sessions.Settings.SqlExceptionConverter;

            ISession session = OpenSession();

            session.BeginTransaction();
            IDbConnection connection = session.Connection;

            // Attempt to insert some bad values into the T_MEMBERSHIP table that should
            // result in a constraint violation
            IDbCommand ps = null;

            try
            {
                ps             = connection.CreateCommand();
                ps.CommandType = CommandType.Text;
                ps.CommandText = "INSERT INTO T_MEMBERSHIP (user_id, group_id) VALUES (@p1, @p2)";
                IDbDataParameter pr = ps.CreateParameter();
                pr.ParameterName = "p1";
                pr.DbType        = DbType.Int64;
                pr.Value         = 52134241L;         // Non-existent user_id
                ps.Parameters.Add(pr);

                pr = ps.CreateParameter();
                pr.ParameterName = "p2";
                pr.DbType        = DbType.Int64;
                pr.Value         = 5342L;         // Non-existent group_id
                ps.Parameters.Add(pr);

                session.Transaction.Enlist(ps);
                ps.ExecuteNonQuery();

                Assert.Fail("INSERT should have failed");
            }
            catch (Exception sqle)
            {
                ADOExceptionReporter.LogExceptions(sqle, "Just output!!!!");
                Exception adoException = converter.Convert(new AdoExceptionContextInfo {
                    SqlException = sqle
                });
                Assert.AreEqual(typeof(ConstraintViolationException), adoException.GetType(),
                                "Bad conversion [" + sqle.Message + "]");
                ConstraintViolationException ex = (ConstraintViolationException)adoException;
                Console.WriteLine("Violated constraint name: " + ex.ConstraintName);
            }
            finally
            {
                if (ps != null)
                {
                    try
                    {
                        ps.Dispose();
                    }
                    catch (Exception)
                    {
                        // ignore...
                    }
                }
            }

            session.Transaction.Rollback();
            session.Close();
        }
Example #10
0
 /// <summary> 
 /// Converts the given SQLException into NHibernate's ADOException hierarchy, as well as performing
 /// appropriate logging. 
 /// </summary>
 /// <param name="converter">The converter to use.</param>
 /// <param name="sqlException">The exception to convert.</param>
 /// <param name="message">An optional error message.</param>
 /// <param name="sql">The SQL executed.</param>
 /// <returns> The converted <see cref="ADOException"/>.</returns>
 public static ADOException Convert(ISQLExceptionConverter converter, Exception sqlException, string message, SqlString sql)
 {
     ADOExceptionReporter.LogExceptions(sqlException, ExtendMessage(message, sql, null, null));
     return converter.Convert(sqlException, message, sql);
 }