mirror of
https://github.com/ansible-collections/community.mysql.git
synced 2025-04-18 16:31:26 -07:00
Backport of PRs to stable-2 (#251)
* Allow the "%" character in database name (#227) The naming rules for MySQL/MariaDB identifiers, when quoted, allow the `%` character. However, currently, the use of the `%` character in database names results in mismatch or missing databases. - Rewrite query to identify the databases in the catalog using `information_schema` instead of `SHOW DATABASES LIKE` - Escape the `%` character in `CREATE DATABASE` query. Signed-off-by: Nicolas Payart <npayart@gmail.com> (cherry picked from commit6b12435b2b
) * mysql_db: Fix assert in tests suite (#239) Signed-off-by: Nicolas Payart <npayart@gmail.com> (cherry picked from commit5522e45284
) * mysql_db: Improve tests (#240) - Define variables "db_names" and "db_formats" in defaults - Use of the "vars" option in includes instead of default parameters that might be overridden by a previous task - Use of the "loop" option in includes instead of duplicating include tasks - Use a nested loop on db_names and db_formats in state_dump_import test Signed-off-by: Nicolas Payart <npayart@gmail.com> (cherry picked from commite4de13aabe
) * MAINTAINERS file: Add new maintainer (#248) (cherry picked from commitd411a8e216
) Co-authored-by: Nicolas PAYART <koleo@users.noreply.github.com>
This commit is contained in:
parent
1cb39cce0a
commit
7aab5cc04f
7 changed files with 352 additions and 298 deletions
|
@ -330,7 +330,7 @@ executed_commands = []
|
|||
def db_exists(cursor, db):
|
||||
res = 0
|
||||
for each_db in db:
|
||||
res += cursor.execute("SHOW DATABASES LIKE %s", (each_db.replace("_", r"\_"),))
|
||||
res += cursor.execute("SELECT SCHEMA_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = %s", (each_db,))
|
||||
return res == len(db)
|
||||
|
||||
|
||||
|
@ -519,7 +519,8 @@ def db_create(cursor, db, encoding, collation):
|
|||
query_params = dict(enc=encoding, collate=collation)
|
||||
res = 0
|
||||
for each_db in db:
|
||||
query = ['CREATE DATABASE %s' % mysql_quote_identifier(each_db, 'database')]
|
||||
# Escape '%' since mysql cursor.execute() uses a format string
|
||||
query = ['CREATE DATABASE %s' % mysql_quote_identifier(each_db, 'database').replace('%', '%%')]
|
||||
if encoding:
|
||||
query.append("CHARACTER SET %(enc)s")
|
||||
if collation:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue