Пример #1
0
        // valid for DateTimeOffset
        internal void SetDateTimeOffset(DateTimeOffset value)
        {
            Debug.Assert(
                SmiXetterAccessMap.IsSetterAccessValid(_metaData, SmiXetterTypeCode.XetDateTimeOffset));
            byte scale;
            byte length;

            if (SqlDbType.Variant == _metaData.SqlDbType)
            {
                // VSTFDevDiv #885208 - DateTimeOffset throws ArgumentException for when passing DateTimeOffset value to a sql_variant TVP
                //                      using a SqlDataRecord or SqlDataReader
                MSS.SmiMetaData dateTimeOffsetMetaData = MSS.SmiMetaData.DefaultDateTimeOffset;
                scale  = MetaType.MetaDateTimeOffset.Scale;
                length = (byte)dateTimeOffsetMetaData.MaxLength;
                _stateObj.Parser.WriteSqlVariantHeader(13, TdsEnums.SQLDATETIMEOFFSET, 1, _stateObj);
                _stateObj.WriteByte(scale); //propbytes: scale
            }
            else
            {
                scale  = _metaData.Scale;
                length = (byte)_metaData.MaxLength;
                _stateObj.WriteByte(length);
            }
            DateTime utcDateTime = value.UtcDateTime;
            Int64    time        = utcDateTime.TimeOfDay.Ticks / TdsEnums.TICKS_FROM_SCALE[scale];
            int      days        = utcDateTime.Subtract(DateTime.MinValue).Days;
            Int16    offset      = (Int16)value.Offset.TotalMinutes;

            _stateObj.WriteByteArray(BitConverter.GetBytes(time), length - 5, 0); // time
            _stateObj.WriteByteArray(BitConverter.GetBytes(days), 3, 0);          // date
            _stateObj.WriteByte((byte)(offset & 0xff));                           // offset byte 1
            _stateObj.WriteByte((byte)((offset >> 8) & 0xff));                    // offset byte 2
        }
Пример #2
0
        public virtual object GetSqlValue(int ordinal)
        {
            EnsureSubclassOverride();
            SmiMetaData metaData = GetSmiMetaData(ordinal);

            return(ValueUtilsSmi.GetSqlValue200(_eventSink, _recordBuffer, ordinal, metaData));
        }
Пример #3
0
        internal static bool IsSetterAccessValid(SmiMetaData metaData, SmiXetterTypeCode xetterType)
        {
            // Make sure no-one adds a new xetter type without updating this file!
            Debug.Assert(SmiXetterTypeCode.XetBoolean <= xetterType && SmiXetterTypeCode.XetDateTimeOffset >= xetterType &&
                         SmiXetterTypeCode.GetVariantMetaData != xetterType);

            return(s_isSetterAccessValid[(int)metaData.SqlDbType, (int)xetterType]);
        }
Пример #4
0
 // Does this type use PLP format values?
 internal static bool IsPlpFormat(SmiMetaData metaData)
 {
     return(metaData.MaxLength == SmiMetaData.UnlimitedMaxLengthIndicator ||
            metaData.SqlDbType == SqlDbType.Image ||
            metaData.SqlDbType == SqlDbType.NText ||
            metaData.SqlDbType == SqlDbType.Text ||
            metaData.SqlDbType == SqlDbType.Udt);
 }
Пример #5
0
        public virtual void SetVariantMetaData(SmiEventSink sink, int ordinal, SmiMetaData metaData)
        {
            // ******** OBSOLETING from SMI -- this should have been removed from ITypedSettersV3
            //  Intended to be removed prior to RTM.  Sub-classes need not implement

            // Implement body with throw because there are only a couple of ways to get to this code:
            //  1) Client is calling this method even though the server negotiated for V3+ and dropped support for V2-.
            //  2) Server didn't implement V2- on some interface and negotiated V2-.
            throw System.Data.Common.Custom.ADP.InternalError(System.Data.Common.Custom.ADP.InternalErrorCode.UnimplementedSMIMethod);
        }
Пример #6
0
 // compare SmiMetaData to SqlMetaData and determine if they are compatible.
 static internal bool IsCompatible(SmiMetaData firstMd, SqlMetaData secondMd)
 {
     return(firstMd.SqlDbType == secondMd.SqlDbType &&
            firstMd.MaxLength == secondMd.MaxLength &&
            firstMd.Precision == secondMd.Precision &&
            firstMd.Scale == secondMd.Scale &&
            firstMd.CompareOptions == secondMd.CompareOptions &&
            firstMd.LocaleId == secondMd.LocaleId &&
            firstMd.SqlDbType != SqlDbType.Structured && // SqlMetaData doesn't support Structured types
            !firstMd.IsMultiValued);                     // SqlMetaData doesn't have a "multivalued" option
 }
Пример #7
0
        internal SmiGettersStream(SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal, SmiMetaData metaData)
        {
            Debug.Assert(null != sink);
            Debug.Assert(null != getters);
            Debug.Assert(0 <= ordinal);
            Debug.Assert(null != metaData);

            _sink         = sink;
            _getters      = getters;
            _ordinal      = ordinal;
            _readPosition = 0;
            _metaData     = metaData;
        }
Пример #8
0
        internal SmiSettersStream(SmiEventSink_Default sink, ITypedSettersV3 setters, int ordinal, SmiMetaData metaData)
        {
            Debug.Assert(null != sink);
            Debug.Assert(null != setters);
            Debug.Assert(0 <= ordinal);
            Debug.Assert(null != metaData);

            _sink          = sink;
            _setters       = setters;
            _ordinal       = ordinal;
            _lengthWritten = 0;
            _metaData      = metaData;
        }
