Skip to content

Add method to query column metadata - #398

Open
etylermoss wants to merge 8 commits into
tiberius-rs:mainfrom
etylermoss:query-column-metadata
Open

Add method to query column metadata#398
etylermoss wants to merge 8 commits into
tiberius-rs:mainfrom
etylermoss:query-column-metadata

Conversation

@etylermoss

Copy link
Copy Markdown

Fixes #397

@etylermoss

Copy link
Copy Markdown
Author

It should be considered to combine with #359 so that you can provide the (possibly subset) list of column metadata to bulk_insert to update only certain columns, without using an additional DB request to retrieve metadata again.

Eden Tyler-Moss and others added 2 commits November 26, 2025 21:50
Adds `bulk_insert_columns(self, table, columns)` and turns `bulk_insert(self, table)` into
a compatibility shim that calls `self.bulk_insert_columns(table, &["*"])`, maintaining the
existing behaviour.
@etylermoss

Copy link
Copy Markdown
Author

Merged with #359.

Eden Tyler-Moss and others added 3 commits November 26, 2025 23:08
joelparkerhenderson added a commit to mssql-rust/mssql-rust that referenced this pull request Aug 29, 2026
Mirrors the ColumnFlag-renumbering portion of tiberius-rs/tiberius#398 (its
column_metadata()/bulk_insert_columns API portion was already implemented
this session as part of #359).

ColumnFlag's bit values did not match MS-TDS 2.2.7.4 COLMETADATA's `Flags`
field (verified against the current Microsoft Learn spec text):
Updateable, UpdateableUnknown, Identity, Computed, FixedLenClrType,
SparseColumnSet, and Encrypted were each off by 1-2 bits (Hidden, Key, and
NullableUnknown were already correct). Concretely, a server's real
`fIdentity` bit (0x10) decoded as `UpdateableUnknown`, and `fComputed`
(0x20) wasn't representable at all under the old numbering.

`usUpdateable` is a 2-bit *value* (0 = read-only, 1 = read/write, 2 =
updateable-unknown), not two independent flags. `bulk_insert_columns`'s
existing filter (`.filter(|c| c.flags.contains(ColumnFlag::Updateable))`)
happened to keep working operationally only because its old, wrong
`Updateable` bit position (1<<3) coincided with the real spec's
`UpdateableUnknown` bit (0x08) - and SQL Server, in practice, reports
ordinary SELECT columns as updateable-unknown rather than definitively
read/write, only marking identity/computed columns definitively
read-only (0). Now that the bits are spec-correct, the filter is updated
to `intersects(Updateable | UpdateableUnknown)`, i.e. "not explicitly
read-only" - checking `Updateable` alone would incorrectly exclude
ordinary columns.

Added:
- 12 unit tests in token_col_metadata.rs decoding a raw wire value per
  flag against its expected bit position (verified 7 of them fail
  against the pre-fix bit numbering, restored to pass with the fix).
- A live regression test (bulk_insert_excludes_identity_and_computed_columns)
  confirming a wildcard bulk_insert against a table with an IDENTITY
  column and a COMPUTED column excludes both while still inserting into
  the ordinary column.

Verified:
- cargo check: default, --features=rustls, --features=vendored-openssl,
  --no-default-features
- cargo clippy --all-targets -- -D warnings
- cargo fmt --check
- cargo test --lib (162 passed)
- Live integration tests against a running Azure SQL Edge container over
  rustls: 294 passed (92 bulk + 202 query)

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0156Di1tRRLsJK8ctU1AmAJr
joelparkerhenderson added a commit to mssql-rust/mssql-rust that referenced this pull request Aug 29, 2026
Completes the remaining API portion of tiberius-rs/tiberius#398 (the
ColumnFlag bit-position fix landed separately in e7eb6e4).

Adds `Client::column_metadata(table, columns)`, factored out of
`bulk_insert_columns`'s existing metadata-fetching logic so both share
one implementation: it runs a `SELECT TOP 0` and returns each column's
name, type, and flags (nullability, identity, computed, etc.) without
touching any row data. `bulk_insert_columns` now calls it and applies
its own Updateable/UpdateableUnknown filter on top.

`MetaDataColumn` is now re-exported at the crate root so the return
type is nameable by callers; added doc comments to it and its fields
to satisfy `#![warn(missing_docs)]` now that it's public API surface.

Verified:
- cargo check: default, --features=rustls, --features=vendored-openssl,
  --no-default-features
- cargo clippy --all-targets -- -D warnings, for default, rustls, and
  vendored-openssl feature sets
- cargo fmt --check
- cargo test --lib (162 passed)
- cargo test --doc --no-default-features --features=rustls,tds73,chrono,
  rust_decimal,bigdecimal,time against a live server (26 passed,
  including the new column_metadata doctest)
