Skip to content

Commit

Permalink
Merge pull request #448 from MarkMpn/executeas
Browse files Browse the repository at this point in the history
Error messages
  • Loading branch information
MarkMpn authored Apr 10, 2024
2 parents 3f68f18 + f7f9df9 commit cd138d0
Show file tree
Hide file tree
Showing 45 changed files with 1,244 additions and 467 deletions.
2 changes: 1 addition & 1 deletion MarkMpn.Sql4Cds.Engine.Tests/AdoProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1782,7 +1782,7 @@ BEGIN CATCH
Assert.AreEqual(1, reader.GetInt32(3));
Assert.IsTrue(reader.IsDBNull(4));
Assert.AreEqual(2, reader.GetInt32(5));
Assert.AreEqual("Invalid object name 'invalid_table'", reader.GetString(6));
Assert.AreEqual("Invalid object name 'invalid_table'.", reader.GetString(6));
Assert.IsFalse(reader.Read());

try
Expand Down
2 changes: 1 addition & 1 deletion MarkMpn.Sql4Cds.Engine.Tests/ExecutionPlanTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3611,7 +3611,7 @@ public void HelpfulErrorMessageOnMissingGroupBy()
}
catch (NotSupportedQueryFragmentException ex)
{
Assert.AreEqual("Column 'new_customentity.new_name' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause", ex.Message);
Assert.AreEqual("Column 'new_customentity.new_name' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.", ex.Message);
}
}

Expand Down
2 changes: 1 addition & 1 deletion MarkMpn.Sql4Cds.Engine.Tests/Sql2FetchXmlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2226,7 +2226,7 @@ public void UpdateMissingAliasAmbiguous()
}
catch (NotSupportedQueryFragmentException ex)
{
Assert.AreEqual("The table 'account' is ambiguous", ex.Message);
Assert.AreEqual("The table 'account' is ambiguous.", ex.Message);
}
}

Expand Down
18 changes: 14 additions & 4 deletions MarkMpn.Sql4Cds.Engine/Ado/Sql4CdsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ protected override DbTransaction DbTransaction
set
{
if (value != null)
throw new Sql4CdsException(new Sql4CdsError(16, 40517, "Transactions are not supported"));
throw new Sql4CdsException(Sql4CdsError.NotSupported(null, "BEGIN TRAN"));
}
}

Expand Down Expand Up @@ -218,7 +218,12 @@ public IRootExecutionPlanNode[] GeneratePlan(bool compileForExecution)
}
catch (Exception ex)
{
_connection.TelemetryClient.TrackException(ex, new Dictionary<string, string> { ["Sql"] = CommandText, ["Source"] = _connection.ApplicationName });
var exProps = new Dictionary<string, string> { ["Sql"] = CommandText, ["Source"] = _connection.ApplicationName };

if (ex is ISql4CdsErrorException sqlEx && sqlEx.Errors.Count > 0)
exProps["ErrorNumber"] = sqlEx.Errors[0].Number.ToString();

_connection.TelemetryClient.TrackException(ex, exProps);

if (ex is Sql4CdsException)
throw;
Expand Down Expand Up @@ -293,7 +298,7 @@ protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
}
}

return new SqlDataReaderWrapper(_connection, this, con, cmd, _connection.Database, node, _cts.Token);
return new SqlDataReaderWrapper(con, cmd, behavior, node, _cts.Token);
}

var options = new CancellationTokenOptionsWrapper(_connection.Options, _cts);
Expand All @@ -311,7 +316,12 @@ protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
}
catch (Exception ex)
{
_connection.TelemetryClient.TrackException(ex, new Dictionary<string, string> { ["Sql"] = CommandText, ["Source"] = _connection.ApplicationName });
var exProps = new Dictionary<string, string> { ["Sql"] = CommandText, ["Source"] = _connection.ApplicationName };

if (ex is ISql4CdsErrorException sqlEx && sqlEx.Errors.Count > 0)
exProps["ErrorNumber"] = sqlEx.Errors[0].Number.ToString();

_connection.TelemetryClient.TrackException(ex, exProps);
throw;
}
}
Expand Down
2 changes: 1 addition & 1 deletion MarkMpn.Sql4Cds.Engine/Ado/Sql4CdsConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ public override void Open()

protected override DbTransaction BeginDbTransaction(System.Data.IsolationLevel isolationLevel)
{
throw new Sql4CdsException(new Sql4CdsError(16, 40517, "Transactions are not supported"));
throw new Sql4CdsException(Sql4CdsError.NotSupported(null, "BEGIN TRAN"));
}

protected override DbCommand CreateDbCommand()
Expand Down
Loading

0 comments on commit cd138d0

Please sign in to comment.