public static SqlBinary MergePHkeys(SqlBinary oldPHkeys, SqlInt16 newSnap, SqlInt32 newPHkey) { SqlIntArray keyArray = new SqlIntArray(oldPHkeys); int[] keys = keyArray.ToArray(); keys[(short) newSnap] = (int) newPHkey; return SqlIntArray.FromArray(keys).ToSqlBuffer(); }
// non-generic methods to extract the value of a nullable type and box it public static object Box(SqlInt16 a) { if (a.IsNull) return null; else return a.Value; }
public void ArithmeticMethods () { SqlInt16 Test64 = new SqlInt16 (64); SqlInt16 Test0 = new SqlInt16 (0); SqlInt16 Test164 = new SqlInt16 (164); SqlInt16 TestMax = new SqlInt16 (SqlInt16.MaxValue.Value); // Add() Assert.AreEqual ((short) 64, SqlInt16.Add (Test64, Test0).Value, "Test#1"); Assert.AreEqual ((short) 228, SqlInt16.Add (Test64, Test164).Value, "Test#2"); Assert.AreEqual ((short) 164, SqlInt16.Add (Test0, Test164).Value, "Test#3"); Assert.AreEqual ((short) SqlInt16.MaxValue, SqlInt16.Add (TestMax, Test0).Value, "Test#4"); try { SqlInt16.Add (TestMax, Test64); Assert.Fail ("Test#5"); } catch (OverflowException e) { Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#6"); } // Divide() Assert.AreEqual ((short) 2, SqlInt16.Divide (Test164, Test64).Value, "Test#7"); Assert.AreEqual ((short) 0, SqlInt16.Divide (Test64, Test164).Value, "Test#8"); try { SqlInt16.Divide (Test64, Test0); Assert.Fail ("Test#9"); } catch (DivideByZeroException e) { Assert.AreEqual (typeof (DivideByZeroException), e.GetType (), "Test#10"); } // Mod() Assert.AreEqual ((SqlInt16) 36, SqlInt16.Mod (Test164, Test64), "Test#11"); Assert.AreEqual ((SqlInt16) 64, SqlInt16.Mod (Test64, Test164), "Test#12"); // Multiply() Assert.AreEqual ((short) 10496, SqlInt16.Multiply (Test64, Test164).Value, "Test#13"); Assert.AreEqual ((short) 0, SqlInt16.Multiply (Test64, Test0).Value, "Test#14"); try { SqlInt16.Multiply (TestMax, Test64); Assert.Fail ("Test#15"); } catch (OverflowException e) { Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#16"); } // Subtract() Assert.AreEqual ((short) 100, SqlInt16.Subtract (Test164, Test64).Value, "Test#17"); try { SqlInt16.Subtract (SqlInt16.MinValue, Test164); Assert.Fail ("Test#18"); } catch (OverflowException e) { Assert.AreEqual (typeof (OverflowException), e.GetType (), "Test#19"); } // Modulus () Assert.AreEqual ((SqlInt16)36, SqlInt16.Modulus (Test164, Test64), "Test#20"); Assert.AreEqual ((SqlInt16)64, SqlInt16.Modulus (Test64, Test164), "Test#21"); }
public static IEnumerable FindPHkeysAndSlots(SqlInt16 partsnap, SqlInt16 fofsnap, SqlString temp_partid_table_name, SqlInt32 numparts) { //string temp_partid_table = "#temp_partid_list"; List<PhkeySlot> keysAndSlots = new List<PhkeySlot>(); using (SqlConnection connection = new SqlConnection("context connection=true")) { connection.Open(); string getFoFGroupIDsCommandString = "select partid from " + temp_partid_table_name.ToString(); SqlCommand getFoFGroupIDsListCommand = new SqlCommand(getFoFGroupIDsCommandString, connection); SqlDataReader getFOFGroupIDsReader = getFoFGroupIDsListCommand.ExecuteReader(); Int64[] partids = new Int64[(int) numparts]; int numlines = 0; while (getFOFGroupIDsReader.Read()) { partids[numlines] = Int64.Parse(getFOFGroupIDsReader["partid"].ToString()); ++numlines; } getFOFGroupIDsReader.Close(); // Find the index blocks we need to look in HashSet<Int64> blocks = new HashSet<Int64>(); foreach (Int64 id in partids) { blocks.Add((id - 1) / 1024 / 1024); } //means we want all snaps string rawCommand = ""; if (partsnap < 0) { rawCommand = "select a.snap, a.phkey, a.slot from particleDB.dbo.index{0} a, " + temp_partid_table_name.ToString() + " b " + " where a.partid = b.partid"; } else { rawCommand = "select a.snap, a.phkey, a.slot from particleDB.dbo.index{0} a, " + temp_partid_table_name.ToString() + " b " + " where a.partid = b.partid and a.snap = @partsnap"; } foreach (Int64 blockID in blocks) { string joinFoFGroupIndexCommandString = string.Format(rawCommand, blockID); SqlCommand joinFofGroupIndexCommand = new SqlCommand(joinFoFGroupIndexCommandString, connection); SqlParameter partsnapParam = new SqlParameter("@partsnap", System.Data.SqlDbType.SmallInt); partsnapParam.Value = partsnap; joinFofGroupIndexCommand.Parameters.Add(partsnapParam); SqlDataReader joinReader = joinFofGroupIndexCommand.ExecuteReader(); while (joinReader.Read()) { int snap = Int32.Parse(joinReader["snap"].ToString()); int phkey = Int32.Parse(joinReader["phkey"].ToString()); short slot = Int16.Parse(joinReader["slot"].ToString()); PhkeySlot current = new PhkeySlot(snap, phkey, slot); keysAndSlots.Add(current); } joinReader.Close(); } } return keysAndSlots; }
public void Properties() { SqlInt16 Test5443 = new SqlInt16 (5443); SqlInt16 Test1 = new SqlInt16 (1); Assert ("Test#1", SqlInt16.Null.IsNull); AssertEquals ("Test#2", (short)5443, Test5443.Value); AssertEquals ("Test#3", (short)1, Test1.Value); }
public void Create () { SqlInt16 TestShort = new SqlInt16 (29); Assert.AreEqual ((short) 29, TestShort.Value, "Test#1"); TestShort = new SqlInt16 (-9000); Assert.AreEqual ((short) -9000, TestShort.Value, "Test#2"); }
public static SqlBinary MergeSlots(SqlBinary oldSlots, SqlInt16 newSnap, SqlInt16 newSlot) { //short[] slots = oldSlots.ToArray(); SqlSmallIntArray slotArray = new SqlSmallIntArray(oldSlots); short[] slots = slotArray.ToArray(); slots[(short) newSnap] = (short) newSlot; return SqlSmallIntArray.FromArray(slots).ToSqlBuffer(); }
public void Properties() { SqlInt16 Test5443 = new SqlInt16(5443); SqlInt16 Test1 = new SqlInt16(1); Assert.True(SqlInt16.Null.IsNull); Assert.Equal((short)5443, Test5443.Value); Assert.Equal((short)1, Test1.Value); }
public void Properties () { SqlInt16 Test5443 = new SqlInt16 (5443); SqlInt16 Test1 = new SqlInt16 (1); Assert.IsTrue (SqlInt16.Null.IsNull, "Test#1"); Assert.AreEqual ((short) 5443, Test5443.Value, "Test#2"); Assert.AreEqual ((short) 1, Test1.Value, "Test#3"); }
public void Create() { SqlInt16 TestShort = new SqlInt16 (29); AssertEquals ("Test#1", (short)29, TestShort.Value); TestShort = new SqlInt16 (-9000); AssertEquals ("Test#2", (short)-9000, TestShort.Value); }
public static void AddToFilterFillRow(Object obj, out SqlInt16 snap, out SqlInt32 outPHKey, out SqlBinary finalFilter, out SqlInt32 hashFunctions, out SqlInt32 expectedCap) { object[] row = (object[])obj; finalFilter = new SqlBinary((byte[])row[2]); snap = new SqlInt16((short) row[0]);// (SqlInt16)row[10]; outPHKey = new SqlInt32((int) row[1]); hashFunctions = new SqlInt32((int)row[3]); expectedCap = new SqlInt32((int)row[4]); }
public static SqlString RegexMatch(SqlString text, SqlString pattern, SqlInt16 groupIndex) { var patternValue = pattern.IsNull ? null : pattern.Value; if (patternValue == null) throw new ArgumentNullException("pattern"); var textValue = text.IsNull ? null : text.Value; if (textValue == null) return SqlString.Null; var groupIndexValue = groupIndex.IsNull ? 0 : groupIndex.Value; var match = Regex.Match(text.Value, pattern.Value, RegexOptions.Compiled /*| RegexOptions.IgnoreCase*/); if (!match.Success) return SqlString.Null; var group = match.Groups[groupIndexValue]; if (!group.Success) return SqlString.Null; return new SqlString(group.Value, text.LCID); }
public void Accumulate(SqlDouble value, SqlInt16 percentile) { // Put your code here if (value.IsNull != true) { doubleList.Add(value.Value); } if (percentile.IsNull != true) { if (percentile.Value > 100) { this.percentile = 100; } else { this.percentile = percentile.Value; } } }
// Alternative method for operator | public static SqlInt16 BitwiseOr(SqlInt16 x, SqlInt16 y) { return(x | y); }
/** * The division operator divides the first SqlInt16 operand by the second. * @param x A SqlInt16 instance. * @param y A SqlInt16 instance. * @return A SqlInt16 instance containing the results of the division operation. * If one of the parameters is null or null value - return SqlInt16.Null. */ public static SqlInt16 Divide(SqlInt16 x, SqlInt16 y) { int val = x._value / y._value; return(new SqlInt16(val)); }
public void SqlInt16ToSqlByte() { SqlInt16 TestInt1664 = new SqlInt16(64); SqlInt16 TestInt16900 = new SqlInt16(900); Assert.AreEqual((byte)64, ((SqlByte)TestInt1664).Value, "SqlInt16ToByte" + Error); try { SqlByte test = (SqlByte)TestInt16900; Assert.Fail("SqlInt16ToByte 2" + Error); } catch (Exception e) { Assert.AreEqual(typeof(OverflowException), e.GetType(), "OverflowException"); } }
// implements SqlClient 1.1-compatible GetSqlValue() semantics for everything except output parameters internal static object GetSqlValue( SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal, SmiMetaData metaData, SmiContext context ) { object result = null; if ( IsDBNull_Unchecked( sink, getters, ordinal ) ) { if (SqlDbType.Udt == metaData.SqlDbType) { result = NullUdtInstance(metaData); } else { result = __typeSpecificNullForSqlValue[(int)metaData.SqlDbType]; } } else { switch( metaData.SqlDbType ) { case SqlDbType.BigInt: result = new SqlInt64( GetInt64_Unchecked( sink, getters, ordinal ) ); break; case SqlDbType.Binary: result = GetSqlBinary_Unchecked( sink, getters, ordinal ); break; case SqlDbType.Bit: result = new SqlBoolean( GetBoolean_Unchecked( sink, getters, ordinal ) ); break; case SqlDbType.Char: result = new SqlString( GetString_Unchecked( sink, getters, ordinal ) ); break; case SqlDbType.DateTime: result = new SqlDateTime( GetDateTime_Unchecked( sink, getters, ordinal ) ); break; case SqlDbType.Decimal: result = GetSqlDecimal_Unchecked( sink, getters, ordinal ); break; case SqlDbType.Float: result = new SqlDouble( GetDouble_Unchecked( sink, getters, ordinal ) ); break; case SqlDbType.Image: result = GetSqlBinary_Unchecked( sink, getters, ordinal ); break; case SqlDbType.Int: result = new SqlInt32( GetInt32_Unchecked( sink, getters, ordinal ) ); break; case SqlDbType.Money: result = GetSqlMoney_Unchecked( sink, getters, ordinal ); break; case SqlDbType.NChar: result = new SqlString( GetString_Unchecked( sink, getters, ordinal ) ); break; case SqlDbType.NText: result = new SqlString( GetString_Unchecked( sink, getters, ordinal ) ); break; case SqlDbType.NVarChar: result = new SqlString( GetString_Unchecked( sink, getters, ordinal ) ); break; case SqlDbType.Real: result = new SqlSingle( GetSingle_Unchecked( sink, getters, ordinal ) ); break; case SqlDbType.UniqueIdentifier: result = new SqlGuid( GetGuid_Unchecked( sink, getters, ordinal ) ); break; case SqlDbType.SmallDateTime: result = new SqlDateTime( GetDateTime_Unchecked( sink, getters, ordinal ) ); break; case SqlDbType.SmallInt: result = new SqlInt16( GetInt16_Unchecked( sink, getters, ordinal ) ); break; case SqlDbType.SmallMoney: result = GetSqlMoney_Unchecked( sink, getters, ordinal ); break; case SqlDbType.Text: result = new SqlString( GetString_Unchecked( sink, getters, ordinal ) ); break; case SqlDbType.Timestamp: result = GetSqlBinary_Unchecked( sink, getters, ordinal ); break; case SqlDbType.TinyInt: result = new SqlByte( GetByte_Unchecked( sink, getters, ordinal ) ); break; case SqlDbType.VarBinary: result = GetSqlBinary_Unchecked( sink, getters, ordinal ); break; case SqlDbType.VarChar: result = new SqlString( GetString_Unchecked( sink, getters, ordinal ) ); break; case SqlDbType.Variant: metaData = getters.GetVariantType( sink, ordinal ); sink.ProcessMessagesAndThrow(); Debug.Assert( SqlDbType.Variant != metaData.SqlDbType, "Variant-within-variant causes endless recursion!" ); result = GetSqlValue( sink, getters, ordinal, metaData, context ); break; case SqlDbType.Xml: result = GetSqlXml_Unchecked( sink, getters, ordinal, context ); break; case SqlDbType.Udt: result = GetUdt_LengthChecked( sink, getters, ordinal, metaData ); break; } } return result; }
private static void SetSqlInt16_Unchecked( SmiEventSink_Default sink, ITypedSettersV3 setters, int ordinal, SqlInt16 value ) { if ( value.IsNull ) { setters.SetDBNull( sink, ordinal ); } else { setters.SetInt16( sink, ordinal, value.Value ); } sink.ProcessMessagesAndThrow(); }
/** * Converts this SqlString structure to SqlInt16. * @return A SqlInt16 structure whose Value equals the Value of this SqlString structure. */ public SqlInt16 ToSqlInt16() { return(SqlInt16.Parse(_value)); }
/** * The ones complement operator performs a bitwise one's complement operation on its SqlInt16 operand. * @param x A SqlInt16 instance * @return A SqlInt16 instance whose Value property contains the ones complement of the SqlInt16 parameter. */ public static SqlInt16 OnesComplement(SqlInt16 x) { int res = x._value ^ 0xFFFF; return(new SqlInt16(res)); }
// Alternative method for operator >= public static SqlBoolean GreaterThanOrEqual(SqlInt16 x, SqlInt16 y) { return(x >= y); }
// Alternative method for operator > public static SqlBoolean GreaterThan(SqlInt16 x, SqlInt16 y) { return(x > y); }
// Alternative method for operator != public static SqlBoolean NotEquals(SqlInt16 x, SqlInt16 y) { return(x != y); }
public int CompareTo(SqlInt16 value) { return(CompareSqlInt16(value)); }
/** * Performs a bitwise exclusive-OR operation on the supplied parameters. * @param x A SqlInt16 instance * @param y A SqlInt16 instance * @return The results of the XOR operation. */ public static SqlInt16 Xor(SqlInt16 x, SqlInt16 y) { int res = x._value ^ y._value; return(new SqlInt16(res)); }
/** * The subtraction operator the second SqlInt16 operand from the first. * @param x A SqlInt16 instance * @param y A SqlInt16 instance * @return The results of the subtraction operation. */ public static SqlInt16 Subtract(SqlInt16 x, SqlInt16 y) { int res = x._value - y._value; return(new SqlInt16(res)); }
// Alternative method for operator ^ public static SqlInt16 Xor(SqlInt16 x, SqlInt16 y) { return(x ^ y); }
// Alternative method for operator == public static SqlBoolean Equals(SqlInt16 x, SqlInt16 y) { return(x == y); }
// Alternative method for operator < public static SqlBoolean LessThan(SqlInt16 x, SqlInt16 y) { return (x < y); }
// Alternative method for operator < public static SqlBoolean LessThan(SqlInt16 x, SqlInt16 y) { return(x < y); }
// Alternative method for operator <= public static SqlBoolean LessThanOrEqual(SqlInt16 x, SqlInt16 y) { return (x <= y); }
// Alternative method for operator <= public static SqlBoolean LessThanOrEqual(SqlInt16 x, SqlInt16 y) { return(x <= y); }
public int CompareTo(SqlInt16 value) { // If both Null, consider them equal. // Otherwise, Null is less than anything. if (IsNull) return value.IsNull ? 0 : -1; else if (value.IsNull) return 1; if (this < value) return -1; if (this > value) return 1; return 0; }
// Alternative method for operator != public static SqlBoolean NotEquals(SqlInt16 x, SqlInt16 y) { return (x != y); }
public override void SetSqlInt16 (object o, SqlInt16 value) { var obj = GetObject(o); if (obj != null) _mapper.SetSqlInt16 (obj, value); }
// Alternative method for operator > public static SqlBoolean GreaterThan(SqlInt16 x, SqlInt16 y) { return (x > y); }
private Boolean ReadValues(System.IO.BinaryReader r) { Int32 count; if(r.BaseStream.Length == 0) return false; count = Sql.Read7BitEncodedInt(r); if (count == 0) return true; for (Int32 i = 0; i < count; i++) { String name = r.ReadString(); SqlDbType LType = (SqlDbType)r.ReadUInt16(); Object value = null; Int32 len; //Int32 lcid; //SqlCompareOptions co; switch (LType) { case SqlDbType.Bit : value = new SqlBoolean(r.ReadBoolean()); break; case SqlDbType.TinyInt : value = new SqlByte(r.ReadByte()); break; case SqlDbType.SmallInt : value = new SqlInt16((Int16)r.ReadInt16()); break; case SqlDbType.Int : value = new SqlInt32((Int32)r.ReadInt32()); break; case SqlDbType.BigInt : value = new SqlInt64(r.ReadInt64()); break; case SqlDbType.Binary : case SqlDbType.VarBinary: len = r.ReadUInt16(); value = new SqlBytes(r.ReadBytes(len)); break; case SqlDbType.Char : case SqlDbType.VarChar : //value = new Sql.SqlAnsiString(r); break; case SqlDbType.NChar: case SqlDbType.NVarChar: //co = (SqlCompareOptions)r.ReadUInt16(); //lcid = r.ReadInt32(); //value = new SqlString(r.ReadString(), lcid, co); value = new SqlString(r.ReadString()); break; case SqlDbType.DateTime : value = new SqlDateTime(DateTime.FromBinary(r.ReadInt64())); break; case SqlDbType.SmallDateTime: case SqlDbType.Date : case SqlDbType.DateTime2 : value = DateTime.FromBinary(r.ReadInt64()); break; case SqlDbType.Time : value = TimeSpan.FromTicks(r.ReadInt64()); break; case SqlDbType.DateTimeOffset: DateTime LDateTime = DateTime.FromBinary(r.ReadInt64()); value = new DateTimeOffset(LDateTime, TimeSpan.FromTicks(r.ReadInt64())); break; case SqlDbType.Decimal: value = new SqlDecimal(r.ReadDecimal()); break; case SqlDbType.Float : value = new SqlDouble(r.ReadDouble()); break; // Not support SqlDbType.Image case SqlDbType.Money : value = new SqlMoney(r.ReadDecimal()); break; case SqlDbType.Real : value = new SqlSingle(r.ReadDouble()); break; case SqlDbType.SmallMoney: value = new SqlMoney(r.ReadDecimal()); break; // Not support SqlDbType.Structured // Not support SqlDbType.Text // Not support SqlDbType.Timestamp case SqlDbType.UniqueIdentifier: value = new SqlGuid(r.ReadString()); break; // Not support SqlDbType.Variant case SqlDbType.Xml: XmlReader rXml = XmlReader.Create(new System.IO.StringReader(r.ReadString())); value = new SqlXml(rXml); break; case SqlDbType.Udt: // TODO: Пока поддержа только TParams //String LTypeName = r.ReadString(); //value = CreateUdtObject(LTypeName); //if (value is IBinarySerialize) // (value as IBinarySerialize).Read(r); //else // throw new Exception(String.Format("Невозможно прочитать данные типа UDT '{0}' - не поддерживается IBinarySerialize", LTypeName)); value = new SqlUdt(r); break; default: throw new Exception(String.Format("Невозможно прочитать данные, тип '{0}' не поддерживается текущей версией {1}", LType.ToString(), this.GetType().Name)); // Not support SqlDbType.NText } if (value != null) FData.Add(name, value); } return true; }
// Alternative method for operator >= public static SqlBoolean GreaterThanOrEqual(SqlInt16 x, SqlInt16 y) { return (x >= y); }
//-------------------------------------------------- // Alternative methods for overloaded operators //-------------------------------------------------- // Alternative method for operator ~ public static SqlInt16 OnesComplement(SqlInt16 x) { return(~x); }
public virtual void SetSqlInt16 (object o, SqlInt16 value) { MemberAccessor.SetSqlInt16 (o, value); }
// Alternative method for operator + public static SqlInt16 Add(SqlInt16 x, SqlInt16 y) { return(x + y); }
public void SetSqlInt16 (int i, SqlInt16 value) { throw new NotImplementedException (); }
// Alternative method for operator - public static SqlInt16 Subtract(SqlInt16 x, SqlInt16 y) { return(x - y); }
internal static void SetSqlInt16( SmiEventSink_Default sink, ITypedSettersV3 setters, int ordinal, SmiMetaData metaData, SqlInt16 value ) { ThrowIfInvalidSetterAccess( metaData, ExtendedClrTypeCode.SqlInt16 ); SetSqlInt16_Unchecked( sink, setters, ordinal, value ); }
// Alternative method for operator * public static SqlInt16 Multiply(SqlInt16 x, SqlInt16 y) { return(x * y); }
internal static SqlInt16 GetSqlInt16( SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal, SmiMetaData metaData ) { SqlInt16 result; if ( CanAccessGetterDirectly( metaData, ExtendedClrTypeCode.SqlInt16 ) ) { if ( IsDBNull_Unchecked( sink, getters, ordinal ) ) { result = SqlInt16.Null; } else { Int16 temp = GetInt16_Unchecked( sink, getters, ordinal ); result = new SqlInt16( temp ); } } else { object obj = GetSqlValue( sink, getters, ordinal, metaData, null ); if (null == obj) { throw ADP.InvalidCast(); } result = (SqlInt16) obj; } return result; }
// Alternative method for operator / public static SqlInt16 Divide(SqlInt16 x, SqlInt16 y) { return(x / y); }
public void SqlInt16ToSqlInt64 () { SqlInt16 Test64 = new SqlInt16 (64); Assert.AreEqual ((long) 64, ((SqlInt64) Test64).Value, "#AC01"); }
public static SqlInt16 Modulus(SqlInt16 x, SqlInt16 y) { return(x % y); }
public SqlInt16 Adjust(SqlInt16 value) { if (SqlDbType.SmallInt != SqlDbType) ThrowInvalidType(); return value; }
// Alternative method for operator & public static SqlInt16 BitwiseAnd(SqlInt16 x, SqlInt16 y) { return(x & y); }