Skip to content

Commit 297eff2

Browse files
committed
feat: Add dynamic and heterogeneous parameter binding tests for ODBC
This commit introduces two new asynchronous tests for the ODBC implementation: one for dynamically binding multiple parameters in a SQL query and another for binding heterogeneous parameters. These tests enhance the coverage of parameterized query handling in the ODBC connection, ensuring correct execution and result retrieval.
1 parent 00b97f9 commit 297eff2

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

tests/odbc/odbc.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,62 @@ async fn it_can_prepare_then_query_with_params_integer_float_text() -> anyhow::R
151151

152152
Ok(())
153153
}
154+
155+
#[tokio::test]
156+
async fn it_can_bind_many_params_dynamically() -> anyhow::Result<()> {
157+
let mut conn = new::<Odbc>().await?;
158+
159+
let count = 20usize;
160+
let mut sql = String::from("SELECT ");
161+
for i in 0..count {
162+
if i != 0 {
163+
sql.push_str(", ");
164+
}
165+
sql.push_str("?");
166+
}
167+
168+
let stmt = (&mut conn).prepare(&sql).await?;
169+
170+
let values: Vec<i32> = (1..=count as i32).collect();
171+
let mut q = stmt.query();
172+
for v in &values {
173+
q = q.bind(*v);
174+
}
175+
176+
let row = q.fetch_one(&mut conn).await?;
177+
for (i, expected) in values.iter().enumerate() {
178+
let got = row.try_get_raw(i)?.to_owned().decode::<i64>();
179+
assert_eq!(got, *expected as i64);
180+
}
181+
Ok(())
182+
}
183+
184+
#[tokio::test]
185+
async fn it_can_bind_heterogeneous_params() -> anyhow::Result<()> {
186+
let mut conn = new::<Odbc>().await?;
187+
188+
let stmt = (&mut conn).prepare("SELECT ?, ?, ?, ?, ?").await?;
189+
190+
let row = stmt
191+
.query()
192+
.bind(7_i32)
193+
.bind(3.5_f64)
194+
.bind("abc")
195+
.bind("xyz")
196+
.bind(42_i32)
197+
.fetch_one(&mut conn)
198+
.await?;
199+
200+
let i = row.try_get_raw(0)?.to_owned().decode::<i64>();
201+
let f = row.try_get_raw(1)?.to_owned().decode::<f64>();
202+
let t = row.try_get_raw(2)?.to_owned().decode::<String>();
203+
let t2 = row.try_get_raw(3)?.to_owned().decode::<String>();
204+
let last = row.try_get_raw(4)?.to_owned().decode::<i64>();
205+
206+
assert_eq!(i, 7);
207+
assert!((f - 3.5).abs() < 1e-9);
208+
assert_eq!(t, "abc");
209+
assert_eq!(t2, "xyz");
210+
assert_eq!(last, 42);
211+
Ok(())
212+
}

0 commit comments

Comments
 (0)