Skip to content

Commit da46cc1

Browse files
authored
Merge pull request #1489 from dolthub/jennifer/laravel
set ReadyForQuery transaction indicator for in transaction query
2 parents bdf207a + 6ceca30 commit da46cc1

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ require (
66
github.com/PuerkitoBio/goquery v1.8.1
77
github.com/cockroachdb/apd/v2 v2.0.3-0.20200518165714-d020e156310a
88
github.com/cockroachdb/errors v1.7.5
9-
github.com/dolthub/dolt/go v0.40.5-0.20250520172729-f53346406459
9+
github.com/dolthub/dolt/go v0.40.5-0.20250521162506-c6ea8c2b8100
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.20250521012141-b56c7c6eb677
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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,8 @@ github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5Xh
256256
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
257257
github.com/dolthub/aws-sdk-go-ini-parser v0.0.0-20250305001723-2821c37f6c12 h1:IdqX7J8vi/Kn3T3Ee0VzqnLqwFmgA2hr8WZETPcQjfM=
258258
github.com/dolthub/aws-sdk-go-ini-parser v0.0.0-20250305001723-2821c37f6c12/go.mod h1:rN7X8BHwkjPcfMQQ2QTAq/xM3leUSGLfb+1Js7Y6TVo=
259-
github.com/dolthub/dolt/go v0.40.5-0.20250520172729-f53346406459 h1:mFO2ikky1GeQpmzJqwHo4gtqYdUWny87jPt/e0vns+Q=
260-
github.com/dolthub/dolt/go v0.40.5-0.20250520172729-f53346406459/go.mod h1:yfrZxLTPXDKTp8GFILkkaDqpQODcOaZZ+14Y6+h2gkc=
259+
github.com/dolthub/dolt/go v0.40.5-0.20250521162506-c6ea8c2b8100 h1:DTETzc2InAOP0ZDNGLaXxaQ0+VeUlKDf+XJdlAvpsko=
260+
github.com/dolthub/dolt/go v0.40.5-0.20250521162506-c6ea8c2b8100/go.mod h1:0Fh/6GdGFk37fejDIap/23XSdv6vMUwoqv99g4sr8O8=
261261
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20241119094239-f4e529af734d h1:gO9+wrmNHXukPNCO1tpfCcXIdMlW/qppbUStfLvqz/U=
262262
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20241119094239-f4e529af734d/go.mod h1:L5RDYZbC9BBWmoU2+TjTekeqqhFXX5EqH9ln00O0stY=
263263
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=
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.20250521012141-b56c7c6eb677 h1:Wn0v7xBxkdzYqDN/4ksI34jstZOskMccT2SYFrvUw4c=
270+
github.com/dolthub/go-mysql-server v0.20.1-0.20250521012141-b56c7c6eb677/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)