浏览代码

FIX: execute script now separates commands correctly

Marco Nolden 15 年之前
父节点
当前提交
039040e07a
共有 3 个文件被更改,包括 27 次插入14 次删除
  1. 5 2
      Libs/DICOM/Core/Resources/dicom-schema.sql
  2. 1 0
      Libs/DICOM/Core/Testing/qCTKDCMTKTest1.cxx
  3. 21 12
      Libs/DICOM/Core/qCTKDCMTK.cxx

+ 5 - 2
Libs/DICOM/Core/Resources/dicom-schema.sql

@@ -1,8 +1,11 @@
 -- 
+-- A simple SQLITE3 database schema for modelling locally stored DICOM files 
 -- 
+-- Note: the semicolon at the end is necessary for the simple parser to separate
+--       the statements since the SQlite driver does not handle multiple
+--       commands per QSqlQuery::exec call!
+-- ;
 
-BEGIN TRANSACTION;
 DROP TABLE IF EXISTS 'Images' ;
 DROP TABLE IF EXISTS 'Patients' ;
 DROP TABLE IF EXISTS 'Series' ;
@@ -46,5 +49,4 @@ CREATE TABLE 'Studies' (
   'ReferringPhysician' VARCHAR(255) NULL ,
   'StudyDescription' VARCHAR(255) NULL ,
   PRIMARY KEY ('StudyInstanceUID') );
-COMMIT;
 

+ 1 - 0
Libs/DICOM/Core/Testing/qCTKDCMTKTest1.cxx

@@ -15,6 +15,7 @@ int qCTKDCMTKTest1(int argc, char** argv) {
     {
     out << "open db success\n";
     myCTK.initializeDatabase();
+    myCTK.database().close();
     }
   else
     { 

+ 21 - 12
Libs/DICOM/Core/qCTKDCMTK.cxx

@@ -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");
 }
+