diff --git a/TDSClient/TDSClient/TDS/Client/TDSSQLTestClient.cs b/TDSClient/TDSClient/TDS/Client/TDSSQLTestClient.cs
index 6f46112..f5ec0b8 100644
--- a/TDSClient/TDSClient/TDS/Client/TDSSQLTestClient.cs
+++ b/TDSClient/TDSClient/TDS/Client/TDSSQLTestClient.cs
@@ -7,16 +7,22 @@
namespace TDSClient.TDS.Client
{
using System;
+ using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Security.Authentication;
+ using System.Threading;
using TDSClient.TDS.Comms;
using TDSClient.TDS.Header;
using TDSClient.TDS.Login7;
using TDSClient.TDS.PreLogin;
+ using TDSClient.TDS.Query;
using TDSClient.TDS.Tokens;
+ using TDSClient.TDS.Tokens.Cols;
+ using TDSClient.TDS.Tranasction.Header.Headers;
+ using TDSClient.TDS.Tranasction.Headers;
using TDSClient.TDS.Utilities;
///
@@ -40,7 +46,7 @@ public class TDSSQLTestClient
/// User password
/// Database to connect to
/// Encryption Protocol
- public TDSSQLTestClient(string server, int port, string userID, string password, string database, SslProtocols encryptionProtocol = SslProtocols.Tls12)
+ public TDSSQLTestClient(string server, int port, string userID, string password, string database, SslProtocols encryptionProtocol = SslProtocols.Tls12, TDSLogin7TypeFlagsReadOnlyIntent readOnlyIntent = TDSLogin7TypeFlagsReadOnlyIntent.Off)
{
if (string.IsNullOrEmpty(server) || string.IsNullOrEmpty(userID) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(database))
{
@@ -55,6 +61,7 @@ public TDSSQLTestClient(string server, int port, string userID, string password,
this.Password = password;
this.Database = database;
this.EncryptionProtocol = encryptionProtocol;
+ this.ReadOnlyIntent = readOnlyIntent;
this.connectionAttempt = 0;
LoggingUtilities.WriteLog($" Instantiating TDSSQLTestClient with the following parameters:");
@@ -110,6 +117,11 @@ public TDSSQLTestClient(string server, int port, string userID, string password,
///
public SslProtocols EncryptionProtocol { get; set; }
+ ///
+ /// Gets or sets the ReadOnly Intent Policy.
+ ///
+ public TDSLogin7TypeFlagsReadOnlyIntent ReadOnlyIntent {get; set;}
+
///
/// Sends PreLogin message to the server.
///
@@ -163,7 +175,7 @@ public void SendLogin7()
tdsMessageBody.TypeFlags.OLEDB = TDSLogin7TypeFlagsOLEDB.On;
tdsMessageBody.TypeFlags.SQLType = TDSLogin7TypeFlagsSQLType.DFLT;
- tdsMessageBody.TypeFlags.ReadOnlyIntent = TDSLogin7TypeFlagsReadOnlyIntent.On;
+ tdsMessageBody.TypeFlags.ReadOnlyIntent = this.ReadOnlyIntent;
this.TdsCommunicator.SendTDSMessage(tdsMessageBody);
@@ -212,46 +224,7 @@ public void ReceiveLogin7Response()
{
foreach (var token in response.Tokens)
{
- if (token is TDSEnvChangeToken)
- {
- var envChangeToken = token as TDSEnvChangeToken;
- if (envChangeToken.Type == Tokens.EnvChange.TDSEnvChangeType.Routing)
- {
- LoggingUtilities.WriteLog($" Client received EnvChange routing token, client is being routed.");
- this.Server = envChangeToken.Values["AlternateServer"];
- this.Port = int.Parse(envChangeToken.Values["ProtocolProperty"]);
- this.reconnect = true;
- LoggingUtilities.WriteLog($" Redirect to {this.Server}:{this.Port}", writeToSummaryLog: true, writeToVerboseLog: false);
- }
- }
- else if (token is TDSErrorToken)
- {
- var errorToken = token as TDSErrorToken;
- LoggingUtilities.WriteLog($" Client received Error token, Number: {errorToken.Number}, State: {errorToken.State}", writeToSummaryLog: true); ;
- LoggingUtilities.WriteLog($" MsgText: {errorToken.MsgText}");
- LoggingUtilities.WriteLog($" Class: {errorToken.Class}");
- LoggingUtilities.WriteLog($" ServerName: {errorToken.ServerName}");
- LoggingUtilities.WriteLog($" ProcName: {errorToken.ProcName}");
- LoggingUtilities.WriteLog($" LineNumber: {errorToken.LineNumber}");
-
- if (errorToken.Number == 18456)
- {
- throw new Exception("Login failure.");
- }
- }
- else if (token is TDSInfoToken)
- {
- var infoToken = token as TDSInfoToken;
- LoggingUtilities.WriteLog($" Client received Info token:");
-
- LoggingUtilities.WriteLog($" Number: {infoToken.Number}");
- LoggingUtilities.WriteLog($" State: {infoToken.State}");
- LoggingUtilities.WriteLog($" Class: {infoToken.Class}");
- LoggingUtilities.WriteLog($" MsgText: {infoToken.MsgText}");
- LoggingUtilities.WriteLog($" ServerName: {infoToken.ServerName}");
- LoggingUtilities.WriteLog($" ProcName: {infoToken.ProcName}");
- LoggingUtilities.WriteLog($" LineNumber: {infoToken.LineNumber}");
- }
+ PrintTdsToken(token);
}
}
else
@@ -262,6 +235,72 @@ public void ReceiveLogin7Response()
LoggingUtilities.WriteLog($" Login7 response received.");
}
+ private void PrintTdsToken(TDSToken token)
+ {
+ if (token is TDSEnvChangeToken)
+ {
+ var envChangeToken = token as TDSEnvChangeToken;
+ if (envChangeToken.Type == Tokens.EnvChange.TDSEnvChangeType.Routing)
+ {
+ LoggingUtilities.WriteLog($" Client received EnvChange routing token, client is being routed.");
+ this.Server = envChangeToken.Values["AlternateServer"];
+ this.Port = int.Parse(envChangeToken.Values["ProtocolProperty"]);
+ this.reconnect = true;
+ LoggingUtilities.WriteLog($" Redirect to {this.Server}:{this.Port}", writeToSummaryLog: true, writeToVerboseLog: false);
+ }
+ }
+ else if (token is TDSErrorToken)
+ {
+ var errorToken = token as TDSErrorToken;
+ LoggingUtilities.WriteLog($" Client received Error token, Number: {errorToken.Number}, State: {errorToken.State}", writeToSummaryLog: true); ;
+ LoggingUtilities.WriteLog($" MsgText: {errorToken.MsgText}");
+ LoggingUtilities.WriteLog($" Class: {errorToken.Class}");
+ LoggingUtilities.WriteLog($" ServerName: {errorToken.ServerName}");
+ LoggingUtilities.WriteLog($" ProcName: {errorToken.ProcName}");
+ LoggingUtilities.WriteLog($" LineNumber: {errorToken.LineNumber}");
+
+ if (errorToken.Number == 18456)
+ {
+ throw new Exception("Login failure.");
+ }
+ }
+ else if (token is TDSInfoToken)
+ {
+ var infoToken = token as TDSInfoToken;
+ LoggingUtilities.WriteLog($" Client received Info token:");
+
+ LoggingUtilities.WriteLog($" Number: {infoToken.Number}");
+ LoggingUtilities.WriteLog($" State: {infoToken.State}");
+ LoggingUtilities.WriteLog($" Class: {infoToken.Class}");
+ LoggingUtilities.WriteLog($" MsgText: {infoToken.MsgText}");
+ LoggingUtilities.WriteLog($" ServerName: {infoToken.ServerName}");
+ LoggingUtilities.WriteLog($" ProcName: {infoToken.ProcName}");
+ LoggingUtilities.WriteLog($" LineNumber: {infoToken.LineNumber}");
+ }
+ else if (token is TDSColMetadataToken colMetadataToken)
+ {
+ LoggingUtilities.WriteLog($" Client Column Metadata Info token:");
+
+ LoggingUtilities.WriteLog($" Columns: {colMetadataToken.Count}");
+ for (int i = 0; i < colMetadataToken.Metadata.Length; i++)
+ {
+ var metadata = colMetadataToken.Metadata[i];
+ LoggingUtilities.WriteLog($" Index: {i}");
+ LoggingUtilities.WriteLog($" Name: {metadata.ColumnName}");
+ LoggingUtilities.WriteLog($" Type: {metadata.Type.Type}");
+ LoggingUtilities.WriteLog("");
+ }
+ }
+ else if (token is TDSRowToken rowToken)
+ {
+ LoggingUtilities.WriteLog($" Client Row data token:");
+ for(int i = 0; i < rowToken.Values.Length; i++)
+ {
+ LoggingUtilities.WriteLog($" Row [{i}]: {rowToken.Values[i]?.ToString() ?? "NUll"}");
+ }
+ }
+ }
+
///
/// Connect to the server.
///
@@ -332,6 +371,59 @@ public void Connect()
}
}
+ public int queryCount = 0;
+ public (string[], object[][]) Query(string query)
+ {
+ var id = Interlocked.Increment(ref queryCount);
+ string[] colNames = Array.Empty();
+ List