public void GetValue() { var readState = new RecordReadState(); var type = new SqlBit(readState, CompressionContext.NoCompression); // No bytes read - length is one Assert.AreEqual(1, type.FixedLength); // Load byte and check length is 0 readState.LoadBitByte(0xD2); Assert.AreEqual(0, type.FixedLength); Assert.IsFalse((bool)type.GetValue(new byte[0])); Assert.IsTrue((bool)type.GetValue(new byte[0])); Assert.IsFalse((bool)type.GetValue(new byte[0])); Assert.IsFalse((bool)type.GetValue(new byte[0])); Assert.IsTrue((bool)type.GetValue(new byte[0])); Assert.IsFalse((bool)type.GetValue(new byte[0])); Assert.IsTrue((bool)type.GetValue(new byte[0])); // One bit left - length should still be 0 Assert.AreEqual(0, type.FixedLength); Assert.IsTrue((bool)type.GetValue(new byte[0])); // All bits consumed - length should be 1 Assert.AreEqual(1, type.FixedLength); }
public void CreateMetaData() { var meta = SqlBit.GetTypeHandler().CreateMetaData("Test"); Assert.AreEqual(SqlDbType.Bit, meta.SqlDbType); Assert.AreEqual("Test", meta.Name); }
public void GetRawValue() { SqlType type = new SqlBit(false, ParameterDirection.Input); Assert.AreEqual(false, type.GetRawValue()); type = new SqlBit(null, ParameterDirection.Input); Assert.Null(type.GetRawValue()); }
public void GetParameter() { SqlType type = new SqlBit(true, ParameterDirection.Input); TestHelper.AssertSqlParameter(type.GetParameter(), SqlDbType.Bit, true); type = new SqlBit(null, ParameterDirection.Input); TestHelper.AssertSqlParameter(type.GetParameter(), SqlDbType.Bit, DBNull.Value); }
public void GetRawValue() { SqlType type = new SqlBit(false, ParameterDirection.Input); Assert.AreEqual(false, type.GetRawValue()); type = new SqlBit(null, ParameterDirection.Input); Assert.Null(type.GetRawValue()); }
public void GetParameter() { SqlType type = new SqlBit(true, ParameterDirection.Input); TestHelper.AssertSqlParameter(type.GetParameter(), SqlDbType.Bit, true); type = new SqlBit(null, ParameterDirection.Input); TestHelper.AssertSqlParameter(type.GetParameter(), SqlDbType.Bit, DBNull.Value); }
protected override string GetColumnCreationMethod(SqlColumn column) { var type = column.Types[Version]; return(type.SqlTypeInfo switch { SqlChar _ => $"{nameof(Generic1Columns.AddChar)}(\"{column.Name}\", {type.Length?.ToString("D", CultureInfo.InvariantCulture)}", SqlNChar _ => $"{nameof(Generic1Columns.AddNChar)}(\"{column.Name}\", {type.Length?.ToString("D", CultureInfo.InvariantCulture)}, {type.IsNullable.ToString(CultureInfo.InvariantCulture)}", SqlVarChar _ => $"{nameof(Generic1Columns.AddVarChar)}(\"{column.Name}\", {type.Length?.ToString("D", CultureInfo.InvariantCulture)}, {type.IsNullable.ToString(CultureInfo.InvariantCulture)}", SqlNVarChar _ => $"{nameof(Generic1Columns.AddNVarChar)}(\"{column.Name}\", {type.Length?.ToString("D", CultureInfo.InvariantCulture)}, {type.IsNullable.ToString(CultureInfo.InvariantCulture)}", SqlFloatSmall _ => $"{nameof(Generic1Columns.AddFloatSmall)}(\"{column.Name}\", {type.IsNullable.ToString(CultureInfo.InvariantCulture)}", SqlFloatLarge _ => $"{nameof(Generic1Columns.AddFloatLarge)}(\"{column.Name}\", {type.IsNullable.ToString(CultureInfo.InvariantCulture)}", SqlBit _ => $"{nameof(Generic1Columns.AddBit)}(\"{column.Name}\", {type.IsNullable.ToString(CultureInfo.InvariantCulture)}", SqlByte _ => $"{nameof(Generic1Columns.AddByte)}(\"{column.Name}\", {type.IsNullable.ToString(CultureInfo.InvariantCulture)}", SqlInt16 _ => $"{nameof(Generic1Columns.AddInt16)}(\"{column.Name}\", {type.IsNullable.ToString(CultureInfo.InvariantCulture)}", SqlInt32 _ => $"{nameof(Generic1Columns.AddInt32)}(\"{column.Name}\", {type.IsNullable.ToString(CultureInfo.InvariantCulture)}", SqlInt64 _ => $"{nameof(Generic1Columns.AddInt64)}(\"{column.Name}\", {type.IsNullable.ToString(CultureInfo.InvariantCulture)}", SqlNumber _ => $"{nameof(Generic1Columns.AddNumber)}(\"{column.Name}\", {type.Length?.ToString("D", CultureInfo.InvariantCulture)}, {type.Scale?.ToString("D", CultureInfo.InvariantCulture)}, {type.IsNullable.ToString(CultureInfo.InvariantCulture)}", SqlDate _ => $"{nameof(Generic1Columns.AddDate)}(\"{column.Name}\", {type.IsNullable.ToString(CultureInfo.InvariantCulture)}", SqlTime _ => $"{nameof(Generic1Columns.AddTime)}(\"{column.Name}\", {type.IsNullable.ToString(CultureInfo.InvariantCulture)}", SqlDateTime _ => $"{nameof(Generic1Columns.AddDateTime)}(\"{column.Name}\", {type.IsNullable.ToString(CultureInfo.InvariantCulture)}", _ => throw new NotImplementedException($"Unmapped type: {type.SqlTypeInfo}"), });
public void GetTypeHandler() { Assert.IsInstanceOf <SqlTypeHandler>(SqlBit.GetTypeHandler()); }
/// <summary /> internal object GetValueFromRow(IRow row, int index, out int copied) { copied = 0; object retval = null; if (this.ScopeType == typeof(long)) { long?longValue = row.Get <long?>(index); if (longValue == null) { retval = DBNull.Value; } else { retval = longValue.Value; copied = sizeof(long); } } else if (this.ScopeType == typeof(SqlInt64)) { SqlInt64 longValue = row.Get <SqlInt64>(index); if (longValue == null) { retval = DBNull.Value; } else { retval = longValue.Value; copied = sizeof(long); } } else if (this.ScopeType == typeof(int)) { int?intValue = row.Get <int?>(index); if (intValue == null) { retval = DBNull.Value; } else { retval = intValue.Value; copied = sizeof(int); } } else if (this.ScopeType == typeof(SqlInt32)) { SqlInt32 intValue = row.Get <SqlInt32>(index); if (intValue == null) { retval = DBNull.Value; } else { retval = intValue.Value; copied = sizeof(int); } } else if (this.ScopeType == typeof(short)) { short?shortValue = row.Get <short?>(index); if (shortValue == null) { retval = DBNull.Value; } else { retval = shortValue.Value; copied = sizeof(short); } } else if (this.ScopeType == typeof(SqlInt16)) { SqlInt16 shortValue = row.Get <SqlInt16>(index); if (shortValue == null) { retval = DBNull.Value; } else { retval = shortValue.Value; copied = sizeof(short); } } else if (this.ScopeType == typeof(byte)) { byte?byteValue = row.Get <byte?>(index); if (byteValue == null) { retval = DBNull.Value; } else { retval = byteValue.Value; copied = 1; } } else if (this.ScopeType == typeof(SqlByte)) { SqlByte byteValue = row.Get <SqlByte>(index); if (byteValue == null) { retval = DBNull.Value; } else { retval = byteValue.Value; copied = 1; } } else if (this.ScopeType == typeof(string)) { string stringValue = row.Get <string>(index); if (stringValue == null) { retval = DBNull.Value; } else { copied = Encoding.UTF8.GetByteCount(stringValue); ValidateDataSize(row.Schema[index].Name, index, copied); retval = Encoding.UTF8.GetBytes(stringValue); } } else if (this.ScopeType == typeof(byte[])) { byte[] binaryValue = row.Get <byte[]>(index); if (binaryValue == null) { retval = DBNull.Value; } else { copied = binaryValue.Length; ValidateDataSize(row.Schema[index].Name, index, copied); retval = binaryValue; } } else if (this.ScopeType == typeof(SqlString)) { SqlString stringValue = row.Get <SqlString>(index); if (stringValue == null) { retval = DBNull.Value; } else { copied = Encoding.UTF8.GetByteCount(stringValue.Value); ValidateDataSize(row.Schema[index].Name, index, copied); retval = Encoding.UTF8.GetBytes(stringValue.Value); } } else if (this.ScopeType == typeof(char)) { char?charValue = row.Get <char?>(index); if (charValue == null) { retval = DBNull.Value; } else { var tmpChar = charValue.Value.ToString(); retval = Encoding.UTF8.GetBytes(tmpChar); copied = Encoding.UTF8.GetByteCount(tmpChar); } } else if (this.ScopeType == typeof(DateTime)) { DateTime?dateTimeValue = row.Get <DateTime?>(index); if (dateTimeValue == null) { retval = DBNull.Value; } else { retval = dateTimeValue.Value; copied = 8; } } else if (this.ScopeType == typeof(SqlDate)) { SqlDate dateTimeValue = row.Get <SqlDate>(index); if (dateTimeValue == null) { retval = DBNull.Value; } else { retval = dateTimeValue.Value; copied = 8; } } else if (this.ScopeType == typeof(decimal)) { decimal?decimalValue = row.Get <decimal?>(index); if (decimalValue == null) { retval = DBNull.Value; } else { retval = DecimalSerializationHelper.SerializeDecToByteArray(decimalValue.Value); copied = DecimalSerializationHelper.StoredDecimalSize; } } else if (this.ScopeType == typeof(SqlDecimal)) { SqlDecimal decimalValue = row.Get <SqlDecimal>(index); if (decimalValue == null) { retval = DBNull.Value; } else { retval = decimalValue.Value; copied = sizeof(decimal); } } else if (this.ScopeType == typeof(bool)) { bool?boolValue = row.Get <bool?>(index); if (boolValue == null) { retval = DBNull.Value; } else { retval = boolValue.Value; copied = 1; } } else if (this.ScopeType == typeof(SqlBit)) { SqlBit boolValue = row.Get <SqlBit>(index); if (boolValue == null) { retval = DBNull.Value; } else { retval = boolValue.Value; copied = 1; } } else if (this.ScopeType == typeof(float)) { float?floatValue = row.Get <float?>(index); if (floatValue == null) { retval = DBNull.Value; } else { retval = floatValue.Value; copied = sizeof(float); } } else if (this.ScopeType == typeof(double)) { double?doubleValue = row.Get <double?>(index); if (doubleValue == null) { retval = DBNull.Value; } else { retval = doubleValue.Value; copied = sizeof(double); } } else if (this.ScopeType == typeof(sbyte)) { sbyte?sbyteValue = row.Get <sbyte?>(index); if (sbyteValue == null) { retval = DBNull.Value; } else { retval = sbyteValue.Value; copied = sizeof(sbyte); } } else if (this.ScopeType == typeof(uint)) { uint?uintValue = row.Get <uint?>(index); if (uintValue == null) { retval = DBNull.Value; } else { retval = uintValue.Value; copied = sizeof(uint); } } else if (this.ScopeType == typeof(ushort)) { ushort?ushortValue = row.Get <ushort?>(index); if (ushortValue == null) { retval = DBNull.Value; } else { retval = ushortValue.Value; copied = sizeof(ushort); } } else if (this.ScopeType == typeof(SqlGuid)) { SqlGuid guidValue = row.Get <SqlGuid>(index); if (guidValue == null) { retval = DBNull.Value; } else { retval = guidValue.Value; copied = 16; } } else if (this.ScopeType == typeof(Guid)) { Guid?guidValue = row.Get <Guid?>(index); if (guidValue == null) { retval = DBNull.Value; } else { retval = guidValue.Value; copied = 16; } } return(retval); }