-
Notifications
You must be signed in to change notification settings - Fork 71
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
String output parameter value is cut off #161
Comments
Does it work if you use |
FWIW we need to overhaul how the driver handles strings in order to work with collations too (eg #129) |
Yes, it works with mssql.NVarCharMax instead of string. But the problem is that now I have a function that accepts sql.NullString in order to support NULL values. If I have to use NVarCharMax then I wont be able to use single parameter type, but do smth like interface{} then cast to either NullString or NVarCharMax. Btw, what if the driver always sets max length (8000 or anything reasonable for NVARCHAR?) for variable length parameters for OUT parameters only? What disadvantages you see in such approach except potential performance issues maybe? |
For OUT parameters using 8k is probably fine for most cases and could be a reasonable short term mitigation. |
Well, thank you! If I file a PR that implements logic above (sets predefined length for var length OUT params), will it have any chances to be merged? If yes, could you please provide some hints on how to implement if any? Its quite straightforward change, but it can be done in 100 different ways and if you have some future plans to correspond with - it would be great. |
In fact, I suggest just stealing the code from JDBC driver:
effectively applying the following changes to types.go (pseudocode, needs passing out parameter to the function):
|
I only see a handful calls to |
Well, when I run the following stored procedure (col8 is a test table column from alwaysencrypted_test.go):
using the following code:
I receve the following errors:
The DB complains about parameter length mismatch and the problem is I don't know how to fix it even in theory - the client is not aware of the required length (if I set type to nvarchar(max) as for unencrypted case the error just reoccurs). Could you please advise, I'm likely missing something... |
what is the query text being sent to |
My approach to figuring out what the driver should be doing for AE is to try to replicate the scenario in SSMS with auto-parameterization turned on. I use Tools/Options/Output Window to turn on sqlclient traces, and an XEvent profiler session to see all queries SqlClient sends under the covers. EG if you connect to the same database using SSMS with AE enabled and do something like this in the query window: declare @p1 nvarchar(4) = "test"
mssqlAep371 @p1 output Does it work? And what is the query that SSMS sends with sp_describe_parameter_encryption? |
I'll answer later regarding SSMS, need some time... |
Btw, while I am trying SSMS... There are two thoughts regarding the subject:
I guess the declared type size will be sent.
As a (preliminary) conclusion - it's impossible to implement AE NVARCHAR parameter using current sql library model since args do not contain size info at all (the size is either deduced by the driver using actual value provided or set to its max which is acceptable for non-AE cases , but not acceptable for AE). |
yeah that's about what I expected.
I'd love to provide a solution but I don't know what developers want the solution to look like. The most straightforward approach is to create a whole new data type like SqlParameter in .Net. I'd prefer that data type be defined in A shortcut solution for 2 could be to accept a slice of runes as the parameter instead of |
Answering to your request above regarding SSMS (the procedure name is slightly different since its generated):
|
In fact Im cowardly suggesting leaving AE support for output parameters out of the issue scope since it requires much more work including reviewing library model (comparing just to passing a bool flag through) :) Regarding using cap() as a type length - Im not authority here, but I personally think its not ideal solution since:
Please let me know if I could file a PR fixing OUT parameter w/o AE support. |
sure, as long as AE doesn't get any worse than it is now. It's a relatively new feature in the driver so I don't think people are yet clamoring for fixes in it. |
I am sorry for off topic, but I found nothing regarding how to get proper access rights to create branches in the repo to file a PR... Could you please help? Or do I have to fork? |
you'll need to fork |
Describe the bug
The driver has to specify parameter maximum length TDS field along with its type when calling stored procedure. Right now for string parameters the driver sets NVarchar as type and provided value length as max length (see types.go). While its acceptable for input parameters it doesn't work correctly for output parameters - if the output parameter value written by the stored procedure is longer than initial one the written value appears to be cut off.
To Reproduce
Create Test stored procedure that accepts POut NVARCHAR output parameter and writes its value back with 'Value' suffix added.
Call the procedure using standard way of specifying output parameters: sql.Named("POut", sql.Out{Dest: &sql.NullString{String: "Test", Valid: true}, In: true})
"Test" value will be returned.
Expected behavior
"TestValue" value is returned.
Further technical details
More to follow.
Additional context
None.
The text was updated successfully, but these errors were encountered: