File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed
main/java/com/google/cloud/spanner
test/java/com/google/cloud/spanner Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff 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 );
Original file line number Diff line number Diff line change 1818
1919import static com .google .common .testing .SerializableTester .reserializeAndAssert ;
2020import static com .google .common .truth .Truth .assertThat ;
21+ import static org .junit .Assert .assertEquals ;
22+ import static org .junit .Assert .assertFalse ;
2123import static org .junit .Assert .assertNotNull ;
2224import 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 =
You can’t perform that action at this time.
0 commit comments