fix(mysql): gate com_stmt_execute encode on non-empty params, not non-null params

This commit is contained in:
Ryan Leckey 2020-07-20 21:49:30 -07:00
parent dc0d325738
commit cf78472d6d
2 changed files with 36 additions and 1 deletions

View File

@ -18,7 +18,7 @@ impl<'q> Encode<'_, Capabilities> for Execute<'q> {
buf.push(0); // NO_CURSOR
buf.extend(&0_u32.to_le_bytes()); // iterations (always 1): int<4>
if !self.arguments.values.is_empty() {
if !self.arguments.types.is_empty() {
buf.extend(&*self.arguments.null_bitmap);
buf.push(1); // send type to server

View File

@ -200,3 +200,38 @@ async fn it_caches_statements() -> anyhow::Result<()> {
Ok(())
}
#[sqlx_macros::test]
async fn it_can_bind_null_and_non_null_issue_540() -> anyhow::Result<()> {
let mut conn = new::<MySql>().await?;
let row = sqlx::query("SELECT ?, ?")
.bind(50_i32)
.bind(None::<i32>)
.fetch_one(&mut conn)
.await?;
let v0: Option<i32> = row.get(0);
let v1: Option<i32> = row.get(1);
assert_eq!(v0, Some(50));
assert_eq!(v1, None);
Ok(())
}
#[sqlx_macros::test]
async fn it_can_bind_only_null_issue_540() -> anyhow::Result<()> {
let mut conn = new::<MySql>().await?;
let row = sqlx::query("SELECT ?")
.bind(None::<i32>)
.fetch_one(&mut conn)
.await?;
let v0: Option<i32> = row.get(0);
assert_eq!(v0, None);
Ok(())
}