MCPcopy Index your code
hub / github.com/dbcli/mycli / connect

Method connect

mycli/client_connection.py:45–289  ·  view source on GitHub ↗
(
        self,
        database: str | None = "",
        user: str | None = "",
        passwd: str | int | None = None,
        host: str | None = "",
        port: str | int | None = "",
        socket: str | None = "",
        character_set: str | None = "",
        local_infile: bool | None = False,
        ssl: dict[str, Any] | None = None,
        init_command: str | None = "",
        unbuffered: bool | None = None,
        use_keyring: bool | None = None,
        reset_keyring: bool | None = None,
        keepalive_ticks: int | None = None,
    )

Source from the content-addressed store, hash-verified

43 def echo(self, *args: Any, **kwargs: Any) -> None: ...
44
45 def connect(
46 self,
47 database: str | None = "",
48 user: str | None = "",
49 passwd: str | int | None = None,
50 host: str | None = "",
51 port: str | int | None = "",
52 socket: str | None = "",
53 character_set: str | None = "",
54 local_infile: bool | None = False,
55 ssl: dict[str, Any] | None = None,
56 init_command: str | None = "",
57 unbuffered: bool | None = None,
58 use_keyring: bool | None = None,
59 reset_keyring: bool | None = None,
60 keepalive_ticks: int | None = None,
61 ) -> None:
62 mylogin_cnf: dict[str, Any] = self.read_mylogin_cnf(self.mylogin_cnf)
63 # Fall back to .mylogin.cnf values only if user did not specify a value.
64 user = user or mylogin_cnf["user"] or os.getenv("USER")
65 host = host or mylogin_cnf["host"]
66 port = port or mylogin_cnf["port"]
67 ssl_config: dict[str, Any] = ssl or {}
68 user_connection_config = self.config_without_package_defaults.get('connection', {})
69 self.keepalive_ticks = keepalive_ticks
70
71 int_port = port and int(port)
72 if not int_port:
73 int_port = DEFAULT_PORT
74 if not host or host == DEFAULT_HOST:
75 socket = socket or user_connection_config.get("default_socket") or mylogin_cnf["socket"] or guess_socket_location()
76
77 passwd = passwd if isinstance(passwd, (str, int)) else mylogin_cnf["password"]
78
79 if not character_set:
80 if 'main' in self.config_without_package_defaults and 'default_character_set' in self.config_without_package_defaults['main']:
81 # migration with notice added with mycli 2.0.0 in 2026-07
82 # todo: entirely remove support for default_character_set in [main]
83 click.secho(
84 'Mycli 2.0 migration: automatically moving default_character_set from [main] to [connection] in ~/.myclirc .',
85 err=True,
86 fg='red',
87 )
88 character_set = self.config_without_package_defaults['main']['default_character_set']
89
90 self.config_without_package_defaults.encoding = 'utf-8'
91 if 'connection' not in self.config_without_package_defaults:
92 self.config_without_package_defaults['connection'] = {}
93 if self.config_without_package_defaults['connection'].get('default_character_set', None) in (None, ''):
94 self.config_without_package_defaults['connection']['default_character_set'] = character_set
95 else:
96 character_set = self.config_without_package_defaults["connection"].get("default_character_set")
97 click.secho(
98 f'But connection.default_character_set already existed, with the value: "{character_set}".',
99 err=True,
100 fg='red',
101 )
102 del self.config_without_package_defaults['main']['default_character_set']

Callers 1

reconnectMethod · 0.45

Calls 10

read_mylogin_cnfMethod · 0.95
echoMethod · 0.95
guess_socket_locationFunction · 0.90
str_to_boolFunction · 0.90
exitMethod · 0.80
getMethod · 0.45
writeMethod · 0.45
promptMethod · 0.45
debugMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected