cardinal_pythonlib.sql.sql_grammar_mysql


Original code copyright (C) 2009-2022 Rudolf Cardinal (rudolf@pobox.com).

This file is part of cardinal_pythonlib.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


SQL grammar for MySQL.

class cardinal_pythonlib.sql.sql_grammar_mysql.SqlGrammarMySQL[source]

SQL grammar (subclass of SqlGrammar) implementing MySQL syntax.

classmethod get_column_spec()[source]

Returns a parser element representing an SQL column name, such as

somecol
sometable.somecol
somedb.sometable.somecol
classmethod get_expr()[source]

Returns a parser element representing an SQL expression, such as

somecol
17
NOT(LENGTH(LEFT(somecol, 5)) + 3 < othercol % 4)
classmethod get_grammar() ParserElement[source]

Returns the full SQL grammar parser.

classmethod get_join_constraint()[source]

Returns a parser element representing an SQL join constraint, such as

ON customer.id = sale.customer_id
classmethod get_join_op()[source]

Returns a parser element representing an SQL JOIN operation, such as

JOIN
INNER JOIN
LEFT OUTER JOIN
classmethod get_result_column()[source]

Returns a parser element representing an SQL result column, such as

somecol
somecol AS somealias
COUNT(*) AS total
3
classmethod get_select_statement()[source]

Returns a parser element representing an SQL SELECT statement, such as

SELECT a, b FROM sometable WHERE c = 5;
SELECT a, COUNT(*) FROM sometable INNER JOIN othertable ON
    sometable.c = othertable.c GROUP BY a;
classmethod get_table_spec()[source]

Returns a parser element representing an SQL table name, such as

sometable
somedb.sometable
classmethod get_where_clause()[source]

Returns a parser element representing an SQL WHERE clause (the WHERE keyword followed by a WHERE expression), such as

WHERE a > 3
WHERE LENGTH(a) < c + 2
classmethod get_where_expr()[source]

Returns a parser element representing an SQL WHERE expression (the condition without the WHERE keyword itself), such as

a > 3
LENGTH(a) < c + 2
classmethod is_quoted(identifier: str) bool[source]

Determines whether an SQL identifier (e.g. table or column name) is already quoted.

classmethod quote_identifier(identifier: str) str[source]

Quotes an SQL identifier (e.g. table or column name); e.g. some databases use [name], some use `name`).

classmethod requires_quoting(identifier: str) bool[source]

Determines whether an SQL identifier (e.g. table or column name) requires to be quoted.

classmethod test_dialect_specific_1()[source]

Override this to add dialect-specific tests (#1).

classmethod test_dialect_specific_2()[source]

Override this to add dialect-specific tests (#2).