Skip to content

Commit f05b2c2

Browse files
committed
feat: Add additional ODBC tests for null values, numeric expressions, and query preparation
This commit introduces several new tests for the ODBC implementation, including checks for null and non-null values, basic numeric and text expressions, optional fetch results, and the ability to prepare and query without parameters.
1 parent bfd4dd4 commit f05b2c2

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

tests/odbc/odbc.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use sqlx_oldapi::Column;
44
use sqlx_oldapi::Connection;
55
use sqlx_oldapi::Executor;
66
use sqlx_oldapi::Row;
7+
use sqlx_oldapi::Statement;
8+
use sqlx_oldapi::ValueRef;
79
use sqlx_test::new;
810

911
#[tokio::test]
@@ -62,3 +64,53 @@ async fn it_handles_empty_result() -> anyhow::Result<()> {
6264
assert!(!saw_row);
6365
Ok(())
6466
}
67+
68+
#[tokio::test]
69+
async fn it_reports_null_and_non_null_values() -> anyhow::Result<()> {
70+
let mut conn = new::<Odbc>().await?;
71+
let mut s = conn.fetch("SELECT 'text' AS s, NULL AS z");
72+
let row = s.try_next().await?.expect("row expected");
73+
74+
let v0 = row.try_get_raw(0)?; // 's'
75+
let v1 = row.try_get_raw(1)?; // 'z'
76+
77+
assert!(!v0.is_null());
78+
assert!(v1.is_null());
79+
Ok(())
80+
}
81+
82+
#[tokio::test]
83+
async fn it_handles_basic_numeric_and_text_expressions() -> anyhow::Result<()> {
84+
let mut conn = new::<Odbc>().await?;
85+
let mut s = conn.fetch("SELECT 1 AS i, 1.5 AS f, 'hello' AS t");
86+
let row = s.try_next().await?.expect("row expected");
87+
88+
// verify metadata is present and values are non-null
89+
assert_eq!(row.column(0).name(), "i");
90+
assert_eq!(row.column(1).name(), "f");
91+
assert_eq!(row.column(2).name(), "t");
92+
93+
assert!(!row.try_get_raw(0)?.is_null());
94+
assert!(!row.try_get_raw(1)?.is_null());
95+
assert!(!row.try_get_raw(2)?.is_null());
96+
Ok(())
97+
}
98+
99+
#[tokio::test]
100+
async fn it_fetch_optional_some_and_none() -> anyhow::Result<()> {
101+
let mut conn = new::<Odbc>().await?;
102+
let some = (&mut conn).fetch_optional("SELECT 1").await?;
103+
let none = (&mut conn).fetch_optional("SELECT 1 WHERE 1=0").await?;
104+
assert!(some.is_some());
105+
assert!(none.is_none());
106+
Ok(())
107+
}
108+
109+
#[tokio::test]
110+
async fn it_can_prepare_then_query_without_params() -> anyhow::Result<()> {
111+
let mut conn = new::<Odbc>().await?;
112+
let stmt = (&mut conn).prepare("SELECT 7 AS seven").await?;
113+
let row = stmt.query().fetch_one(&mut conn).await?;
114+
assert_eq!(row.column(0).name(), "seven");
115+
Ok(())
116+
}

0 commit comments

Comments
 (0)