Пример #1
0
        internal static SqlMetaData SmiExtendedMetaDataToSqlMetaData(SmiExtendedMetaData source)
        {
            if (SqlDbType.Xml == source.SqlDbType)
            {
                return(new SqlMetaData(source.Name,
                                       source.SqlDbType,
                                       source.MaxLength,
                                       source.Precision,
                                       source.Scale,
                                       source.LocaleId,
                                       source.CompareOptions,
                                       source.TypeSpecificNamePart1,
                                       source.TypeSpecificNamePart2,
                                       source.TypeSpecificNamePart3,
                                       true
                                       ));
            }

            return(new SqlMetaData(source.Name,
                                   source.SqlDbType,
                                   source.MaxLength,
                                   source.Precision,
                                   source.Scale,
                                   source.LocaleId,
                                   source.CompareOptions,
                                   null));
        }
 static internal bool IsValidForSmiVersion(SmiExtendedMetaData md, ulong smiVersion)
 {
     if (SmiContextFactory.LatestVersion == smiVersion)
     {
         return(true);
     }
     else
     {
         // Yukon doesn't support Structured nor the new time types
         Debug.Assert(SmiContextFactory.YukonVersion == smiVersion, "Other versions should have been eliminated during link stage");
         return(md.SqlDbType != SqlDbType.Structured &&
                md.SqlDbType != SqlDbType.Date &&
                md.SqlDbType != SqlDbType.DateTime2 &&
                md.SqlDbType != SqlDbType.DateTimeOffset &&
                md.SqlDbType != SqlDbType.Time);
     }
 }
Пример #3
0
 internal static long GetBytes( SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal, SmiExtendedMetaData metaData, long fieldOffset, byte[] buffer, int bufferOffset, int length, bool throwOnNull ) {
     // Additional exclusions not caught by GetBytesInternal
     if ( (SmiMetaData.UnlimitedMaxLengthIndicator != metaData.MaxLength &&
             (SqlDbType.VarChar == metaData.SqlDbType ||
              SqlDbType.NVarChar == metaData.SqlDbType ||
              SqlDbType.Char == metaData.SqlDbType ||
              SqlDbType.NChar == metaData.SqlDbType)) ||
             SqlDbType.Xml == metaData.SqlDbType) {
         throw SQL.NonBlobColumn(metaData.Name);
     }
     else {
         return GetBytesInternal(sink, getters, ordinal, metaData, fieldOffset, buffer, bufferOffset, length, throwOnNull);
     }
 }
Пример #4
0
        static internal SqlMetaData SmiExtendedMetaDataToSqlMetaData(SmiExtendedMetaData source)
        {
            if (SqlDbType.Xml == source.SqlDbType)
            {
                return new SqlMetaData(source.Name,
                    source.SqlDbType,
                    source.MaxLength,
                    source.Precision,
                    source.Scale,
                    source.LocaleId,
                    source.CompareOptions,
                    source.TypeSpecificNamePart1,
                    source.TypeSpecificNamePart2,
                    source.TypeSpecificNamePart3,
                    true
                    );
            }

            return new SqlMetaData(source.Name,
                source.SqlDbType,
                source.MaxLength,
                source.Precision,
                source.Scale,
                source.LocaleId,
                source.CompareOptions,
                null);
        }
