Skip to content

Update the checks on the input DB file

Now, we have:

bool GMDBManager::initDB()
{
	qDebug() << "GMDBManager::initDB()";


	// check if DB is empty
	qDebug() << "checking existing tables...";
	QSqlDatabase db = QSqlDatabase::database();
	QStringList tables = db.tables();
	if (   tables.contains("LogVols",   Qt::CaseInsensitive) 
			|| tables.contains("PhysVols",  Qt::CaseInsensitive)
			|| tables.contains("Materials", Qt::CaseInsensitive)
			|| tables.contains("Elements",  Qt::CaseInsensitive)
			|| tables.contains("Shapes",    Qt::CaseInsensitive)
	) {
		qDebug() << "tables are present already. Skipping tables creation. Loading tables...";
		loadTableNamesFromDB();
		return true;
	} 

  // TODO: we should check if all needed tables are present; if not throw an error message and exit.

  // TODO: we should create tables only if the DB is really completely empty!
	// if DB is empty, then create tables
	qDebug() << "DB file is empty. Creating tables...";
	bool tablesOK = createTables();

But we should check if all needed tables are present in the input DB; if not, we should throw an error message and exit.

Also, before creating tables, we should check that the input file is really completely empty. Only then we should go on creating tables.