sqlx icon indicating copy to clipboard operation
sqlx copied to clipboard

sqlx sqlite return wrong type.

Open yuyang-ok opened this issue 1 year ago • 2 comments

Bug Description

sqlx sqlite missing return type.

Minimal Reproduction

use sqlx::{Column, Connection, Row};

#[tokio::main]
async fn main() {
    let mut x = sqlx::sqlite::SqliteConnection::connect(":memory:")
        .await
        .unwrap();

    sqlx::query(
        r#"
    CREATE TABLE IF NOT EXISTS test_table (
        id INTEGER PRIMARY KEY autoincrement,
         
        numeric_col NUMERIC
    );
"#,
    )
    .execute(&mut x)
    .await
    .unwrap();

    sqlx::query(
        r#"
        INSERT INTO test_table ( 
           numeric_col)         VALUES (  123.45); 
"#,
    )
    .execute(&mut x)
    .await
    .unwrap();

    let rows = sqlx::query("select * from test_table")
        .fetch_all(&mut x)
        .await
        .unwrap();
    for r in rows.iter() {
        for col in 0..r.columns().len() {
            let c = r.column(col);
            println!("{:?}", c);
        }
    }
}
SqliteColumn { name: id, ordinal: 0, type_info: SqliteTypeInfo(Int64) }
SqliteColumn { name: numeric_col, ordinal: 1, type_info: SqliteTypeInfo(Null) }

Info

  • SQLx version: [REQUIRED]
  • sqlx = { version = "0.7.3", features = ["sqlite"] }
  • SQLx features enabled: [REQUIRED]
  • Database server and version: [REQUIRED] (MySQL / Postgres / SQLite <x.y.z>)
  • Operating system: [REQUIRED] windows11
  • rustc --version: [REQUIRED] rustc 1.74.0-nightly (b3aa8e716 2023-09-21)

yuyang-ok avatar Feb 27 '24 05:02 yuyang-ok

Just ran into this error. Was trying to use the NUMERIC type, but it sqlx thought it was NULL

Supergamer1337 avatar Apr 07 '24 11:04 Supergamer1337

I think this docs paragraph could be related to your issue

pxp9 avatar Apr 20 '24 06:04 pxp9