fixing the warnings properly
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
// src/tables_data/handlers/post_table_data.rs
|
||||
use tonic::{Status, Response};
|
||||
use sqlx::{PgPool, Postgres, Arguments, Row};
|
||||
use tonic::Status;
|
||||
use sqlx::{PgPool, Arguments, Row};
|
||||
use sqlx::postgres::PgArguments;
|
||||
use chrono::{DateTime, Utc};
|
||||
use std::collections::HashMap;
|
||||
use common::proto::multieko2::tables_data::{PostTableDataRequest, PostTableDataResponse};
|
||||
|
||||
pub async fn post_table_data(
|
||||
@@ -106,22 +105,28 @@ pub async fn post_table_data(
|
||||
|
||||
match sql_type {
|
||||
"TEXT" | "VARCHAR(15)" | "VARCHAR(255)" => {
|
||||
if let Some(max_len) = sql_type.strip_prefix("VARCHAR(").and_then(|s| s.strip_suffix(')')).and_then(|s| s.parse::<usize>().ok()) {
|
||||
if let Some(max_len) = sql_type.strip_prefix("VARCHAR(")
|
||||
.and_then(|s| s.strip_suffix(')'))
|
||||
.and_then(|s| s.parse::<usize>().ok())
|
||||
{
|
||||
if value.len() > max_len {
|
||||
return Err(Status::invalid_argument(format!("Value too long for {}", col)));
|
||||
}
|
||||
}
|
||||
params.add(value);
|
||||
params.add(value)
|
||||
.map_err(|e| Status::invalid_argument(format!("Failed to add text parameter for {}: {}", col, e)))?;
|
||||
},
|
||||
"BOOLEAN" => {
|
||||
let val = value.parse::<bool>()
|
||||
.map_err(|_| Status::invalid_argument(format!("Invalid boolean for {}", col)))?;
|
||||
params.add(val);
|
||||
params.add(val)
|
||||
.map_err(|e| Status::invalid_argument(format!("Failed to add boolean parameter for {}: {}", col, e)))?;
|
||||
},
|
||||
"TIMESTAMPTZ" => {
|
||||
let dt = DateTime::parse_from_rfc3339(&value)
|
||||
.map_err(|_| Status::invalid_argument(format!("Invalid timestamp for {}", col)))?;
|
||||
params.add(dt.with_timezone(&Utc));
|
||||
params.add(dt.with_timezone(&Utc))
|
||||
.map_err(|e| Status::invalid_argument(format!("Failed to add timestamp parameter for {}: {}", col, e)))?;
|
||||
},
|
||||
_ => return Err(Status::invalid_argument(format!("Unsupported type {}", sql_type))),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user