Improve distinguishing between DSNs and databases - #2082
Merged
Conversation
rolandwalker
force-pushed
the
RW/positional-and-explicit-dsn-vs-database
branch
3 times, most recently
from
August 1, 2026 12:40
8102b1a to
6d6b53a
Compare
We accept DSNs, both as literals and as aliases, as arguments to
--database, as well as to --dsn. This might have been a mistake. The
code is complex to support all cases, including the positional case,
with selective overrides.
In short, while there are many edge cases, the user must be able to run
mycli --database alias
for backward compatibility with this feature. However, the user should
also be able to override the database when connecting to a DSN, so
mycli alias --database overridden
should also be accepted.
However, note that the existing heuristic is that in the case of
combination with flags which specify the coordinates of the server
mycli alias --user username
we make a different assumption: "alias" must refer to a database name,
not a DSN. That heuristic may not be ideal, but is left in place for
backward compatibility. We might consider changing it. The heuristic
might require instead that _all_ relevant coordinates be specified,
instead of just one.
We also clarify here the CLI argument names dbname and database
internally, to database (corresponding to the option name) and
positional_database (since this is the positional value).
Finally, when an explicit --dsn is used, the user definitely wants a
DSN, not a database name.
Incidentally, remove an outdated comment.
rolandwalker
force-pushed
the
RW/positional-and-explicit-dsn-vs-database
branch
from
August 1, 2026 12:43
6d6b53a to
cd0c0f3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
We accept DSNs, both as literals and as aliases, as arguments to
--database, as well as to--dsn. This might have been a mistake. The code is complex to support all cases, including the positional case, with selective overrides.In short, while there are many edge cases, the user must be able to run
mycli --database aliasfor backward compatibility with this feature. However, the user should also be able to override the database when connecting to a DSN, so
mycli alias --database overriddenshould also be accepted.
However, note that the existing heuristic is that in the case of combination with flags which specify the coordinates of the server
mycli alias --user usernamewe make a different assumption:
aliasmust refer to a database name, not a DSN. That heuristic may not be ideal, but is left in place for backward compatibility. We might consider changing it. The heuristic might require instead that all relevant coordinates be specified, instead of just one.We also clarify here the CLI argument names
dbnameanddatabaseinternally, todatabase(corresponding to the option name) andpositional_database(since this is the positional value).Finally, when an explicit
--dsnis used, the user definitely wants a DSN, not a database name.Incidentally, remove an outdated comment.
Checklist
changelog.mdfile.AUTHORSfile (or it's already there).