2682 Commits

Author SHA1 Message Date
zebrapurring
e627673869
chore: upgrade async-io to v2.4.1 (#3911)
* chore: upgrade async-io to v2.4

* refactor: replace `get_mut()` with `get_ref()` in Socket impls

---------

Co-authored-by: zebrapurring <>
2025-07-04 19:10:03 -07:00
Tyler Hawkes
97de03482c
Add PgBindIter for encoding and use it as the implementation encoding &[T] (#3651)
* Add PgBindIter for encoding and use it as the implementation encoding &[T]

* Implement suggestions from review

* Add docs to PgBindIter and test to ensure it works for owned and borrowed types

* Use extension trait for iterators to allow code to flow better. Make struct private. Don't reference unneeded generic T. Make doc tests compile.

* Fix doc function

* Fix doc test to actually compile

* Use Cell<Option<I>> instead of Clone bound
2025-07-04 17:59:38 -07:00
Joey de Waal
60f67dbc39
feat: implement Encode, Decode, Type for Arc<str> and Arc<[u8]> (and Rc equivalents) (#3675)
* implement Encode, Decode, Type for Arc<str> and Arc<[u8]> (and Rc equivalents)

* sqlx-sqlite: Remove clone in Encode impl

* sqlx-sqlite: Remove unnecessary impls
2025-07-04 17:58:33 -07:00
Joey de Waal
0f891a3c56
Remove unnecessary boxfutures (#3525)
* Remove `BoxFuture`'s from `Connection` and `ConnectOptions`

* Remove `BoxFuture`'s for `MigrateDatabase`

* Remove `BoxFuture`'s for `TransactionManager`

* Remove `BoxFuture`'s for `TestSupport`

* Remove `BoxFuture`'s from `PgPoolCopyExt`

* Clippy fixes

* Box timeout future in debug mode
2025-07-04 17:53:46 -07:00
Bogdan Mircea
a9fb581626
fix: use Executor::fetch in QueryAs::fetch (#3886) 2025-07-04 17:44:20 -07:00
Ole Martin Ruud
a0c7769d85
Feature: Add exclusion violation error kind (#3918)
* feat: add exclusion violation error kind

* chore: add test for exclusion error kind
2025-07-04 16:52:58 -07:00
Nicolás Hatcher
9de593a0e5
fix[sqlx-postgres]: do a checked_mul to prevent panic when casting from db (#3919) 2025-07-04 16:51:43 -07:00
Aleh Shapo
29549b14c4
fix(mysql): validate parameter count for prepared statements (#3857)
* fix(mysql): validate parameter count for prepared statements

Add validation to ensure the number of provided parameters matches the
expected count for MySQL prepared statements.
This prevents protocol errors by returning an error if the counts do not match before sending
the statement for execution.

* refactor(mysql): use err_protocol macro for error creation

Replace direct Error::Protocol(format!()) calls with err_protocol!
macro in MySQL connection executor.

* test(mysql): add parameter count validation tests

- Add test for too few parameters provided to query
- Add test for too many parameters provided to query
- Add test for parameters provided when none expected
- All tests verify Error::Protocol is returned for mismatches

Covers cases for issue #3774 parameter validation fix.
2025-07-02 17:24:44 -07:00
Luiz Carvalho
8ebc6f9427
fix: spec_error is used by try_from derive (#3915)
The `try_from` field attribute in `FromRow` uses `__spec_error` to generate a column decode error. The `spec_error` is currently gated behind the macros feature flag only, but should also be available when using only `derive`.
2025-07-02 04:00:59 -07:00
Elichai Turkel
2970559e25
Fix NoHostnameTlsVerifier for rustls 0.23.24 and above (#3861) 2025-07-02 03:48:51 -07:00
Bogdan Mircea
ba23fdeb76
Compile-time support for external drivers (#3889)
* Make sqlx-macros-core::database public

* Move driver installation to bins

* Fix lint
2025-07-02 03:48:08 -07:00
Austin Bonander
a0e40540e3 fix: regenerate test certificates
New versions of RusTLS validate and reject v1 client certificates.
2025-07-01 00:43:52 -07:00
Austin Bonander
eb792a3044 fix(core): lint warning in decode.rs 2025-06-30 19:17:39 -07:00
JP
8ff14dc37c
feat(ok): add correct handling of ok packets in MYSQL implementation (#3910)
* feat(ok): add correct handling of ok packet

* feat(ok): add unit tests
2025-06-30 17:31:55 -07:00
Joey de Waal
69f9ff9180
Postgres: force generic plan for better nullability inference. (#3541)
* Postgres: force generic plan when describing statement with args

* cargo fmt

* Postgres: set plan_cache_mode in transaction

* Postgres: only set force_generic_plan for versions that support it

* Postgres: reduce database calls in query macro's

* Postgres: set generic execution plan only in query macro
2025-06-30 17:25:20 -07:00
miniduikboot
2fd3dabf38
Bump etcetera to 0.10.0 (#3867)
This bumps the underlying version of windows-sys used by this crate.

I've only compile tested this by crosscompiling from Linux.
2025-06-30 17:23:12 -07:00
Nipunn Koorapati
798d1075a7
Return &mut Self from the migrator set_ methods (#3526) 2025-06-30 17:13:26 -07:00
Austin Bonander
7f728295b2
fix: RawSql lifetime issues (#3613)
* chore(raw_sql): create regression test

* fix: `RawSql` lifetime issues

* chore(raw_sql): try not adding another lifetime param
2025-06-30 17:08:48 -07:00
Joey de Waal
8602d94c4d
Implement Decode, Encode and Type for Box, Arc, Cow and Rc (#3674)
* feat: implement Decode,Encode,Type for Box,Arc,Cow

* feat implement Encode,Type for Rc

* feat: implement Decode for Rc

* chore: make tests more concise

* chore: use macro's

* chore: remove conflicting impls

* chore: more macro's

* Relax Sized bound for Decode, Encode

* update unit tests

* fixes after review

* add comment in `Decode` impl

* add comment about `ToOwned` trait bound

* add comment explaining why decoding to `Cow::Owned` was chosen

* Remove unnecessary Decode impls
2025-06-30 17:03:48 -07:00
iamjpotts
64e154abfa
fix(logs): Correct spelling of aquired_after_secs tracing field (#3486)
Signed-off-by: Joshua Potts <8704475+iamjpotts@users.noreply.github.com>
2025-06-30 16:56:47 -07:00
V02460
1341b396bb
Escape PostgreSQL options (#3800)
* Escape PostgreSQL options

* Use raw string literals in test case

Co-authored-by: Austin Bonander <austin.bonander@gmail.com>

* Document escaping behavior for options

* Remove heap allocations for options formatting

* Use an actual config option for the test case

---------

Co-authored-by: Austin Bonander <austin.bonander@gmail.com>
2025-06-30 16:40:44 -07:00
Austin Bonander
25cbeedab4
feat: create sqlx.toml format (#3383)
* feat: create `sqlx.toml` format

* feat: add support for ignored_chars config to sqlx_core::migrate

* chore: test ignored_chars with `U+FEFF` (ZWNBSP/BOM)

https://en.wikipedia.org/wiki/Byte_order_mark

* refactor: make `Config` always compiled

simplifies usage while still making parsing optional for less generated code

* refactor: add origin information to `Column`

* feat(macros): implement `type_override` and `column_override` from `sqlx.toml`

* refactor(sqlx.toml): make all keys kebab-case, create `macros.preferred-crates`

* feat: make macros aware of `macros.preferred-crates`

* feat: make `sqlx-cli` aware of `database-url-var`

* feat: teach macros about `migrate.table-name`, `migrations-dir`

* feat: teach macros about `migrate.ignored-chars`

* chore: delete unused source file `sqlx-cli/src/migration.rs`

* feat: teach `sqlx-cli` about `migrate.defaults`

* feat: teach `sqlx-cli` about `migrate.migrations-dir`

* feat: teach `sqlx-cli` about `migrate.table-name`

* feat: introduce `migrate.create-schemas`

* WIP feat: create multi-tenant database example

* fix(postgres): don't fetch `ColumnOrigin` for transparently-prepared statements

* feat: progress on axum-multi-tenant example

* feat(config): better errors for mislabeled fields

* WIP feat: filling out axum-multi-tenant example

* feat: multi-tenant example

No longer Axum-based because filling out the request routes would have distracted from the purpose of the example.

* chore(ci): test multi-tenant example

* fixup after merge

* fix(ci): enable `sqlx-toml` in CLI build for examples

* fix: CI, README for `multi-tenant`

* fix: clippy warnings

* fix: multi-tenant README

* fix: sequential versioning inference for migrations

* fix: migration versioning with explicit overrides

* fix: only warn on ambiguous crates if the invocation relies on it

* fix: remove unused imports

* fix: doctest

* fix: `sqlx mig add` behavior and tests

* fix: restore original type-checking order

* fix: deprecation warning in `tests/postgres/macros.rs`

* feat: create postgres/multi-database example

* fix: examples/postgres/multi-database

* fix: cargo fmt

* chore: add tests for config `migrate.defaults`

* fix: sqlx-cli/tests/add.rs

* feat(cli): add `--config` override to all relevant commands

* chore: run `sqlx mig add` test with `RUST_BACKTRACE=1`

* fix: properly canonicalize config path for `sqlx mig add` test

* fix: get `sqlx mig add` test passing

* fix(cli): test `migrate.ignored-chars`, fix bugs

* feat: create `macros.preferred-crates` example

* fix(examples): use workspace `sqlx`

* fix: examples

* fix(sqlite): unexpected feature flags in `type_checking.rs`

* fix: run `cargo fmt`

* fix: more example fixes

* fix(ci): preferred-crates setup

* fix(examples): enable default-features for workspace `sqlx`

* fix(examples): issues in `preferred-crates`

* chore: adjust error message for missing param type in `query!()`

* doc: mention new `sqlx.toml` configuration

* chore: add `CHANGELOG` entry

Normally I generate these when cutting the release, but I wanted to take time to editorialize this one.

* doc: fix new example titles

* refactor: make `sqlx-toml` feature non-default, improve errors

* refactor: eliminate panics in `Config` read path

* chore: remove unused `axum` dependency from new examples

* fix(config): restore fallback to default config for macros

* chore(config): remove use of `once_cell` (to match `main`)
2025-06-30 16:34:46 -07:00
Paolo Barbolini
764ae2f702
chore: replace once_cell OnceCell/Lazy with std OnceLock/LazyLock (#3709) 2025-06-17 16:38:02 -07:00
Paolo Barbolini
df47ffedd2
Replace some more futures_util APIs with std variants (#3874) 2025-06-15 15:18:39 -07:00
Austin Bonander
90797200ee
groundwork for 0.9.0-alpha.1 (#3821)
* chore: bump version to `0.9.0-alpha.1`

* chore: delete unused `sqlx-bench` package

* chore: set `rust-version` to 1.85 for all crates

* fix: lots of new Clippy warnings

* fix: lots more Clippy warnings

* fix(cli): add `_sqlite` feature

* fix: lots, *lots* more Clippy warnings

* fix(core): warning in `tls_rustls`

* breaking: delete runtime+TLS combination features

* chore: don't re-export unstable `TransactionManager` trait

* chore: 0.9.0-alplha.1 CHANGELOG

* chore: increase MSRV further to 1.86

* fix: more clippy warnings
2025-06-01 21:09:55 -07:00
Austin Bonander
bab1b022bd
0.8.6 release (#3870) v0.8.6 2025-05-19 16:21:27 -07:00
Gabriel Féron
b27b47ce53
Pick default features to fix docs.rs build of sqlx-sqlite (#3840) 2025-05-19 14:59:01 -07:00
Thom Wright
d335f782cf
Use unnamed statement in pg when not persistent (#3863)
This will automatically close the prepared statement when
another query is run, avoiding a memory leak.
2025-05-19 14:58:40 -07:00
Joey de Waal
760b3953ba
fix(macros): don't mutate environment variables (#3848) 2025-05-19 14:58:26 -07:00
Carson McManus
4259862adf
fix(macros): slightly improve unsupported type error message (#3856) 2025-05-19 14:55:00 -07:00
Josh
1b94e1d07d
chore(doc): clarify compile-time verification and case conversion behavior (#3866)
* chore(doc): clarify compile-time verification and case conversion behavior

* apply review suggestions

Co-authored-by: Austin Bonander <austin.bonander@gmail.com>

* fix(fmt): remove trailing spaces

* fix(doc): links

---------

Co-authored-by: Austin Bonander <austin.bonander@gmail.com>
2025-05-17 21:50:18 -07:00
Nikolai Vincent Vaags
92c3845952
fix attrubute typo in doc (#3855) 2025-05-07 17:06:34 -07:00
Paolo Barbolini
3edc6199db
build: drop unused tempfile dependency (#3830) 2025-05-05 15:44:56 -07:00
Josh McKinney
6b2e0247d4
Add color and wrapping to cli help text (#3849) 2025-05-02 18:48:46 -07:00
tison
5736ab6c21
chore: clean up no longer used imports (#3845)
Signed-off-by: tison <wander4096@gmail.com>
2025-05-02 18:20:34 -07:00
Austin Bonander
91d26bad4d
fix(CHANGELOG): section headings in 0.8.5 2025-04-15 15:14:58 -07:00
Austin Bonander
e7236881a1
Hotfix 0.8.5 (#3824)
* fix(cli): correctly handle `.env` files again

* feat(ci): add functionality tests for sqlx-cli (MySQL)

* feat(ci): add functionality tests for sqlx-cli (Postgres)

* feat(ci): add functionality tests for sqlx-cli (SQLite)

* chore: prepare 0.8.5 release

* feat(ci): run `test-attr` tests twice to catch #3825

* fix: correct bugs in MySQL implementation of `#[sqlx::test]`
v0.8.5
2025-04-15 15:11:07 -07:00
Austin Bonander
f9084035d7
0.8.4 release (#3819)
* chore: prepare 0.8.4 release

* fix(postgres): send `limit: 0` for all `Execute` messages

fixes #3673

* fix: let `CertificateInput::from` infer any PEM-encoded document

https://github.com/launchbadge/sqlx/pull/3809#issuecomment-2800293813

* doc: improve documentation of `PgConnectOptions`

fixes #3740

* chore: update CHANGELOG from PR
2025-04-13 21:55:14 -07:00
Markus Schirp
154878547e
fix: PgConnectOptions docs (#3809) 2025-04-13 17:21:15 -07:00
Cristian Le
97bf270caf
Always set SQLITE_OPEN_URI (#3289) 2025-04-13 17:06:17 -07:00
Joey de Waal
42def59973
fix(macros): cache macro metadata based on CARGO_MANIFEST_DIR (#3815)
* fix(macros): cache macro metadata based on CARGO_MANIFEST_DIR

* fix unrelated typo

* bump dotenvy version

* fix after review
2025-04-13 17:02:14 -07:00
Vladimir Petrzhikovskii
e283bf9645 mysql: Fix panic on invalid text row length field
Previously, `TextRow::decode_with` would read a length-encoded field size
and attempt to advance the buffer by that amount. If the server sent a
malformed packet containing a length value larger than the remaining data
in the buffer, the call to `buf.advance(size)` would panic.

eg: 
```
thread 'main' panicked at /home/user/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/bytes-1.10.1/src/bytes.rs:711:9:
cannot advance past remaining: 8590116092 <= 0
stack backtrace:
0:     0x56119b657e00 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h6d42cc84fc840290
1:     0x56119b67edd3 - core::fmt::write::h5af61a909e3ec64d
2:     0x56119b653ee3 - std::io::Write::write_fmt::h5a7b54aa6e4a315d
3:     0x56119b657c52 - std::sys::backtrace::BacktraceLock::print::h555579e7396c26ac
4:     0x56119b658cef - std::panicking::default_hook::{{closure}}::h9128866118196224
5:     0x56119b658b5a - std::panicking::default_hook::h52e9e7314e0255f6
6:     0x56119b659712 - std::panicking::rust_panic_with_hook::h541791bcc774ef34
7:     0x56119b65949a - std::panicking::begin_panic_handler::{{closure}}::h6479a2f0137c7d19
8:     0x56119b658319 - std::sys::backtrace::__rust_end_short_backtrace::ha04e7c0fc61ded91
9:     0x56119b65912d - rust_begin_unwind
10:     0x56119b67c390 - core::panicking::panic_fmt::h5764ee7030b7a73d
11:     0x56119b572b18 - <sqlx_mysql::protocol::text::row::TextRow as sqlx_core::io::decode::ProtocolDecode<&[sqlx_mysql::column::MySqlColumn]>>::decode_with::h17ac8b44140b5469
12:     0x56119b42df1f - sqlx_mysql::connection::executor::<impl sqlx_mysql::connection::MySqlConnection>::run::{{closure}}::{{closure}}::{{closure}}::h4874a0f73925d55a
```

This commit introduces a bounds check immediately after reading the field length from a packet.

This panic condition was specifically observed when executing a TiDB
`BATCH ON ... DELETE` statement via `pool.execute()`. It sends an OK packet immediately followed by
a full result set describing the batch status (column defs, row data, EOF).


 Observed TiDB response sequence for `BATCH DML` via `COM_QUERY`:
    1. OK Packet (seq=1, `SERVER_MORE_RESULTS_EXISTS` = false)
    2. Column Count Packet (seq=1, non-standard, protocol violation)
    3. Column Definition Packet (seq=2)
    4. Column Definition Packet (seq=3)
    5. Text Row Data Packet (seq=4)
    6. EOF Packet (seq=5, `SERVER_MORE_RESULTS_EXISTS` = false)

This differs from standard MySQL DML response (OK/ERR packet only) and
causes `sqlx` using `execute()` to attempt parsing the unexpected result
set packets after the initial OK packet.
2025-04-10 19:40:16 -07:00
TeCHiScy
082aed5c2b
Fix error message typo in PgPoint::from_str (#3811) 2025-04-01 00:41:28 -07:00
thriller08
f0be19e640
Enable json feature without db enabled (#3801) 2025-03-29 20:05:04 -07:00
Beau Gieskens
1c9cbe939a
feat: add ipnet support (#3710)
* feat: add ipnet support

* fix: ipnet not decoding IP address strings

* fix: prefer ipnetwork to ipnet for compatibility

* fix: unnecessary cfg
2025-03-23 17:19:05 -07:00
Robin Schroer
e474be6d4b
docs: Fix a copy-paste error on get_username docs (#3786)
I suspect this is a copy-paste error, it's meant to say username, not port.
2025-03-15 23:21:56 -07:00
Austin Bonander
393b731d5e
Merge of #3427 (by @mpyw) and #3614 (by @bonsairobo) (#3765)
* feat: Implement `get_transaction_depth` for drivers

* test: Verify `get_transaction_depth()` on postgres

* Refactor: `TransactionManager` delegation without BC

SQLite implementation is currently WIP

* Fix: Avoid breaking changes on `AnyConnectionBackend`

* Refactor: Remove verbose `SqliteConnection` typing

* Feat: Implementation for SQLite

I have included `AtomicUsize` in `WorkerSharedState`. Ideally, it is not desirable to execute `load` and `fetch_add` in two separate steps, but we decided to allow it here since there is only one thread writing. To prevent writing from other threads, the field itself was made private, and a getter method was provided with `pub(crate)`.

* Refactor: Same approach for `cached_statements_size`

ref: a66787d36d62876b55475ef2326d17bade817aed

* Fix: Add missing `is_in_transaction` for backend

* Doc: Remove verbose "synchronously" word

* Fix: Remove useless `mut` qualifier

* feat: add Connection::begin_with

This patch completes the plumbing of an optional statement from these methods to
`TransactionManager::begin` without any validation of the provided statement.

There is a new `Error::InvalidSavePoint` which is triggered by any attempt to
call `Connection::begin_with` when we are already inside of a transaction.

* feat: add Pool::begin_with and Pool::try_begin_with

* feat: add Error::BeginFailed and validate that custom "begin" statements are successful

* chore: add tests of Error::BeginFailed

* chore: add tests of Error::InvalidSavePointStatement

* chore: test begin_with works for all SQLite "BEGIN" statements

* chore: improve comment on Connection::begin_with

* feat: add default impl of `Connection::begin_with`

This makes the new method a non-breaking change.

* refactor: combine if statement + unwrap_or_else into one match

* feat: use in-memory SQLite DB to avoid conflicts across tests run in parallel

* feedback: remove public wrapper for sqlite3_txn_state

Move the wrapper directly into the test that uses it instead.

* fix: cache Status on MySqlConnection

* fix: compilation errors

* fix: format

* fix: postgres test

* refactor: delete `Connection::get_transaction_depth`

* fix: tests

---------

Co-authored-by: mpyw <ryosuke_i_628@yahoo.co.jp>
Co-authored-by: Duncan Fairbanks <duncanfairbanks6@gmail.com>
2025-03-10 14:29:46 -07:00
James H.
2f10c29dfd
feat(postgres): add geometry circle (#3773)
* feat: circle

* docs: comments
2025-03-09 15:01:30 -07:00
James H.
ca3a509036
feat(postgres): add geometry polygon (#3769)
* feat: add polygon

* test: paths for pgpoints in polygon test

* fix: import typo

* chore(Sqlite): remove ci.db from repo (#3768)

* fix: CI

* Fix breakage from Rustup 1.28 <https://blog.rust-lang.org/2025/03/02/Rustup-1.28.0.html>
* Let `Swatinem/rust-cache` generate cache keys

* fix(ci): upgrade Ubuntu image to 24.04

For some reason the `cargo +beta clippy` step is failing because `libsqlite3-sys` starts requiring Glibc >= 2.39 but I don't have time to figure out why and I can't reproduce it in a clean environment.

---------

Co-authored-by: joeydewaal <99046430+joeydewaal@users.noreply.github.com>
Co-authored-by: Austin Bonander <austin.bonander@gmail.com>
2025-03-07 01:25:45 -08:00
Chitoku
a92626d6cc postgres: Use current tracing span when dropping PgListener 2025-03-05 01:30:38 -08:00