mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 15:08:51 +00:00
ifc2sql - warn user if ifc database already exists
This commit is contained in:
@@ -178,6 +178,7 @@ class Patcher(ifcpatch.BasePatcher):
|
|||||||
else:
|
else:
|
||||||
assert False
|
assert False
|
||||||
|
|
||||||
|
self.check_existing_ifc_database()
|
||||||
self.create_id_map()
|
self.create_id_map()
|
||||||
self.create_metadata()
|
self.create_metadata()
|
||||||
|
|
||||||
@@ -295,6 +296,30 @@ class Patcher(ifcpatch.BasePatcher):
|
|||||||
if not iterator.next():
|
if not iterator.next():
|
||||||
break
|
break
|
||||||
|
|
||||||
|
def check_existing_ifc_database(self) -> None:
|
||||||
|
if self.sql_type == "sqlite":
|
||||||
|
cursor = self.c.execute("SELECT 1 FROM sqlite_master WHERE type='table' AND name='id_map'")
|
||||||
|
assert cursor is not None
|
||||||
|
row = cursor.fetchone()
|
||||||
|
elif self.sql_type == "mysql":
|
||||||
|
cursor = self.c.execute(
|
||||||
|
f"""
|
||||||
|
SELECT 1 FROM information_schema.tables
|
||||||
|
WHERE table_schema = '{self.database}' AND table_name = 'id_map'
|
||||||
|
LIMIT 1;
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
row = self.c.fetchone()
|
||||||
|
else:
|
||||||
|
assert_never(self.sql_type)
|
||||||
|
|
||||||
|
if row is not None:
|
||||||
|
# TODO: convert to error as it's unsafe?
|
||||||
|
print(
|
||||||
|
f"WARNING. {self.sql_type} database ('{self.database}') was already used for ifc2sql patch before ('id_map' table found). "
|
||||||
|
"Which could lead to mixed up ids and other unexpected results."
|
||||||
|
)
|
||||||
|
|
||||||
def create_id_map(self) -> None:
|
def create_id_map(self) -> None:
|
||||||
if self.sql_type == "sqlite":
|
if self.sql_type == "sqlite":
|
||||||
statement = (
|
statement = (
|
||||||
|
|||||||
Reference in New Issue
Block a user