Пример #5
0
 static internal bool IsValidForSmiVersion(SmiExtendedMetaData md, ulong smiVersion) {
     if (SmiContextFactory.LatestVersion == smiVersion) {
         return true;
     }
     else {
         // Yukon doesn't support Structured nor the new time types
         Debug.Assert(SmiContextFactory.YukonVersion == smiVersion, "Other versions should have been eliminated during link stage");
         return md.SqlDbType != SqlDbType.Structured &&
                 md.SqlDbType != SqlDbType.Date &&
                 md.SqlDbType != SqlDbType.DateTime2 &&
                 md.SqlDbType != SqlDbType.DateTimeOffset &&
                 md.SqlDbType != SqlDbType.Time;
     }
 }
 private static void SetIEnumerableOfSqlDataRecord_Unchecked(SmiEventSink_Default sink, SmiTypedGetterSetter setters, int ordinal, SmiMetaData metaData, IEnumerable<SqlDataRecord> value, ParameterPeekAheadValue peekAhead)
 {
     setters = setters.GetTypedGetterSetter(sink, ordinal);
     sink.ProcessMessagesAndThrow();
     IEnumerator<SqlDataRecord> enumerator = null;
     try
     {
         SmiExtendedMetaData[] array = new SmiExtendedMetaData[metaData.FieldMetaData.Count];
         metaData.FieldMetaData.CopyTo(array, 0);
         SmiDefaultFieldsProperty useDefaultValues = (SmiDefaultFieldsProperty) metaData.ExtendedProperties[SmiPropertySelector.DefaultFields];
         int recordNumber = 1;
         if ((peekAhead != null) && (peekAhead.FirstRecord != null))
         {
             enumerator = peekAhead.Enumerator;
             setters.NewElement(sink);
             sink.ProcessMessagesAndThrow();
             FillCompatibleSettersFromRecord(sink, setters, array, peekAhead.FirstRecord, useDefaultValues);
             recordNumber++;
         }
         else
         {
             enumerator = value.GetEnumerator();
         }
         using (enumerator)
         {
             while (enumerator.MoveNext())
             {
                 setters.NewElement(sink);
                 sink.ProcessMessagesAndThrow();
                 SqlDataRecord current = enumerator.Current;
                 if (current.FieldCount != array.Length)
                 {
                     throw SQL.EnumeratedRecordFieldCountChanged(recordNumber);
                 }
                 for (int i = 0; i < current.FieldCount; i++)
                 {
                     if (!MetaDataUtilsSmi.IsCompatible(metaData.FieldMetaData[i], current.GetSqlMetaData(i)))
                     {
                         throw SQL.EnumeratedRecordMetaDataChanged(current.GetName(i), recordNumber);
                     }
                 }
                 FillCompatibleSettersFromRecord(sink, setters, array, current, useDefaultValues);
                 recordNumber++;
             }
             setters.EndElements(sink);
             sink.ProcessMessagesAndThrow();
         }
     }
     finally
     {
         IDisposable disposable = enumerator;
         if (disposable != null)
         {
             disposable.Dispose();
         }
     }
 }
 internal static long GetBytes(SmiEventSink_Default sink, ITypedGettersV3 getters, int ordinal, SmiExtendedMetaData metaData, long fieldOffset, byte[] buffer, int bufferOffset, int length, bool throwOnNull)
 {
     if (((-1L != metaData.MaxLength) && (((SqlDbType.VarChar == metaData.SqlDbType) || (SqlDbType.NVarChar == metaData.SqlDbType)) || ((SqlDbType.Char == metaData.SqlDbType) || (SqlDbType.NChar == metaData.SqlDbType)))) || (SqlDbType.Xml == metaData.SqlDbType))
     {
         throw SQL.NonBlobColumn(metaData.Name);
     }
     return GetBytesInternal(sink, getters, ordinal, metaData, fieldOffset, buffer, bufferOffset, length, throwOnNull);
 }
 private void WriteTvpColumnMetaData(SmiExtendedMetaData md, bool isDefault, TdsParserStateObject stateObj)
 {
     if (SqlDbType.Timestamp == md.SqlDbType)
     {
         this.WriteUnsignedInt(80, stateObj);
     }
     else
     {
         this.WriteUnsignedInt(0, stateObj);
     }
     ushort us = 1;
     if (isDefault)
     {
         us = (ushort) (us | 0x200);
     }
     this.WriteUnsignedShort(us, stateObj);
     this.WriteSmiTypeInfo(md, stateObj);
     this.WriteIdentifier(null, stateObj);
 }
 internal virtual SmiExtendedMetaData[] GetInternalSmiMetaData()
 {
     SmiExtendedMetaData[] dataArray = null;
     _SqlMetaDataSet metaData = this.MetaData;
     if ((metaData != null) && (0 < metaData.Length))
     {
         dataArray = new SmiExtendedMetaData[metaData.visibleColumns];
         for (int i = 0; i < metaData.Length; i++)
         {
             _SqlMetaData data = metaData[i];
             if (!data.isHidden)
             {
                 SqlCollation collation = data.collation;
                 string xmlSchemaCollectionDatabase = null;
                 string xmlSchemaCollectionOwningSchema = null;
                 string xmlSchemaCollectionName = null;
                 if (SqlDbType.Xml == data.type)
                 {
                     xmlSchemaCollectionDatabase = data.xmlSchemaCollectionDatabase;
                     xmlSchemaCollectionOwningSchema = data.xmlSchemaCollectionOwningSchema;
                     xmlSchemaCollectionName = data.xmlSchemaCollectionName;
                 }
                 else if (SqlDbType.Udt == data.type)
                 {
                     SqlConnection.CheckGetExtendedUDTInfo(data, true);
                     xmlSchemaCollectionDatabase = data.udtDatabaseName;
                     xmlSchemaCollectionOwningSchema = data.udtSchemaName;
                     xmlSchemaCollectionName = data.udtTypeName;
                 }
                 int length = data.length;
                 if (length > 0x1f40)
                 {
                     length = -1;
                 }
                 else if ((SqlDbType.NChar == data.type) || (SqlDbType.NVarChar == data.type))
                 {
                     length /= ADP.CharSize;
                 }
                 dataArray[i] = new SmiQueryMetaData(data.type, (long) length, data.precision, data.scale, (collation != null) ? ((long) collation.LCID) : ((long) this._defaultLCID), (collation != null) ? collation.SqlCompareOptions : SqlCompareOptions.None, data.udtType, false, null, null, data.column, xmlSchemaCollectionDatabase, xmlSchemaCollectionOwningSchema, xmlSchemaCollectionName, data.isNullable, data.serverName, data.catalogName, data.schemaName, data.tableName, data.baseColumn, data.isKey, data.isIdentity, 0 == data.updatability, data.isExpression, data.isDifferentName, data.isHidden);
             }
         }
     }
     return dataArray;
 }
 internal static bool IsValidForSmiVersion(SmiExtendedMetaData md, ulong smiVersion)
 {
     return ((210L == smiVersion) || ((((md.SqlDbType != SqlDbType.Structured) && (md.SqlDbType != SqlDbType.Date)) && ((md.SqlDbType != SqlDbType.DateTime2) && (md.SqlDbType != SqlDbType.DateTimeOffset))) && (md.SqlDbType != SqlDbType.Time)));
 }
 internal abstract SmiRecordBuffer CreateRecordBuffer(SmiExtendedMetaData[] columnMetaData, SmiEventSink eventSink);
 internal override SmiExtendedMetaData[] GetInternalSmiMetaData()
 {
     if ((this._currentMetaData == null) || (this._visibleColumnCount == this.InternalFieldCount))
     {
         return this._currentMetaData;
     }
     SmiExtendedMetaData[] dataArray = new SmiExtendedMetaData[this._visibleColumnCount];
     for (int i = 0; i < this._visibleColumnCount; i++)
     {
         dataArray[i] = this._currentMetaData[this._indexMap[i]];
     }
     return dataArray;
 }
 internal static bool IsValidForSmiVersion(SmiExtendedMetaData md, ulong smiVersion)
 {
     return((210L == smiVersion) || ((((md.SqlDbType != SqlDbType.Structured) && (md.SqlDbType != SqlDbType.Date)) && ((md.SqlDbType != SqlDbType.DateTime2) && (md.SqlDbType != SqlDbType.DateTimeOffset))) && (md.SqlDbType != SqlDbType.Time)));
 }
 private void WriteTvpTypeInfo(SmiExtendedMetaData metaData, TdsParserStateObject stateObj)
 {
     this.WriteByte(0xf3, stateObj);
     this.WriteIdentifier(metaData.TypeSpecificNamePart1, stateObj);
     this.WriteIdentifier(metaData.TypeSpecificNamePart2, stateObj);
     this.WriteIdentifier(metaData.TypeSpecificNamePart3, stateObj);
     if (metaData.FieldMetaData.Count == 0)
     {
         this.WriteUnsignedShort(0xffff, stateObj);
     }
     else
     {
         this.WriteUnsignedShort((ushort) metaData.FieldMetaData.Count, stateObj);
         SmiDefaultFieldsProperty property = (SmiDefaultFieldsProperty) metaData.ExtendedProperties[SmiPropertySelector.DefaultFields];
         for (int i = 0; i < metaData.FieldMetaData.Count; i++)
         {
             this.WriteTvpColumnMetaData(metaData.FieldMetaData[i], property[i], stateObj);
         }
         this.WriteTvpOrderUnique(metaData, stateObj);
     }
     this.WriteByte(0, stateObj);
 }
 private void WriteTvpOrderUnique(SmiExtendedMetaData metaData, TdsParserStateObject stateObj)
 {
     SmiOrderProperty property2 = (SmiOrderProperty) metaData.ExtendedProperties[SmiPropertySelector.SortOrder];
     SmiUniqueKeyProperty property = (SmiUniqueKeyProperty) metaData.ExtendedProperties[SmiPropertySelector.UniqueKey];
     List<TdsOrderUnique> list = new List<TdsOrderUnique>(metaData.FieldMetaData.Count);
     for (int i = 0; i < metaData.FieldMetaData.Count; i++)
     {
         byte flags = 0;
         SmiOrderProperty.SmiColumnOrder order = property2[i];
         if (order.Order == SortOrder.Ascending)
         {
             flags = 1;
         }
         else if (SortOrder.Descending == order.Order)
         {
             flags = 2;
         }
         if (property[i])
         {
             flags = (byte) (flags | 4);
         }
         if (flags != 0)
         {
             list.Add(new TdsOrderUnique((short) (i + 1), flags));
         }
     }
     if (0 < list.Count)
     {
         this.WriteByte(0x10, stateObj);
         this.WriteShort(list.Count, stateObj);
         foreach (TdsOrderUnique unique in list)
         {
             this.WriteShort(unique.ColumnOrdinal, stateObj);
             this.WriteByte(unique.Flags, stateObj);
         }
     }
 }
