-
Notifications
You must be signed in to change notification settings - Fork 90
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
MS SQL Server: Support access to DB objects in connection's non default DB #376
MS SQL Server: Support access to DB objects in connection's non default DB #376
Conversation
String bracketedName = enquoteAndJoin(objname.split("\\."), ".", "[", "]"); | ||
|
||
try (Statement s = currentConnection.createStatement()) { | ||
s.execute("USE " + objectDatabaseName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I think this has side effect: the current database is changed; and if something dies - it will remain in the new database.
What about just modifying the query above from sys.columns
to something like objectDatabaseName.sys.columns
?
Ah. I've just noticed that I've not checked in the other bit of code that reverts the DB back to the value that I capture in However, your suggestion seems to work perfectly and is much more elegant (and I'm embarrassed I didn't think of it in the first place! 😳). I'll run the tests over it. |
Hmm. This does involve changing both |
Also tidied up the DB setup script whitespace (we've no style guide for the SQL code - I generally use Steven Feuerstein-like formatting). |
String[] objnameParts = procName.split("\\."); | ||
if (objnameParts.length == 3) { | ||
objectDatabaseName = objnameParts[0] + "."; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That snippet is basically the same as the other. Maybe we can move it to a single place?
c30f775
to
caead22
Compare
Do you think it would be better to distribute the tests in the new page I've created into other, existing, test pages or to have an explicit test page for this? |
A separate test page seems OK to me. |
@@ -133,6 +135,16 @@ protected String parseCommandText(String commandText) { | |||
// private static string[] GuidTypes = new string[] { "UNIQUEIDENTIFIER" }; | |||
// private static string[] VariantTypes = new string[] { "SQL_VARIANT" }; | |||
|
|||
private String objectDatabasePrefix(String dbObjectName) { | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the existing code seems we don't have such blank lines after the method header. And right now to me it looks a bit better without this extra line.
Ok. Extra blank lines fixed. |
Now it looks good to me. Might be good to just to clean up the commit history and we can merge then. |
1658852
to
522f02b
Compare
522f02b
to
917da59
Compare
I've squashed to a single commit and rebased. |
…fault-db Support access to DB objects in connection's non default DB
Add support for access to objects that are not in the current database for the connection/session using the full 3 part name.
Users currently have to rely upon either the default database for the connection (specified for each DB user, or overridden for the connection using either the
database=
ordatabaseName=
connection parameter), OR, set the default database using aUSE <db name>
SQL statement.