diff --git a/go.mod b/go.mod index d29f4c6dda..a21b946bca 100644 --- a/go.mod +++ b/go.mod @@ -6,11 +6,11 @@ require ( github.com/PuerkitoBio/goquery v1.8.1 github.com/cockroachdb/apd/v2 v2.0.3-0.20200518165714-d020e156310a github.com/cockroachdb/errors v1.7.5 - github.com/dolthub/dolt/go v0.40.5-0.20250520172729-f53346406459 + github.com/dolthub/dolt/go v0.40.5-0.20250521162506-c6ea8c2b8100 github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20241119094239-f4e529af734d github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2 github.com/dolthub/go-icu-regex v0.0.0-20250327004329-6799764f2dad - github.com/dolthub/go-mysql-server v0.20.1-0.20250520164330-094c26d756a3 + github.com/dolthub/go-mysql-server v0.20.1-0.20250521012141-b56c7c6eb677 github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216 github.com/dolthub/vitess v0.0.0-20250512224608-8fb9c6ea092c github.com/fatih/color v1.13.0 diff --git a/go.sum b/go.sum index 782f0eee80..a97a1b5a39 100644 --- a/go.sum +++ b/go.sum @@ -256,8 +256,8 @@ github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5Xh github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/dolthub/aws-sdk-go-ini-parser v0.0.0-20250305001723-2821c37f6c12 h1:IdqX7J8vi/Kn3T3Ee0VzqnLqwFmgA2hr8WZETPcQjfM= github.com/dolthub/aws-sdk-go-ini-parser v0.0.0-20250305001723-2821c37f6c12/go.mod h1:rN7X8BHwkjPcfMQQ2QTAq/xM3leUSGLfb+1Js7Y6TVo= -github.com/dolthub/dolt/go v0.40.5-0.20250520172729-f53346406459 h1:mFO2ikky1GeQpmzJqwHo4gtqYdUWny87jPt/e0vns+Q= -github.com/dolthub/dolt/go v0.40.5-0.20250520172729-f53346406459/go.mod h1:yfrZxLTPXDKTp8GFILkkaDqpQODcOaZZ+14Y6+h2gkc= +github.com/dolthub/dolt/go v0.40.5-0.20250521162506-c6ea8c2b8100 h1:DTETzc2InAOP0ZDNGLaXxaQ0+VeUlKDf+XJdlAvpsko= +github.com/dolthub/dolt/go v0.40.5-0.20250521162506-c6ea8c2b8100/go.mod h1:0Fh/6GdGFk37fejDIap/23XSdv6vMUwoqv99g4sr8O8= github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20241119094239-f4e529af734d h1:gO9+wrmNHXukPNCO1tpfCcXIdMlW/qppbUStfLvqz/U= github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20241119094239-f4e529af734d/go.mod h1:L5RDYZbC9BBWmoU2+TjTekeqqhFXX5EqH9ln00O0stY= github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2 h1:u3PMzfF8RkKd3lB9pZ2bfn0qEG+1Gms9599cr0REMww= @@ -266,8 +266,8 @@ github.com/dolthub/fslock v0.0.3 h1:iLMpUIvJKMKm92+N1fmHVdxJP5NdyDK5bK7z7Ba2s2U= github.com/dolthub/fslock v0.0.3/go.mod h1:QWql+P17oAAMLnL4HGB5tiovtDuAjdDTPbuqx7bYfa0= github.com/dolthub/go-icu-regex v0.0.0-20250327004329-6799764f2dad h1:66ZPawHszNu37VPQckdhX1BPPVzREsGgNxQeefnlm3g= github.com/dolthub/go-icu-regex v0.0.0-20250327004329-6799764f2dad/go.mod h1:ylU4XjUpsMcvl/BKeRRMXSH7e7WBrPXdSLvnRJYrxEA= -github.com/dolthub/go-mysql-server v0.20.1-0.20250520164330-094c26d756a3 h1:rFkHy4L/GfVQh7KxwFPI/QmkPcBpT/PjnHLp+zde0xA= -github.com/dolthub/go-mysql-server v0.20.1-0.20250520164330-094c26d756a3/go.mod h1:5ZdrW0fHZbz+8CngT9gksqSX4H3y+7v1pns7tJCEpu0= +github.com/dolthub/go-mysql-server v0.20.1-0.20250521012141-b56c7c6eb677 h1:Wn0v7xBxkdzYqDN/4ksI34jstZOskMccT2SYFrvUw4c= +github.com/dolthub/go-mysql-server v0.20.1-0.20250521012141-b56c7c6eb677/go.mod h1:5ZdrW0fHZbz+8CngT9gksqSX4H3y+7v1pns7tJCEpu0= github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63 h1:OAsXLAPL4du6tfbBgK0xXHZkOlos63RdKYS3Sgw/dfI= github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63/go.mod h1:lV7lUeuDhH5thVGDCKXbatwKy2KW80L4rMT46n+Y2/Q= github.com/dolthub/ishell v0.0.0-20240701202509-2b217167d718 h1:lT7hE5k+0nkBdj/1UOSFwjWpNxf+LCApbRHgnCA17XE= diff --git a/server/connection_handler.go b/server/connection_handler.go index 9afdf23ff8..8f3be00f2f 100644 --- a/server/connection_handler.go +++ b/server/connection_handler.go @@ -65,6 +65,8 @@ type ConnectionHandler struct { // copyFromStdinState is set when this connection is in the COPY FROM STDIN mode, meaning it is waiting on // COPY DATA messages from the client to import data into tables. copyFromStdinState *copyFromStdinState + // inTransaction is set to true with BEGIN query and false with COMMIT query. + inTransaction bool } // Set this env var to disable panic handling in the connection, which is useful when debugging a panic @@ -448,6 +450,10 @@ func (h *ConnectionHandler) handleQuery(message *pgproto3.Query) (endOfMessages // and any error that occurred while handling the query. func (h *ConnectionHandler) handleQueryOutsideEngine(query ConvertedQuery) (handled bool, endOfMessages bool, err error) { switch stmt := query.AST.(type) { + case *sqlparser.Begin: + h.inTransaction = true + case *sqlparser.Commit: + h.inTransaction = false case *sqlparser.Deallocate: // TODO: handle ALL keyword return true, true, h.deallocatePreparedStatement(stmt.Name, h.preparedStatements, query, h.Conn()) @@ -1032,10 +1038,15 @@ func (h *ConnectionHandler) handledPSQLCommands(statement string) (bool, error) // query. A nil error should be provided if this is being called naturally. func (h *ConnectionHandler) endOfMessages(err error) { if err != nil { + // TODO: is ReadyForQueryTransactionIndicator_FailedTransactionBlock used here? h.sendError(err) } + ti := ReadyForQueryTransactionIndicator_Idle + if h.inTransaction { + ti = ReadyForQueryTransactionIndicator_TransactionBlock + } if sendErr := h.send(&pgproto3.ReadyForQuery{ - TxStatus: byte(ReadyForQueryTransactionIndicator_Idle), + TxStatus: byte(ti), }); sendErr != nil { // We panic here for the same reason as above. panic(sendErr) diff --git a/testing/go/prepared_statement_test.go b/testing/go/prepared_statement_test.go index 50e4cf5e33..4bbf03fbb8 100755 --- a/testing/go/prepared_statement_test.go +++ b/testing/go/prepared_statement_test.go @@ -425,6 +425,19 @@ var preparedStatementTests = []ScriptTest{ }, }, }, + { + Name: "insert returning", + SetUpScript: []string{ + "CREATE TABLE test (id serial, name text)", + }, + Assertions: []ScriptTestAssertion{ + { + Query: `INSERT INTO test (name) VALUES ($1) RETURNING id;`, + BindVars: []any{"test_name"}, + Expected: []sql.Row{{1}}, + }, + }, + }, } var pgCatalogTests = []ScriptTest{