diff MySQL/Plugins/MySQLIndex.cpp @ 16:9e419261f1c9

mysql storage area working
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 10 Jul 2018 10:10:35 +0200
parents 7cea966b6829
children 1e9bad493475
line wrap: on
line diff
--- a/MySQL/Plugins/MySQLIndex.cpp	Tue Jul 10 07:15:13 2018 +0200
+++ b/MySQL/Plugins/MySQLIndex.cpp	Tue Jul 10 10:10:35 2018 +0200
@@ -82,39 +82,40 @@
       db.Open();
 
       MySQLTransaction t(db);
-      db.Execute("DROP DATABASE IF EXISTS " + database);
-      db.Execute("CREATE DATABASE " + database);
+      db.Execute("DROP DATABASE IF EXISTS " + database, false);
+      db.Execute("CREATE DATABASE " + database, false);
       t.Commit();
     }
     
     std::auto_ptr<MySQLDatabase> db(new MySQLDatabase(parameters_));
 
     db->Open();
-    db->Execute("ALTER DATABASE " + parameters_.GetDatabase() + 
-                " CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
-    db->Execute("SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE");
+    
+    db->Execute("SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE", false);
 
+    if (parameters_.HasLock())
+    {
+      db->AdvisoryLock(42 /* some arbitrary constant */);
+    }
+    
     {
       MySQLTransaction t(*db);
 
+      db->Execute("ALTER DATABASE " + parameters_.GetDatabase() + 
+                  " CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci", false);
+    
       if (!db->DoesTableExist(t, "Resources"))
       {
         std::string query;
 
         Orthanc::EmbeddedResources::GetFileResource
           (query, Orthanc::EmbeddedResources::MYSQL_PREPARE_INDEX);
-        db->Execute(query);
+        db->Execute(query, true);
 
         SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_DatabaseSchemaVersion, expectedVersion);
         SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_DatabasePatchLevel, 1);
       }
 
-      t.Commit();
-    }
-
-    {
-      MySQLTransaction t(*db);
-
       if (!db->DoesTableExist(t, "Resources"))
       {
         LOG(ERROR) << "Corrupted MySQL database";
@@ -142,7 +143,7 @@
         throw Orthanc::OrthancException(Orthanc::ErrorCode_Database);        
       }
 
-      t.Rollback();
+      t.Commit();
     }
           
     return db.release();