Skip to content

Commit d09ae43

Browse files
chore: add unknownLength connection property (#4223)
* chore: add unknownLength connection property Add an unknownLength connection property that can be used to determine what length should be returned by a driver when it is requested to return the length of a data type without a known length. This is similar to the unknownLength connection parameter implemented by the PostgreSQL JDBC driver: https://jdbc.postgresql.org/documentation/use/#connection-parameters * chore: generate libraries at Fri Nov 14 10:56:58 UTC 2025 --------- Co-authored-by: cloud-java-bot <[email protected]>
1 parent 3ee4d3a commit d09ae43

File tree

5 files changed

+32
-1
lines changed

5 files changed

+32
-1
lines changed

google-cloud-spanner/clirr-ignored-differences.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,4 +1057,9 @@
10571057
<differenceType>8001</differenceType>
10581058
<className>com/google/cloud/spanner/LatencyTest</className>
10591059
</difference>
1060+
<difference>
1061+
<differenceType>7012</differenceType>
1062+
<className>com/google/cloud/spanner/connection/Connection</className>
1063+
<method>java.lang.Object getConnectionPropertyValue(com.google.cloud.spanner.connection.ConnectionProperty)</method>
1064+
</difference>
10601065
</differences>

google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/Connection.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ public interface Connection extends AutoCloseable {
189189
*/
190190
void reset();
191191

192+
/** Returns the current value of the given connection property. */
193+
<T> T getConnectionPropertyValue(
194+
com.google.cloud.spanner.connection.ConnectionProperty<T> property);
195+
192196
/**
193197
* Sets autocommit on/off for this {@link Connection}. Connections in autocommit mode will apply
194198
* any changes to the database directly without waiting for an explicit commit. DDL- and DML

google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ConnectionImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,8 @@ public boolean isClosed() {
574574
return closed;
575575
}
576576

577-
private <T> T getConnectionPropertyValue(
577+
@Override
578+
public <T> T getConnectionPropertyValue(
578579
com.google.cloud.spanner.connection.ConnectionProperty<T> property) {
579580
return this.connectionState.getValue(property).getValue();
580581
}

google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ConnectionProperties.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,18 @@ public class ConnectionProperties {
766766
DEFAULT_BATCH_DML_UPDATE_COUNT,
767767
LongConverter.INSTANCE,
768768
Context.USER);
769+
public static final ConnectionProperty<Integer> UNKNOWN_LENGTH =
770+
create(
771+
"unknownLength",
772+
"Spanner does not return the length of the selected columns in query results. When"
773+
+ " returning meta-data about these columns through functions like"
774+
+ " ResultSetMetaData.getColumnDisplaySize and ResultSetMetaData.getPrecision, we"
775+
+ " must provide a value. Various client tools and applications have different ideas"
776+
+ " about what they would like to see. This property specifies the length to return"
777+
+ " for types of unknown length.",
778+
/* defaultValue= */ 50,
779+
NonNegativeIntegerConverter.INSTANCE,
780+
Context.USER);
769781

770782
static final ImmutableMap<String, ConnectionProperty<?>> CONNECTION_PROPERTIES =
771783
CONNECTION_PROPERTIES_BUILDER.build();

google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/ConnectionStateMockServerTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,4 +291,13 @@ public void testSetLocalInvalidValue() {
291291
assertTrue(connection.isRetryAbortsInternally());
292292
}
293293
}
294+
295+
@Test
296+
public void testGetConnectionProperty() {
297+
try (Connection connection = createConnection()) {
298+
ConnectionProperty<Integer> unknownLength = ConnectionProperties.UNKNOWN_LENGTH;
299+
assertEquals(
300+
unknownLength.getDefaultValue(), connection.getConnectionPropertyValue(unknownLength));
301+
}
302+
}
294303
}

0 commit comments

Comments
 (0)