Skip to content

Commit 891aa96

Browse files
[mysql] Fix SQL_TABLES query to use single quotes for ANSI_QUOTES compatibility (DataDog#23593)
* Fix quotes in SQL query for TABLE_TYPE Reference: DataDog#23590 Use single quotes Description The SQL_TABLES query in mysql/datadog_checks/mysql/queries.py uses double quotes for the string literal "BASE TABLE": When sql_mode includes ANSI_QUOTES, MySQL interprets "BASE TABLE" as an identifier (column name) rather than a string literal, causing: ``` SQL_TABLES = """\ SELECT table_name as `name`, engine as `engine`, row_format as `row_format`, create_time as `create_time` FROM information_schema.TABLES WHERE TABLE_SCHEMA = %s AND TABLE_TYPE="BASE TABLE" """ ``` When sql_mode includes ANSI_QUOTES, MySQL interprets "BASE TABLE" as an identifier (column name) rather than a string literal, causing: > pymysql.err.OperationalError: (1054, "Unknown column 'BASE TABLE' in 'where clause'") Fix Replace double quotes with single quotes: > WHERE TABLE_SCHEMA = %s AND TABLE_TYPE='BASE TABLE' Environment Agent version: 7.77.3 Aurora MySQL 8.0 with ANSI_QUOTES in sql_mode Feature: collect_schemas: enabled: true Stack trace > mysql:ef67b735b4a65475 | (tracking.py:84) | operation _get_tables error File "databases_data.py", line 312, in _get_tables self._cursor_run(cursor, query=SQL_TABLES, params=db_name) File "databases_data.py", line 156, in _cursor_run cursor.execute(query, params) pymysql.err.OperationalError: (1054, "Unknown column 'BASE TABLE' in 'where clause'") * Fix SQL_TABLES query for ANSI_QUOTES compatibility - add changelog entry * Update mysql/changelog.d/23593.fixed Co-authored-by: Eric Weaver <eweaver755@gmail.com> --------- Co-authored-by: Eric Weaver <eweaver755@gmail.com>
1 parent db18773 commit 891aa96

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

mysql/changelog.d/23593.fixed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix schema collection query failure when MySQL ANSI_QUOTES sql_mode is enabled

mysql/datadog_checks/mysql/queries.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
row_format as `row_format`,
104104
create_time as `create_time`
105105
FROM information_schema.TABLES
106-
WHERE TABLE_SCHEMA = %s AND TABLE_TYPE="BASE TABLE"
106+
WHERE TABLE_SCHEMA = %s AND TABLE_TYPE='BASE TABLE'
107107
"""
108108

109109
SQL_COLUMNS = """\

0 commit comments

Comments
 (0)