pub struct Command<'a> { /* private fields */ }Expand description
A remote command (stored procedure or user-defined function) with bound parameters, executed by name via an RPC request.
Implementations§
Source§impl<'a> Command<'a>
impl<'a> Command<'a>
Sourcepub fn new(proc_name: impl Into<Cow<'a, str>>) -> Self
pub fn new(proc_name: impl Into<Cow<'a, str>>) -> Self
Constructs a new command with the given procedure or function name.
Sourcepub fn bind_param(
&mut self,
name: impl Into<Cow<'a, str>>,
data: impl IntoSql<'a> + 'a,
)
pub fn bind_param( &mut self, name: impl Into<Cow<'a, str>>, data: impl IntoSql<'a> + 'a, )
Binds a scalar input parameter with the given name.
Sourcepub fn bind_out_param(
&mut self,
name: impl Into<Cow<'a, str>>,
data: impl IntoSql<'a> + 'a,
)
pub fn bind_out_param( &mut self, name: impl Into<Cow<'a, str>>, data: impl IntoSql<'a> + 'a, )
Binds a by-ref (OUT) scalar parameter. The returned value can be found by
the same name in the CommandResult returned values.
The value is returned in the type data is sent as. Strings and binary
are sent as nvarchar(max)/varbinary(max), so nothing is cut off. A
Numeric sets the scale of the result (a
None gives scale 0): bind e.g. Numeric::new_with_scale(0, 4) for a
decimal(10, 4) parameter.
Sourcepub fn bind_table(
&mut self,
name: impl Into<Cow<'a, str>>,
data: impl TableValue<'a> + 'a,
)
pub fn bind_table( &mut self, name: impl Into<Cow<'a, str>>, data: impl TableValue<'a> + 'a, )
Binds a table-valued parameter. The provided argument must implement
TableValue.
§Example
#[derive(TableValueRow)]
struct SomeGeoList {
eid: i32,
lat: Numeric,
lon: Numeric,
}
let r1 = SomeGeoList {
eid: 1,
lat: Numeric::new_with_scale(10, 6),
lon: Numeric::new_with_scale(14, 6),
};
let r2 = SomeGeoList {
eid: 4,
lat: Numeric::new_with_scale(101, 6),
lon: Numeric::new_with_scale(142, 6),
};
let tbl = vec![r1, r2];
let mut cmd = Command::new("dbo.usp_TheGeoProcedure");
cmd.bind_table("@table", tbl);Sourcepub fn bind_table_with_dbtype(
&mut self,
name: impl Into<Cow<'a, str>>,
db_type: &'a str,
data: impl TableValue<'a> + 'a,
)
pub fn bind_table_with_dbtype( &mut self, name: impl Into<Cow<'a, str>>, db_type: &'a str, data: impl TableValue<'a> + 'a, )
The same as bind_table, but overrides the database
type name used for the TVP.
Sourcepub async fn exec<'b, S>(
self,
client: &'b mut Client<S>,
) -> Result<CommandStream<'b>>
pub async fn exec<'b, S>( self, client: &'b mut Client<S>, ) -> Result<CommandStream<'b>>
Executes the command on the server, returning a CommandStream that
can be collected into a CommandResult for convenience.
§Example
let mut cmd = Command::new("dbo.usp_SomeStoredProc");
cmd.bind_param("@foo", 34i32);
cmd.bind_out_param("@bar", "bar");
let res = cmd.exec(&mut client).await?.into_command_result().await?;
let rv: Option<&str> = res.try_return_value("@bar")?;
let rc = res.return_code();