本文整理汇总了C#中System.Data.SqlClient.TdsParserStateObject.TrySkipBytes方法的典型用法代码示例。如果您正苦于以下问题:C# TdsParserStateObject.TrySkipBytes方法的具体用法?C# TdsParserStateObject.TrySkipBytes怎么用?C# TdsParserStateObject.TrySkipBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.SqlClient.TdsParserStateObject
的用法示例。
在下文中一共展示了TdsParserStateObject.TrySkipBytes方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryReadSqlVariant
//
// Read in a SQLVariant
//
// SQLVariant looks like:
// struct
// {
// BYTE TypeTag
// BYTE cbPropBytes
// BYTE[] Properties
// BYTE[] DataVal
// }
internal bool TryReadSqlVariant(SqlBuffer value, int lenTotal, TdsParserStateObject stateObj)
{
// get the SQLVariant type
byte type;
if (!stateObj.TryReadByte(out type))
{
return false;
}
ushort lenMax = 0; // maximum lenData of value inside variant
// read cbPropBytes
byte cbPropsActual;
if (!stateObj.TryReadByte(out cbPropsActual))
{
return false;
}
MetaType mt = MetaType.GetSqlDataType(type, 0 /*no user datatype*/, 0 /* no lenData, non-nullable type */);
byte cbPropsExpected = mt.PropBytes;
int lenConsumed = TdsEnums.SQLVARIANT_SIZE + cbPropsActual; // type, count of propBytes, and actual propBytes
int lenData = lenTotal - lenConsumed; // length of actual data
// read known properties and skip unknown properties
Debug.Assert(cbPropsActual >= cbPropsExpected, "cbPropsActual is less that cbPropsExpected!");
//
// now read the value
//
switch (type)
{
case TdsEnums.SQLBIT:
case TdsEnums.SQLINT1:
case TdsEnums.SQLINT2:
case TdsEnums.SQLINT4:
case TdsEnums.SQLINT8:
case TdsEnums.SQLFLT4:
case TdsEnums.SQLFLT8:
case TdsEnums.SQLMONEY:
case TdsEnums.SQLMONEY4:
case TdsEnums.SQLDATETIME:
case TdsEnums.SQLDATETIM4:
case TdsEnums.SQLUNIQUEID:
if (!TryReadSqlValueInternal(value, type, lenData, stateObj))
{
return false;
}
break;
case TdsEnums.SQLDECIMALN:
case TdsEnums.SQLNUMERICN:
{
Debug.Assert(cbPropsExpected == 2, "SqlVariant: invalid PropBytes for decimal/numeric type!");
byte precision;
if (!stateObj.TryReadByte(out precision))
{
return false;
}
byte scale;
if (!stateObj.TryReadByte(out scale))
{
return false;
}
// skip over unknown properties
if (cbPropsActual > cbPropsExpected)
{
if (!stateObj.TrySkipBytes(cbPropsActual - cbPropsExpected))
{
return false;
}
}
if (!TryReadSqlDecimal(value, TdsEnums.MAX_NUMERIC_LEN, precision, scale, stateObj))
{
return false;
}
break;
}
case TdsEnums.SQLBIGBINARY:
case TdsEnums.SQLBIGVARBINARY:
//Debug.Assert(TdsEnums.VARNULL == lenData, "SqlVariant: data length for Binary indicates null?");
Debug.Assert(cbPropsExpected == 2, "SqlVariant: invalid PropBytes for binary type!");
if (!stateObj.TryReadUInt16(out lenMax))
{
return false;
}
//.........这里部分代码省略.........
示例2: TrySkipPlpValue
internal bool TrySkipPlpValue(ulong cb, TdsParserStateObject stateObj, out ulong totalBytesSkipped)
{
// Read and skip cb bytes or until ReadPlpLength returns 0.
int bytesSkipped;
totalBytesSkipped = 0;
if (stateObj._longlenleft == 0)
{
ulong ignored;
if (!stateObj.TryReadPlpLength(false, out ignored))
{
return false;
}
}
while ((totalBytesSkipped < cb) &&
(stateObj._longlenleft > 0))
{
if (stateObj._longlenleft > Int32.MaxValue)
bytesSkipped = Int32.MaxValue;
else
bytesSkipped = (int)stateObj._longlenleft;
bytesSkipped = ((cb - totalBytesSkipped) < (ulong)bytesSkipped) ? (int)(cb - totalBytesSkipped) : bytesSkipped;
if (!stateObj.TrySkipBytes(bytesSkipped))
{
return false;
}
stateObj._longlenleft -= (ulong)bytesSkipped;
totalBytesSkipped += (ulong)bytesSkipped;
if (stateObj._longlenleft == 0)
{
ulong ignored;
if (!stateObj.TryReadPlpLength(false, out ignored))
{
return false;
}
}
}
return true;
}
示例3: TryProcessColumnHeaderNoNBC
private bool TryProcessColumnHeaderNoNBC(SqlMetaDataPriv col, TdsParserStateObject stateObj, out bool isNull, out ulong length)
{
if (col.metaType.IsLong && !col.metaType.IsPlp)
{
//
// we don't care about TextPtrs, simply go after the data after it
//
byte textPtrLen;
if (!stateObj.TryReadByte(out textPtrLen))
{
isNull = false;
length = 0;
return false;
}
if (0 != textPtrLen)
{
// read past text pointer
if (!stateObj.TrySkipBytes(textPtrLen))
{
isNull = false;
length = 0;
return false;
}
// read past timestamp
if (!stateObj.TrySkipBytes(TdsEnums.TEXT_TIME_STAMP_LEN))
{
isNull = false;
length = 0;
return false;
}
isNull = false;
return TryGetDataLength(col, stateObj, out length);
}
else
{
isNull = true;
length = 0;
return true;
}
}
else
{
// non-blob columns
ulong longlen;
if (!TryGetDataLength(col, stateObj, out longlen))
{
isNull = false;
length = 0;
return false;
}
isNull = IsNull(col.metaType, longlen);
length = (isNull ? 0 : longlen);
return true;
}
}
示例4: TrySkipValue
/// <summary>
/// This method skips bytes of a single column value from the media. It supports NBCROW and handles all types of values, including PLP and long
/// </summary>
internal bool TrySkipValue(SqlMetaDataPriv md, int columnOrdinal, TdsParserStateObject stateObj)
{
if (stateObj.IsNullCompressionBitSet(columnOrdinal))
{
return true;
}
if (md.metaType.IsPlp)
{
ulong ignored;
if (!TrySkipPlpValue(UInt64.MaxValue, stateObj, out ignored))
{
return false;
}
}
else if (md.metaType.IsLong)
{
Debug.Assert(!md.metaType.IsPlp, "Plp types must be handled using SkipPlpValue");
byte textPtrLen;
if (!stateObj.TryReadByte(out textPtrLen))
{
return false;
}
if (0 != textPtrLen)
{
if (!stateObj.TrySkipBytes(textPtrLen + TdsEnums.TEXT_TIME_STAMP_LEN))
{
return false;
}
int length;
if (!TryGetTokenLength(md.tdsType, stateObj, out length))
{
return false;
}
if (!stateObj.TrySkipBytes(length))
{
return false;
}
}
}
else
{
int length;
if (!TryGetTokenLength(md.tdsType, stateObj, out length))
{
return false;
}
// if false, no value to skip - it's null
if (!IsNull(md.metaType, (ulong)length))
{
if (!stateObj.TrySkipBytes(length))
{
return false;
}
}
}
return true;
}
示例5: TryProcessAltMetaData
internal bool TryProcessAltMetaData(int cColumns, TdsParserStateObject stateObj, out _SqlMetaDataSet metaData)
{
Debug.Assert(cColumns > 0, "should have at least 1 column in altMetaData!");
metaData = null;
_SqlMetaDataSet altMetaDataSet = new _SqlMetaDataSet(cColumns);
int[] indexMap = new int[cColumns];
if (!stateObj.TryReadUInt16(out altMetaDataSet.id))
{
return false;
}
byte byCols;
if (!stateObj.TryReadByte(out byCols))
{
return false;
}
while (byCols > 0)
{
if (!stateObj.TrySkipBytes(2))
{ // ignore ColNum ...
return false;
}
byCols--;
}
// pass 1, read the meta data off the wire
for (int i = 0; i < cColumns; i++)
{
// internal meta data class
_SqlMetaData col = altMetaDataSet[i];
byte op;
if (!stateObj.TryReadByte(out op))
{
return false;
}
ushort operand;
if (!stateObj.TryReadUInt16(out operand))
{
return false;
}
if (!TryCommonProcessMetaData(stateObj, col))
{
return false;
}
indexMap[i] = i;
}
altMetaDataSet.indexMap = indexMap;
altMetaDataSet.visibleColumns = cColumns;
metaData = altMetaDataSet;
return true;
}
示例6: TryProcessColInfo
// augments current metadata with table and key information
private bool TryProcessColInfo(_SqlMetaDataSet columns, SqlDataReader reader, TdsParserStateObject stateObj, out _SqlMetaDataSet metaData)
{
Debug.Assert(columns != null && columns.Length > 0, "no metadata available!");
metaData = null;
for (int i = 0; i < columns.Length; i++)
{
_SqlMetaData col = columns[i];
byte ignored;
if (!stateObj.TryReadByte(out ignored))
{ // colnum, ignore
return false;
}
if (!stateObj.TryReadByte(out ignored))
{ // tablenum, ignore
return false;
}
// interpret status
byte status;
if (!stateObj.TryReadByte(out status))
{
return false;
}
col.isKey = (TdsEnums.SQLKey == (status & TdsEnums.SQLKey));
col.isHidden = (TdsEnums.SQLHidden == (status & TdsEnums.SQLHidden));
// read off the base table name if it is different than the select list column name
if (TdsEnums.SQLDifferentName == (status & TdsEnums.SQLDifferentName))
{
byte len;
if (!stateObj.TryReadByte(out len))
{
return false;
}
if (!stateObj.TrySkipBytes(len * ADP.CharSize))
{
return false;
}
}
if (TdsEnums.SQLExpression == (status & TdsEnums.SQLExpression))
{
col.updatability = 0;
}
}
// set the metadata so that the stream knows some metadata info has changed
metaData = columns;
return true;
}
示例7: TryProcessLoginAck
private bool TryProcessLoginAck(TdsParserStateObject stateObj, out SqlLoginAck sqlLoginAck)
{
SqlLoginAck a = new SqlLoginAck();
sqlLoginAck = null;
// read past interface type and version
if (!stateObj.TrySkipBytes(1))
{
return false;
}
byte[] b = new byte[TdsEnums.VERSION_SIZE];
if (!stateObj.TryReadByteArray(b, 0, b.Length))
{
return false;
}
a.tdsVersion = (UInt32)((((((b[0] << 8) | b[1]) << 8) | b[2]) << 8) | b[3]); // bytes are in motorola order (high byte first)
UInt32 majorMinor = a.tdsVersion & 0xff00ffff;
UInt32 increment = (a.tdsVersion >> 16) & 0xff;
// Server responds:
// 0x07000000 -> Sphinx // Notice server response format is different for bwd compat
// 0x07010000 -> Shiloh RTM // Notice server response format is different for bwd compat
// 0x71000001 -> Shiloh SP1
// 0x72xx0002 -> Yukon RTM
// information provided by S. Ashwin
switch (majorMinor)
{
case TdsEnums.YUKON_MAJOR << 24 | TdsEnums.YUKON_RTM_MINOR: // Yukon
if (increment != TdsEnums.YUKON_INCREMENT) { throw SQL.InvalidTDSVersion(); }
break;
case TdsEnums.KATMAI_MAJOR << 24 | TdsEnums.KATMAI_MINOR:
if (increment != TdsEnums.KATMAI_INCREMENT) { throw SQL.InvalidTDSVersion(); }
_isKatmai = true;
break;
case TdsEnums.DENALI_MAJOR << 24 | TdsEnums.DENALI_MINOR:
if (increment != TdsEnums.DENALI_INCREMENT) { throw SQL.InvalidTDSVersion(); }
_isDenali = true;
break;
default:
throw SQL.InvalidTDSVersion();
}
_isKatmai |= _isDenali;
stateObj._outBytesUsed = stateObj._outputHeaderLen;
byte len;
if (!stateObj.TryReadByte(out len))
{
return false;
}
if (!stateObj.TrySkipBytes(len * ADP.CharSize))
{
return false;
}
if (!stateObj.TryReadByte(out a.majorVersion))
{
return false;
}
if (!stateObj.TryReadByte(out a.minorVersion))
{
return false;
}
byte buildNumHi, buildNumLo;
if (!stateObj.TryReadByte(out buildNumHi))
{
return false;
}
if (!stateObj.TryReadByte(out buildNumLo))
{
return false;
}
a.buildNum = (short)((buildNumHi << 8) + buildNumLo);
Debug.Assert(_state == TdsParserState.OpenNotLoggedIn, "ProcessLoginAck called with state not TdsParserState.OpenNotLoggedIn");
_state = TdsParserState.OpenLoggedIn;
{
if (_fMARS)
{
_resetConnectionEvent = new AutoResetEvent(true);
}
}
// Fail if SSE UserInstance and we have not received this info.
if (_connHandler.ConnectionOptions.UserInstance &&
ADP.IsEmpty(_connHandler.InstanceName))
{
stateObj.AddError(new SqlError(0, 0, TdsEnums.FATAL_ERROR_CLASS, Server, SQLMessage.UserInstanceFailure(), "", 0));
ThrowExceptionAndWarning(stateObj);
}
sqlLoginAck = a;
return true;
}
示例8: TryProcessSessionState
//.........这里部分代码省略.........
return false;
}
if (status > 1)
{
throw SQL.ParsingError();
}
bool recoverable = status != 0;
length -= 5;
while (length > 0)
{
byte stateId;
if (!stateObj.TryReadByte(out stateId))
{
return false;
}
int stateLen;
byte stateLenByte;
if (!stateObj.TryReadByte(out stateLenByte))
{
return false;
}
if (stateLenByte < 0xFF)
{
stateLen = stateLenByte;
}
else
{
if (!stateObj.TryReadInt32(out stateLen))
{
return false;
}
}
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)
{
SessionStateRecord 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)
{
if (!stateObj.TryReadByteArray(buffer, 0, stateLen))
{
return false;
}
}
else
{
if (!stateObj.TrySkipBytes(stateLen))
return false;
}
if (stateLenByte < 0xFF)
{
length -= 2 + stateLen;
}
else
{
length -= 6 + stateLen;
}
}
sdata.AssertUnrecoverableStateCountIsCorrect();
return true;
}
示例9: TryProcessEnvChange
//.........这里部分代码省略.........
Debug.Assert(env.oldLength == 0 || env.oldLength == 8, "Improper length for old transaction id!");
if (env.oldLength > 0)
{
if (!stateObj.TryReadInt64(out env.oldLongValue))
{
return false;
}
Debug.Assert(env.oldLongValue != SqlInternalTransaction.NullTransactionId, "Old transaction id is null?"); // the server guarantees that zero is an invalid transaction id.
}
else
{
env.oldLongValue = SqlInternalTransaction.NullTransactionId; // the server guarantees that zero is an invalid transaction id.
}
// env.length includes 1 byte type token
env.length = 3 + env.newLength + env.oldLength;
break;
case TdsEnums.ENV_LOGSHIPNODE:
// env.newBinValue is secondary node, env.oldBinValue is witness node
// comes before LoginAck so we can't assert this
if (!TryReadTwoStringFields(env, stateObj))
{
return false;
}
break;
case TdsEnums.ENV_SPRESETCONNECTIONACK:
if (!TryReadTwoBinaryFields(env, stateObj))
{
return false;
}
break;
case TdsEnums.ENV_USERINSTANCE:
if (!TryReadTwoStringFields(env, stateObj))
{
return false;
}
break;
case TdsEnums.ENV_ROUTING:
ushort newLength;
if (!stateObj.TryReadUInt16(out newLength))
{
return false;
}
env.newLength = newLength;
byte protocol;
if (!stateObj.TryReadByte(out protocol))
{
return false;
}
ushort port;
if (!stateObj.TryReadUInt16(out port))
{
return false;
}
UInt16 serverLen;
if (!stateObj.TryReadUInt16(out serverLen))
{
return false;
}
string serverName;
if (!stateObj.TryReadString(serverLen, out serverName))
{
return false;
}
env.newRoutingInfo = new RoutingInfo(protocol, port, serverName);
UInt16 oldLength;
if (!stateObj.TryReadUInt16(out oldLength))
{
return false;
}
if (!stateObj.TrySkipBytes(oldLength))
{
return false;
}
env.length = env.newLength + oldLength + 5; // 5=2*sizeof(UInt16)+sizeof(byte) [token+newLength+oldLength]
break;
// ENVCHANGE tokens not supported by CoreCLR
case TdsEnums.ENV_ENLISTDTC:
case TdsEnums.ENV_DEFECTDTC:
case TdsEnums.ENV_TRANSACTIONENDED:
case TdsEnums.ENV_PROMOTETRANSACTION:
case TdsEnums.ENV_TRANSACTIONMANAGERADDRESS:
throw SQL.UnsupportedFeatureAndToken(_connHandler, ((TdsEnums.EnvChangeType)env.type).ToString());
default:
Debug.Assert(false, "Unknown environment change token: " + env.type);
break;
}
processedLength += env.length;
}
sqlEnvChange = envarray;
return true;
}
示例10: TryRun
//.........这里部分代码省略.........
stateObj.AddError(error);
// Else we have a fatal error and we need to change the behavior
// since we want the complete error information in the exception.
// Besides - no further results will be received.
runBehavior = RunBehavior.UntilDone;
}
}
}
else if (error.Class >= TdsEnums.FATAL_ERROR_CLASS)
{
stateObj.AddError(error);
}
break;
}
case TdsEnums.SQLCOLINFO:
{
if (null != dataStream)
{
_SqlMetaDataSet metaDataSet;
if (!TryProcessColInfo(dataStream.MetaData, dataStream, stateObj, out metaDataSet))
{
return false;
}
if (!dataStream.TrySetMetaData(metaDataSet, false))
{
return false;
}
dataStream.BrowseModeInfoConsumed = true;
}
else
{ // no dataStream
if (!stateObj.TrySkipBytes(tokenLength))
{
return false;
}
}
break;
}
case TdsEnums.SQLDONE:
case TdsEnums.SQLDONEPROC:
case TdsEnums.SQLDONEINPROC:
{
// RunBehavior can be modified
if (!TryProcessDone(cmdHandler, dataStream, ref runBehavior, stateObj))
{
return false;
}
if ((token == TdsEnums.SQLDONEPROC) && (cmdHandler != null))
{
cmdHandler.OnDoneProc();
}
break;
}
case TdsEnums.SQLORDER:
{
// don't do anything with the order token so read off the pipe
if (!stateObj.TrySkipBytes(tokenLength))
{
return false;
}
break;
示例11: TryProcessAltMetaData
internal bool TryProcessAltMetaData(int cColumns, TdsParserStateObject stateObj, out _SqlMetaDataSet metaData) {
Debug.Assert(cColumns > 0, "should have at least 1 column in altMetaData!");
metaData = null;
_SqlMetaDataSet altMetaDataSet = new _SqlMetaDataSet(cColumns, null);
int[] indexMap = new int[cColumns];
if (!stateObj.TryReadUInt16(out altMetaDataSet.id)) {
return false;
}
byte byCols;
if (!stateObj.TryReadByte(out byCols)) {
return false;
}
while (byCols > 0) {
if (!stateObj.TrySkipBytes(2)) { // ignore ColNum ...
return false;
}
byCols--;
}
// pass 1, read the meta data off the wire
for (int i = 0; i < cColumns; i++) {
// internal meta data class
_SqlMetaData col = altMetaDataSet[i];
if (!stateObj.TryReadByte(out col.op)) {
return false;
}
if (!stateObj.TryReadUInt16(out col.operand)) {
return false;
}
// TCE is not applicable to AltMetadata.
if (!TryCommonProcessMetaData(stateObj, col, null, fColMD: false, columnEncryptionSetting: SqlCommandColumnEncryptionSetting.Disabled)) {
return false;
}
if (ADP.IsEmpty(col.column)) {
// create column name from op
switch (col.op) {
case TdsEnums.AOPAVG:
col.column = "avg";
break;
case TdsEnums.AOPCNT:
col.column = "cnt";
break;
case TdsEnums.AOPCNTB:
col.column = "cntb";
break;
case TdsEnums.AOPMAX:
col.column = "max";
break;
case TdsEnums.AOPMIN:
col.column = "min";
break;
case TdsEnums.AOPSUM:
col.column = "sum";
break;
case TdsEnums.AOPANY:
col.column = "any";
break;
case TdsEnums.AOPNOOP:
col.column = "noop";
break;
case TdsEnums.AOPSTDEV:
col.column = "stdev";
break;
case TdsEnums.AOPSTDEVP:
col.column = "stdevp";
break;
case TdsEnums.AOPVAR:
col.column = "var";
break;
case TdsEnums.AOPVARP:
col.column = "varp";
break;
}
}
indexMap[i] = i;
}
altMetaDataSet.indexMap = indexMap;
altMetaDataSet.visibleColumns = cColumns;
metaData = altMetaDataSet;
return true;
//.........这里部分代码省略.........