Skip to content

Commit

Permalink
fix: return err msg if use wrong database in MySQL (#1866)
Browse files Browse the repository at this point in the history
  • Loading branch information
shuiyisong authored Jul 3, 2023
1 parent 2c0c467 commit e1bb7ac
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/servers/src/mysql/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,16 @@ impl<W: AsyncWrite + Send + Sync + Unpin> AsyncMysqlShim<W> for MysqlInstanceShi

async fn on_init<'a>(&'a mut self, database: &'a str, w: InitWriter<'a, W>) -> Result<()> {
let (catalog, schema) = crate::parse_catalog_and_schema_from_client_database_name(database);
ensure!(
self.query_handler.is_valid_schema(catalog, schema).await?,
error::DatabaseNotFoundSnafu { catalog, schema }
);

if !self.query_handler.is_valid_schema(catalog, schema).await? {
return w
.error(
ErrorKind::ER_WRONG_DB_NAME,
format!("Unknown database '{}'", database).as_bytes(),
)
.await
.map_err(|e| e.into());
}

let user_info = &self.session.user_info();

Expand Down

0 comments on commit e1bb7ac

Please sign in to comment.