Commit 891aa96
[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
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | | - | |
| 106 | + | |
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
| |||
0 commit comments