Skip to content
Open
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 @@ -20,6 +20,7 @@
import com.google.cloud.spanner.pgadapter.error.PGExceptionFactory;
import com.google.cloud.spanner.pgadapter.error.SQLState;
import com.google.cloud.spanner.pgadapter.parsers.Parser;
import com.google.common.base.Preconditions;
import com.google.spanner.v1.StructType;
import java.util.Arrays;
import javax.annotation.Nullable;
Expand All @@ -31,6 +32,10 @@ public class DescribeResult {
@Nullable private final Type columns;
private final int[] parameters;

public static DescribeResult of(int[] givenParameterTypes, @Nullable Type columns) {
return new DescribeResult(givenParameterTypes, columns);
}

public DescribeResult(int[] givenParameterTypes, @Nullable ResultSet resultMetadata) {
this(
givenParameterTypes,
Expand All @@ -40,11 +45,15 @@ public DescribeResult(int[] givenParameterTypes, @Nullable ResultSet resultMetad
resultMetadata == null ? null : resultMetadata.getType());
}

private DescribeResult(int[] givenParameterTypes, @Nullable Type columns) {
this(givenParameterTypes, null, columns);
}

private DescribeResult(
int[] givenParameterTypes,
@Nullable StructType undeclaredParameters,
@Nullable Type columns) {
this.givenParameterTypes = givenParameterTypes;
this.givenParameterTypes = Preconditions.checkNotNull(givenParameterTypes);
this.undeclaredParameters = undeclaredParameters;
this.parameters = extractParameters(givenParameterTypes, undeclaredParameters);
this.columns = columns;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ public IntermediatePreparedStatement getPreparedStatement() {
}

public short getParameterFormatCode(int index) {
if (this.parameterFormatCodes.length == 0) {
if (this.parameterFormatCodes == null || this.parameterFormatCodes.length == 0) {
return 0;
} else if (index >= this.parameterFormatCodes.length) {
} else if (this.parameterFormatCodes.length == 1) {
return this.parameterFormatCodes[0];
} else if (index < 0 || index >= this.parameterFormatCodes.length) {
return 0;
} else {
return this.parameterFormatCodes[index];
}
Expand All @@ -80,6 +82,8 @@ public short getResultFormatCode(int index) {
return super.getResultFormatCode(index);
} else if (this.resultFormatCodes.length == 1) {
return this.resultFormatCodes[0];
} else if (index < 0 || index >= this.resultFormatCodes.length) {
return super.getResultFormatCode(index);
} else {
return this.resultFormatCodes[index];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public Future<StatementResult> describeAsync(BackendConnection backendConnection
new DescribeResult(this.givenParameterDataTypes, result.getResultSet());
result.getResultSet().close();
} else {
describeResult = new DescribeResult(this.givenParameterDataTypes, null);
describeResult = DescribeResult.of(this.givenParameterDataTypes, null);
}
return describeResult;
},
Expand All @@ -158,7 +158,7 @@ public DescribeResult describe() {
if (this.describeResult == null) {
// Just return a DescribeResult that contains whatever information we were given in the
// PARSE message.
return new DescribeResult(this.givenParameterDataTypes, null);
return DescribeResult.of(this.givenParameterDataTypes, null);
}
try {
return this.describeResult.get();
Expand Down
Loading
Loading