Repository navigation
Use simple query protocol for USE database context to prevent MySQL 1295 on SELECT, and bump app version to 0.1.3 - #4
Conversation
USE database context to prevent MySQL 1295 on SELECT
|
@copilot bump the version |
USE database context to prevent MySQL 1295 on SELECTUSE database context to prevent MySQL 1295 on SELECT, and bump app version to 0.1.3
There was a problem hiding this comment.
Pull request overview
Fixes MySQL 8 query execution failures caused by running USE <db> through the prepared-statement protocol, by forcing the simple-query protocol for the per-request database context switch in the Rust backend (mas-core).
Changes:
- Switch
USE \`execution tosqlx::raw_sql(...)inQueryExecutor` to avoid MySQL error 1295 with prepared statements. - Escape backticks in database names before interpolating into
USEstatements. - Add an integration regression test covering
execute(..., Some("test_db"))with a simpleSELECT.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src-tauri/crates/mas-core/src/query/executor.rs | Executes USE via raw_sql (simple protocol) and escapes backticks in db identifiers. |
| src-tauri/crates/mas-core/tests/query_database_context_regression.rs | Adds an integration test to reproduce/guard the database-context USE + SELECT failure path. |
| if let Some(db) = database { | ||
| let use_sql = format!("USE `{}`", db); | ||
| let escaped_db = db.replace('`', "``"); | ||
| let use_sql = format!("USE `{}`", escaped_db); | ||
| tracing::debug!(database = %db, "Switching database context"); | ||
| sqlx::query(&use_sql) | ||
| sqlx::raw_sql(&use_sql) | ||
| .execute(conn.as_mut()) | ||
| .await | ||
| .map_err(|e| CoreError::Query(e.to_string()))?; |
There was a problem hiding this comment.
QueryExecutor::execute currently requires a database: Option<&str> argument, but there are existing call sites in this repo (e.g. src-tauri/crates/mas-core/tests/integration_tests.rs) that still call execute(&info.id, "...") with only two args. This will fail to compile unless those call sites are updated (pass None) or you reintroduce a convenience wrapper like execute(connection_id, sql) that forwards to the new signature with database = None.
| fn test_profile() -> ConnectionProfile { | ||
| ConnectionProfile { | ||
| id: uuid::Uuid::new_v4().to_string(), | ||
| name: "Test MySQL 8".to_string(), | ||
| group: None, | ||
| color: None, | ||
| host: "127.0.0.1".to_string(), | ||
| port: 13306, | ||
| username: "test_user".to_string(), | ||
| password: "test_password".to_string(), | ||
| default_database: Some("test_db".to_string()), | ||
| ssh_config: None, | ||
| ssl_config: None, | ||
| pool_min: 1, | ||
| pool_max: 5, | ||
| read_only: false, | ||
| created_at: Utc::now(), | ||
| updated_at: Utc::now(), | ||
| } | ||
| } |
There was a problem hiding this comment.
This test file duplicates the test_profile() helper that already exists in tests/integration_tests.rs. Consider extracting a shared helper module (e.g., tests/common.rs) and reusing it from both tests so connection settings/credentials stay consistent and updates don’t require touching multiple files.
When running simple
SELECTqueries against MySQL 8, execution could fail with1295 (HY000): This command is not supported in the prepared statement protocol yet. The failure path was the per-request database context switch (USE ...) being executed via prepared statements.Query execution path fix (database context switch)
QueryExecutorto executeUSE \`withsqlx::raw_sql(...)instead of preparedsqlx::query(...)`.USEstatement.Regression coverage
SELECTexecution succeeds when an explicit database context is provided.Version bump requested in PR feedback
0.1.3consistently in:package.jsonpackage-lock.jsonsrc-tauri/Cargo.tomlsrc-tauri/tauri.conf.json