Mercurial > hg > orthanc-databases
comparison Framework/PostgreSQL/PostgreSQLDatabase.cpp @ 266:cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 20 Apr 2021 17:41:44 +0200 |
parents | d663d9e44f8d |
children | b8ba198a8df3 |
comparison
equal
deleted
inserted
replaced
265:cd73e34d5411 | 266:cc7af42d4f23 |
---|---|
28 #include "PostgreSQLStatement.h" | 28 #include "PostgreSQLStatement.h" |
29 #include "PostgreSQLTransaction.h" | 29 #include "PostgreSQLTransaction.h" |
30 | 30 |
31 #include <Logging.h> | 31 #include <Logging.h> |
32 #include <OrthancException.h> | 32 #include <OrthancException.h> |
33 #include <Toolbox.h> | |
33 | 34 |
34 #include <boost/lexical_cast.hpp> | 35 #include <boost/lexical_cast.hpp> |
35 #include <boost/thread.hpp> | 36 #include <boost/thread.hpp> |
36 | 37 |
37 | 38 |
182 ThrowException(false); | 183 ThrowException(false); |
183 } | 184 } |
184 } | 185 } |
185 | 186 |
186 | 187 |
187 bool PostgreSQLDatabase::DoesTableExist(const char* name) | 188 bool PostgreSQLDatabase::DoesTableExist(const std::string& name) |
188 { | 189 { |
189 std::string lower(name); | 190 std::string lower; |
190 std::transform(lower.begin(), lower.end(), lower.begin(), tolower); | 191 Orthanc::Toolbox::ToLowerCase(lower, name); |
191 | 192 |
192 // http://stackoverflow.com/a/24089729/881731 | 193 // http://stackoverflow.com/a/24089729/881731 |
193 | 194 |
194 PostgreSQLStatement statement(*this, | 195 PostgreSQLStatement statement(*this, |
195 "SELECT 1 FROM pg_catalog.pg_class c " | 196 "SELECT 1 FROM pg_catalog.pg_class c " |
198 "AND c.relname=$1"); | 199 "AND c.relname=$1"); |
199 | 200 |
200 statement.DeclareInputString(0); | 201 statement.DeclareInputString(0); |
201 statement.BindString(0, lower); | 202 statement.BindString(0, lower); |
202 | 203 |
204 PostgreSQLResult result(statement); | |
205 return !result.IsDone(); | |
206 } | |
207 | |
208 | |
209 bool PostgreSQLDatabase::DoesColumnExist(const std::string& tableName, | |
210 const std::string& columnName) | |
211 { | |
212 std::string lowerTable, lowerColumn; | |
213 Orthanc::Toolbox::ToLowerCase(lowerTable, tableName); | |
214 Orthanc::Toolbox::ToLowerCase(lowerColumn, columnName); | |
215 | |
216 PostgreSQLStatement statement(*this, | |
217 "SELECT 1 FROM information_schema.columns " | |
218 "WHERE table_schema=$1 AND table_name=$2 AND column_name=$3"); | |
219 | |
220 statement.DeclareInputString(0); | |
221 statement.DeclareInputString(1); | |
222 statement.DeclareInputString(2); | |
223 | |
224 statement.BindString(0, "public" /* schema */); | |
225 statement.BindString(1, lowerTable); | |
226 statement.BindString(2, lowerColumn); | |
227 | |
203 PostgreSQLResult result(statement); | 228 PostgreSQLResult result(statement); |
204 return !result.IsDone(); | 229 return !result.IsDone(); |
205 } | 230 } |
206 | 231 |
207 | 232 |