Skip to content

Commit dbf991c

Browse files
authored
Merge branch 'main' into base-grpc-call-context
2 parents 1064449 + 92494d0 commit dbf991c

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/Statement.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ public static Statement of(String sql) {
144144
return new Statement(sql, ImmutableMap.of(), /*queryOptions=*/ null);
145145
}
146146

147+
/** Creates a {@link Statement} with the given SQL text and parameters. */
148+
public static Statement of(String sql, ImmutableMap<String, Value> parameters) {
149+
return new Statement(sql, parameters, /*queryOptions=*/ null);
150+
}
151+
147152
/** Creates a new statement builder with the SQL text {@code sql}. */
148153
public static Builder newBuilder(String sql) {
149154
return new Builder(sql);

google-cloud-spanner/src/test/java/com/google/cloud/spanner/StatementTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import static com.google.common.testing.SerializableTester.reserializeAndAssert;
2020
import static com.google.common.truth.Truth.assertThat;
21+
import static org.junit.Assert.assertEquals;
22+
import static org.junit.Assert.assertFalse;
2123
import static org.junit.Assert.assertNotNull;
2224
import static org.junit.Assert.assertThrows;
2325

@@ -42,6 +44,17 @@ public void basic() {
4244
reserializeAndAssert(stmt);
4345
}
4446

47+
@Test
48+
public void basicWithParameters() {
49+
String sql = "SELECT @name";
50+
Statement stmt = Statement.of(sql, ImmutableMap.of("name", Value.string("hello")));
51+
assertEquals(sql, stmt.getSql());
52+
assertFalse(stmt.getParameters().isEmpty());
53+
assertEquals(Value.string("hello"), stmt.getParameters().get("name"));
54+
assertEquals(sql + " {name: hello}", stmt.toString());
55+
reserializeAndAssert(stmt);
56+
}
57+
4558
@Test
4659
public void serialization() {
4760
Statement stmt =

0 commit comments

Comments
 (0)