public Guid GetGuid() { return(_value switch { Guid guid => guid, byte[] bytes => TypeDecoder.DecodeGuid(bytes), _ => throw new InvalidOperationException($"Incorrect {nameof(Guid)} value."), });
public ValueTask <Guid> GetGuid(AsyncWrappingCommonArgs async) { return(ValueTask2.FromResult(_value switch { Guid guid => guid, byte[] bytes => TypeDecoder.DecodeGuid(bytes), _ => throw new InvalidOperationException($"Incorrect {nameof(Guid)} value."), }));
public Guid GetGuid() { switch (_value) { case Guid guid: return(guid); case byte[] bytes: return(TypeDecoder.DecodeGuid(bytes)); default: throw new InvalidOperationException($"Incorrect {nameof(Guid)} value."); } }
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; default: throw TypeHelper.InvalidDataType(SqlType); } } }
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); } } }
public void SetValue(byte[] buffer) { if (buffer == null || NullFlag == -1) { Value = System.DBNull.Value; } else { switch (SqlType) { case IscCodes.SQL_TEXT: case IscCodes.SQL_VARYING: if (DbDataType == DbDataType.Guid) { Value = new Guid(buffer); } else { if (Charset.IsOctetsCharset) { Value = buffer; } else { string 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: DateTime date = TypeDecoder.DecodeDate(BitConverter.ToInt32(buffer, 0)); TimeSpan time = TypeDecoder.DecodeTime(BitConverter.ToInt32(buffer, 4)); Value = new System.DateTime( date.Year, date.Month, date.Day, time.Hours, time.Minutes, time.Seconds, time.Milliseconds); 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; default: throw new NotSupportedException("Unknown data type"); } } }