-
Notifications
You must be signed in to change notification settings - Fork 63
sql version telemetry data from input bindings #337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3033edf
207202c
61c0d49
5fc7e00
b3fb013
cbcfa4e
5669021
214b718
9f02a93
f2cf20d
61fb46f
da07358
48c62b0
8b343e2
b5d4b83
8a42748
85e5e7f
d69d896
0d46238
8f6be53
71e5ebd
6559474
5afaabe
cf89b7e
c69065f
c08b7dd
a627e4d
2e35c25
27e0814
5207365
b02ba41
df4c464
ded66ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,13 +7,12 @@ | |
| using System.Threading.Tasks; | ||
| using Microsoft.Data.SqlClient; | ||
| using Newtonsoft.Json; | ||
|
|
||
| namespace Microsoft.Azure.WebJobs.Extensions.Sql | ||
| { | ||
| /// <typeparam name="T">A user-defined POCO that represents a row of the user's table</typeparam> | ||
| internal class SqlAsyncEnumerable<T> : IAsyncEnumerable<T> | ||
| { | ||
| private readonly SqlConnection _connection; | ||
| public SqlConnection Connection { get; private set; } | ||
| private readonly SqlAttribute _attribute; | ||
|
|
||
| /// <summary> | ||
|
|
@@ -26,8 +25,9 @@ internal class SqlAsyncEnumerable<T> : IAsyncEnumerable<T> | |
| /// </exception> | ||
| public SqlAsyncEnumerable(SqlConnection connection, SqlAttribute attribute) | ||
| { | ||
| this._connection = connection ?? throw new ArgumentNullException(nameof(connection)); | ||
| this.Connection = connection ?? throw new ArgumentNullException(nameof(connection)); | ||
| this._attribute = attribute ?? throw new ArgumentNullException(nameof(attribute)); | ||
| this.Connection.Open(); | ||
| } | ||
| /// <summary> | ||
| /// Returns the enumerator associated with this enumerable. The enumerator will execute the query specified | ||
|
|
@@ -38,7 +38,7 @@ public SqlAsyncEnumerable(SqlConnection connection, SqlAttribute attribute) | |
| /// <returns>The enumerator</returns> | ||
| public IAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToken = default) | ||
| { | ||
| return new SqlAsyncEnumerator(this._connection, this._attribute); | ||
| return new SqlAsyncEnumerator(this.Connection, this._attribute); | ||
| } | ||
|
|
||
|
|
||
|
|
@@ -47,7 +47,6 @@ private class SqlAsyncEnumerator : IAsyncEnumerator<T> | |
| private readonly SqlConnection _connection; | ||
| private readonly SqlAttribute _attribute; | ||
| private SqlDataReader _reader; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="SqlAsyncEnumerator<typeparamref name="T"/>"/> class. | ||
| /// </summary> | ||
|
|
@@ -77,7 +76,7 @@ public SqlAsyncEnumerator(SqlConnection connection, SqlAttribute attribute) | |
| public ValueTask DisposeAsync() | ||
| { | ||
| // Doesn't seem like there's an async version of closing the reader/connection | ||
| this._reader.Close(); | ||
| this._reader?.Close(); | ||
| this._connection.Close(); | ||
| return new ValueTask(Task.CompletedTask); | ||
| } | ||
|
|
@@ -101,23 +100,24 @@ public ValueTask<bool> MoveNextAsync() | |
| /// </returns> | ||
| private async Task<bool> GetNextRowAsync() | ||
| { | ||
| if (this._reader == null) | ||
| // check connection state before trying to access the reader | ||
| // if DisposeAsync has already closed it due to the issue described here https://github.com/Azure/azure-functions-sql-extension/issues/350 | ||
| if (this._connection.State != System.Data.ConnectionState.Closed) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assuming the tests pass please create an issue for investigating this and then add a comment explaining why we're doing this with a link to the issue.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I ran locally and they passed (fingers crossed), will add the comment, thanks |
||
| { | ||
| using (SqlCommand command = SqlBindingUtilities.BuildCommand(this._attribute, this._connection)) | ||
| if (this._reader == null) | ||
| { | ||
| await command.Connection.OpenAsync(); | ||
| this._reader = await command.ExecuteReaderAsync(); | ||
| using (SqlCommand command = SqlBindingUtilities.BuildCommand(this._attribute, this._connection)) | ||
| { | ||
| this._reader = await command.ExecuteReaderAsync(); | ||
| } | ||
| } | ||
| if (await this._reader.ReadAsync()) | ||
| { | ||
| this.Current = JsonConvert.DeserializeObject<T>(this.SerializeRow()); | ||
| return true; | ||
| } | ||
| } | ||
| if (await this._reader.ReadAsync()) | ||
| { | ||
| this.Current = JsonConvert.DeserializeObject<T>(this.SerializeRow()); | ||
| return true; | ||
| } | ||
| else | ||
| { | ||
| return false; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.