pub struct DmDate {
pub year: i32,
pub month: u8,
pub day: u8,
}Expand description
达梦日期(年可为负/超 9999,避免 chrono/NaiveDate 限制)
Fields§
§year: i32§month: u8§day: u8Implementations§
Source§impl DmDate
impl DmDate
Sourcepub fn new(year: i32, month: u8, day: u8) -> Self
pub fn new(year: i32, month: u8, day: u8) -> Self
Examples found in repository?
examples/basic.rs (line 34)
8fn main() -> Result<(), Box<dyn std::error::Error>> {
9 let host = std::env::var("DM_HOST").unwrap_or_else(|_| "127.0.0.1".into());
10 let port: u16 = std::env::var("DM_PORT").unwrap_or_else(|_| "5236".into()).parse()?;
11 let user = std::env::var("DM_USER").unwrap_or_else(|_| "SYSDBA".into());
12 let pwd = std::env::var("DM_PWD").unwrap_or_else(|_| "password".into());
13
14 let mut c = DmClient::new(&host, port, &user, &pwd);
15 c.connect()?;
16 println!("✅ 连接成功,会话密钥前缀: {:02x?}...", &c.session_key().unwrap()[..4]);
17
18 // 1. 简单查询(非参数化)
19 let r = c.execute("select 1", &[])?;
20 if let ExecuteResult::Query { columns, rows } = r {
21 println!("select 1 => cols={:?} rows={:?}", columns.iter().map(|c| &c.name).collect::<Vec<_>>(), rows);
22 }
23
24 // 2. 参数化查询(先建表)
25 c.execute(
26 "CREATE TABLE IF NOT EXISTS rust_demo (id INT, name VARCHAR(100), d DATE, f DOUBLE)",
27 &[],
28 )?;
29 let r = c.execute(
30 "INSERT INTO rust_demo VALUES (?, ?, ?, ?)",
31 &[
32 Param::Int(1),
33 Param::Str("测试".into()),
34 Param::Date(dm_pure::DmDate::new(2026, 8, 12)),
35 Param::Float(std::f64::consts::PI),
36 ],
37 )?;
38 println!("INSERT affected: {:?}", r.affected());
39
40 let r = c.execute("SELECT id, name, d, f FROM rust_demo WHERE id >= ?", &[Param::Int(1)])?;
41 if let ExecuteResult::Query { columns, rows } = r {
42 println!("查询 {} 列, {} 行:", columns.len(), rows.len());
43 for row in &rows {
44 println!(" {:?}", row);
45 }
46 }
47
48 // 3. 存储过程 OUT 参数
49 // c.execute("CALL sp_test(?, ?, ?, ?)", &[Param::Int(5), Param::Str("hello".into()),
50 // Param::out(Some(OutType::Int)), Param::out(Some(OutType::Str))])?;
51
52 // 4. 事务
53 c.begin()?;
54 c.execute("UPDATE rust_demo SET name = ? WHERE id = ?", &[Param::Str("改".into()), Param::Int(1)])?;
55 c.rollback()?; // 回滚
56 println!("事务回滚完成");
57
58 c.execute("DROP TABLE rust_demo", &[])?;
59 c.close();
60 println!("✅ 示例结束");
61 Ok(())
62}Trait Implementations§
impl Copy for DmDate
impl Eq for DmDate
impl StructuralPartialEq for DmDate
Auto Trait Implementations§
impl Freeze for DmDate
impl RefUnwindSafe for DmDate
impl Send for DmDate
impl Sync for DmDate
impl Unpin for DmDate
impl UnsafeUnpin for DmDate
impl UnwindSafe for DmDate
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more