Skip to content
Merged
Show file tree
Hide file tree
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
Expand Up @@ -176,8 +176,13 @@ final public String toString() {
}
if (nState == 1) {
if (sToken.trim().length() > 0) {
if (sToken.charAt(0) != ',')
if (sToken.charAt(0) != ',') {
sLastField = escapeParse(st, sToken);

// in case the parameter has braces in its name, e.g. [c2_nvarchar(max)], the original sToken variable just
// contains [c2_nvarchar, sLastField actually has the whole name [c2_nvarchar(max)]
sTokenIndex = sTokenIndex + (sLastField.length() - sToken.length());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public void testParameterMetaDataWrapper() throws SQLException {
finally {
Utils.dropTableIfExists(tableName, stmt);
}

}
}

Expand All @@ -73,4 +72,27 @@ public void testSQLServerExceptionNotWrapped() throws SQLException {
"SQLServerException should not be wrapped by another SQLServerException.");
}
}

/**
* Test ParameterMetaData when parameter name contains braces
*
* @throws SQLException
*/
@Test
public void testNameWithBraces() throws SQLException {
try (Connection con = DriverManager.getConnection(connectionString); Statement stmt = con.createStatement()) {

stmt.executeUpdate("create table " + tableName + " ([c1_varchar(max)] varchar(max))");
try {
String query = "insert into " + tableName + " ([c1_varchar(max)]) values (?)";

try (PreparedStatement pstmt = con.prepareStatement(query)) {
pstmt.getParameterMetaData();
}
}
finally {
Utils.dropTableIfExists(tableName, stmt);
}
}
}
}