Skip to content

Commit 6433965

Browse files
committed
Add a test for last_insert_id
1 parent b6710c3 commit 6433965

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

src/conn/mod.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ impl Conn {
783783
#[cfg(test)]
784784
mod test {
785785
use crate::{
786-
from_row, params, prelude::*, test_misc::get_opts, Conn, Error, OptsBuilder, TxOpts,
786+
from_row, params, prelude::*, test_misc::get_opts, Conn, Error, OptsBuilder, Pool, TxOpts,
787787
WhiteListFsLocalInfileHandler,
788788
};
789789

@@ -1588,6 +1588,43 @@ mod test {
15881588
Ok(())
15891589
}
15901590

1591+
#[tokio::test]
1592+
async fn should_expose_query_result_metadata() -> super::Result<()> {
1593+
let pool = Pool::new(get_opts());
1594+
let mut c = pool.get_conn().await?;
1595+
1596+
c.query_drop(
1597+
r"
1598+
CREATE TEMPORARY TABLE `foo`
1599+
( `id` SERIAL
1600+
, `bar_id` varchar(36) NOT NULL
1601+
, `baz_id` varchar(36) NOT NULL
1602+
, `ctime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP()
1603+
, PRIMARY KEY (`id`)
1604+
, KEY `bar_idx` (`bar_id`)
1605+
, KEY `baz_idx` (`baz_id`)
1606+
);",
1607+
)
1608+
.await?;
1609+
1610+
const QUERY: &str = "INSERT INTO foo (bar_id, baz_id) VALUES (?, ?)";
1611+
let params = ("qwerty", "data.employee_id");
1612+
1613+
let query_result = c.exec_iter(QUERY, params).await?;
1614+
assert_eq!(query_result.last_insert_id(), Some(1));
1615+
query_result.drop_result().await?;
1616+
1617+
c.exec_drop(QUERY, params).await?;
1618+
assert_eq!(c.last_insert_id(), Some(2));
1619+
1620+
let mut tx = c.start_transaction(Default::default()).await?;
1621+
1622+
tx.exec_drop(QUERY, params).await?;
1623+
assert_eq!(tx.last_insert_id(), Some(3));
1624+
1625+
Ok(())
1626+
}
1627+
15911628
#[tokio::test]
15921629
async fn should_handle_local_infile() -> super::Result<()> {
15931630
use std::fs::write;

0 commit comments

Comments
 (0)