Mercurial > hg > orthanc-databases
comparison PostgreSQL/Plugins/PostgreSQLStorageArea.cpp @ 16:9e419261f1c9
mysql storage area working
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 10 Jul 2018 10:10:35 +0200 |
parents | 9774802fd05f |
children | 714c5d2bee76 |
comparison
equal
deleted
inserted
replaced
15:dfc7002add9c | 16:9e419261f1c9 |
---|---|
19 **/ | 19 **/ |
20 | 20 |
21 | 21 |
22 #include "PostgreSQLStorageArea.h" | 22 #include "PostgreSQLStorageArea.h" |
23 | 23 |
24 #include "../../Framework/Common/FileValue.h" | |
25 #include "../../Framework/PostgreSQL/PostgreSQLTransaction.h" | 24 #include "../../Framework/PostgreSQL/PostgreSQLTransaction.h" |
26 | 25 |
27 #include <Plugins/Samples/Common/OrthancPluginCppWrapper.h> | 26 #include <Plugins/Samples/Common/OrthancPluginCppWrapper.h> |
28 #include <Core/Logging.h> | 27 #include <Core/Logging.h> |
29 | 28 |
72 StorageBackend(new Factory(*this)), | 71 StorageBackend(new Factory(*this)), |
73 parameters_(parameters), | 72 parameters_(parameters), |
74 clearAll_(false) | 73 clearAll_(false) |
75 { | 74 { |
76 } | 75 } |
77 | |
78 | |
79 void PostgreSQLStorageArea::Create(DatabaseManager::Transaction& transaction, | |
80 const std::string& uuid, | |
81 const void* content, | |
82 size_t size, | |
83 OrthancPluginContentType type) | |
84 { | |
85 DatabaseManager::CachedStatement statement( | |
86 STATEMENT_FROM_HERE, GetManager(), | |
87 "INSERT INTO StorageArea VALUES (${uuid}, ${content}, ${type})"); | |
88 | |
89 statement.SetParameterType("uuid", ValueType_Utf8String); | |
90 statement.SetParameterType("content", ValueType_File); | |
91 statement.SetParameterType("type", ValueType_Integer64); | |
92 | |
93 Dictionary args; | |
94 args.SetUtf8Value("uuid", uuid); | |
95 args.SetFileValue("content", content, size); | |
96 args.SetIntegerValue("type", type); | |
97 | |
98 statement.Execute(args); | |
99 } | |
100 | |
101 | |
102 void PostgreSQLStorageArea::Read(void*& content, | |
103 size_t& size, | |
104 DatabaseManager::Transaction& transaction, | |
105 const std::string& uuid, | |
106 OrthancPluginContentType type) | |
107 { | |
108 DatabaseManager::CachedStatement statement( | |
109 STATEMENT_FROM_HERE, GetManager(), | |
110 "SELECT content FROM StorageArea WHERE uuid=${uuid} AND type=${type}"); | |
111 | |
112 statement.SetParameterType("uuid", ValueType_Utf8String); | |
113 statement.SetParameterType("type", ValueType_Integer64); | |
114 | |
115 Dictionary args; | |
116 args.SetUtf8Value("uuid", uuid); | |
117 args.SetIntegerValue("type", type); | |
118 | |
119 statement.Execute(args); | |
120 | |
121 if (statement.IsDone()) | |
122 { | |
123 throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource); | |
124 } | |
125 else if (statement.GetResultFieldsCount() != 1 || | |
126 statement.GetResultField(0).GetType() != ValueType_File) | |
127 { | |
128 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); | |
129 } | |
130 else | |
131 { | |
132 const FileValue& value = dynamic_cast<const FileValue&>(statement.GetResultField(0)); | |
133 ReadFromString(content, size, value.GetContent()); | |
134 } | |
135 } | |
136 | |
137 | |
138 void PostgreSQLStorageArea::Remove(DatabaseManager::Transaction& transaction, | |
139 const std::string& uuid, | |
140 OrthancPluginContentType type) | |
141 { | |
142 DatabaseManager::CachedStatement statement( | |
143 STATEMENT_FROM_HERE, GetManager(), | |
144 "DELETE FROM StorageArea WHERE uuid=${uuid} AND type=${type}"); | |
145 | |
146 statement.SetParameterType("uuid", ValueType_Utf8String); | |
147 statement.SetParameterType("type", ValueType_Integer64); | |
148 | |
149 Dictionary args; | |
150 args.SetUtf8Value("uuid", uuid); | |
151 args.SetIntegerValue("type", type); | |
152 | |
153 statement.Execute(args); | |
154 } | |
155 } | 76 } |