Skip to content

feat(rpc): named-procedure RPC with OUT params and TVPs - #18

Merged
MattJackson merged 1 commit into
devfrom
feat/named-rpc
Aug 29, 2026
Merged

MattJackson merged 1 commit into
devfrom
feat/named-rpc

Conversation

@MattJackson

Copy link
Copy Markdown
Owner

Integrates the intent of upstream PR tiberius-rs/tiberius#328 onto current `dev`, resolving #275.

What

Implements calling a stored procedure by name (previously a `todo!()` in `rpc_request.rs`), with input params, OUT params and table-valued parameters, reconciled with the existing by-id RPC path used by `execute`/`query`.

Codec

  • Encode `RpcProcIdValue::Name` as a US_VARCHAR proc name; the by-id path is unchanged.
  • New `RpcValue` enum (`Scalar(ColumnData)` / `Table(TypeInfoTvp)`) replacing the raw `ColumnData` value on `RpcParam`; all existing call sites updated to `RpcValue::Scalar(..)`.
  • New `TypeInfoTvp` encodes TVP type info + rows per MS-TDS 2.2.5.5.5, rewriting fixed-length column types to their nullable var-len equivalents.
  • Nullable scalar values now encode a proper NULL when no `TypeInfo` is supplied.

Public API

  • `Command` with `new`, `bind_param`, `bind_out_param`, `bind_table`, `bind_table_with_dbtype`, `exec`.
  • `CommandStream` yielding `CommandItem` (rows, metadata, return status/value, rows affected), collectible into `CommandResult` which exposes `return_code`, `try_return_value`, `rows_affected` and result sets. RETURNVALUE tokens (already decoded on `dev`) surface as OUT parameter values.
  • New `tvp-macro` crate providing `#[derive(TableValueRow)]`.

Tests

  • Unit tests: named-proc RPC request encoding (proc name, param name, ByRef flag, by-id vs by-name proc slot), TVP type-info encoding, and derive-macro output.
  • Integration tests in `tests/command.rs` (scalar exec, OUT params, TVPs) require a live SQL Server.

Verification

  • `cargo build` (default): clean
  • `cargo test --lib`: 124 passed (incl. new unit tests); `cargo test -p tvp-macro`: passed
  • `cargo fmt --check`: clean
  • `cargo clippy --features=all -- -D warnings`: no findings in the new/changed code (pre-existing repo lints from a newer local toolchain are untouched)

Draft because the integration tests need a live SQL Server to run.

🤖 Generated with Claude Code

…eters

Implement calling a stored procedure by name, resolving the `todo!()`
that previously blocked named-procedure RPC requests.

- Encode `RpcProcIdValue::Name` as a US_VARCHAR proc name in the RPC
  request, alongside the existing by-id path used by execute/query.
- Introduce `RpcValue` (Scalar/Table) so RPC params can carry either a
  scalar `ColumnData` or a table-valued parameter, and thread it through
  the existing execute/query call sites.
- Add `TypeInfoTvp` to encode TVP type info and rows (MS-TDS 2.2.5.5.5),
  rewriting fixed-length column types to their nullable var-len variants.
- Add a `Command` public API (`bind_param`, `bind_out_param`,
  `bind_table`, `bind_table_with_dbtype`, `exec`) plus `CommandStream`,
  `CommandItem`, `CommandResult` and `CommandReturnValue` for reading OUT
  parameter values, return codes and result sets.
- Add the `tvp-macro` crate providing `#[derive(TableValueRow)]`.
- Encode nullable scalar values correctly when no TypeInfo is supplied.

Unit tests cover named-proc request encoding, TVP type-info encoding and
the derive macro output. Integration tests requiring a live SQL Server
are added under tests/command.rs.

Resolves #275.
@MattJackson
MattJackson merged this pull request into dev Aug 29, 2026
2 of 33 checks passed
MattJackson added a commit that referenced this pull request Aug 29, 2026
@MattJackson
MattJackson deleted the feat/named-rpc branch August 29, 2026 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant