internal static bool Equals(SqlCollation collation, uint info, byte sortId) { if (collation is not null) { return(collation._info == info && collation._sortId == sortId); } return(false); }
internal static bool AreSame(SqlCollation a, SqlCollation b) { if (a == null || b == null) { return(a == b); } else { return(a.info == b.info && a.sortId == b.sortId); } }
internal static bool Equals(SqlCollation a, SqlCollation b) { if (a == null || b == null) { return(a == b); } else { return(a._info == b._info && a._sortId == b._sortId); } }
internal void Clear() { type = 0; oldLength = 0; newLength = 0; length = 0; newValue = null; oldValue = null; if (newBinValue != null) { Array.Clear(newBinValue, 0, newBinValue.Length); if (newBinRented) { ArrayPool <byte> .Shared.Return(newBinValue); } newBinValue = null; } if (oldBinValue != null) { Array.Clear(oldBinValue, 0, oldBinValue.Length); if (oldBinRented) { ArrayPool <byte> .Shared.Return(oldBinValue); } oldBinValue = null; } newBinRented = false; oldBinRented = false; newLongValue = 0; oldLongValue = 0; newCollation = null; oldCollation = null; newRoutingInfo = null; Next = null; }
// valid for character types: Char, VarChar, Text, NChar, NVarChar, NText internal void SetString(string value, int offset, int length) { Debug.Assert( SmiXetterAccessMap.IsSetterAccessValid(_metaData, SmiXetterTypeCode.XetString)); // ANSI types must convert to byte[] because that's the tool we have. if (MetaDataUtilsSmi.IsAnsiType(_metaData.SqlDbType)) { byte[] bytes; // Optimize for common case of writing entire string if (offset == 0 && value.Length <= length) { bytes = _stateObj.Parser._defaultEncoding.GetBytes(value); } else { char[] chars = value.ToCharArray(offset, length); bytes = _stateObj.Parser._defaultEncoding.GetBytes(chars); } SetBytes(0, bytes, 0, bytes.Length); SetBytesLength(bytes.Length); } else if (SqlDbType.Variant == _metaData.SqlDbType) { Debug.Assert(null != _variantType && SqlDbType.NVarChar == _variantType.SqlDbType, "Invalid variant type"); SqlCollation collation = new SqlCollation(); collation.LCID = checked ((int)_variantType.LocaleId); collation.SqlCompareOptions = _variantType.CompareOptions; if (length * ADP.CharSize > TdsEnums.TYPE_SIZE_LIMIT) // send as varchar for length greater than 4000 { byte[] bytes; // Optimize for common case of writing entire string if (offset == 0 && value.Length <= length) { bytes = _stateObj.Parser._defaultEncoding.GetBytes(value); } else { bytes = _stateObj.Parser._defaultEncoding.GetBytes(value.ToCharArray(offset, length)); } _stateObj.Parser.WriteSqlVariantHeader(9 + bytes.Length, TdsEnums.SQLBIGVARCHAR, 7, _stateObj); _stateObj.Parser.WriteUnsignedInt(collation.info, _stateObj); // propbytes: collation.Info _stateObj.WriteByte(collation.sortId); // propbytes: collation.SortId _stateObj.Parser.WriteShort(bytes.Length, _stateObj); // propbyte: varlen _stateObj.WriteByteArray(bytes, bytes.Length, 0); } else { _stateObj.Parser.WriteSqlVariantHeader(9 + length * ADP.CharSize, TdsEnums.SQLNVARCHAR, 7, _stateObj); _stateObj.Parser.WriteUnsignedInt(collation.info, _stateObj); // propbytes: collation.Info _stateObj.WriteByte(collation.sortId); // propbytes: collation.SortId _stateObj.Parser.WriteShort(length * ADP.CharSize, _stateObj); // propbyte: varlen _stateObj.Parser.WriteString(value, length, offset, _stateObj); } _variantType = null; } else if (_isPlp) { // Send the string as a complete PLP chunk. _stateObj.Parser.WriteLong(length * ADP.CharSize, _stateObj); // PLP total length _stateObj.Parser.WriteInt(length * ADP.CharSize, _stateObj); // Chunk length _stateObj.Parser.WriteString(value, length, offset, _stateObj); // Data if (length != 0) { _stateObj.Parser.WriteInt(TdsEnums.SQL_PLP_CHUNK_TERMINATOR, _stateObj); // Terminator } } else { _stateObj.Parser.WriteShort(length * ADP.CharSize, _stateObj); _stateObj.Parser.WriteString(value, length, offset, _stateObj); } }