Skip to content

Use simple query protocol for USE database context to prevent MySQL 1295 on SELECT, and bump app version to 0.1.3 - #4

Merged
EVWorth merged 4 commits into
mainfrom
copilot/fix-simple-select-query-error
Apr 17, 2026
Merged

EVWorth merged 4 commits into
mainfrom
copilot/fix-simple-select-query-error

Conversation

Copilot AI commented Apr 17, 2026 •

Copy link
Copy Markdown
Contributor

When running simple SELECT queries against MySQL 8, execution could fail with 1295 (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)

    • Updated QueryExecutor to execute USE \`withsqlx::raw_sql(...)instead of preparedsqlx::query(...)`.
    • Escaped backticks in database identifiers before building the USE statement.
  • Regression coverage

    • Added an integration test to verify SELECT execution succeeds when an explicit database context is provided.
  • Version bump requested in PR feedback

    • Bumped app version to 0.1.3 consistently in:
      • package.json
      • package-lock.json
      • src-tauri/Cargo.toml
      • src-tauri/tauri.conf.json

Copilot AI linked an issue Apr 17, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix error running simple select queries Use simple query protocol for USE database context to prevent MySQL 1295 on SELECT Apr 17, 2026
Copilot AI requested a review from EVWorth April 17, 2026 14:01
@EVWorth
EVWorth marked this pull request as ready for review April 17, 2026 15:12
Copilot AI review requested due to automatic review settings April 17, 2026 15:12
@EVWorth

EVWorth commented Apr 17, 2026

Copy link
Copy Markdown
Owner

@copilot bump the version

Copilot AI commented Apr 17, 2026

Copy link
Copy Markdown
Contributor Author

@copilot bump the version

Done in 3ac3fee — bumped the app version to 0.1.3 across package.json, package-lock.json, src-tauri/Cargo.toml, and src-tauri/tauri.conf.json.

Copilot AI changed the title Use simple query protocol for USE database context to prevent MySQL 1295 on SELECT Use simple query protocol for USE database context to prevent MySQL 1295 on SELECT, and bump app version to 0.1.3 Apr 17, 2026
Copilot AI requested a review from EVWorth April 17, 2026 15:15
@EVWorth
EVWorth merged commit 48baf49 into main Apr 17, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 USE statements.
  • Add an integration regression test covering execute(..., Some("test_db")) with a simple SELECT.

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.

Comment on lines 36 to 43
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()))?;

Copilot AI Apr 17, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +7 to +26
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(),
}
}

Copilot AI Apr 17, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@EVWorth
EVWorth deleted the copilot/fix-simple-select-query-error branch April 19, 2026 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error running simple select queries

3 participants