Ejemplo n.º 1
0
 public Type GetSystemType()
 {
     return(TypeHelper.GetTypeFromDbDataType(DbDataType));
 }
Ejemplo n.º 2
0
        public void SetValue(byte[] buffer)
        {
            if (buffer == null || NullFlag == -1)
            {
                Value = DBNull.Value;
            }
            else
            {
                switch (SqlType)
                {
                case IscCodes.SQL_TEXT:
                case IscCodes.SQL_VARYING:
                    if (DbDataType == DbDataType.Guid)
                    {
                        Value = TypeDecoder.DecodeGuid(buffer);
                    }
                    else
                    {
                        if (Charset.IsOctetsCharset)
                        {
                            Value = buffer;
                        }
                        else
                        {
                            var s = Charset.GetString(buffer, 0, buffer.Length);

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

                            Value = s;
                        }
                    }
                    break;

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

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

                case IscCodes.SQL_FLOAT:
                    Value = BitConverter.ToSingle(buffer, 0);
                    break;

                case IscCodes.SQL_DOUBLE:
                case IscCodes.SQL_D_FLOAT:
                    Value = BitConverter.ToDouble(buffer, 0);
                    break;

                case IscCodes.SQL_QUAD:
                case IscCodes.SQL_INT64:
                case IscCodes.SQL_BLOB:
                case IscCodes.SQL_ARRAY:
                    if (_numericScale < 0)
                    {
                        Value = TypeDecoder.DecodeDecimal(
                            BitConverter.ToInt64(buffer, 0),
                            _numericScale,
                            _dataType);
                    }
                    else
                    {
                        Value = 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));
                    Value = date.Add(time);
                    break;
                }

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

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

                case IscCodes.SQL_BOOLEAN:
                    Value = 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);
                    Value = 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);
                    Value = 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);
                    Value = 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);
                    Value = TypeHelper.CreateZonedTime(time, tzId, offset);
                    break;
                }

                case IscCodes.SQL_DEC16:
                    Value = DecimalCodec.DecFloat16.ParseBytes(buffer);
                    break;

                case IscCodes.SQL_DEC34:
                    Value = DecimalCodec.DecFloat34.ParseBytes(buffer);
                    break;

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

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