|
@@ -70,31 +70,40 @@ QSqlDatabase& qCTKDCMTK::database() {
|
|
|
|
|
|
bool qCTKDCMTKPrivate::executeScript(const QString& script) {
|
|
|
QFile scriptFile(script);
|
|
|
- qDebug() << scriptFile.exists();
|
|
|
- qDebug() << scriptFile.size();
|
|
|
- QString sqlCommands( scriptFile.readAll() );
|
|
|
- qDebug() << sqlCommands ;
|
|
|
+ scriptFile.open(QIODevice::ReadOnly);
|
|
|
+ QString sqlCommands( QTextStream(&scriptFile).readAll() );
|
|
|
sqlCommands.replace( '\n', ' ' );
|
|
|
sqlCommands.replace("; ", ";\n");
|
|
|
+
|
|
|
+ //MITK_INFO << "Query:\n\n" << sqlCommands.toStdString() << "\n";
|
|
|
+
|
|
|
QStringList sqlCommandsLines = sqlCommands.split('\n');
|
|
|
+
|
|
|
QSqlQuery query(Database);
|
|
|
+
|
|
|
for (QStringList::iterator it = sqlCommandsLines.begin(); it != sqlCommandsLines.end()-1; ++it)
|
|
|
- {
|
|
|
- query.exec(*it);
|
|
|
- if (query.lastError().type())
|
|
|
+ {
|
|
|
+ qDebug() << "Statement: " << *it ;
|
|
|
+ if (! (*it).startsWith("--") )
|
|
|
{
|
|
|
- std::cerr
|
|
|
- << "There was an error during execution of the statement: "
|
|
|
- << (*it).toStdString();
|
|
|
+ query.exec(*it);
|
|
|
+ if (query.lastError().type())
|
|
|
+ {
|
|
|
+ qDebug() << "There was an error during execution of the statement: " << (*it);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
- return false;
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
bool qCTKDCMTK::initializeDatabase()
|
|
|
{
|
|
|
QCTK_D(qCTKDCMTK);
|
|
|
return d->executeScript(":/dicom/dicom-schema.sql");
|
|
|
}
|
|
|
+
|
|
|
|