private void BuildSqlState()
        {
            IscError error = Errors.Find(e => e.Type == IscCodes.isc_arg_sql_state);

            // step #1, maybe we already have a SQLSTATE stuffed in the status vector
            if (error != null)
            {
                SQLSTATE = error.StrParam;
            }
            // step #2, see if we can find a mapping.
            else
            {
                SQLSTATE = GetValueOrDefault(SqlStateMapping.Values, ErrorCode, _ => string.Empty);
            }
        }
        private void BuildSqlState()
        {
            IscError error = this.Errors.Find(e => e.Type == IscCodes.isc_arg_sql_state);

            // step #1, maybe we already have a SQLSTATE stuffed in the status vector
            if (error != null)
            {
                this.SQLSTATE = error.StrParam;
            }
            // step #2, see if we can find a mapping.
            else
            {
                ResourceManager rm = new ResourceManager("FirebirdSql.Resources.sqlstate_mapping", Assembly.GetExecutingAssembly());
                this.SQLSTATE = rm.GetString(this.ErrorCode.ToString());
            }
        }
		private void BuildExceptionMessage()
		{
			StringBuilder builder = new StringBuilder();

			for (int i = 0; i < Errors.Count; i++)
			{
				if (Errors[i].Type == IscCodes.isc_arg_gds ||
					Errors[i].Type == IscCodes.isc_arg_warning)
				{
					int code = Errors[i].ErrorCode;
					string message = GetValueOrDefault(IscErrorMessages.Values, code, BuildDefaultErrorMessage);

					ArrayList param = new ArrayList();

					int index = i + 1;

					while (index < Errors.Count && Errors[index].IsArgument)
					{
						param.Add(Errors[index++].StrParam);
						i++;
					}

					object[] args = (object[])param.ToArray(typeof(object));

					try
					{
						if (code == IscCodes.isc_except)
						{
							// Custom exception	add	the	first argument as error	code
							ErrorCode = Convert.ToInt32(args[0], CultureInfo.InvariantCulture);
						}
						else if (code == IscCodes.isc_except2)
						{
							// Custom exception. Next Error should be the exception name.
							// And the next one the Exception message
						}
						else if (code == IscCodes.isc_stack_trace)
						{
							// The next error contains the PSQL Stack Trace
							if (builder.Length > 0)
							{
								builder.Append(Environment.NewLine);
							}
							builder.AppendFormat(CultureInfo.CurrentCulture, "{0}", args);
						}
						else
						{
							if (builder.Length > 0)
							{
								builder.Append(Environment.NewLine);
							}

							builder.AppendFormat(CultureInfo.CurrentCulture, message, args);
						}
					}
					catch
					{
						message = BuildDefaultErrorMessage(code);

						builder.AppendFormat(CultureInfo.CurrentCulture, message, args);
					}
				}
			}

			// Update error	collection only	with the main error
			IscError mainError = new IscError(ErrorCode);
			mainError.Message = builder.ToString();

			Errors.Add(mainError);

			// Update exception	message
			_message = builder.ToString();
		}
        private void BuildExceptionMessage()
        {
            StringBuilder builder = new StringBuilder();

            for (int i = 0; i < Errors.Count; i++)
            {
                if (Errors[i].Type == IscCodes.isc_arg_gds || Errors[i].Type == IscCodes.isc_arg_warning)
                {
                    int    code    = Errors[i].ErrorCode;
                    string message = GetValueOrDefault(IscErrorMessages.Values, code, BuildDefaultErrorMessage);

                    List <string> args  = new List <string>();
                    int           index = i + 1;
                    while (index < Errors.Count && Errors[index].IsArgument)
                    {
                        args.Add(Errors[index++].StrParam);
                        i++;
                    }

                    try
                    {
                        switch (code)
                        {
                        case IscCodes.isc_except:
                            // Custom exception	add	the	first argument as error	code
                            ErrorCode = Convert.ToInt32(args[0], CultureInfo.InvariantCulture);
                            // ignoring the message - historical reason
                            break;

                        case IscCodes.isc_except2:
                            // Custom exception. Next Error should be the exception name.
                            // And the next one the Exception message
                            break;

                        case IscCodes.isc_stack_trace:
                            // The next error contains the PSQL Stack Trace
                            AppendMessage(builder, message, args);
                            break;

                        default:
                            AppendMessage(builder, message, args);
                            break;
                        }
                    }
                    catch
                    {
                        message = BuildDefaultErrorMessage(code);
                        AppendMessage(builder, message, args);
                    }
                }
            }

            // Update error	collection only	with the main error
            IscError mainError = new IscError(ErrorCode);

            mainError.Message = builder.ToString();

            Errors.Add(mainError);

            // Update exception	message
            _message = builder.ToString();
        }
		public IscError Add(IscError error)
		{
			this.List.Add(error);

			return error;
		}
		public void BuildExceptionMessage()
		{
			string resources = "FirebirdSql.Data.Common.Resources.isc_error_msg";			

			StringBuilder builder = new StringBuilder();
			ResourceManager rm = new ResourceManager(resources, Assembly.GetExecutingAssembly());

			this.errorCode = (this.Errors.Count != 0) ? this.Errors[0].ErrorCode : 0;

			for (int i = 0; i < this.Errors.Count; i++)
			{
				if (this.Errors[i].Type == IscCodes.isc_arg_gds ||
					this.Errors[i].Type == IscCodes.isc_arg_warning)
				{
					int code = this.Errors[i].ErrorCode;
					string message = null;

					try
					{
						message = rm.GetString(code.ToString());
					}
					catch
					{
						message = null;
					}
					finally
					{
						if (message == null)
						{
							message = String.Format(CultureInfo.CurrentCulture, "No message for error code {0} found.", code);
						}
					}

					ArrayList param = new ArrayList();

					int index = i + 1;

					while (index < this.Errors.Count && this.Errors[index].IsArgument)
					{
						param.Add(this.Errors[index++].StrParam);
						i++;
					}

					object[] args = (object[])param.ToArray(typeof(object));

					try
					{
						if (code == IscCodes.isc_except)
						{
							// Custom exception	add	the	first argument as error	code
							this.errorCode = Convert.ToInt32(args[0], CultureInfo.InvariantCulture);
						}
						else
						{
							if (builder.Length > 0)
							{
								builder.Append("\n");
							}

							builder.AppendFormat(CultureInfo.CurrentCulture, message, args);
						}
					}
					catch
					{
						message = String.Format(CultureInfo.CurrentCulture, "No message for error code {0} found.", code);

						builder.AppendFormat(CultureInfo.CurrentCulture, message, args);
					}
				}
			}

			// Update error	collection only	with the main error
			IscError mainError = new IscError(this.errorCode);
			mainError.Message = builder.ToString();

			this.errors = new IscErrorCollection();
			this.Errors.Add(mainError);

			// Update exception	message
			this.message = builder.ToString();
		}
