mod common; use snowflake_connector_rs::Result; #[tokio::test] async fn test_decode() -> Result<()> { // Connect to Snowflake let client = common::connect()?; let session = client.create_session().await?; // Create a temporary table // DATETIME aliases TIMESTAMP_NTZ let query = "CREATE TEMPORARY TABLE example ( n NUMBER, s STRING, b BOOLEAN, d DATE, tm TIME, ltz TIMESTAMP_LTZ, ntz TIMESTAMP_NTZ, tz TIMESTAMP_TZ )"; let rows = session.query(query).await?; assert_eq!(rows.len(), 1); assert_eq!( rows[0].get::("STATUS")?, "Table EXAMPLE successfully created." ); // Insert some data let query = "INSERT INTO example (n, s, b, d, tm, ltz, ntz, tz) VALUES ( 42, 'hello', 0, '2024-01-01', '01:23:45', '2024-01-01 00:00:00', '2024-01-01 00:00:00', '2024-01-01 00:00:00')"; let rows = session.query(query).await?; assert_eq!(rows.len(), 1); assert_eq!(rows[0].get::("NUMBER OF ROWS INSERTED")?, 1); // Select the data back let query = "SELECT * FROM example"; let rows = session.query(query).await?; assert_eq!(rows.len(), 1); assert_eq!(rows[0].get::("n")?, 42); assert_eq!(rows[0].get::("s")?, "hello"); assert!(!(rows[0].get::("b")?)); assert_eq!( rows[0].get::("d")?, chrono::NaiveDate::from_ymd_opt(2024, 1, 1).unwrap() ); assert_eq!( rows[0].get::("tm")?, chrono::NaiveTime::from_hms_opt(1, 23, 45).unwrap() ); assert_eq!( rows[0].get::("ltz")?, chrono::NaiveDateTime::parse_from_str("2024-01-01 00:00:00", "%Y-%m-%d %H:%M:%S").unwrap() ); assert_eq!( rows[0].get::("ntz")?, chrono::NaiveDateTime::parse_from_str("2024-01-01 00:00:00", "%Y-%m-%d %H:%M:%S").unwrap() ); assert_eq!( rows[0].get::("tz")?, chrono::NaiveDateTime::parse_from_str("2024-01-01 00:00:00", "%Y-%m-%d %H:%M:%S").unwrap() ); Ok(()) }