Skip to content

Commit

Permalink
#795 Implement disabling of retrieval of extended field info for Resu…
Browse files Browse the repository at this point in the history
…ltSetMetaData
  • Loading branch information
mrotteveel committed Mar 31, 2024
1 parent 7f71275 commit ae8cf6b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/main/org/firebirdsql/jdbc/FBConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -1480,4 +1480,9 @@ int getServerBatchBufferSize() {
return props != null ? props.getServerBatchBufferSize() : PropertyConstants.DEFAULT_SERVER_BATCH_BUFFER_SIZE;
}

boolean isExtendedMetadata() {
DatabaseConnectionProperties props = connectionProperties();
return props != null && props.isExtendedMetadata();
}

}
2 changes: 1 addition & 1 deletion src/main/org/firebirdsql/jdbc/FBResultSetMetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public String getColumnClassName(int column) throws SQLException {
@Override
@SuppressWarnings({ "java:S1994", "java:S135" })
protected Map<FieldKey, ExtendedFieldInfo> getExtendedFieldInfo(FBConnection connection) throws SQLException {
if (connection == null) return Collections.emptyMap();
if (connection == null || !connection.isExtendedMetadata()) return Collections.emptyMap();

final int fieldCount = getFieldCount();
int currentColumn = 1;
Expand Down
35 changes: 33 additions & 2 deletions src/test/org/firebirdsql/jdbc/FBResultSetMetaDataTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.firebirdsql.encodings.EncodingFactory;
import org.firebirdsql.gds.ng.DefaultDatatypeCoder;
import org.firebirdsql.gds.ng.fields.RowDescriptorBuilder;
import org.firebirdsql.jaybird.props.PropertyNames;
import org.firebirdsql.util.FirebirdSupportInfo;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand Down Expand Up @@ -63,7 +64,7 @@ two_byte_field VARCHAR(60) CHARACTER SET BIG_5,
three_byte_field VARCHAR(60) CHARACTER SET UNICODE_FSS,
long_field NUMERIC(15, 2),
int_field NUMERIC(8, 2),
short_field NUMERIC(4, 2),
short_field NUMERIC(3, 2),
char_octets_field CHAR(10) CHARACTER SET OCTETS,
varchar_octets_field VARCHAR(15) CHARACTER SET OCTETS,
calculated_field computed by (int_field + short_field)
Expand Down Expand Up @@ -104,7 +105,7 @@ void testResultSetMetaData() throws Exception {
assertEquals(60, metaData.getPrecision(3), "three_byte_field must have size 60");
assertEquals(15, metaData.getPrecision(4), "long_field must have precision 15");
assertEquals(8, metaData.getPrecision(5), "int_field must have precision 8");
assertEquals(4, metaData.getPrecision(6), "short_field must have precision 4");
assertEquals(3, metaData.getPrecision(6), "short_field must have precision 4");

for (int idx = 1; idx <= 6; idx++) {
assertFalse(metaData.isAutoIncrement(idx),
Expand Down Expand Up @@ -440,4 +441,34 @@ void isAutoIncrement_identityColumn(JDBCType columnType) throws Exception {
}
}

@ParameterizedTest
@EnumSource(value = JDBCType.class, names = { "SMALLINT", "INTEGER", "BIGINT" })
void isAutoIncrement_extendedMetadataDisabled(JDBCType columnType) throws Exception {
assumeFeature(FirebirdSupportInfo::supportsIdentityColumns, "Test requires identity column support");
try (var connection = getConnectionViaDriverManager(PropertyNames.extendedMetadata, "false");
var stmt = connection.createStatement()) {
stmt.execute(RECREATE_AUTO_INC_TABLE_TEMPLATE.formatted(columnType.name()));

var rs = stmt.executeQuery(TEST_QUERY_AUTO_INC);
ResultSetMetaData rsmd = rs.getMetaData();
assertFalse(rsmd.isAutoIncrement(1), "Expected autoIncrement false when extendedMetadata=false");
}
}

@Test
void getPrecision_extendedMetadataDisabled() throws Exception {
try (var connection = getConnectionViaDriverManager(PropertyNames.extendedMetadata, "false");
var stmt = connection.createStatement()) {
var rs = stmt.executeQuery("select long_field, int_field, short_field from test_rs_metadata");

ResultSetMetaData rsmd = rs.getMetaData();
assertEquals(18, rsmd.getPrecision(1),
"Expected estimated precision 18 for long_field when extendedMetadata = false");
assertEquals(9, rsmd.getPrecision(2),
"Expected estimated precision 9 for int_field when extendedMetadata = false");
assertEquals(4, rsmd.getPrecision(3),
"Expected estimated precision 4 for short_field when extendedMetadata = false");
}
}

}

0 comments on commit ae8cf6b

Please sign in to comment.