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()); }
// read feature ID public static void FeatureExtAck(this TdsPackageReader reader) { while (true) { var featureId = reader.ReadByte(); if (featureId == TdsEnums.FEATUREEXT_TERMINATOR) { break; } var dataLen = reader.ReadUInt32(); var data = reader.GetBytes(checked ((int)dataLen)); if (dataLen > 0) { OnFeatureExtAck(featureId, data); } } }
public static void ParseSessionState(this TdsPackageReader reader, int length) { var sdata = reader.CurrentSession.CurrentSessionData; if (length < 5) { throw SQL.ParsingError(); } var seqNum = reader.ReadUInt32(); if (seqNum == uint.MaxValue) { reader.CurrentSession.DoNotPoolThisConnection = true; } var status = reader.ReadByte(); if (status > 1) { throw SQL.ParsingError(); } var recoverable = status != 0; length -= 5; while (length > 0) { var stateId = reader.ReadByte(); var stateLenByte = reader.ReadByte(); var stateLen = stateLenByte < 0xFF ? stateLenByte : reader.ReadInt32(); byte[] buffer = null; lock (sdata.Delta) { if (sdata.Delta[stateId] == null) { buffer = new byte[stateLen]; sdata.Delta[stateId] = new SessionStateRecord { Version = seqNum, DataLength = stateLen, Data = buffer, Recoverable = recoverable }; sdata.DeltaDirty = true; if (!recoverable) { checked { sdata.UnrecoverableStatesCount++; } } } else { if (sdata.Delta[stateId].Version <= seqNum) { var sv = sdata.Delta[stateId]; sv.Version = seqNum; sv.DataLength = stateLen; if (sv.Recoverable != recoverable) { if (recoverable) { Debug.Assert(sdata.UnrecoverableStatesCount > 0, "Unrecoverable states count >0"); sdata.UnrecoverableStatesCount--; } else { checked { sdata.UnrecoverableStatesCount++; } } sv.Recoverable = recoverable; } buffer = sv.Data; if (buffer.Length < stateLen) { buffer = new byte[stateLen]; sv.Data = buffer; } } } } if (buffer != null) { reader.ReadByteArray(buffer, 0, stateLen); } else { reader.GetBytes(stateLen); } length -= stateLenByte < 0xFF ? 2 + stateLen : 6 + stateLen; } }
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); }