Пример #16
0
        private static void SetIEnumerableOfSqlDataRecord_Unchecked(
            SmiEventSink_Default        sink,
            SmiTypedGetterSetter        setters,
            int                         ordinal,
            SmiMetaData                 metaData,
            IEnumerable<SqlDataRecord>  value,
            ParameterPeekAheadValue     peekAhead
            ) {
            // Get target gettersetter
            setters = setters.GetTypedGetterSetter(sink, ordinal);
            sink.ProcessMessagesAndThrow();

            IEnumerator<SqlDataRecord> enumerator = null;
            try {
                // Need to copy field metadata to an array to call FillCompatibleITypeSettersFromRecord
                SmiExtendedMetaData[] mdFields = new SmiExtendedMetaData[metaData.FieldMetaData.Count];
                metaData.FieldMetaData.CopyTo(mdFields, 0);

                SmiDefaultFieldsProperty defaults = (SmiDefaultFieldsProperty) metaData.ExtendedProperties[SmiPropertySelector.DefaultFields];

                int recordNumber = 1;   // used only for reporting position when there are errors.

                // obtain enumerator and handle any peekahead values
                if (null != peekAhead && null != peekAhead.FirstRecord) {
                    // hook up to enumerator
                    enumerator = peekAhead.Enumerator;

                    // send the first record that was obtained earlier
                    setters.NewElement(sink);
                    sink.ProcessMessagesAndThrow();
                    FillCompatibleSettersFromRecord(sink, setters, mdFields, peekAhead.FirstRecord, defaults);
                    recordNumber++;
                }
                else {
                    enumerator = value.GetEnumerator();
                }

                using (enumerator) {
                    while(enumerator.MoveNext()) {
                        setters.NewElement(sink);
                        sink.ProcessMessagesAndThrow();

                        SqlDataRecord record = enumerator.Current;

                        if (record.FieldCount != mdFields.Length) {
                            throw SQL.EnumeratedRecordFieldCountChanged(recordNumber);
                        }

                        for(int i=0; i<record.FieldCount; i++) {
                            if (!MetaDataUtilsSmi.IsCompatible(metaData.FieldMetaData[i], record.GetSqlMetaData(i))) {
                                throw SQL.EnumeratedRecordMetaDataChanged(record.GetName(i), recordNumber);
                            }
                        }

                        FillCompatibleSettersFromRecord(sink, setters, mdFields, record, defaults);
                        recordNumber++;
                    }

                    setters.EndElements(sink);
                    sink.ProcessMessagesAndThrow();
                }
            }
            finally {
                // Clean up!
                IDisposable disposable = enumerator as IDisposable;
                if (null != disposable) {
                    disposable.Dispose();
                }
            }
        }
