# HG changeset patch # User Mads Kiilerich # Date 1592566951 -7200 # Node ID 8305790b95335ab13e37080eb94690f7298757b5 # Parent 33a57f96c5e0d88e0a9ddb75bab9689c4172d833 db: better support for databases with "odd" characters in the name, such as "-" Add missing quoting, using the quoting flavour preferred by the DB. Tested with echo "CREATE USER 'kallithea-test'@'localhost' IDENTIFIED BY 'password'"|sudo -u mysql mysql echo "GRANT ALL PRIVILEGES ON \`kallithea-test\`.* TO 'kallithea-test'@'localhost'" | sudo -u mysql mysql TEST_DB='mysql://kallithea-test:password@localhost/kallithea-test?charset=utf8mb4' py.test sudo -u postgres createuser 'kallithea-test' --pwprompt --createdb TEST_DB='postgresql://kallithea-test:password@localhost/kallithea-test' py.test diff -r 33a57f96c5e0 -r 8305790b9533 kallithea/lib/db_manage.py --- a/kallithea/lib/db_manage.py Sun Jun 21 19:32:15 2020 +0200 +++ b/kallithea/lib/db_manage.py Fri Jun 19 13:42:31 2020 +0200 @@ -96,16 +96,16 @@ url.database = None # don't connect to the database (it might not exist) engine = sqlalchemy.create_engine(url) with engine.connect() as conn: - conn.execute('DROP DATABASE IF EXISTS ' + database) - conn.execute('CREATE DATABASE ' + database) + conn.execute('DROP DATABASE IF EXISTS `%s`' % database) + conn.execute('CREATE DATABASE `%s`' % database) elif url.drivername == 'postgresql': from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT url.database = 'postgres' # connect to the system database (as the real one might not exist) engine = sqlalchemy.create_engine(url) with engine.connect() as conn: conn.connection.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT) - conn.execute('DROP DATABASE IF EXISTS ' + database) - conn.execute('CREATE DATABASE ' + database) + conn.execute('DROP DATABASE IF EXISTS "%s"' % database) + conn.execute('CREATE DATABASE "%s"' % database) else: # known to work on SQLite - possibly not on other databases with strong referential integrity Base.metadata.drop_all()