Skip to content

Error 1054: Unknown column 'sys' in 'where clause' when connecting with ANSI_QUOTES sql_mode — crashes thread with TypeError #88

@lucasgdutra

Description

@lucasgdutra

Description

When opening a SQL Editor connection (gui.sqlEditor.openConnection) on a MySQL server that has ANSI_QUOTES enabled in @@sql_mode, the connection fails with MySQL Error (1054): Unknown column 'sys' in 'where clause', followed by a secondary TypeError crash in the error handling path.

Root Cause

In DbMySQLSessionSetupTasks.py, the HeatWaveCheckTask.on_connected() method executes:

result = self.execute("""
    SELECT ROUTINE_NAME
    FROM information_schema.routines
    WHERE ROUTINE_SCHEMA="sys"
    AND ROUTINE_NAME="mle_explain_error"
    AND ROUTINE_TYPE="PROCEDURE"
    """).fetch_all()

This query uses double quotes for string literals ("sys", "mle_explain_error", "PROCEDURE"). When ANSI_QUOTES is enabled in sql_mode, MySQL interprets double-quoted values as identifiers (column names) rather than string literals, causing Error 1054.

Fix: Replace double quotes with single quotes:

result = self.execute("""
    SELECT ROUTINE_NAME
    FROM information_schema.routines
    WHERE ROUTINE_SCHEMA='sys'
    AND ROUTINE_NAME='mle_explain_error'
    AND ROUTINE_TYPE='PROCEDURE'
    """).fetch_all()

Secondary Bug: TypeError in error handling

When the above error occurs, DbSession.terminate_thread() (DbSession.py line ~247) calls:

self._message_callback('ERROR', self.thread_error)

However, DbModuleSession.on_session_message() (DbModuleSession.py) expects 3 positional arguments plus an optional one:

def on_session_message(self, type, message, result, request_id=None):

The result argument is not passed by terminate_thread(), causing:

TypeError: DbModuleSession.on_session_message() missing 1 required positional argument: 'result'

Fix: Either update terminate_thread() to pass a result argument:

self._message_callback('ERROR', self.thread_error, None)

Or make result optional in on_session_message():

def on_session_message(self, type, message, result=None, request_id=None):

Steps to Reproduce

  1. Configure MySQL server with ANSI_QUOTES in sql_mode:
    SET GLOBAL sql_mode = CONCAT(@@sql_mode, ',ANSI_QUOTES');
  2. Open VS Code with MySQL Shell for VS Code extension (v2026.2.0)
  3. Create a database connection and attempt to connect via the SQL Editor

Expected Behavior

Connection opens successfully regardless of the server's sql_mode setting.

Actual Behavior

Connection fails. Two errors are raised:

  1. MySQL Error (1054): Unknown column 'sys' in 'where clause'
  2. TypeError: DbModuleSession.on_session_message() missing 1 required positional argument: 'result'

The thread crashes and no useful error is returned to the user.

Stack Trace

ERROR: Thread ServiceSession-58220351-1d69-11f1-80e9-d03745fcfc48 exiting with code MySQL Error (1054): Unknown column 'sys' in 'where clause'

Exception in thread sql-ServiceSession-58220351-1d69-11f1-80e9-d03745fcfc48:
Traceback (most recent call last):
  File "...\threading.py", line 1043, in _bootstrap_inner
    self.run()
  File "...\DbSession.py", line 480, in run
    self.terminate_thread()
  File "...\DbSession.py", line 247, in terminate_thread
    self._message_callback('ERROR', self.thread_error)
TypeError: DbModuleSession.on_session_message() missing 1 required positional argument: 'result'

Environment

  • Extension: Oracle MySQL Shell for VS Code v2026.2.0 (win32-x64)
  • OS: Windows
  • MySQL sql_mode: includes ANSI_QUOTES

Affected Files

File Issue
gui/backend/gui_plugin/core/dbms/DbMySQLSessionSetupTasks.py Double quotes used as string delimiters in SQL — incompatible with ANSI_QUOTES
gui/backend/gui_plugin/core/dbms/DbSession.py (~L247) terminate_thread() calls _message_callback with wrong number of arguments
gui/backend/gui_plugin/core/modules/DbModuleSession.py on_session_message() requires result but caller doesn't provide it

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions