sea-orm icon indicating copy to clipboard operation
sea-orm copied to clipboard

Issue when using `on_conflict` with sqlite

Open bWanShiTong opened this issue 1 year ago • 2 comments
trafficstars

Description

Steps to Reproduce

  1. Create table with:
CREATE TABLE IF NOT EXISTS heart_rate (
	unix BIGINT NOT NULL primary key,
	heart_rate smallint NOT NULL,
	rr TEXT NOT NULL
);
CREATE UNIQUE INDEX IF NOT EXISTS unix_index on heart_rate(unix);
  1. Run:

#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
    let db_url = env::var("DATABASE_URL").expect("DATABASE_URL not set in env");
    let pool = Database::connect(db_url).await?;

    let model = heart_rate::ActiveModel {
        unix: Set(10000),
        heart_rate: Set(120),
        rr: Set(format!("{:?}", vec![100,312])),
    };

    heart_rate::Entity::insert(model)
        .on_conflict(OnConflict::column(heart_rate::Column::Unix))
        .do_nothing()
        .exec(&pool)
        .await?;
    Ok(())
}

Expected Behavior

To insert pass even if row with same unix exists

Actual Behavior

Fail even if there are no items in table

[2024-07-27T17:11:24Z INFO  sqlx::query] summary="PRAGMA foreign_keys = ON; …" db.statement="\n\nPRAGMA foreign_keys = ON;\n" rows_affected=0 rows_returned=0 elapsed=93.502µs elapsed_secs=9.3502e-5
Error: Execution Error: error returned from database: (code: 1) incomplete input

Caused by:
    0: error returned from database: (code: 1) incomplete input
    1: error returned from database: (code: 1) incomplete input
    2: (code: 1) incomplete input

Reproduces How Often

Every time

Workarounds

No

Reproducible Example

See above

Versions

sea-orm = { version = "0.12.15", features = [
    "runtime-tokio-rustls",
    "sqlx-sqlite",
    "macros",
]}

bWanShiTong avatar Jul 27 '24 17:07 bWanShiTong