-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Opening "sqlite::memory:" is broken for SqlitePool #362
Comments
@mehcode I think we need |
On master we now have All @therocode I do have a question what you're doing with a pool around |
@mehcode oh I was not aware that each connection will be a different database... I'm using pool becuase that's what I want my application to use when being run for real with a database file, but for manual testing and automatic tests, I use |
@therocode It's unfortunately a SQLite limitation. One connection with Here is a work-around if this is just for tests. This will create a pool that will only ever produce the same SQLite connection (and thus the same data). SqlitePool::builder()
.max_size(1)
.idle_timeout(None)
.max_lifetime(None)
.build("sqlite://") |
This is fixed on master |
With sqlx 0.3.5 It is not possible to do
sqlx::SqlitePool::new("sqlite::memory:")
The connection seems like it works, but when using queries with this pool, sqlx panics with "Error: bad parameter or other API misuse".
I have drilled down the issue to the hack in url.rs line 82 in sqlx_core. That is the following snippet:
This turns "sqlite::memory:" into "memory:" which is not a valid sqlite file to open. This path is not hit at all when using a direct connection instead of a pool, so that's why this error doesn't show up on the tests since they don't use pools.
I can fix it locally by doing
afterwards but that's an as ugly of a hack and I'm not happy to make a PR out of that. I feel there's a better fix but I am not knowledgable enough to know what it would be.
Note that you cannot workaround this by opening just ":memory:" instead of "sqlite::memory:" since the URL parser will panic saying that it's a relative URL with no base
The following application reproduces the error:
The text was updated successfully, but these errors were encountered: