Skip to content

Commit

Permalink
Added test cases for QUOTED_IDENTIFIER/CONCAT_NULL_YIELDS_NULL flags'…
Browse files Browse the repository at this point in the history
… value for new and pooled connection
  • Loading branch information
Divang Sharma committed Mar 4, 2025
1 parent e3d0cf2 commit 4e7192a
Showing 1 changed file with 120 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,126 @@ public void testConnectionPoolGetTwice() throws SQLException {
}
}

/**
* Test connection properties: CONCAT_NULL_YIELDS_NULL with SQLServerXADataSource for new connection and pooled connection
* @throws SQLException
*/
@Test
public void testConcatNullYieldsNull() throws SQLException {
SQLServerDataSource ds = new SQLServerDataSource();
ds.setURL(connectionString);
ds.setConcatNullYieldsNull("OFF");
int expectedResultForNewConnection = 0;
// Server default is CONCAT_NULL_YIELDS_NULL = ON
int expectedResultForPooledConnection = 1;

String sqlSelect = "SELECT SESSIONPROPERTY('CONCAT_NULL_YIELDS_NULL')";

try (Connection con = ds.getConnection(); Statement stmt = con.createStatement()) {
try (ResultSet rs = stmt.executeQuery(sqlSelect)) {
if (rs.next()) {
assertEquals(expectedResultForNewConnection, rs.getInt(1));
} else {
assertTrue(false, "Expected row of data was not found.");
}
}
}

// Test pooled connections
SQLServerXADataSource pds = new SQLServerXADataSource();
pds.setURL(connectionString);
pds.setConcatNullYieldsNull("OFF");

PooledConnection pc = pds.getPooledConnection();
try {
try (Connection con = pc.getConnection(); Statement statement = con.createStatement()) {
try (ResultSet rs = statement.executeQuery(sqlSelect)) {
if (rs.next()) {
assertEquals(expectedResultForNewConnection, rs.getInt(1));
} else {
assertTrue(false, "Expected row of data was not found.");
}
}
}
// Repeat getConnection to put the physical connection through a RESETCONNECTION
try (Connection con = pc.getConnection(); Statement statement = con.createStatement()) {
try (ResultSet rs = statement.executeQuery(sqlSelect)) {
if (rs.next()) {
assertEquals(expectedResultForPooledConnection, rs.getInt(1));
} else {
assertTrue(false, "Expected row of data was not found.");
}
}
}
} catch (Exception e) {
fail(TestResource.getResource("R_unexpectedErrorMessage") + e.getMessage());
} finally {
if (null != pc) {
pc.close();
}
}
}

/**
* Test connection properties: QUOTED_IDENTIFIER with SQLServerXADataSource for new connection and pooled connection
* @throws SQLException
*/
@Test
public void testQuptedIdentifier() throws SQLException {
SQLServerDataSource ds = new SQLServerDataSource();
ds.setURL(connectionString);
ds.setQuotedIdentifier("OFF");
int expectedResultForNewConnection = 0;
// Server default is QUOTED_IDENTIFIER = ON
int expectedResultForPooledConnection = 1;

String sqlSelect = "SELECT SESSIONPROPERTY('QUOTED_IDENTIFIER')";

try (Connection con = ds.getConnection(); Statement stmt = con.createStatement()) {
try (ResultSet rs = stmt.executeQuery(sqlSelect)) {
if (rs.next()) {
assertEquals(expectedResultForNewConnection, rs.getInt(1));
} else {
assertTrue(false, "Expected row of data was not found.");
}
}
}

// Test pooled connections
SQLServerXADataSource pds = new SQLServerXADataSource();
pds.setURL(connectionString);
pds.setQuotedIdentifier("OFF");

PooledConnection pc = pds.getPooledConnection();
try {
try (Connection con = pc.getConnection(); Statement statement = con.createStatement()) {
try (ResultSet rs = statement.executeQuery(sqlSelect)) {
if (rs.next()) {
assertEquals(expectedResultForNewConnection, rs.getInt(1));
} else {
assertTrue(false, "Expected row of data was not found.");
}
}
}
// Repeat getConnection to put the physical connection through a RESETCONNECTION
try (Connection con = pc.getConnection(); Statement statement = con.createStatement()) {
try (ResultSet rs = statement.executeQuery(sqlSelect)) {
if (rs.next()) {
assertEquals(expectedResultForPooledConnection, rs.getInt(1));
} else {
assertTrue(false, "Expected row of data was not found.");
}
}
}
} catch (Exception e) {
fail(TestResource.getResource("R_unexpectedErrorMessage") + e.getMessage());
} finally {
if (null != pc) {
pc.close();
}
}
}

/**
* Runs the `testConnectCountInLoginAndCorrectRetryCount` test several times with different values of
* connectRetryCount.
Expand Down

0 comments on commit 4e7192a

Please sign in to comment.