server: fix remaining broken mysql queries
All checks were successful
All checks were successful
This commit is contained in:
@@ -52,7 +52,7 @@ pub async fn complete_database_name(
|
|||||||
) -> CompleteDatabaseNameResponse {
|
) -> CompleteDatabaseNameResponse {
|
||||||
let result = sqlx::query(
|
let result = sqlx::query(
|
||||||
r#"
|
r#"
|
||||||
SELECT `SCHEMA_NAME` AS `database`
|
SELECT CAST(`SCHEMA_NAME` AS CHAR(64)) AS `database`
|
||||||
FROM `information_schema`.`SCHEMATA`
|
FROM `information_schema`.`SCHEMATA`
|
||||||
WHERE `SCHEMA_NAME` NOT IN ('information_schema', 'performance_schema', 'mysql', 'sys')
|
WHERE `SCHEMA_NAME` NOT IN ('information_schema', 'performance_schema', 'mysql', 'sys')
|
||||||
AND `SCHEMA_NAME` REGEXP ?
|
AND `SCHEMA_NAME` REGEXP ?
|
||||||
@@ -244,7 +244,7 @@ pub async fn list_databases(
|
|||||||
|
|
||||||
let result = sqlx::query_as::<_, DatabaseRow>(
|
let result = sqlx::query_as::<_, DatabaseRow>(
|
||||||
r#"
|
r#"
|
||||||
SELECT `SCHEMA_NAME` AS `database`
|
SELECT CAST(`SCHEMA_NAME` AS CHAR(64)) AS `database`
|
||||||
FROM `information_schema`.`SCHEMATA`
|
FROM `information_schema`.`SCHEMATA`
|
||||||
WHERE `SCHEMA_NAME` = ?
|
WHERE `SCHEMA_NAME` = ?
|
||||||
"#,
|
"#,
|
||||||
@@ -276,7 +276,7 @@ pub async fn list_all_databases_for_user(
|
|||||||
) -> ListAllDatabasesResponse {
|
) -> ListAllDatabasesResponse {
|
||||||
let result = sqlx::query_as::<_, DatabaseRow>(
|
let result = sqlx::query_as::<_, DatabaseRow>(
|
||||||
r#"
|
r#"
|
||||||
SELECT `SCHEMA_NAME` AS `database`
|
SELECT CAST(`SCHEMA_NAME` AS CHAR(64)) AS `database`
|
||||||
FROM `information_schema`.`SCHEMATA`
|
FROM `information_schema`.`SCHEMATA`
|
||||||
WHERE `SCHEMA_NAME` NOT IN ('information_schema', 'performance_schema', 'mysql', 'sys')
|
WHERE `SCHEMA_NAME` NOT IN ('information_schema', 'performance_schema', 'mysql', 'sys')
|
||||||
AND `SCHEMA_NAME` REGEXP ?
|
AND `SCHEMA_NAME` REGEXP ?
|
||||||
|
|||||||
@@ -184,29 +184,34 @@ pub async fn get_databases_privilege_data(
|
|||||||
results
|
results
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// TODO: make this constant
|
||||||
|
fn get_all_db_privs_query() -> String {
|
||||||
|
format!(
|
||||||
|
indoc! {r#"
|
||||||
|
SELECT {} FROM `db` WHERE `db` IN
|
||||||
|
(SELECT DISTINCT CAST(`SCHEMA_NAME` AS CHAR(64)) AS `database`
|
||||||
|
FROM `information_schema`.`SCHEMATA`
|
||||||
|
WHERE `SCHEMA_NAME` NOT IN ('information_schema', 'performance_schema', 'mysql', 'sys')
|
||||||
|
AND `SCHEMA_NAME` REGEXP ?)
|
||||||
|
"#},
|
||||||
|
DATABASE_PRIVILEGE_FIELDS
|
||||||
|
.iter()
|
||||||
|
.map(|field| quote_identifier(field))
|
||||||
|
.join(","),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/// Get all database + user + privileges pairs that are owned by the current user.
|
/// Get all database + user + privileges pairs that are owned by the current user.
|
||||||
pub async fn get_all_database_privileges(
|
pub async fn get_all_database_privileges(
|
||||||
unix_user: &UnixUser,
|
unix_user: &UnixUser,
|
||||||
connection: &mut MySqlConnection,
|
connection: &mut MySqlConnection,
|
||||||
_db_is_mariadb: bool,
|
_db_is_mariadb: bool,
|
||||||
) -> ListAllPrivilegesResponse {
|
) -> ListAllPrivilegesResponse {
|
||||||
let result = sqlx::query_as::<_, DatabasePrivilegeRow>(&format!(
|
let result = sqlx::query_as::<_, DatabasePrivilegeRow>(&get_all_db_privs_query())
|
||||||
indoc! {r#"
|
.bind(create_user_group_matching_regex(unix_user))
|
||||||
SELECT {} FROM `db` WHERE `db` IN
|
.fetch_all(connection)
|
||||||
(SELECT DISTINCT `SCHEMA_NAME` AS `database`
|
.await
|
||||||
FROM `information_schema`.`SCHEMATA`
|
.map_err(|e| GetAllDatabasesPrivilegeDataError::MySqlError(e.to_string()));
|
||||||
WHERE `SCHEMA_NAME` NOT IN ('information_schema', 'performance_schema', 'mysql', 'sys')
|
|
||||||
AND `SCHEMA_NAME` REGEXP ?)
|
|
||||||
"#},
|
|
||||||
DATABASE_PRIVILEGE_FIELDS
|
|
||||||
.iter()
|
|
||||||
.map(|field| quote_identifier(field))
|
|
||||||
.join(","),
|
|
||||||
))
|
|
||||||
.bind(create_user_group_matching_regex(unix_user))
|
|
||||||
.fetch_all(connection)
|
|
||||||
.await
|
|
||||||
.map_err(|e| GetAllDatabasesPrivilegeDataError::MySqlError(e.to_string()));
|
|
||||||
|
|
||||||
if let Err(e) = &result {
|
if let Err(e) = &result {
|
||||||
tracing::error!("Failed to get all database privileges: {:?}", e);
|
tracing::error!("Failed to get all database privileges: {:?}", e);
|
||||||
@@ -215,6 +220,7 @@ pub async fn get_all_database_privileges(
|
|||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: make these queries constant strings.
|
||||||
async fn unsafe_apply_privilege_diff(
|
async fn unsafe_apply_privilege_diff(
|
||||||
database_privilege_diff: &DatabasePrivilegesDiff,
|
database_privilege_diff: &DatabasePrivilegesDiff,
|
||||||
connection: &mut MySqlConnection,
|
connection: &mut MySqlConnection,
|
||||||
|
|||||||
Reference in New Issue
Block a user