Repository navigation
Conversation
Remove extra terminator when encoding zero-length values for large va…
aersam
marked this pull request as ready for review
November 21, 2023 08:00
Closed
ibotty
reviewed
Jan 24, 2024
| if options.bits() > 0 || order_hints.len() > 0 { | ||
| let mut add_separator = false; | ||
| query.push_str(" WITH ("); | ||
| if options.contains(SqlBulkCopyOptions::KeepNulls) { |
There was a problem hiding this comment.
Can't you use bitflags's Flag::iter and join to simplify the whole separator business?
|
It would be great to have this pull request merged. |
joelparkerhenderson
added a commit
to mssql-rust/mssql-rust
that referenced
this pull request
Aug 29, 2026
Mirrors tiberius-rs/tiberius#312, reimplemented against this fork's already- merged column_metadata()/bulk_insert_columns (#398/#359) rather than patched, and fixing several issues along the way: - New `Client::bulk_insert_with_options(table, columns, options, order_hints)`, mirroring .NET's SqlBulkCopy: `SqlBulkCopyOption` flags (CheckConstraints, TableLock, KeepNulls, FireTriggers, KeepIdentity) and an optional per-column `ORDER` hint. `bulk_insert` and `bulk_insert_columns` are now thin wrappers around it with no options. Uses `enumflags2` (already a dependency, used for `ColumnFlag`/`RpcParam` flags elsewhere) instead of adding a second bitflags crate as upstream's PR did. - Fixed `KeepIdentity` to actually do something: upstream's PR defined the flag but never referenced it in the generated SQL, so it was a no-op. The TDS bulk-load protocol has no WITH-clause keyword for preserving identity values anyway (unlike CHECK_CONSTRAINTS/ FIRE_TRIGGERS/KEEP_NULLS/TABLOCK, which are real INSERT BULK options) - SQL Server's own BULK INSERT/SqlBulkCopy preserve identity values by including the identity column in the column list instead. So `KeepIdentity` now overrides the existing Updateable-based column filter for identity columns specifically. - Fixed 4 clippy-style issues present in the original PR: `len() > 0` -> `!is_empty()`, `push_str(")")` -> `push(')')`, a needless `return`, and uninlined format args in the improved "unrepresentable character" error message (now includes the offending char). - Did not carry over the PR's unrelated deletion of a decode-completeness assertion in a column_data.rs test (`reader.read_u8().await .expect_err(...)`) - that assertion was never touched here since this was a from-scratch reimplementation rather than a patch apply, so there was nothing to restore. - Live-tested and found (and fixed) a real bug of my own along the way: the initial `if !options.is_empty() || !order_hints.is_empty() { ... WITH (...) }` condition emitted an empty, syntactically invalid `WITH ()` clause when the only option set was `KeepIdentity` (which contributes no WITH-clause text) - now the clause is only emitted when there's an actual hint to put in it. Added 12 unit tests (bulk_options.rs has none of its own logic beyond plain enum/type definitions) plus 3 new live integration tests: KeepIdentity preserving supplied identity values, confirming identity is still excluded without it, and TableLock+CheckConstraints+FireTriggers+KeepNulls+ORDER together. 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 (169 passed) - cargo test --doc against a live server (27 passed, doctest included) - Live integration tests over rustls: 300 passed (98 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
Mirrors tiberius-rs/tiberius#312, reimplemented against this fork's already- merged column_metadata()/bulk_insert_columns (#398/#359) rather than patched, and fixing several issues along the way: - New `Client::bulk_insert_with_options(table, columns, options, order_hints)`, mirroring .NET's SqlBulkCopy: `SqlBulkCopyOption` flags (CheckConstraints, TableLock, KeepNulls, FireTriggers, KeepIdentity) and an optional per-column `ORDER` hint. `bulk_insert` and `bulk_insert_columns` are now thin wrappers around it with no options. Uses `enumflags2` (already a dependency, used for `ColumnFlag`/`RpcParam` flags elsewhere) instead of adding a second bitflags crate as upstream's PR did. - Fixed `KeepIdentity` to actually do something: upstream's PR defined the flag but never referenced it in the generated SQL, so it was a no-op. The TDS bulk-load protocol has no WITH-clause keyword for preserving identity values anyway (unlike CHECK_CONSTRAINTS/ FIRE_TRIGGERS/KEEP_NULLS/TABLOCK, which are real INSERT BULK options) - SQL Server's own BULK INSERT/SqlBulkCopy preserve identity values by including the identity column in the column list instead. So `KeepIdentity` now overrides the existing Updateable-based column filter for identity columns specifically. - Fixed 4 clippy-style issues present in the original PR: `len() > 0` -> `!is_empty()`, `push_str(")")` -> `push(')')`, a needless `return`, and uninlined format args in the improved "unrepresentable character" error message (now includes the offending char). - Did not carry over the PR's unrelated deletion of a decode-completeness assertion in a column_data.rs test (`reader.read_u8().await .expect_err(...)`) - that assertion was never touched here since this was a from-scratch reimplementation rather than a patch apply, so there was nothing to restore. - Live-tested and found (and fixed) a real bug of my own along the way: the initial `if !options.is_empty() || !order_hints.is_empty() { ... WITH (...) }` condition emitted an empty, syntactically invalid `WITH ()` clause when the only option set was `KeepIdentity` (which contributes no WITH-clause text) - now the clause is only emitted when there's an actual hint to put in it. Added 12 unit tests (bulk_options.rs has none of its own logic beyond plain enum/type definitions) plus 3 new live integration tests: KeepIdentity preserving supplied identity values, confirming identity is still excluded without it, and TableLock+CheckConstraints+FireTriggers+KeepNulls+ORDER together. 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 (169 passed) - cargo test --doc against a live server (27 passed, doctest included) - Live integration tests over rustls: 300 passed (98 bulk + 202 query) Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0156Di1tRRLsJK8ctU1AmAJr
Contributor
|
Bulk options/order hints landed in #451 — shipped in tiberius v0.13.0. Thanks for this! Closing. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.