Skip to main content

DmDate

Struct DmDate 

Source
pub struct DmDate {
    pub year: i32,
    pub month: u8,
    pub day: u8,
}
Expand description

达梦日期(年可为负/超 9999,避免 chrono/NaiveDate 限制)

Fields§

§year: i32§month: u8§day: u8

Implementations§

Source§

impl DmDate

Source

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§

Source§

impl Clone for DmDate

Source§

fn clone(&self) -> DmDate

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for DmDate

Source§

impl Debug for DmDate

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for DmDate

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for DmDate

Source§

impl PartialEq for DmDate

Source§

fn eq(&self, other: &DmDate) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for DmDate

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V