protected override object GetValue(INullable value) { return ((SqlInt16) value).Value; }
private static void ThrowIfArgumentNull(INullable argument, string name) { if (argument == null || argument.IsNull) { throw new ArgumentNullException(name); } }
public void NullTest() { using (SqlConnection conn = new SqlConnection(_connStr)) { conn.Open(); SqlCommand com = new SqlCommand() { Connection = conn, CommandText = "insert into TestTableNull values (@p);" + "SELECT * FROM TestTableNull" }; SqlParameter p = com.Parameters.Add("@p", SqlDbType.Udt); p.UdtTypeName = "Utf8String"; p.Value = DBNull.Value; using (SqlTransaction trans = conn.BeginTransaction()) { com.Transaction = trans; SqlDataReader reader = com.ExecuteReader(); Utf8String[] expectedValues = { new Utf8String("this"), new Utf8String("is"), new Utf8String("a"), new Utf8String("test") }; int currentValue = 0; do { while (reader.Read()) { DataTestUtility.AssertEqualsWithDescription(1, reader.FieldCount, "Unexpected FieldCount."); if (currentValue < expectedValues.Length) { DataTestUtility.AssertEqualsWithDescription(expectedValues[currentValue], reader.GetValue(0), "Unexpected Value."); DataTestUtility.AssertEqualsWithDescription(expectedValues[currentValue], reader.GetSqlValue(0), "Unexpected SQL Value."); } else { DataTestUtility.AssertEqualsWithDescription(DBNull.Value, reader.GetValue(0), "Unexpected Value."); Utf8String sqlValue = (Utf8String)reader.GetSqlValue(0); INullable iface = sqlValue as INullable; Assert.True(iface != null, "Expected interface cast to return a non-null value."); Assert.True(iface.IsNull, "Expected interface cast to have IsNull==true."); } currentValue++; Assert.True(currentValue <= (expectedValues.Length + 1), "Expected to only hit one extra result."); } }while (reader.NextResult()); DataTestUtility.AssertEqualsWithDescription(currentValue, (expectedValues.Length + 1), "Did not hit all expected values."); reader.Close(); } } }
public static object smethod_12(INullable inullable_0) { if (inullable_0 == null) { return(null); } if (inullable_0 is SqlInt32) { return(smethod_12((SqlInt32)inullable_0)); } if (inullable_0 is SqlInt64) { return(smethod_12((SqlInt64)inullable_0)); } if (inullable_0 is SqlBoolean) { return(smethod_12((SqlBoolean)inullable_0)); } if (inullable_0 is SqlString) { return(smethod_12((SqlString)inullable_0)); } if (!(inullable_0 is SqlDateTime)) { throw new ArgumentException("Unsupported INullable type: {0}".smethod_0(CultureInfo.InvariantCulture, inullable_0.GetType())); } return(smethod_12((SqlDateTime)inullable_0)); }
public static object ToValue(INullable nullableValue) { switch (nullableValue) { case (null): return(null); break; } if (nullableValue is SqlInt32) { return(ToValue((SqlInt32)nullableValue)); } if (nullableValue is SqlInt64) { return(ToValue((SqlInt64)nullableValue)); } if (nullableValue is SqlBoolean) { return(ToValue((SqlBoolean)nullableValue)); } if (nullableValue is SqlString) { return(ToValue((SqlString)nullableValue)); } if (!(nullableValue is SqlDateTime)) { throw new ArgumentException("Unsupported INullable type: {0}".FormatWith(CultureInfo.InvariantCulture, nullableValue.GetType())); } return(ToValue((SqlDateTime)nullableValue)); }
internal override void Normalize(FieldInfo fi, object obj, Stream s) { object obj2; if (fi == null) { obj2 = obj; } else { obj2 = base.GetValue(fi, obj); } INullable nullable = obj2 as INullable; if ((nullable != null) && !this.m_isTopLevelUdt) { if (nullable.IsNull) { s.WriteByte(0); s.Write(this.m_PadBuffer, 0, this.m_PadBuffer.Length); return; } s.WriteByte(1); } foreach (FieldInfoEx ex in this.m_fieldsToNormalize) { ex.normalizer.Normalize(ex.fieldInfo, obj2, s); } }
public static object ToValue(INullable nullableValue) { if (nullableValue == null) { return((object)null); } if (nullableValue is SqlInt32) { return(ConvertUtils.ToValue(nullableValue)); } if (nullableValue is SqlInt64) { return(ConvertUtils.ToValue(nullableValue)); } if (nullableValue is SqlBoolean) { return(ConvertUtils.ToValue(nullableValue)); } if (nullableValue is SqlString) { return(ConvertUtils.ToValue(nullableValue)); } if (nullableValue is SqlDateTime) { return(ConvertUtils.ToValue(nullableValue)); } throw new ArgumentException( "Unsupported INullable type: {0}".FormatWith((IFormatProvider)CultureInfo.InvariantCulture, (object)nullableValue.GetType())); }
public static object ToValue(INullable nullableValue) { if (nullableValue == null) { return(null); } else if (nullableValue is SqlInt32) { return(ToValue((SqlInt32)nullableValue)); } else if (nullableValue is SqlInt64) { return(ToValue((SqlInt64)nullableValue)); } else if (nullableValue is SqlBoolean) { return(ToValue((SqlBoolean)nullableValue)); } else if (nullableValue is SqlString) { return(ToValue((SqlString)nullableValue)); } else if (nullableValue is SqlDateTime) { return(ToValue((SqlDateTime)nullableValue)); } throw new Exception("Unsupported INullable type: {0}".FormatWith(CultureInfo.InvariantCulture, nullableValue.GetType())); }
public static string GetNullableSql(INullable sqlObject) { var text = ""; if (!sqlObject.IsNullable) text += "NOT"; text += " NULL"; return text; }
public override sealed void Set(IDbCommand cmd, object value, int index) { INullable nullableValue = (INullable)value; object parameterValue = nullableValue.IsNull ? DBNull.Value : GetValue(nullableValue); ((IDataParameter)cmd.Parameters[index]).Value = parameterValue; }
public static String GetBindVariableText(Object bindVariable) { if (bindVariable is INullable) { INullable nullable = bindVariable as INullable; if (nullable.IsNull) { return(GetBindVariableText(null)); } else { PropertyInfo pi = bindVariable.GetType().GetProperty("Value"); return(GetBindVariableText(pi.GetValue(bindVariable, null))); } } else if (bindVariable is string) { return("'" + bindVariable + "'"); } else if (bindVariable == null) { return("null"); } else if (bindVariable.GetType().IsPrimitive) { return(bindVariable.ToString()); } else if (bindVariable is decimal) { return(bindVariable.ToString()); } else if (bindVariable is DateTime) { if ((DateTime)bindVariable == ((DateTime)bindVariable).Date) { return("'" + ((DateTime)bindVariable).ToString(sqlLogDateFormat) + "'"); } else { return("'" + ((DateTime)bindVariable).ToString(sqlLogDateTimeFormat) + "'"); } } else if (bindVariable is bool) { return(bindVariable.ToString()); } else if (bindVariable.GetType().IsEnum) { object o = Convert.ChangeType(bindVariable, Enum.GetUnderlyingType(bindVariable.GetType())); return(o.ToString()); } else { return("'" + bindVariable + "'"); } }
internal static bool IsNull(object value) { if ((null == value) || (DBNull.Value == value)) { return(true); } INullable nullable = (value as INullable); return((null != nullable) && nullable.IsNull); }
public static bool IsObjectSqlNull(object value) { INullable nullable = value as INullable; if (nullable != null) { return(nullable.IsNull); } return(false); }
/// <summary> /// Sets the parameter value, disposing the previous value if necessary /// </summary> /// <param name="sqlValue">New value for the parameter</param> internal void SetValue(INullable sqlValue) { if ((Parameter.Direction != ParameterDirection.Input) && (Parameter.Direction != ParameterDirection.InputOutput)) { throw new InvalidOperationException(string.Format(DBSqlServerLocalizedText.DBSqlServerParameter_InvalidParameterDirectionSetValue, Parameter.ParameterName)); } DisposeParameterValue(); Parameter.SqlValue = sqlValue; }
public static object Unwrap(object o) { INullable sqlType = o as INullable; if (sqlType == null) { return(o); } if (sqlType.IsNull) { return(null); } return(o.GetType().GetProperty("Value").GetValue(o, null)); }
internal static bool IsNull(object value) { if (value == null || DBNull.Value == value) { return(true); } INullable nullable = value as INullable; if (nullable != null) { return(nullable.IsNull); } return(false); }
public static bool IsNull(object v) { if (v == null) { return(true); } if (v is decimal) { return(IsBlank((decimal)v)); } INullable nullable = v as INullable; return((nullable != null) && nullable.IsNull); }
/// <summary> /// Indicates whether the passed in INullable's String value is null or a String with just blank /// characters in it. /// </summary> /// <param name="o">The INullable object to test</param> /// <returns>True if the object's IsNull property is true or its String value is blank</returns> public static bool IsNullOrBlank(INullable o) { if (o == null) { return(true); } if (o.IsNull) { return(true); } else { return(IsNullOrBlank(o.ToString())); } }
static Nullable() //void setDefaults() { var typeT = typeof(T); if (typeT.IsValueType) { defaultInner = (INullable <T>)System.Activator.CreateInstance( typeof(NullableS <>).MakeGenericType(typeT)); } else { defaultInner = (INullable <T>)System.Activator.CreateInstance( typeof(NullableC <>).MakeGenericType(typeT)); } }
protected bool IsNull(object value) { if (value == null) { return(true); } INullable inull = value as INullable; if (inull != null) { return(inull.IsNull); } return(value == DBNull.Value); }
public void Test2() { TestClass tc = (TestClass)TypeAccessor.CreateInstance(typeof(TestClass)); ITestInterface ti = (ITestInterface)tc; INullable tn = (INullable)tc; int n = 10; object o = new object(); Assert.AreEqual(10, ti.Test1(ref n)); Assert.AreSame(o, ti.Test2(ref o)); Assert.AreEqual(15, ti.Test3(null)); Assert.AreEqual(20, ti.Test4(0)); Assert.AreEqual(35, ti.Test5); Assert.AreEqual(40, ti.Test6); Assert.That(tn.IsNull, Is.True); }
protected virtual bool IsNull( DbManager db, object value, object parameter) { // Speed up for scalar and nullable types. // switch (System.Convert.GetTypeCode(value)) { // null, DBNull.Value, Nullable<T> without a value. // case TypeCode.Empty: case TypeCode.DBNull: return(true); case TypeCode.Object: break; // int, byte, string, DateTime and other primitives except Guid. // Also Nullable<T> with a value. // default: return(false); } // Speed up for SqlTypes. // INullable nullable = value as INullable; if (nullable != null) { return(nullable.IsNull); } // All other types which have 'IsNull' property but does not implement 'INullable' interface. // For example: 'Oracle.DataAccess.Types.OracleDecimal'. // // For types without 'IsNull' property the return value is always false. // INullableInternal nullableInternal = (INullableInternal)DuckTyping.Implement(typeof(INullableInternal), value); return(nullableInternal.IsNull); }
override public int CompareValueTo(int recordNo1, Object value) { if (DBNull.Value == value) // it is not meaningful compare UDT with DBNull.Value WebData 113372 { value = NullValue; } if (implementsIComparable) { IComparable comparable = (IComparable)values[recordNo1]; return(comparable.CompareTo(value)); } else if (NullValue == value) { INullable nullableValue = (INullable)values[recordNo1]; return(nullableValue.IsNull ? 0 : 1); // left may be null, right is null } // else throw ExceptionBuilder.IComparableNotImplemented(DataType.AssemblyQualifiedName); }
public override int CompareValueTo(int recordNo1, object value) { if (DBNull.Value == value) { // it is not meaningful compare UDT with DBNull.Value value = _nullValue; } if (_implementsIComparable) { IComparable comparable = (IComparable)_values[recordNo1]; return(comparable.CompareTo(value)); } else if (_nullValue == value) { INullable nullableValue = (INullable)_values[recordNo1]; return(nullableValue.IsNull ? 0 : 1); // left may be null, right is null } throw ExceptionBuilder.IComparableNotImplemented(_dataType.AssemblyQualifiedName); }
protected bool AreEqualˡ <A>(A a, A b) { if (a == null && b == null) { return(true); } if (a == null || b == null) { return(false); } // compare byte arrays if (a is byte[] && b is byte[]) { IEnumerable <byte> a1 = a as IEnumerable <byte>; IEnumerable <byte> b1 = b as IEnumerable <byte>; return(a1.SequenceEqual(b1)); } // compare udt's if (a is INullable && b is INullable) { INullable a1 = a as INullable; INullable b1 = b as INullable; if (a1.IsNull && b1.IsNull) { return(true); } if (a1.IsNull || b1.IsNull) { return(false); } return(a.ToString().Equals(b.ToString())); } return(a.Equals(b)); }
internal static void IsNullOrSqlType(object value, out bool isNull, out bool isSqlType) { if ((value == null) || (value == DBNull.Value)) { isNull = true; isSqlType = false; } else { INullable nullable = (value as INullable); if (nullable != null) { isNull = nullable.IsNull; // Duplicated from DataStorage.cs // For back-compat, SqlXml is not in this list isSqlType = ((value is SqlBinary) || (value is SqlBoolean) || (value is SqlByte) || (value is SqlBytes) || (value is SqlChars) || (value is SqlDateTime) || (value is SqlDecimal) || (value is SqlDouble) || (value is SqlGuid) || (value is SqlInt16) || (value is SqlInt32) || (value is SqlInt64) || (value is SqlMoney) || (value is SqlSingle) || (value is SqlString)); } else { isNull = false; isSqlType = false; } } }
protected A GetValueˡ <A>(Dictionary <string, object> dic, string col) { object o = dic[col]; if (o == null) { return(default(A)); } if (o == DBNull.Value) { return(default(A)); } if (o is INullable) // udt's implement this guy { INullable n = o as INullable; if (n.IsNull) { return(default(A)); } } return((A)o); }
public override int CompareValueTo(int recordNo1, object value) { if (DBNull.Value == value) { value = base.NullValue; } if (this.implementsIComparable) { IComparable comparable = (IComparable)this.values[recordNo1]; return(comparable.CompareTo(value)); } if (base.NullValue != value) { throw ExceptionBuilder.IComparableNotImplemented(base.DataType.AssemblyQualifiedName); } INullable nullable = (INullable)this.values[recordNo1]; if (!nullable.IsNull) { return(1); } return(0); }
/// <summary> /// Creates a new bind parameter /// </summary> /// <param name="parameterName">Parameter name</param> /// <param name="sqlValue">Parameter initial value</param> /// <param name="type">SQL Server bind parameter type</param> /// <param name="maxSize">Maximum length for the value (if applicable), may be null for input or input/output parameters; if null, the value may be truncated by the server when storing into a smaller column</param> /// <param name="direction">Parameter type (input, output, input/output, or return value)</param> internal DBSqlServerParameter(string parameterName, INullable sqlValue, SqlDbType type, ParameterDirection direction, int?maxSize = null) { if (string.IsNullOrWhiteSpace(parameterName)) { throw new ArgumentNullException(nameof(parameterName), DBSqlServerLocalizedText.DBSqlServerParameter_InvalidName); } Parameter = new SqlParameter(); try { Parameter.ParameterName = parameterName?.Trim()?.ToUpper(); Parameter.SqlDbType = type; Parameter.Direction = direction; Parameter.Size = maxSize ?? 0; Parameter.SqlValue = sqlValue; } catch (Exception) { Close(); throw; } }
protected A GetParameterValueˡ <A>(SqlParameter param) { object o = param.Value; if (o == null) { return(default(A)); } if (o == DBNull.Value) { return(default(A)); } if (o is INullable) // udt's implement this guy { INullable n = o as INullable; if (n.IsNull) { return(default(A)); } } return((A)o); }
/// <summary> /// Get the wrapped value from an <see cref="INullable"/> (Int32 for SqlInt32, etc.) /// </summary> /// <param name="value">An INullable that is not null</param> /// <returns></returns> protected abstract object GetValue(INullable value);
protected override object GetValue(INullable value) { return ((SqlDateTime) value).Value; }
public static bool IsObjectSqlNull(object value) { INullable inullable = (value as INullable); return((null != inullable) && inullable.IsNull); }
/// <summary> /// Writes a Nullable type (generally a Sql* type) to the file. The function provided by /// <paramref name="valueWriteFunc"/> is used to write to the file if <paramref name="val"/> /// is not null. <see cref="WriteNull"/> is used if <paramref name="val"/> is null. /// </summary> /// <param name="val">The value to write to the file</param> /// <param name="valueWriteFunc">The function to use if val is not null</param> /// <returns>Number of bytes used to write value to the file</returns> private int WriteNullable(INullable val, Func <object, int> valueWriteFunc) { return(val.IsNull ? WriteNull() : valueWriteFunc(val)); }
protected override object GetValue(INullable value) { return ((SqlDecimal) value).Value; }
public static Binary ToBinary(INullable nullable) { if (nullable == null || nullable.IsNull) { return null; } // most likely first ... else if (nullable is SqlBytes) { return new Binary(((SqlBytes)nullable).Value, /*clone*/false); } else if (nullable is SqlBinary) { return new Binary(((SqlBinary)nullable).Value, /*clone*/false); } else if (nullable is SqlGuid) { return new Binary(((SqlGuid)nullable).ToByteArray(), /*clone*/false); } // then, in alphabetical order... else if (nullable is SqlBoolean) { return ToBinary(((SqlBoolean)nullable).Value); } else if (nullable is SqlByte) { return ToBinary(((SqlByte)nullable).Value); } else if (nullable is SqlChars) { ToBinary(((SqlChars)nullable).ToSqlString()); } else if (nullable is SqlDecimal) { return ToBinary(((SqlDecimal)nullable).Value); } else if (nullable is SqlDouble) { return ToBinary(((SqlDouble)nullable).Value); } if (nullable is SqlInt16) { return ToBinary(((SqlInt16)nullable).Value); } else if (nullable is SqlInt32) { return ToBinary(((SqlInt32)nullable).Value); } else if (nullable is SqlInt64) { return ToBinary(((SqlInt64)nullable).Value); } else if (nullable is SqlMoney) { return ToBinary(((SqlMoney)nullable).Value); } else if (nullable is SqlSingle) { return ToBinary(((SqlSingle)nullable).Value); } else if (nullable is SqlString) { return ToBinary(((SqlString)nullable).Value); } throw HsqlConvert.WrongDataType(nullable); }
public static JavaLong ToBigInt(INullable nullable) { if (nullable == null || nullable.IsNull) { return null; } if (nullable is SqlInt64) // most likely first { return ToBigInt(((SqlInt64)nullable).Value); } if (nullable is SqlInt32) { return ToBigInt(((SqlInt32)nullable).Value); } if (nullable is SqlInt16) { return ToBigInt(((SqlInt16)nullable).Value); } if (nullable is SqlByte) { return ToBigInt(((SqlByte)nullable).Value); } if (nullable is SqlSingle) { return ToBigInt(((SqlSingle)nullable).Value); } if (nullable is SqlDouble) { return ToBigInt(((SqlDouble)nullable).Value); } if (nullable is SqlDecimal) { try { checked { long longValue = (long) ((SqlDecimal)nullable).Value; return ToBigInt(longValue); } } catch (OverflowException) { throw HsqlConvert.NumericValueOutOfRange(nullable); } } if (nullable is SqlMoney) { try { checked { long longValue = (long) ((SqlMoney)nullable).Value; return ToBigInt(longValue); } } catch (OverflowException) { throw HsqlConvert.NumericValueOutOfRange(nullable); } } if (nullable is SqlBoolean) { return ToBigInt(((SqlBoolean)nullable).Value); } if (nullable is SqlString) { try { checked { long longValue = (long) ((SqlString)nullable).ToSqlDecimal().Value; return ToBigInt(longValue); } } catch (FormatException) { throw HsqlConvert.UnsupportedSourceDataFormat(nullable, Types.BIGINT); } catch (OverflowException) { throw HsqlConvert.NumericValueOutOfRange(nullable); } } if (nullable is SqlChars) { try { checked { long longValue = (long)((SqlChars)nullable).ToSqlString().ToSqlDecimal().Value; return ToBigInt(longValue); } } catch (FormatException) { throw HsqlConvert.UnsupportedSourceDataFormat(nullable, Types.BIGINT); } catch (OverflowException) { throw HsqlConvert.NumericValueOutOfRange(nullable); } } throw HsqlConvert.WrongDataType(nullable); }
public static JavaDouble ToReal(INullable nullable) { if (nullable == null || nullable.IsNull) { return null; } // most likely first if (nullable is SqlSingle) { return ToReal(((SqlSingle)nullable).Value); } if (nullable is SqlDouble) { return ToReal(((SqlDouble)nullable).Value); } if (nullable is SqlMoney) { return ToReal(((SqlMoney)nullable).Value); } if (nullable is SqlDecimal) { return ToReal(((SqlDecimal)nullable).Value); } // then the rest if (nullable is SqlInt64) { return ToReal(((SqlInt64)nullable).Value); } if (nullable is SqlInt32) { return ToReal(((SqlInt32)nullable).Value); } if (nullable is SqlInt16) { return ToReal(((SqlInt16)nullable).Value); } if (nullable is SqlByte) { return ToReal(((SqlByte)nullable).Value); } if (nullable is SqlBoolean) { return ToReal(((SqlBoolean)nullable).Value); } if (nullable is SqlString) { return ToReal(((SqlString)nullable).Value); } if (nullable is SqlChars) { return ToReal(((SqlChars)nullable).Value); } throw HsqlConvert.WrongDataType(nullable); }
/// <summary> /// Converts the given <see cref="INullable"/> value to an /// equivalent SQL literal value character sequence. /// <remarks> /// <para> /// Note that to be parsed as an embedded part of an SQL command /// text character sequence, the returned character sequence may /// need to be additionally converted to a specific SQL value /// literal form (i.e. prefixed and suffixed to indicate an SQL /// literal of the desired data type, possibly with occurrences of /// certain internal characters escaped using the convention /// of the target SQL environment). /// </para> /// <para> /// Because there is no guarantee that quoting conventions are /// standard or consistent across different data providers, it is /// safer and more portable to avoid such issues using parameter /// markers, allowing each provider to handle any additional /// conversions internally. /// </para> /// </summary> /// <param name="nullable"> /// To convert to an SQL literal value character sequence. /// </param> /// <returns> /// The SQL literal value character sequence corresponding to the given /// <c>nullable</c> value. /// </returns> /// <exception cref="HsqlDataSourceException"> /// When the concrete type of the given <c>INullable</c> is not handled /// </exception> public static string ToString(INullable nullable) { if (nullable == null || nullable.IsNull) { /* CHECKME: "NULL" in this context?*/ return null; } else if (nullable is SqlBinary) { return ValuePool.getString(StringConverter.byteToHex( ((SqlBinary)nullable).Value)); } else if (nullable is SqlBoolean) { return ((SqlBoolean)nullable).Value ? "TRUE" : "FALSE"; } else if (nullable is SqlByte) { return ValuePool.getString( ((SqlByte)nullable).Value.ToString()); } else if (nullable is SqlBytes) { return ValuePool.getString(StringConverter.byteToHex( ((SqlBytes)nullable).Value)); } else if (nullable is SqlChars) { return ValuePool.getString( new string(((SqlChars)nullable).Value)); } else if (nullable is SqlDateTime) { return ToString(((SqlDateTime)nullable).Value); } else if (nullable is SqlDecimal) { return ValuePool.getString( ((SqlDecimal)nullable).Value.ToString()); } else if (nullable is SqlDouble) { return ValuePool.getString( ((SqlDouble)nullable).Value.ToString()); } else if (nullable is SqlGuid) { return ValuePool.getString( ((SqlGuid)nullable).Value.ToString()); } else if (nullable is SqlInt16) { return ValuePool.getString( ((SqlInt16)nullable).Value.ToString()); } else if (nullable is SqlInt32) { return ValuePool.getString( ((SqlInt32)nullable).Value.ToString()); } else if (nullable is SqlInt64) { ValuePool.getString( ((SqlInt64)nullable).Value.ToString()); } else if (nullable is SqlMoney) { return ValuePool.getString( ((SqlMoney)nullable).Value.ToString()); } else if (nullable is SqlSingle) { return ValuePool.getString( ((SqlSingle)nullable).Value.ToString()); } else if (nullable is SqlString) { return ValuePool.getString( ((SqlString)nullable).Value); } else if (nullable is SqlXml) { return ValuePool.getString( ((SqlXml)nullable).Value); } throw HsqlConvert.WrongDataType(nullable); }
protected override object GetValue(INullable value) { return ((SqlBoolean) value).Value; }
public static JavaBoolean ToBoolean(INullable nullable) { if (nullable == null || nullable.IsNull) { return null; } //if (nullable is SqlBinary) //{ // throw HsqlConvert.WrongDataType(nullable); //} else if (nullable is SqlBoolean) { return ((SqlBoolean)nullable).Value ? TRUE : FALSE; } else if (nullable is SqlByte) { return (((SqlByte)nullable).Value == 0) ? FALSE : TRUE; } //else if (nullable is SqlBytes) //{ // throw HsqlConvert.WrongDataType(nullable); //} else if (nullable is SqlChars) { SqlChars chars = (SqlChars)nullable; return ((chars.Length == 5) && "TRUE".Equals(new string(chars.Value), IgnoreCase)) ? TRUE : FALSE; } //else if (nullable is SqlDateTime) //{ // throw HsqlConvert.WrongDataType(nullable); //} else if (nullable is SqlDecimal) { return (((SqlDecimal)nullable).Value == 0M) ? FALSE : TRUE; } else if (nullable is SqlDouble) { return (((SqlDouble)nullable).Value == 0D) ? FALSE : TRUE; } else if (nullable is SqlGuid) { return (((SqlGuid)nullable).Value == Guid.Empty) ? FALSE : TRUE; } else if (nullable is SqlInt16) { return (((SqlInt16)nullable).Value == 0) ? FALSE : TRUE; } else if (nullable is SqlInt32) { return (((SqlInt32)nullable).Value == 0) ? FALSE : TRUE; } else if (nullable is SqlInt64) { return (((SqlInt64)nullable).Value == 0L) ? FALSE : TRUE; } else if (nullable is SqlMoney) { return (((SqlMoney)nullable).Value == 0M) ? FALSE : TRUE; } else if (nullable is SqlSingle) { return (((SqlSingle)nullable).Value == 0F) ? FALSE : TRUE; } else if (nullable is SqlString) { return "TRUE".Equals(((SqlString)nullable).Value, IgnoreCase) ? TRUE : FALSE; } //else if (nullable is SqlXml) //{ // throw HsqlConvert.WrongDataType(nullable); //} throw HsqlConvert.WrongDataType(nullable); }
public static JavaTimestamp ToTimestamp(INullable nullable) { if (nullable == null || nullable.IsNull) { return null; } else if (nullable is SqlDateTime) { return ToTimestamp(((SqlDateTime)nullable).Value); } else if (nullable is SqlString) { return ToTimestamp(((SqlString)nullable).Value); } else if (nullable is SqlChars) { return ToTimestamp(((SqlChars)nullable).ToSqlString()); } throw WrongDataType(nullable); }