Skip to content

Commit 06f9d78

Browse files
committed
refactor(pool): simplify database URL handling and improve SQL statement execution
- Extracted DATABASE_URL into a variable for clarity. - Split SQL statements for compatibility with ODBC drivers that do not support multi-statement execution.
1 parent b616de3 commit 06f9d78

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

tests/any/pool.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,14 @@ async fn pool_should_be_returned_failed_transactions() -> anyhow::Result<()> {
7474
#[sqlx_macros::test]
7575
async fn big_pool() -> anyhow::Result<()> {
7676
use sqlx_oldapi::Row;
77+
78+
let database_url = dotenvy::var("DATABASE_URL")?;
7779

7880
let pool = Arc::new(
7981
AnyPoolOptions::new()
8082
.max_connections(2)
8183
.acquire_timeout(Duration::from_secs(3))
82-
.connect(&dotenvy::var("DATABASE_URL")?)
84+
.connect(&database_url)
8385
.await?,
8486
);
8587

@@ -138,21 +140,23 @@ async fn test_pool_callbacks() -> anyhow::Result<()> {
138140
let id = current_id.fetch_add(1, Ordering::AcqRel);
139141

140142
Box::pin(async move {
141-
let statement = format!(
142-
// language=SQL
143+
// Split into separate statements for ODBC drivers that don't support multi-statement execution
144+
let create_statement =
143145
r#"
144146
CREATE TEMPORARY TABLE conn_stats(
145147
id int primary key,
146148
before_acquire_calls int default 0,
147149
after_release_calls int default 0
148-
);
149-
INSERT INTO conn_stats(id) VALUES ({});
150-
"#,
151-
// Until we have generalized bind parameters
150+
)
151+
"#;
152+
153+
let insert_statement = format!(
154+
"INSERT INTO conn_stats(id) VALUES ({})",
152155
id
153156
);
154157

155-
conn.execute(&statement[..]).await?;
158+
conn.execute(create_statement).await?;
159+
conn.execute(&insert_statement[..]).await?;
156160
Ok(())
157161
})
158162
})

0 commit comments

Comments
 (0)