changeset 667:88d016b2a117 attach-custom-data

handle null customdata
author Alain Mazy <am@orthanc.team>
date Mon, 26 May 2025 10:18:08 +0200 (3 weeks ago)
parents fb71c140ce2d
children f0b43129cc08
files Framework/Plugins/IndexBackend.cpp
diffstat 1 files changed, 11 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Plugins/IndexBackend.cpp	Thu May 22 11:42:44 2025 +0200
+++ b/Framework/Plugins/IndexBackend.cpp	Mon May 26 10:18:08 2025 +0200
@@ -4373,9 +4373,10 @@
                                      const std::string& key,
                                      const std::string& value)
     {
+      // TODO: that probably needs to be adapted in ODBC and MySQL
       DatabaseManager::CachedStatement statement(
         STATEMENT_FROM_HERE, manager,
-        "INSERT INTO KeyValueStores VALUES(${storeId}, ${key}, ${value})");
+        "INSERT INTO KeyValueStores VALUES(${storeId}, ${key}, ${value}) ON CONFLICT (storeId, key) DO UPDATE SET value = EXCLUDED.value;");
 
       Dictionary args;
 
@@ -4619,7 +4620,7 @@
         response.mutable_get_attachment()->mutable_attachment()->set_compression_type(statement.ReadInteger32(4));
         response.mutable_get_attachment()->mutable_attachment()->set_compressed_size(statement.ReadInteger64(5));
         response.mutable_get_attachment()->mutable_attachment()->set_compressed_hash(statement.ReadString(6));
-        response.mutable_get_attachment()->mutable_attachment()->set_custom_data(statement.ReadString(8));
+        response.mutable_get_attachment()->mutable_attachment()->set_custom_data(statement.ReadStringOrNull(8));
 
         return true;        
       }
@@ -4639,7 +4640,14 @@
 
       Dictionary args;
       args.SetUtf8Value("uuid", attachmentUuid);
-      args.SetUtf8Value("customData", customData);
+      if (customData.empty())
+      {
+        args.SetUtf8NullValue("customData");
+      }
+      else
+      {
+        args.SetUtf8Value("customData", customData);
+      }
       
       statement.Execute(args);
     }