Exemple #7
0
        private void BuildExceptionMessage()
        {
            StringBuilder builder = new StringBuilder();

            for (int i = 0; i < this.Errors.Count; i++)
            {
                if (this.Errors[i].Type == IscCodes.isc_arg_gds ||
                    this.Errors[i].Type == IscCodes.isc_arg_warning)
                {
                    int    code    = this.Errors[i].ErrorCode;
                    string message = GetValueOrDefault(IscErrorMessages.Values, code, BuildDefaultErrorMessage);

                    ArrayList param = new ArrayList();

                    int index = i + 1;

                    while (index < this.Errors.Count && this.Errors[index].IsArgument)
                    {
                        param.Add(this.Errors[index++].StrParam);
                        i++;
                    }

                    object[] args = (object[])param.ToArray(typeof(object));

                    try
                    {
                        if (code == IscCodes.isc_except)
                        {
                            // Custom exception	add	the	first argument as error	code
                            this.ErrorCode = Convert.ToInt32(args[0], CultureInfo.InvariantCulture);
                        }
                        else if (code == IscCodes.isc_except2)
                        {
                            // Custom exception. Next Error should be the exception name.
                            // And the next one the Exception message
                        }
                        else if (code == IscCodes.isc_stack_trace)
                        {
                            // The next error contains the PSQL Stack Trace
                            if (builder.Length > 0)
                            {
                                builder.Append(Environment.NewLine);
                            }
                            builder.AppendFormat(CultureInfo.CurrentCulture, "{0}", args);
                        }
                        else
                        {
                            if (builder.Length > 0)
                            {
                                builder.Append(Environment.NewLine);
                            }

                            builder.AppendFormat(CultureInfo.CurrentCulture, message, args);
                        }
                    }
                    catch
                    {
                        message = BuildDefaultErrorMessage(code);

                        builder.AppendFormat(CultureInfo.CurrentCulture, message, args);
                    }
                }
            }

            // Update error	collection only	with the main error
            IscError mainError = new IscError(this.ErrorCode);

            mainError.Message = builder.ToString();

            this.Errors.Add(mainError);

            // Update exception	message
            _message = builder.ToString();
        }
Exemple #8
0
        public IscError Add(IscError error)
        {
            this.List.Add(error);

            return(error);
        }
Exemple #9
0
        public void BuildExceptionMessage()
        {
            string resources = "FirebirdSql.Data.Common.Resources.isc_error_msg";

            StringBuilder   builder = new StringBuilder();
            ResourceManager rm      = new ResourceManager(resources, Assembly.GetExecutingAssembly());

            this.errorCode = (this.Errors.Count != 0) ? this.Errors[0].ErrorCode : 0;

            for (int i = 0; i < this.Errors.Count; i++)
            {
                if (this.Errors[i].Type == IscCodes.isc_arg_gds ||
                    this.Errors[i].Type == IscCodes.isc_arg_warning)
                {
                    int    code    = this.Errors[i].ErrorCode;
                    string message = null;

                    try
                    {
                        message = rm.GetString(code.ToString());
                    }
                    catch
                    {
                        message = null;
                    }
                    finally
                    {
                        if (message == null)
                        {
                            message = String.Format(CultureInfo.CurrentCulture, "No message for error code {0} found.", code);
                        }
                    }

                    ArrayList param = new ArrayList();

                    int index = i + 1;

                    while (index < this.Errors.Count && this.Errors[index].IsArgument)
                    {
                        param.Add(this.Errors[index++].StrParam);
                        i++;
                    }

                    object[] args = (object[])param.ToArray(typeof(object));

                    try
                    {
                        if (code == IscCodes.isc_except)
                        {
                            // Custom exception	add	the	first argument as error	code
                            this.errorCode = Convert.ToInt32(args[0], CultureInfo.InvariantCulture);
                        }
                        else
                        {
                            if (builder.Length > 0)
                            {
                                builder.Append("\n");
                            }

                            builder.AppendFormat(CultureInfo.CurrentCulture, message, args);
                        }
                    }
                    catch
                    {
                        message = String.Format(CultureInfo.CurrentCulture, "No message for error code {0} found.", code);

                        builder.AppendFormat(CultureInfo.CurrentCulture, message, args);
                    }
                }
            }

            // Update error	collection only	with the main error
            IscError mainError = new IscError(this.errorCode);

            mainError.Message = builder.ToString();

            this.errors = new IscErrorCollection();
            this.Errors.Add(mainError);

            // Update exception	message
            this.message = builder.ToString();
        }