Skip to content

Commit

Permalink
fix dialect_name
Browse files Browse the repository at this point in the history
Co-authored-by: Nicola Soranzo <[email protected]>
  • Loading branch information
bernt-matthias and nsoranzo committed Jul 9, 2020
1 parent 743aa21 commit 15dc668
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions sqlalchemy_utils/functions/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,26 +463,27 @@ 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
engine = sa.create_engine(url)
text = "SELECT 1 FROM pg_database WHERE datname='%s'" % database
try:
ret = bool(get_scalar_result(engine, text))
except OperationalError:
except (ProgrammingError, OperationalError):
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 15dc668

Please sign in to comment.