Replies: 6 comments
-
读取的时候反序列化类型使用rbatis::rbdc::types::Bytes类型,尝试一下 |
Beta Was this translation helpful? Give feedback.
-
这个试过了,是空的,所以我才hex转成字符串,但是写的时候unhex不能转了,定义成string后写入是字符串了。我用拦截器把字符串转成binary后无效的,还是按字符串处理的,是否可以增加源字符处理机制?这样可能不安全,也和数据库关系比较密切了。 |
Beta Was this translation helpful? Give feedback.
-
展示一下代码看看? |
Beta Was this translation helpful? Give feedback.
-
我读的库是wordpress的 /// wp_wfblockediplog 内容主要信息
// #[crud_table(table_name:"wp_wfblockediplog" | formats_pg:"id:{}::uuid,create_time:{}::timestamp")]
// #[py_sql(formats_mysql:"IP:UNHEX({})")]
#[allow(non_snake_case)]
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct WpWfblockediplog {
// pub IP: Option<Vec<char>>,
// pub IP: Option<rbatis::rbdc::bytes::Bytes>,
// pub IP: Option<serde_bytes::ByteBuf>,
// pub IP: Option<rbs::Value>,
// pub IP: Option<Vec<u8>>,
// pub IP: Option<rbatis::rbdc::bytes::Bytes>,
pub IP: Option<String>,
pub countryCode: Option<String>,
pub blockCount: Option<usize>,
pub unixday: Option<usize>,
pub blockType: Option<String>,
}```
IP如果不用hex转换的话用注释掉的读取出来的都是空的。
数据库IP类型是binary(16)的。 |
Beta Was this translation helpful? Give feedback.
-
我尝试了binary(16)的类型,mysql在插入时会吧字符串类型 转bytes,查询时会吧byte转字符串,因此 ip用Option就行了 create table mock
(
id int null,
ip binary(16) null
); *code #[macro_use]
extern crate rbatis;
pub mod model;
use serde::{Deserialize, Serialize};
use crate::{init_db};
use model::*;
use rbatis::rbatis::Rbatis;
use rbatis::rbdc::bytes::Bytes;
use rbatis::rbdc::datetime::FastDateTime;
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Mock {
pub id: Option<i32>,
pub ip:Option<String>
}
crud!(Mock{});
/// doc you can see https://rbatis.github.io/rbatis.io
#[sql("select * from mock where id = '22'")]
async fn raw_sql(rb: &Rbatis, delete_flag: &i32) -> rbatis::Result<rbs::Value> {
impled!()
}
#[tokio::main]
pub async fn main() {
fast_log::init(fast_log::Config::new().console()).expect("rbatis init fail");
//use static ref
let rb = init_db().await;
Mock::insert(&mut rb.clone(),&Mock{
id: Some(22),
ip: Some("192.168.1.199".to_string())
}).await.unwrap();
let a = raw_sql(&rb, &0).await.unwrap();
println!("{:?}", a);
} *log
|
Beta Was this translation helpful? Give feedback.
-
收到,非常感谢,这样是没有问题;wordpress的应该是用PHP处理过的数据,所以不能直接取出,再次感谢 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
类似这样的如何写入?
Some(format!("UNDEX(0x{})", ip))
读取的时候我用select hex(ip)读出来,有没有可以直接读取二进制的方法呢?
Beta Was this translation helpful? Give feedback.
All reactions