Пример #17
0
 internal abstract SmiRecordBuffer CreateRecordBuffer (
     SmiExtendedMetaData[]   columnMetaData,     // Extended metadata because it requires names, udttypename and xmlschemaname ignored
     SmiEventSink            eventSink
 );
        private void WriteSmiTypeInfo(SmiExtendedMetaData metaData, TdsParserStateObject stateObj)
        {
            switch (metaData.SqlDbType)
            {
                case SqlDbType.BigInt:
                    this.WriteByte(0x26, stateObj);
                    this.WriteByte((byte) metaData.MaxLength, stateObj);
                    return;

                case SqlDbType.Binary:
                    this.WriteByte(0xad, stateObj);
                    this.WriteUnsignedShort((ushort) metaData.MaxLength, stateObj);
                    return;

                case SqlDbType.Bit:
                    this.WriteByte(0x68, stateObj);
                    this.WriteByte((byte) metaData.MaxLength, stateObj);
                    return;

                case SqlDbType.Char:
                    this.WriteByte(0xaf, stateObj);
                    this.WriteUnsignedShort((ushort) metaData.MaxLength, stateObj);
                    this.WriteUnsignedInt(this._defaultCollation.info, stateObj);
                    this.WriteByte(this._defaultCollation.sortId, stateObj);
                    return;

                case SqlDbType.DateTime:
                    this.WriteByte(0x6f, stateObj);
                    this.WriteByte((byte) metaData.MaxLength, stateObj);
                    return;

                case SqlDbType.Decimal:
                    this.WriteByte(0x6c, stateObj);
                    this.WriteByte((byte) MetaType.MetaDecimal.FixedLength, stateObj);
                    this.WriteByte((metaData.Precision == 0) ? ((byte) 1) : metaData.Precision, stateObj);
                    this.WriteByte(metaData.Scale, stateObj);
                    return;

                case SqlDbType.Float:
                    this.WriteByte(0x6d, stateObj);
                    this.WriteByte((byte) metaData.MaxLength, stateObj);
                    return;

                case SqlDbType.Image:
                    this.WriteByte(0xa5, stateObj);
                    this.WriteUnsignedShort(0xffff, stateObj);
                    return;

                case SqlDbType.Int:
                    this.WriteByte(0x26, stateObj);
                    this.WriteByte((byte) metaData.MaxLength, stateObj);
                    return;

                case SqlDbType.Money:
                    this.WriteByte(110, stateObj);
                    this.WriteByte((byte) metaData.MaxLength, stateObj);
                    return;

                case SqlDbType.NChar:
                    this.WriteByte(0xef, stateObj);
                    this.WriteUnsignedShort((ushort) (metaData.MaxLength * 2L), stateObj);
                    this.WriteUnsignedInt(this._defaultCollation.info, stateObj);
                    this.WriteByte(this._defaultCollation.sortId, stateObj);
                    return;

                case SqlDbType.NText:
                    this.WriteByte(0xe7, stateObj);
                    this.WriteUnsignedShort(0xffff, stateObj);
                    this.WriteUnsignedInt(this._defaultCollation.info, stateObj);
                    this.WriteByte(this._defaultCollation.sortId, stateObj);
                    return;

                case SqlDbType.NVarChar:
                    this.WriteByte(0xe7, stateObj);
                    if (-1L != metaData.MaxLength)
                    {
                        this.WriteUnsignedShort((ushort) (metaData.MaxLength * 2L), stateObj);
                        break;
                    }
                    this.WriteUnsignedShort(0xffff, stateObj);
                    break;

                case SqlDbType.Real:
                    this.WriteByte(0x6d, stateObj);
                    this.WriteByte((byte) metaData.MaxLength, stateObj);
                    return;

                case SqlDbType.UniqueIdentifier:
                    this.WriteByte(0x24, stateObj);
                    this.WriteByte((byte) metaData.MaxLength, stateObj);
                    return;

                case SqlDbType.SmallDateTime:
                    this.WriteByte(0x6f, stateObj);
                    this.WriteByte((byte) metaData.MaxLength, stateObj);
                    return;

                case SqlDbType.SmallInt:
                    this.WriteByte(0x26, stateObj);
                    this.WriteByte((byte) metaData.MaxLength, stateObj);
                    return;

                case SqlDbType.SmallMoney:
                    this.WriteByte(110, stateObj);
                    this.WriteByte((byte) metaData.MaxLength, stateObj);
                    return;

                case SqlDbType.Text:
                    this.WriteByte(0xa7, stateObj);
                    this.WriteUnsignedShort(0xffff, stateObj);
                    this.WriteUnsignedInt(this._defaultCollation.info, stateObj);
                    this.WriteByte(this._defaultCollation.sortId, stateObj);
                    return;

                case SqlDbType.Timestamp:
                    this.WriteByte(0xad, stateObj);
                    this.WriteShort((int) metaData.MaxLength, stateObj);
                    return;

                case SqlDbType.TinyInt:
                    this.WriteByte(0x26, stateObj);
                    this.WriteByte((byte) metaData.MaxLength, stateObj);
                    return;

                case SqlDbType.VarBinary:
                    this.WriteByte(0xa5, stateObj);
                    this.WriteUnsignedShort((ushort) metaData.MaxLength, stateObj);
                    return;

                case SqlDbType.VarChar:
                    this.WriteByte(0xa7, stateObj);
                    this.WriteUnsignedShort((ushort) metaData.MaxLength, stateObj);
                    this.WriteUnsignedInt(this._defaultCollation.info, stateObj);
                    this.WriteByte(this._defaultCollation.sortId, stateObj);
                    return;

                case SqlDbType.Variant:
                    this.WriteByte(0x62, stateObj);
                    this.WriteInt((int) metaData.MaxLength, stateObj);
                    return;

                case (SqlDbType.SmallInt | SqlDbType.Int):
                case (SqlDbType.Text | SqlDbType.Int):
                case (SqlDbType.Xml | SqlDbType.Bit):
                case (SqlDbType.TinyInt | SqlDbType.Int):
                    return;

                case SqlDbType.Xml:
                    this.WriteByte(0xf1, stateObj);
                    if ((!ADP.IsEmpty(metaData.TypeSpecificNamePart1) || !ADP.IsEmpty(metaData.TypeSpecificNamePart2)) || !ADP.IsEmpty(metaData.TypeSpecificNamePart3))
                    {
                        this.WriteByte(1, stateObj);
                        this.WriteIdentifier(metaData.TypeSpecificNamePart1, stateObj);
                        this.WriteIdentifier(metaData.TypeSpecificNamePart2, stateObj);
                        this.WriteIdentifierWithShortLength(metaData.TypeSpecificNamePart3, stateObj);
                        return;
                    }
                    this.WriteByte(0, stateObj);
                    return;

                case SqlDbType.Udt:
                    this.WriteByte(240, stateObj);
                    this.WriteIdentifier(metaData.TypeSpecificNamePart1, stateObj);
                    this.WriteIdentifier(metaData.TypeSpecificNamePart2, stateObj);
                    this.WriteIdentifier(metaData.TypeSpecificNamePart3, stateObj);
                    return;

                case SqlDbType.Structured:
                    if (metaData.IsMultiValued)
                    {
                        this.WriteTvpTypeInfo(metaData, stateObj);
                    }
                    return;

                case SqlDbType.Date:
                    this.WriteByte(40, stateObj);
                    return;

                case SqlDbType.Time:
                    this.WriteByte(0x29, stateObj);
                    this.WriteByte(metaData.Scale, stateObj);
                    return;

                case SqlDbType.DateTime2:
                    this.WriteByte(0x2a, stateObj);
                    this.WriteByte(metaData.Scale, stateObj);
                    return;

                case SqlDbType.DateTimeOffset:
                    this.WriteByte(0x2b, stateObj);
                    this.WriteByte(metaData.Scale, stateObj);
                    return;

                default:
                    return;
            }
            this.WriteUnsignedInt(this._defaultCollation.info, stateObj);
            this.WriteByte(this._defaultCollation.sortId, stateObj);
        }