Skip to content
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

Test query database compatibility #8

Merged
merged 1 commit into from
Mar 4, 2020

Conversation

jor-rit
Copy link
Contributor

@jor-rit jor-rit commented Mar 4, 2020

Use 'SELECT 1', it's the more compatible. This works on most commonly
used databases, like postgreSQL, mysql, mariadb, mssql (and probably
others). But does not work on, for example, oracle (and probably
others).

This is a, minimal impact, 'quick fix', better solution would be to go
through Django's database backend 'is_usable' method.

Fixes issue #3

Use 'SELECT 1', it's the more compatible. This works on most commonly
used databases, like postgreSQL, mysql, mariadb, mssql (and probably
others). But does _not_ work on, for example, oracle (and probably
others).

This is a, minimal impact, 'quick fix', better solution would be to go
through Django's database backend 'is_usable' method.

Fixes issue painless-software#3
@jor-rit
Copy link
Contributor Author

jor-rit commented Mar 4, 2020

Going through the Django database backend API would solve it for all databases, but a bit more work.
Maybe if I find some time, i'll follow up with and alternative pull request that does that.

@bittner
Copy link
Member

bittner commented Mar 4, 2020

Did you take a look at @dismine's suggestion, a list of compatible ping queries on StackOverflow?

@jor-rit
Copy link
Contributor Author

jor-rit commented Mar 4, 2020

yeah, read that issue. Though instead of detecting the database type and using some hardcoded list, I would prefer just going through Django's own database abstraction. Each backend has a .is_usable method, which kinda does this (it would do a SELECT 1 on postgreSQL, on mysql a native connection ping method and probably something else on oracle).

But that's not a one-liner fix :) Bit of extra work to, think you also need manually do the connect before that, requiring some extra exception handling, testing etc... so like I said, if I find some spare time, i'll do a follow up pull for that

@bittner
Copy link
Member

bittner commented Mar 4, 2020

True. Also, SELECT 1 is not totally bad as a quick fix. According to the list, it covers the most popular backends supported by Django, with the only exception of the lawyer's database engine (Oracle).

Would you mind opening a separate issue on fixing things "the professional way" after I get this PR merged? That would help to track the issue properly.

@bittner bittner merged commit 7bccfb7 into painless-software:master Mar 4, 2020
@bittner
Copy link
Member

bittner commented Mar 9, 2020

Thanks for opening the follow-up ticket! 🥇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants