| 1296 | |
| 1297 | |
| 1298 | class MySQLCompiler( |
| 1299 | _mariadb_shim.MariaDBSQLCompilerShim, compiler.SQLCompiler |
| 1300 | ): |
| 1301 | dialect: MySQLDialect |
| 1302 | render_table_with_column_in_update_from = True |
| 1303 | """Overridden from base SQLCompiler value""" |
| 1304 | |
| 1305 | extract_map = compiler.SQLCompiler.extract_map.copy() |
| 1306 | extract_map.update({"milliseconds": "millisecond"}) |
| 1307 | |
| 1308 | def default_from(self) -> str: |
| 1309 | """Called when a ``SELECT`` statement has no froms, |
| 1310 | and no ``FROM`` clause is to be appended. |
| 1311 | |
| 1312 | """ |
| 1313 | if self.stack: |
| 1314 | stmt = self.stack[-1]["selectable"] |
| 1315 | if stmt._where_criteria: # type: ignore[attr-defined] |
| 1316 | return " FROM DUAL" |
| 1317 | |
| 1318 | return "" |
| 1319 | |
| 1320 | def visit_random_func(self, fn: random, **kw: Any) -> str: |
| 1321 | return "rand%s" % self.function_argspec(fn) |
| 1322 | |
| 1323 | def visit_rollup_func(self, fn: rollup[Any], **kw: Any) -> str: |
| 1324 | clause = ", ".join( |
| 1325 | elem._compiler_dispatch(self, **kw) for elem in fn.clauses |
| 1326 | ) |
| 1327 | return f"{clause} WITH ROLLUP" |
| 1328 | |
| 1329 | def visit_aggregate_strings_func( |
| 1330 | self, fn: aggregate_strings, **kw: Any |
| 1331 | ) -> str: |
| 1332 | |
| 1333 | order_by = getattr(fn.clauses, "aggregate_order_by", None) |
| 1334 | |
| 1335 | cl = list(fn.clauses) |
| 1336 | expr, delimiter = cl[0:2] |
| 1337 | |
| 1338 | literal_exec = dict(kw) |
| 1339 | literal_exec["literal_execute"] = True |
| 1340 | |
| 1341 | if order_by is not None: |
| 1342 | return ( |
| 1343 | f"group_concat({expr._compiler_dispatch(self, **kw)} " |
| 1344 | f"ORDER BY {order_by._compiler_dispatch(self, **kw)} " |
| 1345 | "SEPARATOR " |
| 1346 | f"{delimiter._compiler_dispatch(self, **literal_exec)})" |
| 1347 | ) |
| 1348 | else: |
| 1349 | return ( |
| 1350 | f"group_concat({expr._compiler_dispatch(self, **kw)} " |
| 1351 | "SEPARATOR " |
| 1352 | f"{delimiter._compiler_dispatch(self, **literal_exec)})" |
| 1353 | ) |
| 1354 | |
| 1355 | def visit_sysdate_func(self, fn: sysdate, **kw: Any) -> str: |