@@ -144,6 +144,58 @@ public async Task LastInsertedIdTwoInserts()
144
144
}
145
145
}
146
146
147
+ [ SkippableFact ( Baseline = "https://bugs.mysql.com/bug.php?id=97061" ) ]
148
+ public async Task LastInsertedIdLockTables ( )
149
+ {
150
+ await m_database . Connection . ExecuteAsync ( @"drop table if exists insert_ai;
151
+ create table insert_ai(rowid integer not null primary key auto_increment, text varchar(100) not null);
152
+ " ) ;
153
+ try
154
+ {
155
+ await m_database . Connection . OpenAsync ( ) ;
156
+ using var command = new MySqlCommand ( @"LOCK TABLES insert_ai WRITE;
157
+ INSERT INTO insert_ai (text) VALUES ('test');
158
+ UNLOCK TABLES;" , m_database . Connection ) ;
159
+ await command . ExecuteNonQueryAsync ( ) ;
160
+ Assert . Equal ( 1L , command . LastInsertedId ) ;
161
+ }
162
+ finally
163
+ {
164
+ m_database . Connection . Close ( ) ;
165
+ }
166
+ }
167
+
168
+ [ SkippableFact ( Baseline = "https://bugs.mysql.com/bug.php?id=97061" ) ]
169
+ public async Task LastInsertedIdInsertForeignKey ( )
170
+ {
171
+ await m_database . Connection . ExecuteAsync ( @"drop table if exists TestTableWithForeignKey;
172
+ drop table if exists TestTable;
173
+
174
+ Create Table TestTable(
175
+ id BIGINT NOT NULL AUTO_INCREMENT,
176
+ column1 CHAR(100),
177
+ Primary Key(id)
178
+ );
179
+
180
+ Create Table TestTableWithForeignKey(
181
+ foreign_id BIGINT NOT NULL,
182
+ column2 CHAR(100),
183
+ Foreign Key(foreign_id) REFERENCES TestTable(id)
184
+ );" ) ;
185
+ try
186
+ {
187
+ await m_database . Connection . OpenAsync ( ) ;
188
+ using var command = new MySqlCommand ( @"INSERT INTO TestTable(column1) VALUES('hello');
189
+ INSERT INTO TestTableWithForeignKey(foreign_id, column2) VALUES(LAST_INSERT_ID(), 'test');" , m_database . Connection ) ;
190
+ await command . ExecuteNonQueryAsync ( ) ;
191
+ Assert . Equal ( 1L , command . LastInsertedId ) ;
192
+ }
193
+ finally
194
+ {
195
+ m_database . Connection . Close ( ) ;
196
+ }
197
+ }
198
+
147
199
[ Fact ]
148
200
public async Task RowsAffected ( )
149
201
{
0 commit comments