Commit graph

473 commits

Author SHA1 Message Date
Austin Bonander
791433afbb chore(sqlite): create regression test for RUSTSEC-2024-0363 2024-08-23 23:39:32 -07:00
Austin Bonander
b1539b60a1 chore(postgres): create regression test for RUSTSEC-2024-0363 2024-08-23 23:39:32 -07:00
Austin Bonander
823261aefc fix(mysql): don't use an arbitrary cfg for one test 2024-08-23 23:39:32 -07:00
Frank Elsinga
cc481827d9
fixed deprecation warnings (#3384) 2024-07-27 18:04:20 -07:00
Austin Bonander
6651d2df72
Fix CI after Rust 1.80, remove dead feature references (#3381)
* fix(ci): update workflows/examples.yml

* Removed archived `actions-rs` actions
* Upgraded `Swatinem/rust-cache`, `actions/checkout`, `actions/download-artifact`, `actions/upload-artifact`

* chore: deprecate `AnyKind`

* fix: remove dead references to DB features in `sqlx-core`

This reactivates a couple of tests that had stopped working.

* chore(ci): move sqlx-cli checks to their own workflow

* fix(ci): remove remaining `uses: actions-rs/cargo`

* fix warnings

* chore: add titles to sqlx-cli jobs

* fix warnings (2)

* fix error in pool example

* fix warnings (3)

* fix query_builder test

* fix: don't run CLI tests on Windows

* chore: upgrade `rust-toolchain` to 1.80

* fix(postgres): fix missing Tokio specialization in `PgCopyIn`

Caught by the new `unexpected_cfgs` lint.

* fix new warnings
2024-07-26 23:15:32 -07:00
Yuta Kobayashi
f2fea27cba
Fix encoding and decoding of MySQL enums in sqlx::Type (#3371) 2024-07-25 02:47:36 -07:00
Austin Bonander
4fc5b30d65
breaking: fix name collision in FromRow, return Error::ColumnDecode for TryFrom errors (#3356)
* chore: create regression test for #3344

* fix(derives): use a parameter name that's less likely to collide

* breaking(derives): emit `Error::ColumnDecode` when a `TryFrom` conversion fails in `FromRow`

Breaking because `#[sqlx(default)]` on an individual field or the struct itself would have previously suppressed the error. This doesn't seem like good behavior as it could result in some potentially very difficult bugs.

Instead of using `TryFrom` for these fields, just implement `From` and apply the default explicitly.

* fix: run `cargo fmt`

* fix: use correct field in `ColumnDecode`
2024-07-19 23:03:47 -07:00
James H
0db12a9846
feat(cube): support postgres cube (#3188)
* feat: add cube

* docs: cube docs

* docs: update readme

* fix: cube is now not feature flagged

* fix: formatting

* fix: typeo for PgCube vs Cube

* fix: correct types

* fix: postgres only types for cube

* fix: cube readme

* fix: dont unwrap cubes

* fix: typo on interval

* fix: zero volume cube array

* fix: return type

* fix: update tests

* fix: run with one test type

* fix: log bytes in error

* fix: typo in test

* fix: log bytes for failed length

* fix: string deser

* docs: remove cube from readme

* fix: int to float

* fix: trim floats

* fix: exttra test

* fix: type safe into vectors

* fix: improve error messages

* docs: remove comments

* fix: front load most important logic and const at start

* fix: extract constants

* fix: flags

* fix: avoid redundant buffer creation and use FromStr trait

* fix: handle serializing

* test: cube vec test

* fix: no array cube test

* fix: update test with array for cube

* fix: dont use try from for u8

* fix: conditionally remove padding

* fix: conditional trimming

* fix: idiomatic trimming

* fix: linting

* fix: remove whitespace

* fix: lower case array

* fix: spacing input

* test: one more vec test

* fix: trim square brackets in case they are using postgres spec page

* fix: result types

* fix: format

* fix: box error

* fix: the borrow produces a value

* fix: self serialise

* chore: merge main

* fix: borrow

* fix: clippy

---------

Co-authored-by: James Holman <james.holman@betashares.com.au>
2024-07-11 22:30:49 -07:00
Austin Bonander
16e3f1025a fix(postgres): add missing type resolution for arrays by name 2024-07-08 00:14:19 -07:00
Austin Bonander
efbf57265c fix: use correct syntax in tests/postgres/setup.sql 2024-07-08 00:14:19 -07:00
Austin Bonander
32143363bc fix trailing line break 2024-06-15 11:57:33 -07:00
Austin Bonander
80359d1ada fix(postgres): derive PgHasArrayType for enums 2024-06-15 11:57:33 -07:00
Austin Bonander
10192019d8 fix(postgres): get correctly qualified type name in describe 2024-06-15 11:57:33 -07:00
Austin Bonander
3418455482 fix: ignore flaky copy_can_work_with_failed_transactions test 2024-06-13 13:11:36 -07:00
Austin Bonander
948264ff93 fix: ignore flaky test_connection_maintenance test 2024-06-13 13:11:36 -07:00
Austin Bonander
41089f3655 fix: add mariadb:11.4 to tests/docker-compose.yml 2024-06-13 13:11:36 -07:00
gridbox
0ea90881c1
feat: Add set_update_hook on SqliteConnection (#3260)
* feat: Add set_update_hook on SqliteConnection

* refactor: Address PR comments

* fix: Expose UpdateHookResult for public use

---------

Co-authored-by: John Smith <asserta4@gmail.com>
2024-06-05 19:06:15 -07:00
tyrelr
f960d5bc3b
Sqlite explain graph (#3064)
* convert logger to output a query graph

* avoid duplicating branch paths to shrink output graph

* separate different branching paths

* include all branches which found unique states

* track the reason for ending each branches execution

* track the result type of each branch

* make edges rely on history index instead of program_id, to avoid errors when looping

* add state diff to query graph

* drop redundant table info

* rework graph to show state changes, rework logger to store state snapshots

* show state on the previous operation

* gather duplicate state changes into clusters to reduce repetition

* draw invisible connections between unknown instructions by program_i

* clean up dot format string escaping

* add test case from #1960 (update returning all columns)

* add tests for #2939 (update returning only the PK column)

* allow inserting into a table using only the index

* improve null handling of IfNull, fix output type of NewRowId

* add NoResult nodes for branches which don't log a result, as a sanity check

* add short-circuit to all logging operations

* remove duplicate logging checks, and make logging enabled/disabled consistently depend on sqlx::explain instead of sqlx for capture & sqlx::explain for output

* add failing test for awkwardly nested/filtered count subquery

* handle special case of return operation to fix failing test

* require trace log level instead of using whatever log level  statement logging was configured to use
2024-05-31 12:57:54 -07:00
Max Bruckner
c57b46ceb6
Make Encode return a result (#3126)
* Make encode and encode_by_ref fallible

This only changes the trait for now and makes it compile, calling .expect() on all users. Those will be removed in a later commit.

* PgNumeric: Turn TryFrom Decimal to an infallible From

* Turn panics in Encode implementations into errors

* Add Encode error analogous to the Decode error

* Propagate decode errors through Arguments::add

This pushes the panics one level further to mostly bind calls. Those will also be removed later.

* Only check argument encoding at the end

* Use Result in Query internally

* Implement query_with functions in terms of _with_result

* Surface encode errors when executing a query.

* Remove remaining panics in AnyConnectionBackend implementations

* PostgreSQL BigDecimal: Return encode error immediately

* Arguments: Add len method to report how many arguments were added

* Query::bind: Report which argument failed to encode

* IsNull: Add is_null method

* MySqlArguments: Replace manual bitmap code with NullBitMap helper type

* Roll back buffer in MySqlArguments if encoding fails

* Roll back buffer in SqliteArguments if encoding fails

* Roll back PgArgumentBuffer if encoding fails
2024-05-31 12:42:36 -07:00
Feike Steenbergen
17d832b3de
PostgreSQL Bugfix: Ensure connection is usable after failed COPY inside a transaction (#3138)
* Include test case for regular subtransactions

While using COPY and subtransactions I kept running into errors.
This test case documents that error, it currently fails with:

    Error: encountered unexpected or invalid data: expecting ParseComplete but received CommandComplete

* PostgreSQL Copy: Consume ReadyForQuery on error

When a COPY statement was in error inside a subtransaction,
a Protocol Error used to be raised. By consuming the ReadyForQuery
message when there is an error, we no longer have this issue.
2024-04-19 15:45:05 -07:00
Jaime
40aef6da2c
feat: no tx migration (#3181)
* test: add a failing test

* feat: add no_tx to migration struct

* feat: execute migration with no tx block

* fix: expected string literal compilation error

* test: update no tx to content comment

* refactor: use the sql comment instead of file name semantics

* docs: remove no_tx from file format comment

* fix: remove filename matches

* fix: messed up merge

* refactor: dedupe migration

* fix: move comment to where it makes sense

* fix: linter error
2024-04-19 15:42:44 -07:00
Austin Bonander
25efb2f7f4
breaking(sqlite): always use i64 as intermediate when decoding (#3184)
Breaking changes:

* integer decoding will now loudly error on overflow instead of silently truncating.
* some usages of the query!() macros might change an i32 to an i64.

Also adds support for *decoding* `u64`s because there's no reason not to.

Closes #3179
2024-04-13 16:59:13 -07:00
Austin Bonander
7102a7a254
feat: add MySqlTime, audit mysql::types for panics (#3154)
Also clarifies the handling of `TIME` (we never realized it's used for both time-of-day and signed intervals) and adds appropriate impls for `std::time::Duration`, `time::Duration`, `chrono::TimeDelta`
2024-03-30 11:49:12 -07:00
Austin Bonander
0b91ea68e5
fix(tests): extend fresh-connection threshold
This assert is failing with durations _just_ over the line, suggesting a timing issue.
2024-03-22 15:50:54 -07:00
Austin Bonander
34860b7f99 fix(ci): just cfg-out the whole tests/sqlite/sqlcipher.rs 2024-03-05 18:33:56 -08:00
Austin Bonander
791a7f5417 doc(pg): document behavior of bigdecimal and rust_decimal with out-of-range values
also add a regression test
2024-03-05 18:33:56 -08:00
Austin Bonander
e5c18b354e fix: gate sqlcipher testing behind cfg to make development less annoying 2024-03-05 18:33:56 -08:00
Mirek Klimos
b4f6596b06
Improve max_lifetime handling (#3065)
* Check max lifetime in return_to_pool, not on acquire

* Improve checks in backgrand maintenance task

* add tests

* adjust test to fix
2024-03-04 16:39:59 -08:00
Austin Bonander
ca518b7185
feat: add raw_sql API (#3007)
This is meant to be much easier to discover than the current approach of directly invoking `Executor` methods.

In addition, I'm improving documentation for the `query*()` functions across the board.
2024-02-18 15:38:23 -08:00
iamjpotts
5890afe95b
chore(deps): Replace unmaintained tempdir crate with tempfile (#3006)
Signed-off-by: Joshua Potts <8704475+iamjpotts@users.noreply.github.com>
2024-01-22 20:16:06 -08:00
Lars Schumacher
29dcd44a6a
fix(mysql): Close prepared statement if persistence is disabled (#2905)
* close prepared statement if persistence or statement cache are disabled

* add tests
2024-01-20 18:20:04 -08:00
Thomas de Zeeuw
31e541ac7a
Fix handling of deferred constraints for PostgreSQL (#2913) 2024-01-20 02:36:06 -08:00
Austin Bonander
9fc9e7518e
feat: Text adapter (#2894) 2023-11-22 17:06:47 -08:00
Roberto Ripamonti
16eeea8611
Add fixtures_path in sqlx::test args (#2545)
* feat: add fixtures_path

* test: add test for fixtures_path

* docs: expand test docs with fixtures_path

* test: add new test instead of co-opting and old one.

* feat: add explicit path operating mode for fixtures parameters and allow combining multiple fixtures parameters

* fix: require .sql extension for explicit path fixtures

* feat: add custom relative path style to fixtures argument

* fix: missing cfg feature

* docs: update

* fix: explicit fixtures styling checks for paths. Remove strict sql extension requirement for explicit path, they still need an extension. Add .sql extension to implicit fixtures style only if missing.

* style: cargo fmt

* docs: update documentation
2023-11-15 16:08:24 -08:00
qwerty2501
00b077ab14
Is tests/x.py maintained? And I tried fix it. (#2754)
* chore:Added ipaddr extension library to gitignore

* fix:In a Linux environment, shared libraries in the current directory are not loaded, so add the current directory to the LD_LIBRARY_PATH environment variable.

* fix: Since confrict primary key when running multiple sqlite tests, removed specific primary key in insert.

* chore: Since avoid git modified targeting, copy the db file to new test db file.

* fix: Since docker mysql 5.7 using yaSSL(It only supports TLSv1.1), avoid running when using rustls.
2023-10-19 14:54:01 -07:00
Gregor Giesen
54c5d6bc3c
derive FromRow: sqlx(default) for all fields (#2801)
* derive FromRow: sqlx(default) for all fields

* error in test_struct_default fixed

* derive FromRow: struct level sqlx(default) requires and uses Default implementation

* Update sqlx-core/src/from_row.rs

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

* Update sqlx-core/src/from_row.rs

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

* satify cargo fmt

---------

Co-authored-by: Austin Bonander <austin.bonander@gmail.com>
2023-10-17 16:13:40 -07:00
Austin Bonander
58cb18a47a
fix: correct decoding of rust_decimal::Decimal for high-precision values (#2820)
also fixes handling of feature flags
2023-10-16 14:03:28 -07:00
hgranthorner
56945d7396
feat(citext): support postgres citext (#2478)
* feat(citext): implement citext for postgres

* feat(citext): add citext -> String conversion test

* feat(citext): fix ltree -> citree

* feat(citext): add citext to the setup.sql

* chore: address nits to #2478

* Rename `PgCitext` to `PgCiText`
* Document when use of `PgCiText` is warranted
* Document potentially surprising `PartialEq` behavior
* Test that the macros consider `CITEXT` to be compatible with `String` and friends

* doc: add `PgCiText` to `postgres::types` listing

* chore: restore missing trailing line break to `tests/postgres/setup.sql`

---------

Co-authored-by: Austin Bonander <austin@launchbadge.com>
2023-10-11 18:03:17 -07:00
tk2217
5ebe296ecb
feat(mysql): support packet splitting (#2665)
* Writing split packets

* Reading split packets

* Add tests for packet splitting

* Fix test for packet splitting
2023-10-11 13:59:06 -07:00
Yudai Fukushima
846dcfe52a
fix: decode postgres time without subsecond (#2784)
* fix: decode postgres time without subsecond

* update: decode postgres time without subsecond by making subsecond optional
2023-10-04 16:56:14 -07:00
kryptan
ca608a964e
Clarify where optional features should be enabled (#2706) 2023-09-21 17:49:51 -07:00
Daniel Black
a6a2af115e
Bump mariadb CI images + mysql unpin (#2739)
With MariaDB 10.3 EOL it seems prudent to include
the latest 10.11 LTS release in the CI tests.

To catch #1664 sort of issues prior to release, add
a container image test for mariadb that contains the
finished pre-release code changes (and container changes)
to ensure that compatibilty is maintianed. When
server code hits the branch associated with this tag
it is considered finished by its server developers and
has passes CI so no regressions are expected, but
it wouldn't hurt to have CI in other systems testing
it too.

Since MySQL has fixed the regression that caused #1664
this puts it back to their 8.0 release tag.

Append the :z tag to the docker compose volume mounts
so on selinux systems enough permissions occur for the
volume to be able to read the volume contents.
2023-09-11 19:19:28 -07:00
Austin Bonander
487b89a4b6
fix: ignore extra fields in Postgres describe parsing (#2670)
* fix(postgres): sqlx prepare fails if shared_preload_libraries=pg_stat_statements

closes #2622

refs:
* https://serde.rs/enum-representations.html#untagged
* https://serde.rs/field-attrs.html#skip
* https://www.postgresql.org/docs/current/pgstatstatements.html
  * https://www.postgresql.org/docs/current/runtime-config-statistics.html#GUC-COMPUTE-QUERY-ID

* fix(postgres): regression of #1449

```
error: error occurred while decoding column 0: data did not match any variant of untagged enum Explain at line 3 column 1
Error:    --> tests/postgres/macros.rs:103:15
    |
103 |     let row = sqlx::query!(r#"CALL forty_two(null)"#)
    |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: this error originates in the macro `$crate::sqlx_macros::expand_query` which comes from the expansion of the macro `sqlx::query` (in Nightly builds, run with -Z macro-backtrace for more info)

error: could not compile `sqlx` (test "postgres-macros") due to previous error
```

* refactor(postgres): don't define unused fields in QueryPlan

* refactor(postgres): simplify query plan handling, add unit test

* chore: document why we load `pg_stat_statements` in tests

---------

Co-authored-by: mrl5 <31549762+mrl5@users.noreply.github.com>
2023-07-31 14:52:55 -07:00
Yuri Astrakhan
a824e8468c
Cleanup format arguments (#2650)
Inlined format args make code more readable, and code more compact.

I ran this clippy command to fix most cases, and then cleaned up a few trailing commas and uncaught edge cases.

```
cargo clippy --bins --examples  --benches --tests --lib --workspace --fix -- -A clippy::all -W clippy::uninlined_format_args
```
2023-07-31 13:27:04 -07:00
Marco Cameriero
9463b7592f
Add JSON support to FromRow derive (#2121)
* Add `json` attribute to `FromRow` derive

* Add docs and fix formatting
2023-07-31 12:52:42 -07:00
Luiz Carvalho
3662bdab84
fix(sqlite): encode bool as integer (#2620) 2023-07-14 16:27:53 -07:00
Austin Bonander
1d1095e94f
feat: allow opt-out of PgHasArrayType with #[derive(sqlx::Type)] (#2619)
closes #2611
2023-07-14 16:16:18 -07:00
Tim Geoghegan
0c8fe729ff
Traverse symlinks when resolving migrations (#2445)
* Traverse symlinks when resolving migrations

When enumerating the source directory seeking migration files, `sqlx`
ignores entries that aren't files. This was previously reported as #614
and fixed in #985 but apparently regressed somewhere along the way. This
commit reintroduces the fix from #985 to the current implementation: use
`std::fs::metadata` instead of `std::fs::DirEntry::metadata`. The former
is documented to traverse symlinks; the latter does not.

* add migrations_symlink test
2023-06-13 11:21:09 -07:00
tyrelr
238a95b0f3
Sqlite analytical (#2508)
* Add failing tests

* remove unnecessary functions, clarify function names

* simplify access to cursor columns with helper methods

* split table info from cursor info so that cursors can share table info

* fix test expectations
2023-06-12 12:48:32 -07:00
Midas Lambrichts
cbf8dd37e9
Add Simple format for Uuid for MySQL & SQLite. (#2469)
* Add Simple format for Uuid for MySQL & SQLite.

Copy pasted the implementation for `Hyphenated` and adapt.

* Add uuid Simple docs for SQLite
2023-05-04 13:14:06 -07:00