1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! Statement results returned by the engine.
use crate::relational::{SqlType, SqlValue};
/// An output column descriptor.
#[derive(Clone, Debug)]
pub struct OutField {
pub name: String,
pub ty: SqlType,
/// Originating table OID and column attribute number, when known (for
/// RowDescription). Zero means "not a simple column reference".
pub table_oid: u32,
pub column_id: i16,
}
impl OutField {
pub fn new(name: impl Into<String>, ty: SqlType) -> Self {
Self {
name: name.into(),
ty,
table_oid: 0,
column_id: 0,
}
}
}
/// The result of executing a single SQL statement.
#[derive(Clone, Debug)]
pub enum ExecResult {
/// A row-producing statement (SELECT, RETURNING, SHOW, ...).
Rows {
fields: Vec<OutField>,
rows: Vec<Vec<SqlValue>>,
},
/// A command with a completion tag (INSERT/UPDATE/DELETE/DDL/transaction).
Command { tag: String },
}
impl ExecResult {
/// The PostgreSQL command-completion tag.
pub fn command_tag(&self) -> String {
match self {
ExecResult::Command { tag } => tag.clone(),
ExecResult::Rows { rows, .. } => format!("SELECT {}", rows.len()),
}
}
pub fn empty_command(tag: impl Into<String>) -> Self {
ExecResult::Command { tag: tag.into() }
}
}