/// <summary>
        /// Returns a boolean indicating whether or not the given dbException is for a primary key constraint
        /// </summary>
        /// <param name="dbe">DbException object</param>
        /// <returns>True if dbException is a primary key violation</returns>
        public override bool IsPrimaryKeyViolation(DbException dbException)
        {
            DB2Exception db2Exception = (DB2Exception)dbException;

            if (db2Exception.ErrorCode == DB2.Constants.DBError_UniqueConstraintViolation)
            {
                return(true);
            }
            return(false);
        }
Beispiel #2
0
        private bool CheckDB2ErrorMessage(DB2Exception ex, string SQLMessageCode)
        {
            for (int i = 0; i < ex.Errors.Count; i++)
            {
                var error = ex.Errors[i];
                if (error.Message.Contains(SQLMessageCode))
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #3
0
        /// <summary>
        /// Determines if a database exception is a transient exception and if the operation could be retried.
        /// </summary>
        /// <param name="exception">The exception to test.</param>
        /// <returns>True if the exception is transient.</returns>
        public override bool IsTransientException(Exception exception)
        {
            DB2Exception db2Exception = (DB2Exception)exception;

            return(db2Exception.Errors.OfType <DB2Error>().Any(
                       e =>
            {
                switch (e.NativeError)
                {
                case -30080:                                                            // communication error
                case -30081:                                                            // communication error
                    return true;
                }

                return false;
            }));
        }
Beispiel #4
0
        public override object Convert(object value, ConvertType convertType)
        {
            switch (convertType)
            {
            case ConvertType.NameToQueryParameter:
                return("@" + value);

            case ConvertType.NameToCommandParameter:
            case ConvertType.NameToSprocParameter:
                return(":" + value);

            case ConvertType.SprocParameterToName:
                if (value != null)
                {
                    string str = value.ToString();
                    return(str.Length > 0 && str[0] == ':'? str.Substring(1): str);
                }

                break;

            case ConvertType.NameToQueryField:
            case ConvertType.NameToQueryFieldAlias:
            case ConvertType.NameToQueryTable:
            case ConvertType.NameToQueryTableAlias:
                return("\"" + value + "\"");

            case ConvertType.ExceptionToErrorNumber:
                if (value is DB2Exception)
                {
                    DB2Exception ex = (DB2Exception)value;

                    foreach (DB2Error error in ex.Errors)
                    {
                        return(error.RowNumber);
                    }

                    return(0);
                }

                break;
            }

            return(value);
        }