microsoft / go-mssqldb

Microsoft SQL server driver written in go language
BSD 3-Clause "New" or "Revised" License
283 stars 63 forks source link

Fix process query response missing errors #182

Closed njdullea closed 6 months ago

njdullea commented 6 months ago

In processQueryResponse if a token is an array of columnStruct, it would break the loop and fail to process the following tokens. These tokens should be processed since they may contain errors from the query that should be returned.

There is a test included which sets up a table, and performs an insert query with output variables. The first token returned in process query response is an array of column struct, relating to the output variables, and second token is an error indicating you cannot insert a value for an identity column. Previously, it would return with no error and an empty set of rows, and now it catches the error and returns it from the query.

njdullea commented 6 months ago

I'm am checking in with my company to confirm I can sign for the CLA, and will return.

If there is anything else missing from the PR I can provide please let me know.

shueybubbles commented 6 months ago

thx for the PR!

Do we need a separate test case for the message loop version of a query?

njdullea commented 6 months ago

Thank you for the feedback! I am working on the suggested changes.

njdullea commented 6 months ago

I'm unsure what a message loop version of a query is and was wondering if you could clarify?

I also moved the state management to a Rows method as you suggested, but ran into some challenges I described in the thread above. Let me know if I can provide any more info, thanks!

shueybubbles commented 6 months ago

the message loop version of a query is tested here https://github.com/microsoft/go-mssqldb/blob/ada30cbaf031d81144e5c5487ddefd4f3dac0ef5/queries_go19_test.go#L1255

njdullea commented 6 months ago

Thank you for the message loop query test reference, I will add a test case for this.

njdullea commented 6 months ago

I did not understand that a query in golang may result in an error, but that error will not be returned from the query method, rather it must be checked via rows.Err() after closing the error. Sorry for the distraction.