Skip to content

Commit 61579ae

Browse files
authored
[no-release-notes] fix bug in memory session data management (#2353)
1 parent a4f33df commit 61579ae

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

enginetest/queries/script_queries.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,30 @@ var ScriptTests = []ScriptTest{
121121
},
122122
},
123123
},
124+
{
125+
Name: "GMS issue 2349",
126+
SetUpScript: []string{
127+
"CREATE TABLE table1 (id int NOT NULL AUTO_INCREMENT primary key, name text)",
128+
`
129+
CREATE TABLE table2 (
130+
id int NOT NULL AUTO_INCREMENT,
131+
name text,
132+
fk int,
133+
PRIMARY KEY (id),
134+
CONSTRAINT myConstraint FOREIGN KEY (fk) REFERENCES table1 (id)
135+
)`,
136+
},
137+
Assertions: []ScriptTestAssertion{
138+
{
139+
Query: "INSERT INTO table1 (name) VALUES ('tbl1 row 1');",
140+
Expected: []sql.Row{{types.OkResult{RowsAffected: 1, InsertID: 1}}},
141+
},
142+
{
143+
Query: "INSERT INTO table1 (name) VALUES ('tbl1 row 2');",
144+
Expected: []sql.Row{{types.OkResult{RowsAffected: 1, InsertID: 2}}},
145+
},
146+
},
147+
},
124148
{
125149
Name: "missing indexes",
126150
SetUpScript: []string{

memory/session.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ func (s *Session) dropTable(d *TableData) {
118118
// Because we don't support concurrency, we store table data changes in the session, rather than the transaction itself.
119119
func (s *Session) StartTransaction(ctx *sql.Context, tCharacteristic sql.TransactionCharacteristic) (sql.Transaction, error) {
120120
s.tables = make(map[tableKey]*TableData)
121+
s.editAccumulators = make(map[tableKey]tableEditAccumulator)
121122
return &Transaction{tCharacteristic == sql.ReadOnly}, nil
122123
}
123124

0 commit comments

Comments
 (0)