コード例 #1
0
 public static BigInteger DecodeInt128(byte[] value)
 {
     if (BitConverter.IsLittleEndian)
     {
         Array.Reverse(value);
     }
     return(Int128Helper.GetInt128(value));
 }
コード例 #2
0
        public void SetValue(byte[] buffer)
        {
            if (buffer == null || NullFlag == -1)
            {
                DbValue.SetValue(DBNull.Value);
            }
            else
            {
                switch (SqlType)
                {
                case IscCodes.SQL_TEXT:
                case IscCodes.SQL_VARYING:
                    if (DbDataType == DbDataType.Guid)
                    {
                        DbValue.SetValue(TypeDecoder.DecodeGuid(buffer));
                    }
                    else
                    {
                        if (Charset.IsOctetsCharset)
                        {
                            DbValue.SetValue(buffer);
                        }
                        else
                        {
                            var s = Charset.GetString(buffer, 0, buffer.Length);

                            if ((Length % Charset.BytesPerCharacter) == 0 &&
                                s.Length > CharCount)
                            {
                                s = s.Substring(0, CharCount);
                            }

                            DbValue.SetValue(s);
                        }
                    }
                    break;

                case IscCodes.SQL_SHORT:
                    if (_numericScale < 0)
                    {
                        DbValue.SetValue(TypeDecoder.DecodeDecimal(BitConverter.ToInt16(buffer, 0), _numericScale, _dataType));
                    }
                    else
                    {
                        DbValue.SetValue(BitConverter.ToInt16(buffer, 0));
                    }
                    break;

                case IscCodes.SQL_LONG:
                    if (_numericScale < 0)
                    {
                        DbValue.SetValue(TypeDecoder.DecodeDecimal(BitConverter.ToInt32(buffer, 0), _numericScale, _dataType));
                    }
                    else
                    {
                        DbValue.SetValue(BitConverter.ToInt32(buffer, 0));
                    }
                    break;

                case IscCodes.SQL_FLOAT:
                    DbValue.SetValue(BitConverter.ToSingle(buffer, 0));
                    break;

                case IscCodes.SQL_DOUBLE:
                case IscCodes.SQL_D_FLOAT:
                    DbValue.SetValue(BitConverter.ToDouble(buffer, 0));
                    break;

                case IscCodes.SQL_QUAD:
                case IscCodes.SQL_INT64:
                case IscCodes.SQL_BLOB:
                case IscCodes.SQL_ARRAY:
                    if (_numericScale < 0)
                    {
                        DbValue.SetValue(TypeDecoder.DecodeDecimal(BitConverter.ToInt64(buffer, 0), _numericScale, _dataType));
                    }
                    else
                    {
                        DbValue.SetValue(BitConverter.ToInt64(buffer, 0));
                    }
                    break;

                case IscCodes.SQL_TIMESTAMP:
                {
                    var date = TypeDecoder.DecodeDate(BitConverter.ToInt32(buffer, 0));
                    var time = TypeDecoder.DecodeTime(BitConverter.ToInt32(buffer, 4));
                    DbValue.SetValue(date.Add(time));
                    break;
                }

                case IscCodes.SQL_TYPE_TIME:
                    DbValue.SetValue(TypeDecoder.DecodeTime(BitConverter.ToInt32(buffer, 0)));
                    break;

                case IscCodes.SQL_TYPE_DATE:
                    DbValue.SetValue(TypeDecoder.DecodeDate(BitConverter.ToInt32(buffer, 0)));
                    break;

                case IscCodes.SQL_BOOLEAN:
                    DbValue.SetValue(TypeDecoder.DecodeBoolean(buffer));
                    break;

                case IscCodes.SQL_TIMESTAMP_TZ:
                {
                    var date = TypeDecoder.DecodeDate(BitConverter.ToInt32(buffer, 0));
                    var time = TypeDecoder.DecodeTime(BitConverter.ToInt32(buffer, 4));
                    var tzId = BitConverter.ToUInt16(buffer, 8);
                    var dt   = DateTime.SpecifyKind(date.Add(time), DateTimeKind.Utc);
                    DbValue.SetValue(TypeHelper.CreateZonedDateTime(dt, tzId, null));
                    break;
                }

                case IscCodes.SQL_TIMESTAMP_TZ_EX:
                {
                    var date   = TypeDecoder.DecodeDate(BitConverter.ToInt32(buffer, 0));
                    var time   = TypeDecoder.DecodeTime(BitConverter.ToInt32(buffer, 4));
                    var tzId   = BitConverter.ToUInt16(buffer, 8);
                    var offset = BitConverter.ToInt16(buffer, 10);
                    var dt     = DateTime.SpecifyKind(date.Add(time), DateTimeKind.Utc);
                    DbValue.SetValue(TypeHelper.CreateZonedDateTime(dt, tzId, offset));
                    break;
                }

                case IscCodes.SQL_TIME_TZ:
                {
                    var time = TypeDecoder.DecodeTime(BitConverter.ToInt32(buffer, 0));
                    var tzId = BitConverter.ToUInt16(buffer, 4);
                    DbValue.SetValue(TypeHelper.CreateZonedTime(time, tzId, null));
                    break;
                }

                case IscCodes.SQL_TIME_TZ_EX:
                {
                    var time   = TypeDecoder.DecodeTime(BitConverter.ToInt32(buffer, 0));
                    var tzId   = BitConverter.ToUInt16(buffer, 4);
                    var offset = BitConverter.ToInt16(buffer, 6);
                    DbValue.SetValue(TypeHelper.CreateZonedTime(time, tzId, offset));
                    break;
                }

                case IscCodes.SQL_DEC16:
                    DbValue.SetValue(DecimalCodec.DecFloat16.ParseBytes(buffer));
                    break;

                case IscCodes.SQL_DEC34:
                    DbValue.SetValue(DecimalCodec.DecFloat34.ParseBytes(buffer));
                    break;

                case IscCodes.SQL_INT128:
                    if (_numericScale < 0)
                    {
                        DbValue.SetValue(TypeDecoder.DecodeDecimal(Int128Helper.GetInt128(buffer), _numericScale, _dataType));
                    }
                    else
                    {
                        DbValue.SetValue(Int128Helper.GetInt128(buffer));
                    }
                    break;

                default:
                    throw TypeHelper.InvalidDataType(SqlType);
                }
            }
        }