Skip to content
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

fix for getSchema when using "-" in name #718

Merged
merged 6 commits into from
Jun 20, 2018
Merged

Conversation

rene-ye
Copy link
Member

@rene-ye rene-ye commented Jun 6, 2018

Fix for issue #715 by @fabiocorneti

@fabiocorneti
Copy link

Apologies for not opening the PR myself, was busy at work :)

@codecov-io
Copy link

codecov-io commented Jun 6, 2018

Codecov Report

Merging #718 into dev will increase coverage by 0.04%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##                dev     #718      +/-   ##
============================================
+ Coverage     48.29%   48.33%   +0.04%     
- Complexity     2614     2622       +8     
============================================
  Files           113      113              
  Lines         26625    26626       +1     
  Branches       4480     4480              
============================================
+ Hits          12858    12871      +13     
+ Misses        11613    11598      -15     
- Partials       2154     2157       +3
Flag Coverage Δ Complexity Δ
#JDBC42 47.78% <100%> (+0.08%) 2571 <0> (+8) ⬆️
#JDBC43 48.19% <100%> (-0.03%) 2618 <0> (+5)
Impacted Files Coverage Δ Complexity Δ
...soft/sqlserver/jdbc/SQLServerDatabaseMetaData.java 33.53% <100%> (+1.26%) 65 <0> (+7) ⬆️
...om/microsoft/sqlserver/jdbc/SimpleInputStream.java 51.11% <0%> (-1.49%) 11% <0%> (-1%)
...in/java/com/microsoft/sqlserver/jdbc/IOBuffer.java 54.78% <0%> (-0.14%) 0% <0%> (ø)
...om/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java 52.42% <0%> (-0.13%) 238% <0%> (ø)
...om/microsoft/sqlserver/jdbc/ReaderInputStream.java 44.94% <0%> (ø) 16% <0%> (ø) ⬇️
...rc/main/java/com/microsoft/sqlserver/jdbc/dtv.java 63.36% <0%> (+0.05%) 0% <0%> (ø) ⬇️
...ncurrentlinkedhashmap/ConcurrentLinkedHashMap.java 39% <0%> (+0.21%) 43% <0%> (ø) ⬇️
...m/microsoft/sqlserver/jdbc/SQLServerResultSet.java 33.63% <0%> (+0.31%) 250% <0%> (+3%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5887439...fc78177. Read the comment docs.

@ulvii ulvii added this to the 6.5.4 milestone Jun 13, 2018
assertEquals(catalogName, catalogMsgArgs[0]);
}

final MessageFormat atLeastOneFoundFormat = new MessageFormat(TestResource.getResource("R_atLeastOneFound"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything else looks okay, there's just too many final objects here in both new methods, which don't really have a purpose. Let's keep it consistent with other tests.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed all instances of final.

assertTrue(hasResults, atLeastOneFoundFormat.format(schemaMsgArgs));
} finally {
if (dropDatabase) {
connection.createStatement().execute(String.format("DROP DATABASE [%s]", testCatalog));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're using the generic connection and creating statement, which is not closed (same for other method), you could use Utils functions to drop database for consistency and that clear up objects as well.

try (final Connection dashConn = DriverManager.getConnection(connectionString);
final Statement dashStatement = dashConn.createStatement()) {

connection.createStatement().execute(String.format("CREATE DATABASE [%s]", testCatalog));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unclosed Statement, either close this Statement, or use dashStatement instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created with try-with-resources, auto closed at the end of the blocks.

final UUID id = UUID.randomUUID();
final String testCatalog = "dash-catalog"+id;
final String testSchema = "some-schema"+id;
boolean dropDatabase = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This varible can be avoided if you'd use Utils drop functions, that check for existence of objects in sql.

Copy link
Member Author

@rene-ye rene-ye Jun 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Utils is able to drop (if exists) stored procedures and tables. There doesn't seem to be one to handle databases.
Edit 1: I have gone ahead and removed the database creation tracking on the Java side, and replaced it with a 'DROP IF EXISTS' on the SQL side.

removed finals
removed database creation tracking
@Test
public void testDBSchemasForDashedCatalogName() throws SQLException {
UUID id = UUID.randomUUID();
String testCatalog = "dash-catalog"+id;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both testCatalog and testSchema should not be hard-coded. You can at least append a random number.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Catalog name and Schema name are appended with an ID, and the ID is generated from our UUID class.

try (Connection dashConn = DriverManager.getConnection(connectionString);
Statement dashStatement = dashConn.createStatement()) {

connection.createStatement().execute(String.format("CREATE DATABASE [%s]", testCatalog));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want to drop the database if it exists first. You can call Utils.dropDatabaseIfExists().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unique id makes this unlikely, and Utils does not have a dropDatabaseIfExists functionality (only stored procedure and table). However, I will adjust the code to check for this as it's a good habit.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dropDatabaseIfExists is already on dev branch.

MessageFormat dashCatalogFormat = new MessageFormat(TestResource.getResource("R_atLeastOneFound"));
assertTrue(hasDashCatalogSchema, dashCatalogFormat.format(new Object[] {testSchema}));
} finally {
connection.createStatement().execute("IF EXISTS (SELECT name FROM sys.databases WHERE name = N'" + testCatalog + "') " +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace this with the method from Utils class too.

rene-ye and others added 3 commits June 18, 2018 13:36
UUID id = UUID.randomUUID();
String testCatalog = "dash-catalog" + id;
String testSchema = "some-schema" + id;
Statement stmt = connection.createStatement();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can move this into try with resources.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot resolve variables declared in try-with-resources in a finally block, and a finally block is used to drop the created db.

ulvii
ulvii previously approved these changes Jun 18, 2018
avoid manually closing statements, and safetly handles resources.
@rene-ye rene-ye merged commit 3fbb7d2 into microsoft:dev Jun 20, 2018
@rene-ye rene-ye deleted the issue715 branch June 20, 2018 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants