public IscException ReadStatusVector()
        {
            IscException exception = null;
            bool         eof       = false;

            while (!eof)
            {
                int arg = ReadInt32();

                switch (arg)
                {
                case IscCodes.isc_arg_gds:
                default:
                    int er = ReadInt32();
                    if (er != 0)
                    {
                        if (exception == null)
                        {
                            exception = IscException.ForBuilding();
                        }
                        exception.Errors.Add(new IscError(arg, er));
                    }
                    break;

                case IscCodes.isc_arg_end:
                    exception?.BuildExceptionData();
                    eof = true;
                    break;

                case IscCodes.isc_arg_interpreted:
                case IscCodes.isc_arg_string:
                    exception.Errors.Add(new IscError(arg, ReadString()));
                    break;

                case IscCodes.isc_arg_number:
                    exception.Errors.Add(new IscError(arg, ReadInt32()));
                    break;

                case IscCodes.isc_arg_sql_state:
                    exception.Errors.Add(new IscError(arg, ReadString()));
                    break;
                }
            }

            return(exception);
        }
Пример #2
0
        public async ValueTask <IscException> ReadStatusVectorAsync(CancellationToken cancellationToken = default)
        {
            IscException exception = null;
            var          eof       = false;

            while (!eof)
            {
                var arg = await ReadInt32Async(cancellationToken).ConfigureAwait(false);

                switch (arg)
                {
                case IscCodes.isc_arg_gds:
                default:
                    var er = await ReadInt32Async(cancellationToken).ConfigureAwait(false);

                    if (er != 0)
                    {
                        if (exception == null)
                        {
                            exception = IscException.ForBuilding();
                        }
                        exception.Errors.Add(new IscError(arg, er));
                    }
                    break;

                case IscCodes.isc_arg_end:
                    exception?.BuildExceptionData();
                    eof = true;
                    break;

                case IscCodes.isc_arg_interpreted:
                case IscCodes.isc_arg_string:
                case IscCodes.isc_arg_sql_state:
                    exception.Errors.Add(new IscError(arg, await ReadStringAsync(cancellationToken).ConfigureAwait(false)));
                    break;

                case IscCodes.isc_arg_number:
                    exception.Errors.Add(new IscError(arg, await ReadInt32Async(cancellationToken).ConfigureAwait(false)));
                    break;
                }
            }

            return(exception);
        }
        public static IscException ParseStatusVector(IntPtr[] statusVector, Charset charset)
        {
            IscException exception = null;
            bool         eof       = false;

            for (int i = 0; i < statusVector.Length;)
            {
                IntPtr arg = statusVector[i++];

                switch (arg.AsInt())
                {
                case IscCodes.isc_arg_gds:
                default:
                    IntPtr er = statusVector[i++];
                    if (er != IntPtr.Zero)
                    {
                        if (exception == null)
                        {
                            exception = IscException.ForBuilding();
                        }
                        exception.Errors.Add(new IscError(arg.AsInt(), er.AsInt()));
                    }
                    break;

                case IscCodes.isc_arg_end:
                    exception?.BuildExceptionData();
                    eof = true;
                    break;

                case IscCodes.isc_arg_interpreted:
                case IscCodes.isc_arg_string:
                {
                    IntPtr ptr       = statusVector[i++];
                    string s         = Marshal.PtrToStringAnsi(ptr);
                    string arg_value = charset.GetString(Encoding2.Default.GetBytes(s));
                    exception.Errors.Add(new IscError(arg.AsInt(), arg_value));
                }
                break;

                case IscCodes.isc_arg_cstring:
                {
                    i++;

                    IntPtr ptr       = statusVector[i++];
                    string s         = Marshal.PtrToStringAnsi(ptr);
                    string arg_value = charset.GetString(Encoding2.Default.GetBytes(s));
                    exception.Errors.Add(new IscError(arg.AsInt(), arg_value));
                }
                break;

                case IscCodes.isc_arg_win32:
                case IscCodes.isc_arg_number:
                    exception.Errors.Add(new IscError(arg.AsInt(), statusVector[i++].AsInt()));
                    break;

                case IscCodes.isc_arg_sql_state:
                {
                    IntPtr ptr       = statusVector[i++];
                    string s         = Marshal.PtrToStringAnsi(ptr);
                    string arg_value = charset.GetString(Encoding2.Default.GetBytes(s));
                    exception.Errors.Add(new IscError(arg.AsInt(), arg_value));
                }
                break;
                }

                if (eof)
                {
                    break;
                }
            }

            return(exception);
        }