Skip to content

Commit 698cb00

Browse files
committed
test(odbc): enhance mixed null and values tests
This commit updates the test for handling mixed null and non-null values in ODBC queries. The test now verifies the retrieval of multiple rows, including cases with null values, ensuring accurate validation of the query results.
1 parent 2ef1213 commit 698cb00

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

tests/odbc/odbc.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -457,25 +457,30 @@ async fn it_handles_binary_data() -> anyhow::Result<()> {
457457
async fn it_handles_mixed_null_and_values() -> anyhow::Result<()> {
458458
let mut conn = new::<Odbc>().await?;
459459

460-
let stmt = conn.prepare("SELECT ?, ?, ?, ?").await?;
461-
let row = stmt
460+
let stmt = conn
461+
.prepare("SELECT ?, ?, ?, ? UNION ALL SELECT NULL, NULL, NULL, NULL")
462+
.await?;
463+
let rows = stmt
462464
.query()
463465
.bind(42_i32)
464466
.bind(Option::<i32>::None)
465467
.bind("hello")
466468
.bind(Option::<String>::None)
467-
.fetch_one(&mut conn)
469+
.fetch_all(&mut conn)
468470
.await?;
469471

470-
let int_val = row.try_get_raw(0)?.to_owned().decode::<i32>();
471-
let null_int = row.try_get_raw(1)?.to_owned();
472-
let str_val = row.try_get_raw(2)?.to_owned().decode::<String>();
473-
let null_str = row.try_get_raw(3)?.to_owned();
474-
475-
assert_eq!(int_val, 42);
476-
assert!(null_int.is_null());
477-
assert_eq!(str_val, "hello");
478-
assert!(null_str.is_null());
472+
assert_eq!(rows.len(), 2, "should have 2 rows");
473+
assert_eq!(rows[0].get::<Option<i32>, _>(0), Some(42));
474+
assert_eq!(rows[0].get::<Option<i32>, _>(1), None);
475+
assert_eq!(
476+
rows[0].get::<Option<String>, _>(2),
477+
Some("hello".to_owned())
478+
);
479+
assert_eq!(rows[0].get::<Option<String>, _>(3), None);
480+
assert_eq!(rows[1].get::<Option<i32>, _>(0), None);
481+
assert_eq!(rows[1].get::<Option<i32>, _>(1), None);
482+
assert_eq!(rows[1].get::<Option<String>, _>(2), None);
483+
assert_eq!(rows[1].get::<Option<String>, _>(3), None);
479484
Ok(())
480485
}
481486

0 commit comments

Comments
 (0)