Commit graph

100 commits

Author SHA1 Message Date
joeydewaal
1d8eb2add4
Fix (#3395) sqlx::test macro in 0.8 (#3403)
* fix: fixture macro attribute

* remove extra new line

* add extra new line

* feat: add test for slqx::test macro

* feat: update test for sqlx::test macro

* remove old macro test

* feat: add postgres and sqlite test

* rust format

* cargo fmt

* fix fixtures execution order in test
2024-08-26 14:03:22 -07:00
Austin Bonander
791433afbb chore(sqlite): create regression test for RUSTSEC-2024-0363 2024-08-23 23:39:32 -07:00
Frank Elsinga
cc481827d9
fixed deprecation warnings (#3384) 2024-07-27 18:04:20 -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
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
34860b7f99 fix(ci): just cfg-out the whole tests/sqlite/sqlcipher.rs 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
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
Austin Bonander
9fc9e7518e
feat: Text adapter (#2894) 2023-11-22 17:06:47 -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
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
Luiz Carvalho
3662bdab84
fix(sqlite): encode bool as integer (#2620) 2023-07-14 16:27:53 -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
Nisheeth Barthwal
4f1ac1d606
add progress handler support to sqlite (#2256)
* rebase main

* fmt

* use NonNull to fix UB

* apply code suggestions

* add test for multiple handler drops

* remove nightly features for test
2023-03-24 14:27:16 -07:00
Alexander Lyon
bd3eb94737 fix(#2407): respect the HaltIfNull opcode when determining nullability 2023-03-20 14:12:20 -07:00
Austin Bonander
eade49cfb0
0.7.0-alpha.1 release 2023-02-21 14:56:54 -08:00
Thibs
c4130d45e3 Add client SSL authentication using key-file for Postgres, MySQL and MariaDB (#1850)
* use native-tls API

* Add client cert and key to MySQL connector

* Add client ssl tests for PostgreSQL

* Add client ssl tests for MariaDB and MySQL

* Adapt GA tests

* Fix RUSTFLAGS to run all tests

* Remove containers to free the DB port before running SSL auth tests

* Fix CI bad naming

* Use docker-compose down to remove also the network

* Fix main rebase

* Stop trying to stop service using docker-compose, simply use docker cmd

* Fix RUSTFLAGS for Postgres

* Name the Docker images for MariaDB and MySQL so we can stop them using their name

* Add the exception for mysql 5.7 not supporting compatible TLS version with RusTLS

* Rebase fixes

* Set correctly tls struct (fix merge)

* Handle Elliptic Curve variant for private key

* Fix tests suite

* Fix features in CI

* Add tests for Postgres 15 + rebase

* Python tests: fix exception for MySQL 5.7 + remove unneeded for loops

* CI: run SSL tests only when building with TLS support

---------

Co-authored-by: Barry Simons <linuxuser586@gmail.com>
2023-02-21 13:25:25 -08:00
Luiz Carvalho
c09532864d feat: better database errors (#2109)
* feat(core): create error kind enum

* feat(core): add error kind for postgres

* feat(core): add error kind for sqlite

* feat(core): add error kind for mysql

* test(postgres): add error tests

* test(sqlite): add error tests

* test(mysql): add error tests

* fix(tests): fix tests rebasing

* refac(errors): add `ErrorKind::Other` variant
2023-02-21 13:25:25 -08:00
tyrelr
5378dea6af Sqlite describe fixes (#2253)
* add failing test for nested orderby

* log query paths which were abandoned due to invalid state or looping.  Allow instructions to be executed a small number of times to fix nested order by query

* add failing testcase using nested orderby

* fix handling of sequence/offset and rewind

* fix handling when sqlite nests records inside of records

* add test of temporary table handling

* WIP add test failure for temp table access

* fix support for temp tables

* add tests for sqlite datetime functions

* add basic date and time function support

* handle gosub opcode correctly

* add group by test

* fix group by handling

* add additional passing group by test

* add test case for simple limit query

* fix IfPos & If touching wrong branches state, fix IfPos using wrong branch criteria

* add test for large offsets

* add short-circuit for possible query offset loops

* add groupby query that is predicted incorrectly

* fix handling of integer cast failures

* add tests for single-row aggregate results

* fix handling of null-based branching

* add test for coercion of text by sum

* fix calculation of sum value coercion

* add failing test for recursive with query

* add logic for delete operation to fix queries grouping by columns from a recursive query
2023-02-21 13:25:25 -08:00
Austin Bonander
b5312c3b6f Break drivers out into separate crates, clean up some technical debt (#2039)
* WIP rt refactors

* refactor: break drivers out into separate crates

also cleans up significant technical debt
2023-02-21 13:25:25 -08:00
tyrelr
d5b8c66e24 Fix sqlite update return and order by type inference (#1960)
* add failing test cases for update/delete return into

* fix regression in null tracking by improving tracking of cursor empty/full state

* add failing test case for order by column types

* Add support for SorterOpen,SorterInsert,SorterData

* add failing test case for unions

* fix range copy/move implementation

* fix wrong copy/move range

* remove calls to dbg!
2023-02-21 13:25:25 -08:00
Marco Neumann
5e56da87e0
fix: ensure migration progress is not lost for PG, mysql and sqlite (#1991)
* fix: ensure migration progress is not lost for PG

Fixes #1966.

* fix: ensure migration progress is not lost for sqlite

This is similar to #1966.

* fix: ensure reverse migration progress is not lost for PG

See #1966.

* fix: ensure reverse migration progress is not lost for sqlite

See #1966.

* fix: ensure migration progress is not lost for mysql

This is similar to #1966.

* fix: ensure reverse migration progress is not lost for mysql

See #1966.

* test: check migration type as well

* test: extend migrations testing

* fix: work around MySQL implicit commits

* refactor: simplify migration testing
2022-09-12 17:52:04 -07:00
Richard Bradfield
20877d83fd
Add extension support for SQLite (#2062)
* Add extension support for SQLite

While SQLite supports loading extensions at run-time via either the C
API or the SQL interface, they strongly recommend [1] only enabling the C
API so that SQL injections don't allow attackers to run arbitrary
extension code.

Here we take the most conservative approach, we enable only the C
function, and then only when the user requests extensions be loaded in
their `SqliteConnectOptions`, and disable it again once we're done
loading those requested modules. We don't add any support for loading
extensions via environment variables or connection strings.

Extensions in the options are stored as an IndexMap as the load order
can have side effects, they will be loaded in the order they are
supplied by the caller.

Extensions with custom entry points are supported, but a default API
is exposed as most users will interact with extensions using the
defaults.

[1]: https://sqlite.org/c3ref/enable_load_extension.html

* Add extension testing for SQlite

Extends x.py to download an appropriate shared object file for supported
operating systems, and uses wget to fetch one into the GitHub Actions
context for use by CI.

Overriding LD_LIBRARY_PATH for only this specific DB minimises the
impact on the rest of the suite.
2022-09-01 15:03:27 -07:00
szymek156
c931cab95f
Szymek156/issue2009 (#2014)
* SQLite: Execute SQLCipher pragmas as very first operations on the database

SQLCipher requires, apart from 'key' pragma also other cipher-related
to be executed before read/write to the database.

* Added tests for SQLCipher functionality

* remove default-features from libsqlite3-sys when building from dev-dependencies

Co-authored-by: Szymon Zimnowoda <szimnowoda.memri@gmail.com>
2022-08-05 12:20:14 -07:00
Austin Bonander
054f61980a
feat: implement testing utilities (#2001) 2022-08-02 14:38:12 -07:00
Austin Bonander
a2eceec33b
chore: replace dotenv with dotenvy (#2003)
* chore: replace `dotenv` with `dotenvy`

The former appears to be unmaintained and the latter is a drop-in replacement.

* chore: fix all warnings
2022-07-28 14:33:44 -07:00
Austin Bonander
bc3e70545b
sqlite improvements (#1965)
* use direct blocking calls for SQLite in `sqlx_macros`
    * this also ensures the database is closed properly, cleaning up tempfiles
* don't send `PRAGMA journal_mode` unless set
    * this previously defaulted to WAL mode which is a permanent setting
      on databases which doesn't necessarily apply to all use-cases
    * changing into or out of WAL mode acquires an exclusive lock on the database
      that can't be waited on by `sqlite3_busy_timeout()`
    * for consistency, `sqlx-cli` commands that create databases will still
      create SQLite databases in WAL mode; added a flag to disable this.
* in general, don't send `PRAGMA`s unless different than default
    * we were sending a bunch of `PRAGMA`s with their default values just to enforce
      an execution order on them, but we can also do this by inserting empty slots
      for their keys into the `IndexMap`
* add error code to `SqliteError` printout
* document why `u64` is not supported
2022-07-12 13:59:37 -07:00
John B Codes
cfef70a796
Add Sqlite support for the time crate (#1865)
* feat(sqlite): Add 'time' crate support for date/time types
docs(sqlite): Update types module docs for JSON and Chrono
docs(mysql): Update types module docs for JSON

* More efficient time crate decoding with FormatItem::First and hand-crafting of format descriptions

* Replace temporary testing code with original intention

* Replace duplicated formatting test with intended test

* Performance improvements to decoding OffsetDateTime, PrimitiveDateTime, and Time

* Use correct iteration for OffsetDateTime

* Reduce visibility of format constants

Co-authored-by: John B Codes <johnbcodes@users.noreply.github.com>
2022-07-08 16:51:50 -07:00
Kian-Meng Ang
d52f301a94
Fix typos (#1894)
* Fix typos

* Update CHANGELOG.md

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

Co-authored-by: Austin Bonander <austin.bonander@gmail.com>
2022-06-08 14:56:56 -07:00
tyrelr
ed56622526
Improve Sqlite support for sub-queries and CTE's (#1816)
* reproduce incorrect nullability for materialized views

* split ephemeral/index-only table handling from real table handling

* add test for literal null, expect nullability to be identified from table information

* gather interpreter state into a struct, no change in behaviour

* prevent infinite loops that could arise once branching is supported

* track nullability alongside the datatype instead of in a separate lookup

* implement basic comprehension of branching opcodes

* fix datatype calculation of aggregates which are never 'stepped' through

* implement coroutine and return operations, including tracking of 'actual' integer value stored in the register by Integer/InitCoroutine/Yield operations.

* strip unnecessary history field out

* Modify variable test to expect bind-variable outputs to be nullable, rather than unknown

* add partially commented-out union tests, simplify code to satisfy simplest union case

* fix unit test incorrectly expecting primary keys to be implicitly not-null

* add failing test for recursive tables

* add logging of query explain plan

* track explain plan execution history

* broken RowData implementation (doesn't alias)

* Implement OpenPseudo tables as an alias of a register value

* fix comment

* clean up logging code warnings

* use cfg to omit QueryPlanLogger unless sqlite feature is used
2022-06-07 14:24:08 -07:00
Paolo Barbolini
ec15f6b30c
Update uuid crate to v1 (#1821) 2022-04-20 12:48:29 -07:00
05storm26
f328cc15d8
Sqlite chrono::DateTime<FixedOffset> timezone fix (#1618) 2022-04-14 15:06:55 -07:00
tyrelr
217dc55062
Fix #1249 Left joins in SQLite can break the query macros (#1789)
* Reproduce github issue#1249: Left joins in sqlite can break the query macros

* Fix panic caused by unknown cursor columns when executing NullRow command. Fixes #1249
2022-04-07 13:18:37 -07:00
Adam Cigánek
347374b94b
SQLite unlock notification (#1658)
* sqlite: add test for concurrent table access (failing)

* sqlite: implement unlock notification
2022-02-15 20:10:36 -08:00
Austin Bonander
fdbfc5dfc3
Prepare 0.5.10 release (#1603)
* fix(cli): change new `rustls` and `native-tls` features to use correct runtime feature

* chore: upgrade SQLx crates to 0.5.10, upgrade all dependencies to latest versions

chore(cli): upgraded `clap` to `3.0.0-rc.9`

* fix(tests/sqlite): ignore `issue_1467()` as spuriously failing

I'm well aware of the principle that a spuriously failing test is a failing test, but even though I have it outputting the seed used with a reproducible PRNG, I can't reproduce the failures locally, so 🤷.

* chore: add CHANGELOG entry for 0.5.10
2021-12-29 17:25:49 -08:00
Austin Bonander
63ca2ccc6c
refactor(sqlite): make background thread responsible for all FFI calls (#1551) 2021-12-29 15:23:02 -08:00
Austin Bonander
1b5dd6514b
preparing 0.5.8 release (#1466)
* preparing 0.5.8 release

* fix warnings before release
2021-10-01 14:45:25 -07:00
Andrew Whitehead
ba3e373b7e
Shut down statement worker in Sqlite Connection::close (#1453)
* add explicit shutdown of sqlite statement worker in Connection::close()

Signed-off-by: Andrew Whitehead <cywolf@gmail.com>

* test sqlite database close method

Signed-off-by: Andrew Whitehead <cywolf@gmail.com>

* await worker shutdown after dropping SqliteConnection

Signed-off-by: Andrew Whitehead <cywolf@gmail.com>

* restore explicit drop

Signed-off-by: Andrew Whitehead <cywolf@gmail.com>
2021-09-30 18:14:30 -07:00
Austin Bonander
8b30f3059b
Fix a panic in the worker thread when dropping the connection while SqliteRows still exist (#1450)
* chore(sqlite): add repro for #1419

* fix(sqlite): hold a reference to the connection in `SqliteRow`

fixes #1419
2021-09-22 16:55:22 -07:00
Montana Low
ec510b37e7
Finish support for Postgres COPY (#1345)
* feat(postgres): WIP implement `COPY FROM/TO STDIN`

Signed-off-by: Austin Bonander <austin@launchbadge.com>

* feat(postgres): WIP implement `COPY FROM/TO STDIN`

Signed-off-by: Austin Bonander <austin@launchbadge.com>

* test and complete support for postgres copy

Co-authored-by: Austin Bonander <austin@launchbadge.com>
2021-09-13 13:03:38 -07:00
Austin Bonander
71388a7ef2
sqlite: fix a couple segfaults (#1351)
* sqlite: use Arc instead of Copy-able StatementHandle

This guarantees that StatementHandle is never used after calling
`sqlite3_finalize`. Now `sqlite3_finalize` is only called when
StatementHandle is dropped.

(cherry picked from commit 5eebc05dc3)

* sqlite: use Weak poiter to StatementHandle in the worker

Otherwise some tests fail to close connection.

(cherry picked from commit 5461eeeee3)

* Fix segfault due to race condition in sqlite (#1300)

(cherry picked from commit bb62cf767e)

* fix(sqlite): run `sqlite3_reset()` in `StatementWorker`

this avoids possible race conditions without using a mutex

* fix(sqlite): have `StatementWorker` keep a strong ref to `ConnectionHandle`

this should prevent the database handle from being finalized before all statement handles
have been finalized

* fix(sqlite/test): make `concurrent_resets_dont_segfault` runtime-agnostic

Co-authored-by: link2xt <link2xt@testrun.org>
Co-authored-by: Adam Cigánek <adam.ciganek@gmail.com>
2021-08-16 14:39:45 -07:00
Atkins
9f7205e80f
Fix GitHub Actions and integration test (#1346)
* fix test suite

* rustfmt

* need Row

* test: fix integration test scripts and update the upstream supported databases

Signed-off-by: Atkins Chang <atkinschang@gmail.com>

* ci(actions): update supported databases

Signed-off-by: Atkins Chang <atkinschang@gmail.com>

* ci(actions): use `pg_isready` instead of `sleep` to avoid error cause by database not ready

Signed-off-by: Atkins Chang <atkinschang@gmail.com>

* feat(core): add `trait PgConnectionInfo` for connection parameter status from server

Signed-off-by: Atkins Chang <atkinschang@gmail.com>

* test(postgres): fix integration test for postgres

Signed-off-by: Atkins Chang <atkinschang@gmail.com>

* test(mysql): fix integration tests

Signed-off-by: Atkins Chang <atkinschang@gmail.com>

* ci(actions): test database against the oldest and newest supported versions

Signed-off-by: Atkins Chang <atkinschang@gmail.com>

* docs(core): document `trait PgConnectionInfo`

Signed-off-by: Atkins Chang <atkinschang@gmail.com>

Co-authored-by: Montana Low <montanalow@gmail.com>
2021-07-28 14:00:34 -07:00
marshoepial
cb3ff28721
Keep track of column typing in SQLite EXPLAIN parsing (#1323)
* NewRowid, Column opcodes, better pointer handling

* Implement tracking of column typing on sqlite explain parser

* fmt for sqlite column typing for explain parsing

Co-authored-by: marshoepial <marshoepial@gmail.com>
2021-07-21 16:27:47 -07:00
link2xt
bd06836fba test(sqlite): extend it_caches_statements() test
Test that initial PRAGMA statements and &str statements are not
cached, but sqlx::query() statements are cached by default.
2021-04-15 18:26:06 -07:00
Alexander Krotov
78656eb469 fix(sqlite): reset the statement when fetch_many() stream is dropped
Unlike `Executor.fetch_optional()`, `Executor.fetch_many()` does not
have a single exit.  The stream can be dropped at any time.  To catch
this event, we create a `StatementResetter` structure inside the stream
loop and reset the statement when it is dropped.

A test case `it_resets_prepared_statement_after_fetch_many` is
similar to `it_resets_prepared_statement_after_fetch_one` which tests
`Executor.fetch_optional()`.
2021-04-09 00:23:17 -07:00
crajcan
469c4ac130
Correct Postgres' Length Limit for Bind Parameters (#1141)
* Bump limit for postgres' bind parameters

* Fix lingering fmt error
2021-03-29 19:39:27 -07:00
Ryan Leckey
b6e1275617
fix: derive(Type) should emit a forwarded impl for the compatible function 2021-03-18 16:12:00 -07:00