private static void ReadMetadata(TdsPackageReader reader, ColumnMetadata col) { // read user type - 4 bytes Yukon, 2 backwards reader.ReadUInt32(); // read the 2 flags and set appropriate flags in structure col.Flag1 = reader.ReadByte(); col.Flag2 = reader.ReadByte(); var tdsType = col.TdsType = reader.ReadByte(); var tmp = col.MetaType = TdsMetaType.TdsTypes[tdsType]; col.IsPlp = tmp.IsPlp; col.IsTextOrImage = tmp.IsTextOrImage; var length = ReadTdsTypeLen(reader, tmp.LenBytes); if (length == TdsEnums.SQL_USHORTVARMAXLEN && tmp.LenBytes == 2) { col.IsPlp = true; } if (tdsType == TdsEnums.SQLUDT) { reader.ReadUdtMetadata(); } if (tdsType == TdsEnums.SQLXMLTYPE) { ReadXmlSchema(reader); } if (tmp.HasPrecision) { reader.ReadByte(); } if (tmp.HasScale) { col.Scale = reader.ReadByte(); } if (tmp.HasCollation) { col.Encoding = GetEncodingFromCollation(reader); } if (col.TdsType == TdsEnums.SQLTEXT || col.TdsType == TdsEnums.SQLNTEXT || col.TdsType == TdsEnums.SQLIMAGE) { ReadMultiPartTableName(reader); } col.Column = reader.ReadString(reader.ReadByte()); }
private static MetadataBulkCopy ReadMetadata(TdsPackageReader reader) { var col = new MetadataBulkCopy(); // read user type - 4 bytes Yukon, 2 backwards reader.ReadUInt32(); // read the 2 flags and set appropriate flags in structure col.Flag1 = reader.ReadByte(); col.Flag2 = reader.ReadByte(); var tdsType = reader.ReadByte(); col.TdsType = tdsType; var tmp = col.MetaType = TdsMetaType.TdsTypes[tdsType]; col.IsPlp = tmp.IsPlp; col.IsTextOrImage = tmp.IsTextOrImage; var length = col.Length = reader.ReadTdsTypeLen(tmp.LenBytes); if (length == TdsEnums.SQL_USHORTVARMAXLEN && tmp.LenBytes == 2) { col.IsPlp = true; } if (tdsType == TdsEnums.SQLUDT) { reader.ReadUdtMetadata(); } if (tdsType == TdsEnums.SQLXMLTYPE) { reader.ReadXmlSchema(); } if (tmp.HasPrecision) { col.Precision = reader.ReadByte(); } if (tmp.HasScale) { col.Scale = reader.ReadByte(); } if (tmp.HasCollation) { col.Collation = reader.ReadCollation(); col.Encoding = reader.CurrentSession.GetEncodingFromCache(col.Collation.GetCodePage()); } if (col.IsTextOrImage) { col.PartTableName = reader.ReadMultiPartTableName(); } //bulkcopy typeCorrection if (tdsType == TdsEnums.SQLXMLTYPE) { col.TdsType = TdsEnums.SQLNVARCHAR; col.Length = TdsEnums.SQL_USHORTVARMAXLEN; col.Collation = new SqlCollations(); } if (tdsType == TdsEnums.SQLUDT) { col.TdsType = TdsEnums.SQLBIGVARBINARY; col.Length = TdsEnums.SQL_USHORTVARMAXLEN; } col.Column = reader.ReadString(reader.ReadByte()); return(col); }