Skip to content

Commit

Permalink
z
Browse files Browse the repository at this point in the history
  • Loading branch information
everpcpc committed Jul 31, 2024
1 parent 688fd38 commit fd1c804
Showing 1 changed file with 40 additions and 6 deletions.
46 changes: 40 additions & 6 deletions driver/tests/driver/select_simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,46 @@ async fn prepare() -> Box<dyn Connection> {

#[tokio::test]
async fn select_null() {
let conn = prepare().await;
let row = conn.query_row("select null").await.unwrap();
assert!(row.is_some());
let row = row.unwrap();
let (val,): (Option<u8>,) = row.try_into().unwrap();
assert_eq!(val, None);
{
let conn = prepare().await;
conn.exec("DROP TABLE IF EXISTS select_null").await.unwrap();
let sql_create = format!(
"CREATE TABLE `select_null` (
a String,
b UInt64,
c String
);"
);
conn.exec(&sql_create).await.unwrap();
let sql_insert = format!("INSERT INTO `select_null` (a) VALUES ('NULL')");
conn.exec(&sql_insert).await.unwrap();
}
{
let dsn = option_env!("TEST_DATABEND_DSN").unwrap_or(DEFAULT_DSN);
let client = Client::new(format!("{dsn}&format_null_as_str=1"));
let conn = client.get_conn().await.unwrap();
let row = conn.query_row("select * from select_null").await.unwrap();
assert!(row.is_some());
let row = row.unwrap();
let (val1, val2, val3): (Option<String>, Option<u64>, Option<String>) =
row.try_into().unwrap();
assert_eq!(val1, Some("NULL".to_string()));
assert_eq!(val2, None);
assert_eq!(val3, Some("NULL".to_string()));
}
{
let dsn = option_env!("TEST_DATABEND_DSN").unwrap_or(DEFAULT_DSN);
let client = Client::new(format!("{dsn}&format_null_as_str=0"));
let conn = client.get_conn().await.unwrap();
let row = conn.query_row("select * from select_null").await.unwrap();
assert!(row.is_some());
let row = row.unwrap();
let (val1, val2, val3): (Option<String>, Option<u64>, Option<String>) =
row.try_into().unwrap();
assert_eq!(val1, Some("NULL".to_string()));
assert_eq!(val2, None);
assert_eq!(val3, None);
}
}

#[tokio::test]
Expand Down

0 comments on commit fd1c804

Please sign in to comment.