- Live integration tests over rustls: 294 passed (92 bulk + 202 query)

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0156Di1tRRLsJK8ctU1AmAJr
MattJackson referenced this pull request in MattJackson/tiberius-ng Aug 29, 2026
…397, #217, #403)

Adapted from upstream #398 (author @etylermoss), reconciled with the
already-integrated bulk_insert_columns (#359):
- Client::column_metadata(table, columns) returns owned Vec<MetaDataColumn>
  (names, types, size/precision/scale, nullability, identity); bulk insert
  now shares this path.
- MetaDataColumn::col_name()/base() accessors; BaseMetaDataColumn::
  is_identity()/is_nullable()/ty()/flags() (resolves #403).
joelparkerhenderson added a commit to mssql-rust/mssql-rust that referenced this pull request Aug 30, 2026
Mirrors the ColumnFlag-renumbering portion of tiberius-rs/tiberius#398 (its
column_metadata()/bulk_insert_columns API portion was already implemented
this session as part of #359).

ColumnFlag's bit values did not match MS-TDS 2.2.7.4 COLMETADATA's `Flags`
field (verified against the current Microsoft Learn spec text):
Updateable, UpdateableUnknown, Identity, Computed, FixedLenClrType,
SparseColumnSet, and Encrypted were each off by 1-2 bits (Hidden, Key, and
NullableUnknown were already correct). Concretely, a server's real
`fIdentity` bit (0x10) decoded as `UpdateableUnknown`, and `fComputed`
(0x20) wasn't representable at all under the old numbering.

`usUpdateable` is a 2-bit *value* (0 = read-only, 1 = read/write, 2 =
updateable-unknown), not two independent flags. `bulk_insert_columns`'s
existing filter (`.filter(|c| c.flags.contains(ColumnFlag::Updateable))`)
happened to keep working operationally only because its old, wrong
`Updateable` bit position (1<<3) coincided with the real spec's
`UpdateableUnknown` bit (0x08) - and SQL Server, in practice, reports
ordinary SELECT columns as updateable-unknown rather than definitively
read/write, only marking identity/computed columns definitively
read-only (0). Now that the bits are spec-correct, the filter is updated
to `intersects(Updateable | UpdateableUnknown)`, i.e. "not explicitly
read-only" - checking `Updateable` alone would incorrectly exclude
ordinary columns.

Added:
- 12 unit tests in token_col_metadata.rs decoding a raw wire value per
  flag against its expected bit position (verified 7 of them fail
  against the pre-fix bit numbering, restored to pass with the fix).
- A live regression test (bulk_insert_excludes_identity_and_computed_columns)
  confirming a wildcard bulk_insert against a table with an IDENTITY
  column and a COMPUTED column excludes both while still inserting into
  the ordinary column.

Verified:
- cargo check: default, --features=rustls, --features=vendored-openssl,
  --no-default-features
- cargo clippy --all-targets -- -D warnings
- cargo fmt --check
- cargo test --lib (162 passed)
- Live integration tests against a running Azure SQL Edge container over
  rustls: 294 passed (92 bulk + 202 query)

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0156Di1tRRLsJK8ctU1AmAJr
joelparkerhenderson added a commit to mssql-rust/mssql-rust that referenced this pull request Aug 30, 2026
Completes the remaining API portion of tiberius-rs/tiberius#398 (the
ColumnFlag bit-position fix landed separately in b258866).

Adds `Client::column_metadata(table, columns)`, factored out of
`bulk_insert_columns`'s existing metadata-fetching logic so both share
one implementation: it runs a `SELECT TOP 0` and returns each column's
name, type, and flags (nullability, identity, computed, etc.) without
touching any row data. `bulk_insert_columns` now calls it and applies
its own Updateable/UpdateableUnknown filter on top.

`MetaDataColumn` is now re-exported at the crate root so the return
type is nameable by callers; added doc comments to it and its fields
to satisfy `#![warn(missing_docs)]` now that it's public API surface.

Verified:
- cargo check: default, --features=rustls, --features=vendored-openssl,
  --no-default-features
- cargo clippy --all-targets -- -D warnings, for default, rustls, and
  vendored-openssl feature sets
- cargo fmt --check
- cargo test --lib (162 passed)
- cargo test --doc --no-default-features --features=rustls,tds73,chrono,
  rust_decimal,bigdecimal,time against a live server (26 passed,
  including the new column_metadata doctest)
- Live integration tests over rustls: 294 passed (92 bulk + 202 query)

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0156Di1tRRLsJK8ctU1AmAJr
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.

Expose BaseMetaDataColumn & TypeInfo

2 participants