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 pipeline failure by handling strict mode exceptions for null values. #2628

Merged
merged 2 commits into from
Mar 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.microsoft.sqlserver.jdbc.unit.lobs;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
Expand Down Expand Up @@ -310,23 +311,15 @@ public void testGetAsciiStreamOnXml() {
stmt.executeUpdate("INSERT INTO " + tableName + " (col1) VALUES (NULL)");

try (ResultSet rs = stmt.executeQuery("SELECT col1 FROM " + tableName)) {
int rowIndex = 0;
while (rs.next()) {
rowIndex++;
try {
InputStream asciiStream = rs.getAsciiStream(1);
if (rowIndex == 1) {
fail("Expected SQLException was not thrown for non-null value"); // Non-null value: Should throw an exception
} else {
assertNull(asciiStream, "Expected null for NULL value, but got a non-null InputStream"); // Null value: Should return null without throwing an exception
}
// If no exception is thrown, assert the value is null
assertNull(asciiStream, "Expected null for NULL value, but got a non-null InputStream");
} catch (SQLException e) {
if (rowIndex == 1) {
assertTrue(e.getMessage().contains("The conversion from xml to AsciiStream is unsupported."),
"Unexpected SQLException message: " + e.getMessage());
} else {
fail("Unexpected SQLException for NULL value: " + e.getMessage());
}
// Ensure that only expected exceptions occur
assertTrue(e.getMessage().contains("The conversion from xml to AsciiStream is unsupported."),
"Unexpected SQLException message: " + e.getMessage());
}
}
}
Expand All @@ -345,22 +338,15 @@ public void testGetBinaryStreamOnVarchar() {
stmt.executeUpdate("INSERT INTO " + tableName + " (col1) VALUES (NULL)");

try (ResultSet rs = stmt.executeQuery("SELECT col1 FROM " + tableName)) {
int rowIndex = 0;
while (rs.next()) {
rowIndex++;
try {
InputStream binaryStream = rs.getBinaryStream(1);
if (rowIndex == 1)
fail("Expected SQLException was not thrown for non-null value"); // Non-null value
else
assertNull(binaryStream, "Expected null for NULL value, but got a non-null InputStream"); // Null value
// If no exception is thrown, assert the value is null
assertNull(binaryStream, "Expected null for NULL value, but got a non-null InputStream");
} catch (SQLException e) {
if (rowIndex == 1) {
assertTrue(e.getMessage().contains("The conversion from varchar to BinaryStream is unsupported."),
"Unexpected SQLException message: " + e.getMessage());
} else {
fail("Unexpected SQLException for NULL value: " + e.getMessage());
}
// Ensure that only expected exceptions occur
assertTrue(e.getMessage().contains("The conversion from varchar to BinaryStream is unsupported."),
"Unexpected SQLException message: " + e.getMessage());
}
}
}
Expand Down
Loading