diff --git a/store/command_processor.go b/store/command_processor.go index 50b60c0a..c8c51043 100644 --- a/store/command_processor.go +++ b/store/command_processor.go @@ -11,22 +11,6 @@ import ( sql "github.com/rqlite/rqlite/v8/db" ) -// ExecuteResults is a slice of ExecuteResult, which detects mutations. -type ExecuteResults []*proto.ExecuteResult - -// Mutation returns true if any of the results mutated the database. -func (e ExecuteResults) Mutation() bool { - if len(e) == 0 { - return false - } - for i := range e { - if e[i].RowsAffected > 0 { - return true - } - } - return false -} - // ExecuteQueryResponses is a slice of ExecuteQueryResponse, which detects mutations. type ExecuteQueryResponses []*proto.ExecuteQueryResponse @@ -36,7 +20,7 @@ func (e ExecuteQueryResponses) Mutation() bool { return false } for i := range e { - if e[i].GetE() != nil && e[i].GetE().RowsAffected > 0 { + if e[i].GetE() != nil { return true } } @@ -78,7 +62,7 @@ func (c *CommandProcessor) Process(data []byte, pDB **sql.DB) (*proto.Command, b panic(fmt.Sprintf("failed to unmarshal execute subcommand: %s", err.Error())) } r, err := db.Execute(er.Request, er.Timings) - return cmd, ExecuteResults(r).Mutation(), &fsmExecuteResponse{results: r, error: err} + return cmd, true, &fsmExecuteResponse{results: r, error: err} case proto.Command_COMMAND_TYPE_EXECUTE_QUERY: var eqr proto.ExecuteQueryRequest if err := command.UnmarshalSubCommand(cmd, &eqr); err != nil { diff --git a/store/command_processor_test.go b/store/command_processor_test.go index 8144ad13..df285a26 100644 --- a/store/command_processor_test.go +++ b/store/command_processor_test.go @@ -6,35 +6,6 @@ import ( "github.com/rqlite/rqlite/v8/command/proto" ) -func Test_ExecuteResultsMutation_Nil(t *testing.T) { - var e ExecuteResults - if e.Mutation() { - t.Fatalf("expected no mutations for empty ExecuteResults") - } -} - -func Test_ExecuteResultsMutation_Check(t *testing.T) { - er0 := &proto.ExecuteResult{ - RowsAffected: 0, - } - er1 := &proto.ExecuteResult{ - RowsAffected: 1, - } - - e := ExecuteResults{er0} - if e.Mutation() { - t.Fatalf("expected no mutations") - } - e = ExecuteResults{er1} - if !e.Mutation() { - t.Fatalf("expected mutations") - } - e = ExecuteResults{er0, er1} - if !e.Mutation() { - t.Fatalf("expected mutations") - } -} - func Test_ExecuteQueryResponsesMutation(t *testing.T) { var e ExecuteQueryResponses if e.Mutation() { @@ -67,8 +38,8 @@ func Test_ExecuteQueryResponsesMutation_Check(t *testing.T) { } e := ExecuteQueryResponses{eqr0} - if e.Mutation() { - t.Fatalf("expected no mutations") + if !e.Mutation() { + t.Fatalf("expected mutations") } e = ExecuteQueryResponses{eqr1} if !e.Mutation() { @@ -83,10 +54,14 @@ func Test_ExecuteQueryResponsesMutation_Check(t *testing.T) { t.Fatalf("expected mutations") } e = ExecuteQueryResponses{eqr0, qqr} + if !e.Mutation() { + t.Fatalf("expected mutations") + } + e = ExecuteQueryResponses{qqr} if e.Mutation() { t.Fatalf("expected no mutations") } - e = ExecuteQueryResponses{qqr} + e = ExecuteQueryResponses{qqr, qqr} if e.Mutation() { t.Fatalf("expected no mutations") }