Mercurial > kallithea
changeset 8575:8305790b9533
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
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Fri, 19 Jun 2020 13:42:31 +0200 |
parents | 33a57f96c5e0 |
children | a63ccbc632d1 |
files | kallithea/lib/db_manage.py |
diffstat | 1 files changed, 4 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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()