diff --git a/.github/workflows/sqlx.yml b/.github/workflows/sqlx.yml index a234c9d7a9..50ef29dd92 100644 --- a/.github/workflows/sqlx.yml +++ b/.github/workflows/sqlx.yml @@ -301,6 +301,22 @@ jobs: SQLX_OFFLINE_DIR: .sqlx RUSTFLAGS: -D warnings --cfg postgres="${{ matrix.postgres }}" + # Run tests again with implied linux user + - run: | + SKIP_ARGS=() + for test in $PG_ISOLATED_TESTS; do + SKIP_ARGS+=(--skip "$test") + done + cargo test \ + --no-default-features \ + --features any,postgres,macros,migrate,_unstable-all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }} \ + -- \ + "${SKIP_ARGS[@]}" + env: + DATABASE_URL: postgres:///sqlx?password=runner-password + SQLX_OFFLINE_DIR: .sqlx + RUSTFLAGS: -D warnings --cfg postgres="${{ matrix.postgres }}" + # Run the `test-attr` test again to cover cleanup. - run:> cargo test diff --git a/sqlx-core/Cargo.toml b/sqlx-core/Cargo.toml index 5c20bad050..90ed446b4b 100644 --- a/sqlx-core/Cargo.toml +++ b/sqlx-core/Cargo.toml @@ -91,7 +91,7 @@ percent-encoding = "2.3.0" serde = { version = "1.0.219", features = ["derive", "rc"], optional = true } serde_json = { version = "1.0.142", features = ["raw_value"], optional = true } toml = { version = "0.8.16", optional = true } -sha2 = { version = "0.10.0", default-features = false, optional = true } +sha2 = { workspace = true, optional = true } #sqlformat = "0.2.0" tokio-stream = { version = "0.1.8", features = ["fs"], optional = true } tracing = { version = "0.1.37", features = ["log"] } diff --git a/sqlx-macros-core/Cargo.toml b/sqlx-macros-core/Cargo.toml index 534b92764d..42bf0f5e8c 100644 --- a/sqlx-macros-core/Cargo.toml +++ b/sqlx-macros-core/Cargo.toml @@ -75,7 +75,7 @@ either = "1.6.1" proc-macro2 = { version = "1.0.83", default-features = false } serde = { version = "1.0.219", features = ["derive"] } serde_json = { version = "1.0.142" } -sha2 = { version = "0.10.0" } +sha2 = { workspace = true } syn = { version = "2.0.87", default-features = false, features = ["full", "derive", "parsing", "printing", "clone-impls"] } quote = { version = "1.0.35", default-features = false } url = { version = "2.2.2" } diff --git a/sqlx-postgres/Cargo.toml b/sqlx-postgres/Cargo.toml index d5bf41f9b1..701cabff85 100644 --- a/sqlx-postgres/Cargo.toml +++ b/sqlx-postgres/Cargo.toml @@ -64,7 +64,7 @@ num-bigint = { version = "0.4.3", optional = true } smallvec = { version = "1.13.1" } stringprep = "0.1.2" tracing = { version = "0.1.37", features = ["log"] } -whoami = { version = "2.0.2", default-features = false } +whoami = { version = "2.0.2", features = ["std"], default-features = false } dotenvy.workspace = true thiserror.workspace = true diff --git a/sqlx-sqlite/src/connection/execute.rs b/sqlx-sqlite/src/connection/execute.rs index 733a1abbe6..f26a540510 100644 --- a/sqlx-sqlite/src/connection/execute.rs +++ b/sqlx-sqlite/src/connection/execute.rs @@ -108,7 +108,15 @@ impl Iterator for ExecuteIter<'_> { Ok(false) => { let last_insert_rowid = self.handle.last_insert_rowid(); - let changes = statement.handle.changes(); + // `sqlite3_changes()` returns the row count for the most recently completed + // INSERT/UPDATE/DELETE on the connection, not necessarily this statement. + // For read-only statements (SELECT, BEGIN, COMMIT, etc.) we must report 0. + // See https://sqlite.org/c3ref/changes.html + let changes = if statement.handle.read_only() { + 0 + } else { + statement.handle.changes() + }; self.logger.increase_rows_affected(changes); let done = SqliteQueryResult { diff --git a/tests/postgres/setup.sql b/tests/postgres/setup.sql index 49b7fcfeea..6a1b925abe 100644 --- a/tests/postgres/setup.sql +++ b/tests/postgres/setup.sql @@ -1,3 +1,6 @@ +-- Create extra user to be used on runner +CREATE USER runner WITH SUPERUSER PASSWORD 'runner-password'; + -- https://www.postgresql.org/docs/current/ltree.html CREATE EXTENSION IF NOT EXISTS ltree; diff --git a/tests/sqlite/migrations_issue_4300/000_init.sql b/tests/sqlite/migrations_issue_4300/000_init.sql new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/sqlite/sqlite.rs b/tests/sqlite/sqlite.rs index 5355cf7c97..8791443b4b 100644 --- a/tests/sqlite/sqlite.rs +++ b/tests/sqlite/sqlite.rs @@ -1437,3 +1437,35 @@ async fn issue_3982() -> anyhow::Result<()> { Ok(()) } + +#[sqlx_macros::test] +async fn issue_4300() -> anyhow::Result<()> { + use sqlx::migrate::Migrator; + use sqlx::sqlite::SqlitePoolOptions; + use std::path::Path; + + let pool = SqlitePoolOptions::new().connect("sqlite::memory:").await?; + + let migrator = Migrator::new(Path::new("tests/sqlite/migrations_issue_4300")).await?; + migrator.run(&pool).await?; + + sqlx::query("CREATE TABLE my_table ( qqq TEXT )") + .execute(&pool) + .await?; + + sqlx::query("CREATE TABLE other_table ( www TEXT )") + .execute(&pool) + .await?; + + sqlx::query("INSERT INTO my_table (qqq) VALUES ('temporary')") + .execute(&pool) + .await?; + + let result = sqlx::query("BEGIN TRANSACTION; COMMIT;") + .execute(&pool) + .await?; + + assert_eq!(result.rows_affected(), 0); + + Ok(()) +}

AltStyle によって変換されたページ (->オリジナル) /