@@ -188,12 +188,13 @@ async fn test_column_override_nullable() -> anyhow::Result<()> {
188
188
189
189
async fn with_test_row < ' a > (
190
190
conn : & ' a mut MySqlConnection ,
191
- ) -> anyhow:: Result < Transaction < ' a , MySql > > {
191
+ ) -> anyhow:: Result < ( Transaction < ' a , MySql > , i64 ) > {
192
192
let mut transaction = conn. begin ( ) . await ?;
193
- sqlx:: query!( "INSERT INTO tweet(id, text, owner_id) VALUES (1, '#sqlx is pretty cool!', 1)" )
193
+ let id = sqlx:: query!( "INSERT INTO tweet(text, owner_id) VALUES ('#sqlx is pretty cool!', 1)" )
194
194
. execute ( & mut transaction)
195
- . await ?;
196
- Ok ( transaction)
195
+ . await ?
196
+ . last_insert_id ( ) ;
197
+ Ok ( ( transaction, id as i64 ) )
197
198
}
198
199
199
200
#[ derive( PartialEq , Eq , Debug , sqlx:: Type ) ]
@@ -211,13 +212,13 @@ struct OptionalRecord {
211
212
#[ sqlx_macros:: test]
212
213
async fn test_column_override_wildcard ( ) -> anyhow:: Result < ( ) > {
213
214
let mut conn = new :: < MySql > ( ) . await ?;
214
- let mut conn = with_test_row ( & mut conn) . await ?;
215
+ let ( mut conn, id ) = with_test_row ( & mut conn) . await ?;
215
216
216
217
let record = sqlx:: query_as!( Record , "select id as `id: _` from tweet" )
217
218
. fetch_one ( & mut conn)
218
219
. await ?;
219
220
220
- assert_eq ! ( record. id, MyInt ( 1 ) ) ;
221
+ assert_eq ! ( record. id, MyInt ( id ) ) ;
221
222
222
223
// this syntax is also useful for expressions
223
224
let record = sqlx:: query_as!( Record , "select * from (select 1 as `id: _`) records" )
@@ -238,7 +239,7 @@ async fn test_column_override_wildcard() -> anyhow::Result<()> {
238
239
#[ sqlx_macros:: test]
239
240
async fn test_column_override_wildcard_not_null ( ) -> anyhow:: Result < ( ) > {
240
241
let mut conn = new :: < MySql > ( ) . await ?;
241
- let mut conn = with_test_row ( & mut conn) . await ?;
242
+ let ( mut conn, _ ) = with_test_row ( & mut conn) . await ?;
242
243
243
244
let record = sqlx:: query_as!( Record , "select owner_id as `id!: _` from tweet" )
244
245
. fetch_one ( & mut conn)
@@ -252,27 +253,27 @@ async fn test_column_override_wildcard_not_null() -> anyhow::Result<()> {
252
253
#[ sqlx_macros:: test]
253
254
async fn test_column_override_wildcard_nullable ( ) -> anyhow:: Result < ( ) > {
254
255
let mut conn = new :: < MySql > ( ) . await ?;
255
- let mut conn = with_test_row ( & mut conn) . await ?;
256
+ let ( mut conn, id ) = with_test_row ( & mut conn) . await ?;
256
257
257
258
let record = sqlx:: query_as!( OptionalRecord , "select id as `id?: _` from tweet" )
258
259
. fetch_one ( & mut conn)
259
260
. await ?;
260
261
261
- assert_eq ! ( record. id, Some ( MyInt ( 1 ) ) ) ;
262
+ assert_eq ! ( record. id, Some ( MyInt ( id ) ) ) ;
262
263
263
264
Ok ( ( ) )
264
265
}
265
266
266
267
#[ sqlx_macros:: test]
267
268
async fn test_column_override_exact ( ) -> anyhow:: Result < ( ) > {
268
269
let mut conn = new :: < MySql > ( ) . await ?;
269
- let mut conn = with_test_row ( & mut conn) . await ?;
270
+ let ( mut conn, id ) = with_test_row ( & mut conn) . await ?;
270
271
271
272
let record = sqlx:: query!( "select id as `id: MyInt` from tweet" )
272
273
. fetch_one ( & mut conn)
273
274
. await ?;
274
275
275
- assert_eq ! ( record. id, MyInt ( 1 ) ) ;
276
+ assert_eq ! ( record. id, MyInt ( id ) ) ;
276
277
277
278
// we can also support this syntax for expressions
278
279
let record = sqlx:: query!( "select * from (select 1 as `id: MyInt`) records" )
@@ -293,7 +294,7 @@ async fn test_column_override_exact() -> anyhow::Result<()> {
293
294
#[ sqlx_macros:: test]
294
295
async fn test_column_override_exact_not_null ( ) -> anyhow:: Result < ( ) > {
295
296
let mut conn = new :: < MySql > ( ) . await ?;
296
- let mut conn = with_test_row ( & mut conn) . await ?;
297
+ let ( mut conn, _ ) = with_test_row ( & mut conn) . await ?;
297
298
298
299
let record = sqlx:: query!( "select owner_id as `id!: MyInt` from tweet" )
299
300
. fetch_one ( & mut conn)
@@ -307,13 +308,13 @@ async fn test_column_override_exact_not_null() -> anyhow::Result<()> {
307
308
#[ sqlx_macros:: test]
308
309
async fn test_column_override_exact_nullable ( ) -> anyhow:: Result < ( ) > {
309
310
let mut conn = new :: < MySql > ( ) . await ?;
310
- let mut conn = with_test_row ( & mut conn) . await ?;
311
+ let ( mut conn, id ) = with_test_row ( & mut conn) . await ?;
311
312
312
313
let record = sqlx:: query!( "select id as `id?: MyInt` from tweet" )
313
314
. fetch_one ( & mut conn)
314
315
. await ?;
315
316
316
- assert_eq ! ( record. id, Some ( MyInt ( 1 ) ) ) ;
317
+ assert_eq ! ( record. id, Some ( MyInt ( id ) ) ) ;
317
318
318
319
Ok ( ( ) )
319
320
}
0 commit comments