File: any.rs

package info (click to toggle)
rust-sqlx 0.8.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,744 kB
  • sloc: sql: 335; python: 268; sh: 71; makefile: 2
file content (35 lines) | stat: -rw-r--r-- 913 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use sqlx::{Any, Sqlite};
use sqlx_test::new;

#[sqlx_macros::test]
async fn it_encodes_bool_with_any() -> anyhow::Result<()> {
    sqlx::any::install_default_drivers();
    let mut conn = new::<Any>().await?;

    let res = sqlx::query("INSERT INTO accounts (name, is_active) VALUES (?, ?)")
        .bind("Harrison Ford")
        .bind(true)
        .execute(&mut conn)
        .await
        .expect("failed to encode bool");
    assert_eq!(res.rows_affected(), 1);

    Ok(())
}

#[sqlx_macros::test]
async fn issue_3179() -> anyhow::Result<()> {
    sqlx::any::install_default_drivers();

    let mut conn = new::<Any>().await?;

    // 4294967297 = 2^32
    let number: i64 = sqlx::query_scalar("SELECT 4294967296")
        .fetch_one(&mut conn)
        .await?;

    // Previously, the decoding would use `i32` as an intermediate which would overflow to 0.
    assert_eq!(number, 4294967296);

    Ok(())
}