Skip to content

Commit

Permalink
fix dialect_name
Browse files Browse the repository at this point in the history
Co-authored-by: Nicola Soranzo <nicola.soranzo@gmail.com>
  • Loading branch information
bernt-matthias and nsoranzo committed Jul 9, 2020
1 parent 743aa21 commit cc53be0
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions sqlalchemy_utils/functions/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,9 @@ def sqlite_file_exists(database):
url = copy(make_url(url))
database, url.database = url.database, None
engine = None
dialect_name = url.get_dialect().name

if engine.dialect.name.startswith('postgresql'):
if dialect_name == 'postgresql':
ret = False
for pdb in postgres_db:
url.database = pdb
Expand All @@ -476,13 +477,13 @@ def sqlite_file_exists(database):
pass
engine.dispose()

elif engine.dialect.name == 'mysql':
elif dialect_name == 'mysql':
engine = sa.create_engine(url)
text = ("SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA "
"WHERE SCHEMA_NAME = '%s'" % database)
ret = bool(get_scalar_result(engine, text))

elif engine.dialect.name == 'sqlite':
elif dialect_name == 'sqlite':
engine = sa.create_engine(url)
if database:
ret = database == ':memory:' or sqlite_file_exists(database)
Expand All @@ -501,7 +502,7 @@ def sqlite_file_exists(database):

except (ProgrammingError, OperationalError):
ret = False

if engine is not None:
engine.dispose()
return ret
Expand Down

0 comments on commit cc53be0

Please sign in to comment.