Пример #9
0
        // Internal setter to be used by constructors only!  Modifies state!
        private void SetDefaultsForType(SqlDbType dbType)
        {
            SmiMetaData smdDflt = GetDefaultForType(dbType);

            _databaseType       = dbType;
            _maxLength          = smdDflt.MaxLength;
            _precision          = smdDflt.Precision;
            _scale              = smdDflt.Scale;
            _localeId           = smdDflt.LocaleId;
            _compareOptions     = smdDflt.CompareOptions;
            _isMultiValued      = smdDflt._isMultiValued;
            _fieldMetaData      = smdDflt._fieldMetaData;       // This is ok due to immutability
            _extendedProperties = smdDflt._extendedProperties;  // This is ok due to immutability
        }
Пример #10
0
        public virtual string GetString(int ordinal)
        {
            EnsureSubclassOverride();
            SmiMetaData colMeta = GetSmiMetaData(ordinal);

            if (_usesStringStorageForXml && SqlDbType.Xml == colMeta.SqlDbType)
            {
                return(ValueUtilsSmi.GetString(_eventSink, _recordBuffer, ordinal, s_maxNVarCharForXml));
            }
            else
            {
                return(ValueUtilsSmi.GetString(_eventSink, _recordBuffer, ordinal, GetSmiMetaData(ordinal)));
            }
        }
Пример #11
0
 // valid for SqlDbType.Variant
 public override void SetVariantMetaData(SmiEventSink sink, int ordinal, SmiMetaData metaData)
 {
     _buffer[ordinal].VariantType = metaData;
 }
Пример #12
0
        private bool _isMetaSet;       // flag to indicate whether we have set the variant metadata

        internal SqlRecordBuffer(SmiMetaData metaData)
        {
            _isNull = true;
        }
Пример #13
0
        // This is a modified version of SmiMetaDataFromSchemaTableRow above
        // Since CoreCLR doesn't have GetSchema, we need to infer the MetaData from the CLR Type alone
        static internal SmiExtendedMetaData SmiMetaDataFromType(string colName, Type colType)
        {
            // Determine correct SqlDbType.
            SqlDbType colDbType = InferSqlDbTypeFromType_Katmai(colType);

            if (InvalidSqlDbType == colDbType)
            {
                // Unknown through standard mapping, use VarBinary for columns that are Object typed, otherwise we error out.
                if (typeof(object) == colType)
                {
                    colDbType = SqlDbType.VarBinary;
                }
                else
                {
                    throw SQL.UnsupportedColumnTypeForSqlProvider(colName, colType.ToString());
                }
            }

            // Determine metadata modifier values per type (maxlength, precision, scale, etc)
            long maxLength = 0;
            byte precision = 0;
            byte scale     = 0;

            switch (colDbType)
            {
            case SqlDbType.BigInt:
            case SqlDbType.Bit:
            case SqlDbType.DateTime:
            case SqlDbType.Float:
            case SqlDbType.Image:
            case SqlDbType.Int:
            case SqlDbType.Money:
            case SqlDbType.NText:
            case SqlDbType.Real:
            case SqlDbType.UniqueIdentifier:
            case SqlDbType.SmallDateTime:
            case SqlDbType.SmallInt:
            case SqlDbType.SmallMoney:
            case SqlDbType.Text:
            case SqlDbType.Timestamp:
            case SqlDbType.TinyInt:
            case SqlDbType.Variant:
            case SqlDbType.Xml:
            case SqlDbType.Date:
                // These types require no  metadata modifiers
                break;

            case SqlDbType.Binary:
            case SqlDbType.VarBinary:
                // source isn't specifying a size, so assume the Maximum
                if (SqlDbType.Binary == colDbType)
                {
                    maxLength = SmiMetaData.MaxBinaryLength;
                }
                else
                {
                    maxLength = SmiMetaData.UnlimitedMaxLengthIndicator;
                }
                break;

            case SqlDbType.Char:
            case SqlDbType.VarChar:
                // source isn't specifying a size, so assume the Maximum
                if (SqlDbType.Char == colDbType)
                {
                    maxLength = SmiMetaData.MaxANSICharacters;
                }
                else
                {
                    maxLength = SmiMetaData.UnlimitedMaxLengthIndicator;
                }
                break;

            case SqlDbType.NChar:
            case SqlDbType.NVarChar:
                // source isn't specifying a size, so assume the Maximum
                if (SqlDbType.NChar == colDbType)
                {
                    maxLength = SmiMetaData.MaxUnicodeCharacters;
                }
                else
                {
                    maxLength = SmiMetaData.UnlimitedMaxLengthIndicator;
                }
                break;

            case SqlDbType.Decimal:
                // Decimal requires precision and scale
                precision = SmiMetaData.DefaultDecimal.Precision;
                scale     = SmiMetaData.DefaultDecimal.Scale;
                break;

            case SqlDbType.Time:
            case SqlDbType.DateTime2:
            case SqlDbType.DateTimeOffset:
                // requires scale
                scale = SmiMetaData.DefaultTime.Scale;
                break;

            case SqlDbType.Udt:
            case SqlDbType.Structured:
            default:
                // These types are not supported from SchemaTable
                throw SQL.UnsupportedColumnTypeForSqlProvider(colName, colType.ToString());
            }

            return(new SmiExtendedMetaData(
                       colDbType,
                       maxLength,
                       precision,
                       scale,
                       Locale.GetCurrentCultureLcid(),
                       SmiMetaData.GetDefaultForType(colDbType).CompareOptions,
                       false,                   // no support for multi-valued columns in a TVP yet
                       null,                    // no support for structured columns yet
                       null,
                       colName,
                       null,
                       null,
                       null));
        }