Skip to content

Commit 84bc56d

Browse files
Include Command Context
1 parent 6a8ab66 commit 84bc56d

File tree

5 files changed

+36
-59
lines changed

5 files changed

+36
-59
lines changed

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClientX/SqlConnectionX.cs

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ internal sealed class SqlConnectionX : DbConnection, ICloneable
3535
private SqlConnector? _internalConnection;
3636

3737
private bool _disposed;
38-
private int _closeCount;
3938

4039
//TODO: Investigate if we can just use dataSource.ConnectionString. Do this when this class can resolve its own data source.
4140
private string _connectionString = string.Empty;
@@ -337,53 +336,6 @@ protected override DbCommand CreateDbCommand()
337336

338337
#region internal helpers
339338

340-
// If wrapCloseInAction is defined, then the action it defines will be run with the connection close action passed in as a parameter
341-
// The close action also supports being run asynchronously
342-
internal void OnError(SqlException exception, bool breakConnection, Action<Action> wrapCloseInAction)
343-
{
344-
Debug.Assert(exception != null && exception.Errors.Count != 0, "SqlConnection: OnError called with null or empty exception!");
345-
346-
if (breakConnection && (ConnectionState.Open == State))
347-
{
348-
if (wrapCloseInAction != null)
349-
{
350-
int capturedCloseCount = _closeCount;
351-
352-
Action closeAction = () =>
353-
{
354-
if (capturedCloseCount == _closeCount)
355-
{
356-
Close();
357-
}
358-
};
359-
360-
wrapCloseInAction(closeAction);
361-
}
362-
else
363-
{
364-
Close();
365-
}
366-
}
367-
368-
if (exception.Class >= TdsEnums.MIN_ERROR_CLASS)
369-
{
370-
// It is an error, and should be thrown. Class of TdsEnums.MIN_ERROR_CLASS or above is an error,
371-
// below TdsEnums.MIN_ERROR_CLASS denotes an info message.
372-
throw exception;
373-
}
374-
else
375-
{
376-
// If it is a class < TdsEnums.MIN_ERROR_CLASS, it is a warning collection - so pass to handler
377-
this.OnInfoMessage(new SqlInfoMessageEventArgs(exception));
378-
}
379-
}
380-
381-
internal void OnInfoMessage(SqlInfoMessageEventArgs imevent)
382-
{
383-
bool notified;
384-
OnInfoMessage(imevent, out notified);
385-
}
386-
387339
internal void OnInfoMessage(SqlInfoMessageEventArgs imevent, out bool notified)
388340
{
389341
// TODO review event source traces later

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClientX/SqlConnector.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88
using System.Data;
99
using System.Threading;
1010
using System.Threading.Tasks;
11-
using Microsoft.Data.Common;
12-
using Microsoft.Data.SqlClient;
1311
using Microsoft.Data.SqlClientX.Handlers.Connection;
14-
using Microsoft.Data.SqlClientX.Tds;
15-
using Microsoft.Data.SqlClientX.Tds.State;
1612

1713
#nullable enable
1814

@@ -25,13 +21,12 @@ internal sealed class SqlConnector
2521
{
2622
private static int s_spoofedServerProcessId = 1;
2723

28-
private readonly TdsParserX _parser;
24+
// private readonly TdsParserX _parser;
2925
private readonly ConnectionHandlerContext _connectionHandlerContext;
3026

31-
internal SqlConnector(SqlConnectionX? owningConnection, SqlConnectionString connectionOptions, SqlDataSource dataSource)
27+
internal SqlConnector(SqlConnectionX? owningConnection, SqlDataSource dataSource)
3228
{
3329
OwningConnection = owningConnection;
34-
ConnectionOptions = connectionOptions;
3530
DataSource = dataSource;
3631

3732
//TODO: Set this based on the real server process id.
@@ -44,7 +39,8 @@ internal SqlConnector(SqlConnectionX? owningConnection, SqlConnectionString conn
4439
// TODO initialize and pass ConnectionOptions into connection handler context
4540
};
4641

47-
_parser = new TdsParserX(new TdsContext(this));
42+
// TODO enable parser registration with Parser introduction.
43+
// _parser = new TdsParserX(new TdsContext(this));
4844
}
4945

5046
#region properties
@@ -55,8 +51,6 @@ internal SqlConnector(SqlConnectionX? owningConnection, SqlConnectionString conn
5551
/// </summary>
5652
internal SqlDataSource DataSource { get; }
5753

58-
internal DbConnectionOptions ConnectionOptions { get; set; }
59-
6054
/// <summary>
6155
/// The server version this connector is connected to.
6256
/// </summary>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace Microsoft.Data.SqlClientX.Tds.State
6+
{
7+
internal class TdsCommandContext
8+
{
9+
// TDS stream processing variables
10+
/// <summary>
11+
/// PLP data length indicator
12+
/// </summary>
13+
public ulong PlpLength;
14+
15+
/// <summary>
16+
/// Length of data left to read (64 bit lengths)
17+
/// </summary>
18+
public ulong PlpLengthLeft;
19+
}
20+
}

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClientX/Tds/State/TdsTransactionState.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ internal class TdsTransactionState
2828

2929
internal SqlInternalTransaction PendingTransaction => _pendingTransaction;
3030

31+
internal void UpdateCurrentTransaction(SqlInternalTransaction transaction)
32+
{
33+
_currentTransaction = transaction;
34+
}
35+
36+
internal void UpdatePendingTransaction(SqlInternalTransaction transaction)
37+
{
38+
_pendingTransaction = transaction;
39+
}
40+
3141
internal int IncrementNonTransactedOpenResultCount()
3242
{
3343
// IMPORTANT - this increments the connection wide open result count for all

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClientX/Tds/Tokens/TokenStreamHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#if NET8_0_OR_GREATER
66

7+
using System;
78
using System.Collections.Generic;
89
using System.Diagnostics;
910
using System.Threading;
@@ -54,7 +55,7 @@ public async ValueTask<Token> ReceiveTokenAsync(TdsContext context, bool isAsync
5455
{
5556
byte type = await context.TdsStream.ReadByteAsync(isAsync, ct).ConfigureAwait(false);
5657

57-
if (!TdsUtils.IsValidTdsToken(type))
58+
if (!Enum.IsDefined(typeof(TokenType), type))
5859
{
5960
Debug.Fail($"unexpected token; token = {type-2:X2}");
6061
context.ParserState = TdsParserState.Broken;

0 commit comments

Comments
 (0)