diff --git a/rows.go b/rows.go index 35e85d0..d652caf 100644 --- a/rows.go +++ b/rows.go @@ -16,6 +16,7 @@ package spannerdriver import ( "database/sql/driver" + "fmt" "io" "sync" @@ -265,7 +266,11 @@ func (r *rows) Next(dest []driver.Value) error { return err } dest[i] = v + default: + return fmt.Errorf("unsupported element type ARRAY<%v>", col.Type.ArrayElementType.Code) } + default: + return fmt.Errorf("unsupported element type %v", col.Type.Code) } // TODO: Implement struct } diff --git a/rows_test.go b/rows_test.go index 81409ac..a3dca4c 100644 --- a/rows_test.go +++ b/rows_test.go @@ -22,6 +22,7 @@ import ( "cloud.google.com/go/spanner" sppb "cloud.google.com/go/spanner/apiv1/spannerpb" + "google.golang.org/protobuf/types/known/structpb" ) type testIterator struct { @@ -81,6 +82,9 @@ func TestRows_Next(t *testing.T) { if err == io.EOF { break } + if err != nil { + t.Fatal(err) + } row := make([]driver.Value, 3) copy(row, dest) values = append(values, row) @@ -109,3 +113,37 @@ func TestRows_Next(t *testing.T) { } } } + +func TestRows_Next_Unsupported(t *testing.T) { + unspecifiedType := &sppb.Type{Code: sppb.TypeCode_TYPE_CODE_UNSPECIFIED} + + it := testIterator{ + metadata: &sppb.ResultSetMetadata{ + RowType: &sppb.StructType{ + Fields: []*sppb.StructType_Field{ + {Name: "COL1", Type: unspecifiedType}, + }, + }, + }, + rows: []*spanner.Row{ + newRow(t, []string{"COL1"}, []any{ + spanner.GenericColumnValue{ + Type: unspecifiedType, + Value: &structpb.Value{}, + }, + }), + }, + } + + rows := rows{it: &it} + + dest := make([]driver.Value, 1) + err := rows.Next(dest) + if err == nil { + t.Fatal("expected an error, but got nil") + } + const expectedError = "unsupported element type TYPE_CODE_UNSPECIFIED" + if err.Error() != expectedError { + t.Fatalf("expected error %q, but got %q", expectedError, err.Error()) + } +}