@@ -708,23 +708,91 @@ func TestIntegration_ReadsAndQueries(t *testing.T) {
708
708
spanner .Insert ("SomeStrings" , []string {"i" , "str" }, []interface {}{1 , "abar" }),
709
709
spanner .Insert ("SomeStrings" , []string {"i" , "str" }, []interface {}{2 , nil }),
710
710
spanner .Insert ("SomeStrings" , []string {"i" , "str" }, []interface {}{3 , "bbar" }),
711
-
712
- spanner .Insert ("Updateable" , []string {"id" , "first" , "last" }, []interface {}{0 , "joe" , nil }),
713
- spanner .Insert ("Updateable" , []string {"id" , "first" , "last" }, []interface {}{1 , "doe" , "joan" }),
714
- spanner .Insert ("Updateable" , []string {"id" , "first" , "last" }, []interface {}{2 , "wong" , "wong" }),
715
711
})
716
712
if err != nil {
717
713
t .Fatalf ("Inserting sample data: %v" , err )
718
714
}
719
715
716
+ // Perform INSERT DML; the results are checked later on.
717
+ n = 0
718
+ _ , err = client .ReadWriteTransaction (ctx , func (ctx context.Context , tx * spanner.ReadWriteTransaction ) error {
719
+ for _ , u := range []string {
720
+ `INSERT INTO Updateable (id, first, last) VALUES (0, "joe", nil)` ,
721
+ `INSERT INTO Updateable (id, first, last) VALUES (1, "doe", "joan")` ,
722
+ `INSERT INTO Updateable (id, first, last) VALUES (2, "wong", "wong")` ,
723
+ } {
724
+ nr , err := tx .Update (ctx , spanner .NewStatement (u ))
725
+ if err != nil {
726
+ return err
727
+ }
728
+ n += nr
729
+ }
730
+ return nil
731
+ })
732
+ if err != nil {
733
+ t .Fatalf ("Inserting with DML: %v" , err )
734
+ }
735
+ if n != 3 {
736
+ t .Errorf ("Inserting with DML affected %d rows, want 3" , n )
737
+ }
738
+
739
+ // Perform INSERT DML with statement.Params; the results are checked later on.
740
+ n = 0
741
+ _ , err = client .ReadWriteTransaction (ctx , func (ctx context.Context , tx * spanner.ReadWriteTransaction ) error {
742
+ stmt := spanner.Statement {
743
+ SQL : "INSERT INTO Updateable (id, first, last) VALUES (@id, @first, @last)" ,
744
+ Params : map [string ]interface {}{
745
+ "id" : 3 ,
746
+ "first" : "tom" ,
747
+ "last" : "jerry" ,
748
+ },
749
+ }
750
+ nr , err := tx .Update (ctx , stmt )
751
+ if err != nil {
752
+ return err
753
+ }
754
+ n += nr
755
+ return nil
756
+ })
757
+ if err != nil {
758
+ t .Fatalf ("Inserting with DML: %v" , err )
759
+ }
760
+ if n != 1 {
761
+ t .Errorf ("Inserting with DML affected %d rows, want 1" , n )
762
+ }
763
+
764
+ // Perform INSERT DML with statement.Params and inline parameter; the results are checked later on.
765
+ n = 0
766
+ _ , err = client .ReadWriteTransaction (ctx , func (ctx context.Context , tx * spanner.ReadWriteTransaction ) error {
767
+ stmt := spanner.Statement {
768
+ SQL : `INSERT INTO Updateable (id, first, last) VALUES (@id, "jim", @last)` ,
769
+ Params : map [string ]interface {}{
770
+ "id" : 4 ,
771
+ "last" : nil ,
772
+ },
773
+ }
774
+ nr , err := tx .Update (ctx , stmt )
775
+ if err != nil {
776
+ return err
777
+ }
778
+ n += nr
779
+ return nil
780
+ })
781
+ if err != nil {
782
+ t .Fatalf ("Inserting with DML: %v" , err )
783
+ }
784
+ if n != 1 {
785
+ t .Errorf ("Inserting with DML affected %d rows, want 1" , n )
786
+ }
787
+
720
788
// Perform UPDATE DML; the results are checked later on.
721
789
n = 0
722
790
_ , err = client .ReadWriteTransaction (ctx , func (ctx context.Context , tx * spanner.ReadWriteTransaction ) error {
723
791
for _ , u := range []string {
724
792
`UPDATE Updateable SET last = "bloggs" WHERE id = 0` ,
725
793
`UPDATE Updateable SET first = last, last = first WHERE id = 1` ,
726
794
`UPDATE Updateable SET last = DEFAULT WHERE id = 2` ,
727
- `UPDATE Updateable SET first = "noname" WHERE id = 3 ` , // no id=3
795
+ `UPDATE Updateable SET first = "noname" WHERE id = 5 ` , // no id=5
728
796
} {
729
797
nr , err := tx .Update (ctx , spanner .NewStatement (u ))
730
798
if err != nil {
@@ -1156,6 +1224,8 @@ func TestIntegration_ReadsAndQueries(t *testing.T) {
1156
1224
{int64 (0 ), "joe" , "bloggs" },
1157
1225
{int64 (1 ), "joan" , "doe" },
1158
1226
{int64 (2 ), "wong" , nil },
1227
+ {int64 (3 ), "tom" , "jerry" },
1228
+ {int64 (4 ), "jim" , nil },
1159
1229
},
1160
1230
},
1161
1231
// Regression test for aggregating no rows; it used to return an empty row.
0 commit comments