2656 Commits

Author SHA1 Message Date
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
Austin Bonander
c3fd645409 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.
2025-03-04 14:31:38 -08:00
Austin Bonander
7a2a94e7b5 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
2025-03-04 14:31:38 -08:00
joeydewaal
7af998c2ab
chore(Sqlite): remove ci.db from repo (#3768) 2025-03-04 12:56:08 -08:00
James H.
5c573e15eb
feat(postgres): add geometry path (#3716)
* feat: add geometry path

* fix: paths to pg point

* test: remove array tests for path

* Fix readme: uuid feature is gating for all repos (#3720)

The readme previously stated that the uuid feature is only for postres but it actually also gates the functionality in mysql and sqlite.

* Replace some futures_util APIs with std variants (#3721)

* feat(sqlx-cli): Add flag to disable automatic loading of .env files (#3724)

* Add flag to disable automatic loading of .env files

* Update sqlx-cli/src/opt.rs

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

---------

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

* chore: expose bstr feature (#3714)

* chore: replace rustls-pemfile with rustls-pki-types (#3725)

* QueryBuilder: add `debug_assert` when `push_values` is passed an empty set of tuples (#3734)

* throw a warning in tracing so that the empty tuples would be noticed

* use debug assertion to throw a panic in debug mode

* fix: merge conflicts

* chore(cli): remove unused async-trait crate from dependencies (#3754)

* Update pull_request_template.md

* Fix example calculation (#3741)

* Avoid privilege requirements by using an advisory lock in test setup (postgres). (#3753)

* feat(sqlx-postgres): use advisory lock to avoid setup race condition

* fix(sqlx-postgres): numeric hex constants not supported before postgres 16

* Small doc correction. (#3755)

When sqlx-core/src/from_row.rs was updated to implement FromRow for tuples of up to 16 values, a comment was left stating that it was implemented up to tuples of 9 values.

* Update FAQ.md

* refactor(cli): replace promptly with dialoguer (#3669)

* docs(pool): recommend actix-web ThinData over Data to avoid two Arcs (#3762)

Both actix_web::web::Data and sqlx::PgPool internally wrap an Arc. Thus,
using Data<PgPool> as an extractor in an actix-web route handler results
in two Arcs wrapping the data of interest, which isn't ideal.

Actix-web 4.9.0 introduced a new web::ThinData extractor for cases like
this, where the data is already wrapped in an `Arc` (or is otherwise
similarly cheap and sensible to simply clone), which doesn't wrap the
inner value in a (second) Arc.

Since the new extractor is better suited to the task, suggest it in
place of web::Data when giving an example on how to share a pool.

* fix: merge conflicts

* fix: use types mod from main

* fix: merge conflicts

* fix: merge conflicts

* fix: merge conflicts

* fix: ordering of types mod

* fix: path import

* test: no array test for path

---------

Co-authored-by: Jon Thacker <thacker.jon@gmail.com>
Co-authored-by: Paolo Barbolini <paolo.barbolini@m4ss.net>
Co-authored-by: Ben Wilber <benwilber@users.noreply.github.com>
Co-authored-by: Austin Bonander <austin.bonander@gmail.com>
Co-authored-by: joeydewaal <99046430+joeydewaal@users.noreply.github.com>
Co-authored-by: tottoto <tottotodev@gmail.com>
Co-authored-by: Ethan Wang <mailme@ethanavania.org>
Co-authored-by: Stefan Schindler <dns2utf8@users.noreply.github.com>
Co-authored-by: kildrens <5198060+kildrens@users.noreply.github.com>
Co-authored-by: Marti Serra <marti.serra+github@protonmail.com>
Co-authored-by: Jonas Malaco <jonas@protocubo.io>
2025-03-02 14:29:53 -08:00
Mattia Righetti
c5ea6c4435
feat: sqlx sqlite expose de/serialize (#3745)
* feat: implement serialze no copy on lockedsqlitehandle

* feat: implement serialize on sqliteconnection

* feat: implement deserialize on sqliteconnection and add sqlitebuf wrapper type

* refactor: misc sqlite type and deserialize refactoring

* chore: misc clippy refactoring

* fix: misc refactoring and fixes

- pass non-owned byte slice to deserialize
- `SqliteBufError` and better error handling
- more impl for `SqliteOnwedBuf` so it can be used as a slice
- default serialize for `SqliteConnection`

* refactor: move serialize and deserialize on worker thread

This implements `Command::Serialize` and `Command::Deserialize` and moves the
serialize and deserialize logic to the worker thread.

`Serialize` will need some more iterations as it's not clear whether it would
need to wait for other write transactions before running.

* refactor: misc refactoring and changes

- Merged deserialize module with serialize module
- Moved `SqliteOwnedBuf` into serialize module
- Fixed rustdocs

* chore: API tweaks, better docs, tests

* fix: unused import

* fix: export `SqliteOwnedBuf`, docs and safety tweaks

---------

Co-authored-by: Austin Bonander <austin.bonander@gmail.com>
2025-03-02 14:29:29 -08:00
Jonas Malaco
5d6d6985cd
docs(pool): recommend actix-web ThinData over Data to avoid two Arcs (#3762)
Both actix_web::web::Data and sqlx::PgPool internally wrap an Arc. Thus,
using Data<PgPool> as an extractor in an actix-web route handler results
in two Arcs wrapping the data of interest, which isn't ideal.

Actix-web 4.9.0 introduced a new web::ThinData extractor for cases like
this, where the data is already wrapped in an `Arc` (or is otherwise
similarly cheap and sensible to simply clone), which doesn't wrap the
inner value in a (second) Arc.

Since the new extractor is better suited to the task, suggest it in
place of web::Data when giving an example on how to share a pool.
2025-02-28 16:42:53 -08:00
Paolo Barbolini
277dd36c78
refactor(cli): replace promptly with dialoguer (#3669) 2025-02-27 12:17:09 -08:00
Austin Bonander
9bd3d61929
Update FAQ.md 2025-02-22 18:07:43 -08:00
Marti Serra
3dec1d186a
Small doc correction. (#3755)
When sqlx-core/src/from_row.rs was updated to implement FromRow for tuples of up to 16 values, a comment was left stating that it was implemented up to tuples of 9 values.
2025-02-22 13:33:14 -08:00
kildrens
a9dfb4f2c1
Avoid privilege requirements by using an advisory lock in test setup (postgres). (#3753)
* feat(sqlx-postgres): use advisory lock to avoid setup race condition

* fix(sqlx-postgres): numeric hex constants not supported before postgres 16
2025-02-20 18:13:56 -08:00
Stefan Schindler
8dce6bd9e1
Fix example calculation (#3741) 2025-02-20 12:57:54 -08:00
Austin Bonander
26b4e5f166
Update pull_request_template.md 2025-02-20 12:51:54 -08:00
tottoto
520d25c453
chore(cli): remove unused async-trait crate from dependencies (#3754) 2025-02-20 11:35:44 -08:00
Sam Lyon
8cdad44366
docs: add some missing backticks (#3749)
* add ending backticks to starting backticks that were missing them

* fix table alignment
2025-02-19 15:23:45 -08:00
Ethan Wang
b859914153
QueryBuilder: add debug_assert when push_values is passed an empty set of tuples (#3734)
* throw a warning in tracing so that the empty tuples would be noticed

* use debug assertion to throw a panic in debug mode
2025-02-17 17:39:40 -08:00
tottoto
3a20a92a3f
chore: replace rustls-pemfile with rustls-pki-types (#3725) 2025-02-05 13:48:19 -08:00
joeydewaal
f42561b8d7
chore: expose bstr feature (#3714) 2025-02-04 10:53:05 -08:00
Ben Wilber
91291beb23
feat(sqlx-cli): Add flag to disable automatic loading of .env files (#3724)
* Add flag to disable automatic loading of .env files

* Update sqlx-cli/src/opt.rs

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

---------

Co-authored-by: Austin Bonander <austin.bonander@gmail.com>
2025-02-04 10:52:43 -08:00
Paolo Barbolini
65229f7ff9
Replace some futures_util APIs with std variants (#3721) 2025-02-01 16:01:56 -08:00
Jon Thacker
5b26369a59
Fix readme: uuid feature is gating for all repos (#3720)
The readme previously stated that the uuid feature is only for postres but it actually also gates the functionality in mysql and sqlite.
2025-01-31 15:22:47 -08:00
Tobias Bieniek
4d638c9e24
FromRow: Fix documentation order (#3712)
The `try_from` and `json` sections are "Field attributes" so they should probably be part of the corresponding section instead of subsections of "Manual implementation". `flatten` should be H4 instead of H3, since "Field attributes" is H3 and all other field attribute sections are H4 too.
2025-01-29 15:00:21 -08:00
James H.
97cada3e16
feat(postgres): add geometry box (#3711)
* feat: add geometry box

* test: cannot compare box arrays

* test: regular equals check for boxes

* test: try box array test
2025-01-29 14:59:50 -08:00
joeydewaal
d8af1fa33e
chore: add pg_copy regression tests (#3715) 2025-01-29 14:56:46 -08:00
Sean Aye
2aab4cd237
Add json(nullable) macro attribute (#3677)
* add json optional attribute parser and expansion

* rename attribute

* add test

* fix tests

* fix lints

* Add docs
2025-01-28 10:56:33 -08:00
joeydewaal
546ec960a9
feat(Sqlite): add LockedSqliteHandle::last_error (#3707) 2025-01-27 20:56:21 -08:00
Nicolas Séverin
6ca52fe80c
Added missing special casing for encoding embedded arrays of custom types (#3603)
* Added missing special casing for encoding arrays of custom types

* Added the matching test

* Formatting
2025-01-27 17:30:02 -08:00