Skip to content

Commit 99e3532

Browse files
danielnuldDaniel Noé Núñez Lópezdebba
authored
fix(mysql): route view DDL through text protocol (#390)
create_view, alter_view and drop_view executed their statements via sqlx::query(), which uses MySQL's prepared-statement protocol. MySQL rejects CREATE VIEW / ALTER VIEW there with error 1295 ("This command is not supported in the prepared statement protocol yet"), so saving a view from the view editor failed. Route all three through sqlx::raw_sql() (COM_QUERY text protocol), matching the existing handling for transaction-control statements. Co-authored-by: Daniel Noé Núñez López <daniel.nunez@stjsonora.gob.mx> Co-authored-by: Andrea Debernardi <andrea@debbaweb.it>
1 parent 11d4806 commit 99e3532

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

  • src-tauri/src/drivers/mysql

src-tauri/src/drivers/mysql/mod.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,8 @@ pub async fn create_view(
935935
let text = resolve_text_proto(&pool, params).await?;
936936
let escaped_name = escape_identifier(view_name);
937937
let query = format!("CREATE VIEW `{}` AS {}", escaped_name, definition);
938-
exec_stmt(&pool, text, &query)
938+
sqlx::raw_sql(&query)
939+
.execute(&pool)
939940
.await
940941
.map_err(|e| format!("Failed to create view: {}", e))?;
941942
Ok(())
@@ -950,7 +951,11 @@ pub async fn alter_view(
950951
let text = resolve_text_proto(&pool, params).await?;
951952
let escaped_name = escape_identifier(view_name);
952953
let query = format!("ALTER VIEW `{}` AS {}", escaped_name, definition);
953-
exec_stmt(&pool, text, &query)
954+
// `ALTER VIEW` is not supported by MySQL's prepared-statement protocol
955+
// (server error 1295), so it must go through `raw_sql()` (text protocol)
956+
// rather than `sqlx::query()`. See `is_text_protocol_stmt` for context.
957+
sqlx::raw_sql(&query)
958+
.execute(&pool)
954959
.await
955960
.map_err(|e| format!("Failed to alter view: {}", e))?;
956961
Ok(())
@@ -961,7 +966,11 @@ pub async fn drop_view(params: &ConnectionParams, view_name: &str) -> Result<(),
961966
let text = resolve_text_proto(&pool, params).await?;
962967
let escaped_name = escape_identifier(view_name);
963968
let query = format!("DROP VIEW IF EXISTS `{}`", escaped_name);
964-
exec_stmt(&pool, text, &query)
969+
// Routed through `raw_sql()` (text protocol) for consistency with
970+
// create/alter view, which the prepared-statement protocol rejects
971+
// with server error 1295.
972+
sqlx::raw_sql(&query)
973+
.execute(&pool)
965974
.await
966975
.map_err(|e| format!("Failed to drop view: {}", e))?;
967976
Ok(())

0 commit comments

Comments
 (0)