Skip to content

Commit

Permalink
generalise approach
Browse files Browse the repository at this point in the history
  • Loading branch information
colombod committed Feb 29, 2024
1 parent b6defd4 commit 07977b2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
9 changes: 0 additions & 9 deletions src/Microsoft.DotNet.Interactive.SqlServer/MsSqlKernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ public override async Task ConnectAsync()

protected override string CreateVariableDeclaration(string name, object value)
{
if (value is PasswordString ps)
{
value = ps.GetClearTextPassword();
}

return $"DECLARE @{name} {MapToSqlDataType(name, value)} = {MapToSqlValueDeclaration(value)};";

static string MapToSqlDataType(string name, object value)
Expand Down Expand Up @@ -92,10 +87,6 @@ protected override bool CanDeclareVariable(string name, object value, out string
msg = default;
try
{
if (value is PasswordString)
{
return true;
}
SqlMetaData.InferFromValue(
value,
name);
Expand Down
14 changes: 13 additions & 1 deletion src/Microsoft.DotNet.Interactive.SqlServer/ToolsServiceKernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,14 @@ private string PrependVariableDeclarationsToCode(SubmitCode command, KernelInvoc

foreach (var variableNameAndValue in _variables)
{
var declareStatement = CreateVariableDeclaration(variableNameAndValue.Key, variableNameAndValue.Value);
var value = variableNameAndValue.Value;

if (value is PasswordString ps)
{
value = ps.GetClearTextPassword();
}

var declareStatement = CreateVariableDeclaration(variableNameAndValue.Key, value);

var displayStatement = declareStatement;

Expand Down Expand Up @@ -442,6 +449,11 @@ private string PrependVariableDeclarationsToCode(SubmitCode command, KernelInvoc
throw new ArgumentNullException(nameof(value), $"Sharing null values is not supported at this time.");
}
if (value is PasswordString ps)
{
value = ps.GetClearTextPassword();
}
if (!CanDeclareVariable(name, value, out string msg))
{
throw new ArgumentException($"Cannot support value of Type {value.GetType()}. {msg}");
Expand Down

0 comments on commit 07977b2

Please sign in to comment.