Open tgy3300 opened 3 months ago
Hi. Similar question was recently asked — blackbeam/rust_mysql_common#141
All the query_*
methods uses mysql so called "text protocol" (MYSQL_COM_QUERY command) — this "text protocol" works in a way that server converts all the values into their textual representation before sending them back to the client.
If you want binary values being sent to you as-is please use the so called "binary protocol" that is prepared statements.
From another perspective — if you just need properly typed values on your side without thinking about protocols then just convert them to matching rust types. In the case of your struct you can do it via an intermediate tuple or using the FromRow
derive macro:
use mysql::prelude::{Queryable, FromRow};
#[derive(Debug, FromRow)]
struct Company {
id: i64,
name: String,
status: i16,
err_info: Option<String>,
account_id: i64,
create_at: i64,
update_at: i64,
}
fn get_first_company(
conn: &mut impl Queryable,
) -> Result<Option<Company>, Box<dyn std::error::Error + Send + Sync + 'static>> {
Ok(conn.query_first("select * from company")?)
}
I used rust's mysql library to connect to the mysql database, and the result of the query was that every data item was a character type
The data obtained by calling the info method is as follows, as if each data is a string, through the printing type, it should be the corresponding data of different types, how to restore the original data, ask for help
The following is the data table structure https://global.discourse-cdn.com/business5/uploads/rust_lang/original/3X/1/6/1626aaa494901a2b70aaca862aa722a9614a4d47.png