Skip to main content

ExecuteResult

Enum ExecuteResult 

Source
pub enum ExecuteResult {
    Query {
        columns: Vec<Column>,
        rows: Vec<Vec<Value>>,
    },
    Affected(u64),
    Call {
        affected: u64,
        out: Vec<Value>,
    },
}
Expand description

执行结果。

Variants§

§

Query

查询:列描述符 + 行

Fields

§columns: Vec<Column>
§rows: Vec<Vec<Value>>
§

Affected(u64)

DML:影响行数

§

Call

存储过程 CALL:影响行数 + OUT 参数值

Fields

§affected: u64
§out: Vec<Value>

Implementations§

Source§

impl ExecuteResult

Source

pub fn rows(&self) -> Option<&Vec<Vec<Value>>>

Source

pub fn columns(&self) -> Option<&Vec<Column>>

Source

pub fn affected(&self) -> Option<u64>

Examples found in repository?
examples/basic.rs (line 38)
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 ExecuteResult

Source§

fn clone(&self) -> Self

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 Debug for ExecuteResult

Source§

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

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

impl PartialEq for ExecuteResult

Source§

fn eq(&self, other: &Self) -> 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 ExecuteResult

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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