robustness, one test still failing, will fix it

This commit is contained in:
filipriec
2025-06-22 23:02:41 +02:00
parent 7403b3c3f8
commit 070d091e07
4 changed files with 587 additions and 21 deletions

View File

@@ -182,7 +182,8 @@ pub async fn post_table_data(
"BOOLEAN" => params.add(None::<bool>),
"TEXT" => params.add(None::<String>),
"TIMESTAMPTZ" => params.add(None::<DateTime<Utc>>),
"BIGINT" | "INTEGER" => params.add(None::<i64>),
"BIGINT" => params.add(None::<i64>),
"INTEGER" => params.add(None::<i32>),
s if s.starts_with("NUMERIC") => params.add(None::<Decimal>),
_ => return Err(Status::invalid_argument(format!("Unsupported type for null value: {}", sql_type))),
}.map_err(|e| Status::internal(format!("Failed to add null parameter for {}: {}", col, e)))?;
@@ -223,12 +224,37 @@ pub async fn post_table_data(
} else {
return Err(Status::invalid_argument(format!("Expected ISO 8601 string for column '{}'", col)));
}
} else if sql_type == "BIGINT" || sql_type == "INTEGER" {
} else if sql_type == "BIGINT" {
if let Kind::NumberValue(val) = kind {
if val.fract() != 0.0 {
return Err(Status::invalid_argument(format!("Expected integer for column '{}', but got a float", col)));
}
params.add(*val as i64).map_err(|e| Status::invalid_argument(format!("Failed to add integer parameter for {}: {}", col, e)))?;
// Simple universal check: try the conversion and verify it's reversible
// This handles ALL edge cases: infinity, NaN, overflow, underflow, precision loss
let as_i64 = *val as i64;
if (as_i64 as f64) != *val {
return Err(Status::invalid_argument(format!("Integer value out of range for BIGINT column '{}'", col)));
}
params.add(as_i64).map_err(|e| Status::invalid_argument(format!("Failed to add bigint parameter for {}: {}", col, e)))?;
} else {
return Err(Status::invalid_argument(format!("Expected number for column '{}'", col)));
}
} else if sql_type == "INTEGER" {
if let Kind::NumberValue(val) = kind {
if val.fract() != 0.0 {
return Err(Status::invalid_argument(format!("Expected integer for column '{}', but got a float", col)));
}
// Simple universal check: try the conversion and verify it's reversible
// This handles ALL edge cases: infinity, NaN, overflow, underflow, precision loss
let as_i32 = *val as i32;
if (as_i32 as f64) != *val {
return Err(Status::invalid_argument(format!("Integer value out of range for INTEGER column '{}'", col)));
}
params.add(as_i32).map_err(|e| Status::invalid_argument(format!("Failed to add integer parameter for {}: {}", col, e)))?;
} else {
return Err(Status::invalid_argument(format!("Expected number for column '{}'", col)));
}