[MySQL] Allow not specifying database on initial connect

This commit is contained in:
Ryan Leckey 2019-12-30 01:31:01 -08:00
parent 1d2240848b
commit 27759a12c7
2 changed files with 12 additions and 9 deletions

View File

@ -152,10 +152,12 @@ impl MySqlConnection {
let handshake_packet = self_.receive().await?;
let handshake = Handshake::decode(handshake_packet)?;
let client_capabilities = Capabilities::PROTOCOL_41
| Capabilities::IGNORE_SPACE
| Capabilities::FOUND_ROWS
| Capabilities::CONNECT_WITH_DB;
let mut client_capabilities =
Capabilities::PROTOCOL_41 | Capabilities::IGNORE_SPACE | Capabilities::FOUND_ROWS;
if url.database().is_some() {
client_capabilities |= Capabilities::CONNECT_WITH_DB;
}
// Fails if [Capabilities::PROTOCOL_41] is not in [server_capabilities]
self_.capabilities =
@ -167,8 +169,7 @@ impl MySqlConnection {
client_collation: 192, // utf8_unicode_ci
max_packet_size: 1024,
username: url.username().unwrap_or("root"),
// TODO: Remove the panic!
database: url.database().expect("required database"),
database: url.database(),
auth_plugin_name: handshake.auth_plugin_name.as_deref(),
auth_response: None,
});

View File

@ -11,7 +11,7 @@ pub struct HandshakeResponse<'a> {
pub max_packet_size: u32,
pub client_collation: u8,
pub username: &'a str,
pub database: &'a str,
pub database: Option<&'a str>,
pub auth_plugin_name: Option<&'a str>,
pub auth_response: Option<&'a str>,
}
@ -55,8 +55,10 @@ impl Encode for HandshakeResponse<'_> {
}
if capabilities.contains(Capabilities::CONNECT_WITH_DB) {
if let Some(database) = self.database {
// database : string<NUL>
buf.put_str_nul(self.database);
buf.put_str_nul(database);
}
}
if capabilities.contains(Capabilities::PLUGIN_AUTH) {