-
Notifications
You must be signed in to change notification settings - Fork 433
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
[FEATURE REQUEST] Provide a way to set SQLServer-specific connection-state via utility methods on SQLServerConnection, esp sp_setapprole since it faces 'special' issues. #1540
Comments
Hi @dtbullock, thanks for submitting this issue. I see that you've offered two solutions to enhance the driver, where the first solution is to treat As for handling Therefore, I believe that it would be best if you were to keep using the workaround you have, instead of having the driver do String parsing or add an API that replicates your workaround, given that this |
Hi @peterbae thanks for giving this some thought. I agree that if the driver doesn't already parse stuff, then it would be foolishness to make it do so to support this-particular use-case. I do think it would be worth 'cluttering the API' though. There are quite a few responsibilities that the hapless app author must assume:
Like In fact, any sort of SQL-Server-specific feature which affects the connection-state would profit from this: assumed identities, opened symmetric keys, etc. It'd make my life as a user of the database much simpler if such nothing-to-do-with-data, DBMS-vendor-specific, connection-state travelled with the Connection object itself, and was eminently controllable by a 'framework' that I didn't have to write. Do you want to add value to your technology stack, and increase customer stickiness to SQL Server? Or would you rather not 'clutter' the API? We're talking about:
In contrast, here is what I have to do. Resarching, prototyping, and polishing all this took me away from solving my business problems for double-digit hours. It is still incomplete in regards to exception-handling, but I've got an app to write and it's not bothering me yet.
not to forget the supporting binary-to-hex:
|
sp_setapprole
and sp_unsetapprole
specially, to avoid the futile attempt to sp_prepexec
them when using Connection#prepareCall()
the problem with doing the following:- |
Hi @c-m-d-1234 I had a hard time understanding why you were able to get a parameterized/compiled version of statements which used That would only make sense if Probably the MS JDBC driver doesn't want to make it a general option to choose between the |
FWIW, I have asked the SQL Server team to permit sp_setapprole under sp_prepexec: |
Is your feature request related to a problem? If so, please give a short summary of the problem and how the feature would resolve it
It's impossible to use
sp_setapprole
andsp_unsetapprole
using a JDBCCallableStatement
because when the client code does this:the JDBC driver always tries to
sp_prepexec
, butsp_setapprole
can't be used in that way ... per the 'Remarks' of sp_setappRole (Transact-SQL):... nor when the SQL is given to
sp_prepexec
. We get an exception:This is an impedance mismatch between the JDBC view of the world, where a
CallableStatement
inherits fromPreparedStatement
, butsys.sp_setapprole
is 'special' and cannot be prepared.Describe the preferred solution
In this case, we don't care about re-using query plans, nor sending multiple updates in a batch. We just care getting/setting in/out parameters.
Sincesys.sp_setapprole
andsys.sp_setapprole
are so fussy about how they are called, the JDBC driver should provide special treatment for these stored procedures, and simply pass them toEXEC
, not try tosp_prepexec
them.Alternatively (and better),
SQLServerConnection
could offer 'pushAppRole(String)' and 'popAppRole()' methods. Working with this DBMS-specific feature via a DBMS-specific API is just fine.Describe alternatives you've considered
It is possible to work-around and get the cookie using
conn.createStatement(sql).executyQuery()
wheresql
is:and then later follow this up with:
... with notable API-ugliness forced upon the user to:
Additional context
Sure, application roles are of limited value, providing mainly a means of keeping state which is specific to an application hidden from users when they access the database using a different application.
But the OAuth use-case, where an application collects access-tokens on behalf of many users who have chosen to trust that application (ie. the 'client' in OAuth terminology) is exactly the scenario which benefits from an application-role.
Reference Documentations/Specifications
sp_setappRole (Transact-SQL)
https://stackoverflow.com/questions/6833278/jdbc-set-approle/6944693#6944693
The text was updated successfully, but these errors were encountered: