Skip to content

Commit c4b6d92

Browse files
committed
set ReadyForQuery transaction indicater for in transaction query
1 parent bdf207a commit c4b6d92

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20241119094239-f4e529af734d
1111
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2
1212
github.com/dolthub/go-icu-regex v0.0.0-20250327004329-6799764f2dad
13-
github.com/dolthub/go-mysql-server v0.20.1-0.20250520164330-094c26d756a3
13+
github.com/dolthub/go-mysql-server v0.20.1-0.20250520221132-8961ce0f4cab
1414
github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216
1515
github.com/dolthub/vitess v0.0.0-20250512224608-8fb9c6ea092c
1616
github.com/fatih/color v1.13.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ github.com/dolthub/fslock v0.0.3 h1:iLMpUIvJKMKm92+N1fmHVdxJP5NdyDK5bK7z7Ba2s2U=
266266
github.com/dolthub/fslock v0.0.3/go.mod h1:QWql+P17oAAMLnL4HGB5tiovtDuAjdDTPbuqx7bYfa0=
267267
github.com/dolthub/go-icu-regex v0.0.0-20250327004329-6799764f2dad h1:66ZPawHszNu37VPQckdhX1BPPVzREsGgNxQeefnlm3g=
268268
github.com/dolthub/go-icu-regex v0.0.0-20250327004329-6799764f2dad/go.mod h1:ylU4XjUpsMcvl/BKeRRMXSH7e7WBrPXdSLvnRJYrxEA=
269-
github.com/dolthub/go-mysql-server v0.20.1-0.20250520164330-094c26d756a3 h1:rFkHy4L/GfVQh7KxwFPI/QmkPcBpT/PjnHLp+zde0xA=
270-
github.com/dolthub/go-mysql-server v0.20.1-0.20250520164330-094c26d756a3/go.mod h1:5ZdrW0fHZbz+8CngT9gksqSX4H3y+7v1pns7tJCEpu0=
269+
github.com/dolthub/go-mysql-server v0.20.1-0.20250520221132-8961ce0f4cab h1:gbxIHdLroWf8fdPRvs2o5CyvcHcgRJIF2D9Lw+L6Wd8=
270+
github.com/dolthub/go-mysql-server v0.20.1-0.20250520221132-8961ce0f4cab/go.mod h1:5ZdrW0fHZbz+8CngT9gksqSX4H3y+7v1pns7tJCEpu0=
271271
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63 h1:OAsXLAPL4du6tfbBgK0xXHZkOlos63RdKYS3Sgw/dfI=
272272
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63/go.mod h1:lV7lUeuDhH5thVGDCKXbatwKy2KW80L4rMT46n+Y2/Q=
273273
github.com/dolthub/ishell v0.0.0-20240701202509-2b217167d718 h1:lT7hE5k+0nkBdj/1UOSFwjWpNxf+LCApbRHgnCA17XE=

server/connection_handler.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ type ConnectionHandler struct {
6565
// copyFromStdinState is set when this connection is in the COPY FROM STDIN mode, meaning it is waiting on
6666
// COPY DATA messages from the client to import data into tables.
6767
copyFromStdinState *copyFromStdinState
68+
// inTransaction is set to true with BEGIN query and false with COMMIT query.
69+
inTransaction bool
6870
}
6971

7072
// 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
448450
// and any error that occurred while handling the query.
449451
func (h *ConnectionHandler) handleQueryOutsideEngine(query ConvertedQuery) (handled bool, endOfMessages bool, err error) {
450452
switch stmt := query.AST.(type) {
453+
case *sqlparser.Begin:
454+
h.inTransaction = true
455+
case *sqlparser.Commit:
456+
h.inTransaction = false
451457
case *sqlparser.Deallocate:
452458
// TODO: handle ALL keyword
453459
return true, true, h.deallocatePreparedStatement(stmt.Name, h.preparedStatements, query, h.Conn())
@@ -1032,10 +1038,15 @@ func (h *ConnectionHandler) handledPSQLCommands(statement string) (bool, error)
10321038
// query. A nil error should be provided if this is being called naturally.
10331039
func (h *ConnectionHandler) endOfMessages(err error) {
10341040
if err != nil {
1041+
// TODO: is ReadyForQueryTransactionIndicator_FailedTransactionBlock used here?
10351042
h.sendError(err)
10361043
}
1044+
ti := ReadyForQueryTransactionIndicator_Idle
1045+
if h.inTransaction {
1046+
ti = ReadyForQueryTransactionIndicator_TransactionBlock
1047+
}
10371048
if sendErr := h.send(&pgproto3.ReadyForQuery{
1038-
TxStatus: byte(ReadyForQueryTransactionIndicator_Idle),
1049+
TxStatus: byte(ti),
10391050
}); sendErr != nil {
10401051
// We panic here for the same reason as above.
10411052
panic(sendErr)

testing/go/prepared_statement_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,19 @@ var preparedStatementTests = []ScriptTest{
425425
},
426426
},
427427
},
428+
{
429+
Name: "insert returning",
430+
SetUpScript: []string{
431+
"CREATE TABLE test (id serial, name text)",
432+
},
433+
Assertions: []ScriptTestAssertion{
434+
{
435+
Query: `INSERT INTO test (name) VALUES ($1) RETURNING id;`,
436+
BindVars: []any{"test_name"},
437+
Expected: []sql.Row{{1}},
438+
},
439+
},
440+
},
428441
}
429442

430443
var pgCatalogTests = []ScriptTest{

0 commit comments

Comments
 (0)