Mercurial > hg > orthanc-databases
comparison Framework/Plugins/IndexBackend.cpp @ 117:ca0ecd412988 OrthancMySQL-2.0
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 04 Feb 2019 16:03:17 +0100 |
parents | eb08ec14fb04 |
children | 260fc55f10cd 4cd7e45b671e |
comparison
equal
deleted
inserted
replaced
116:569e17419eae | 117:ca0ecd412988 |
---|---|
1737 std::string name = variablePrefix + boost::lexical_cast<std::string>(i); | 1737 std::string name = variablePrefix + boost::lexical_cast<std::string>(i); |
1738 | 1738 |
1739 args.SetUtf8Value(name, tags[i].value); | 1739 args.SetUtf8Value(name, tags[i].value); |
1740 | 1740 |
1741 std::string insert = ("(" + boost::lexical_cast<std::string>(tags[i].resource) + ", " + | 1741 std::string insert = ("(" + boost::lexical_cast<std::string>(tags[i].resource) + ", " + |
1742 boost::lexical_cast<std::string>(tags[i].group) + ", " + | 1742 boost::lexical_cast<std::string>(tags[i].group) + ", " + |
1743 boost::lexical_cast<std::string>(tags[i].element) + ", " + | 1743 boost::lexical_cast<std::string>(tags[i].element) + ", " + |
1744 "${" + name + "})"); | 1744 "${" + name + "})"); |
1745 | 1745 |
1746 if (sql.empty()) | 1746 if (sql.empty()) |
1747 { | 1747 { |
1748 sql = "INSERT INTO " + table + " VALUES " + insert; | 1748 sql = "INSERT INTO " + table + " VALUES " + insert; |
1749 } | 1749 } |
1785 | 1785 |
1786 args.SetUtf8Value(name, metadata[i].value); | 1786 args.SetUtf8Value(name, metadata[i].value); |
1787 | 1787 |
1788 std::string insert = ("(" + boost::lexical_cast<std::string>(metadata[i].resource) + ", " + | 1788 std::string insert = ("(" + boost::lexical_cast<std::string>(metadata[i].resource) + ", " + |
1789 boost::lexical_cast<std::string>(metadata[i].metadata) + ", " + | 1789 boost::lexical_cast<std::string>(metadata[i].metadata) + ", " + |
1790 "${" + name + "})"); | 1790 "${" + name + "})"); |
1791 | 1791 |
1792 std::string remove = ("(id=" + boost::lexical_cast<std::string>(metadata[i].resource) + | 1792 std::string remove = ("(id=" + boost::lexical_cast<std::string>(metadata[i].resource) + |
1793 " AND type=" + boost::lexical_cast<std::string>(metadata[i].metadata) | 1793 " AND type=" + boost::lexical_cast<std::string>(metadata[i].metadata) |
1794 + ")"); | 1794 + ")"); |
1795 | 1795 |
1949 args.SetIntegerValue("id", patient); | 1949 args.SetIntegerValue("id", patient); |
1950 | 1950 |
1951 statement.Execute(args); | 1951 statement.Execute(args); |
1952 } | 1952 } |
1953 } | 1953 } |
1954 | |
1955 | |
1956 #if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) // Macro introduced in 1.3.1 | |
1957 # if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 4) | |
1958 // New primitive since Orthanc 1.5.4 | |
1959 bool IndexBackend::LookupResourceAndParent(int64_t& id, | |
1960 OrthancPluginResourceType& type, | |
1961 std::string& parentPublicId, | |
1962 const char* publicId) | |
1963 { | |
1964 DatabaseManager::CachedStatement statement( | |
1965 STATEMENT_FROM_HERE, manager_, | |
1966 "SELECT resource.internalId, resource.resourceType, parent.publicId " | |
1967 "FROM Resources AS resource LEFT JOIN Resources parent ON parent.internalId=resource.parentId " | |
1968 "WHERE resource.publicId=${id}"); | |
1969 | |
1970 statement.SetParameterType("id", ValueType_Utf8String); | |
1971 | |
1972 Dictionary args; | |
1973 args.SetUtf8Value("id", publicId); | |
1974 | |
1975 statement.Execute(args); | |
1976 | |
1977 if (statement.IsDone()) | |
1978 { | |
1979 return false; | |
1980 } | |
1981 else | |
1982 { | |
1983 if (statement.GetResultFieldsCount() != 3) | |
1984 { | |
1985 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
1986 } | |
1987 | |
1988 statement.SetResultFieldType(0, ValueType_Integer64); | |
1989 statement.SetResultFieldType(1, ValueType_Integer64); | |
1990 statement.SetResultFieldType(2, ValueType_Utf8String); | |
1991 | |
1992 id = ReadInteger64(statement, 0); | |
1993 type = static_cast<OrthancPluginResourceType>(ReadInteger32(statement, 1)); | |
1994 | |
1995 const IValue& value = statement.GetResultField(2); | |
1996 | |
1997 switch (value.GetType()) | |
1998 { | |
1999 case ValueType_Null: | |
2000 parentPublicId.clear(); | |
2001 break; | |
2002 | |
2003 case ValueType_Utf8String: | |
2004 parentPublicId = dynamic_cast<const Utf8StringValue&>(value).GetContent(); | |
2005 break; | |
2006 | |
2007 default: | |
2008 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
2009 } | |
2010 | |
2011 assert((statement.Next(), statement.IsDone())); | |
2012 return true; | |
2013 } | |
2014 } | |
2015 # endif | |
2016 #endif | |
2017 | |
2018 | |
2019 #if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) // Macro introduced in 1.3.1 | |
2020 # if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 4) | |
2021 // New primitive since Orthanc 1.5.4 | |
2022 void IndexBackend::GetAllMetadata(std::map<int32_t, std::string>& result, | |
2023 int64_t id) | |
2024 { | |
2025 DatabaseManager::CachedStatement statement( | |
2026 STATEMENT_FROM_HERE, manager_, | |
2027 "SELECT type, value FROM Metadata WHERE id=${id}"); | |
2028 | |
2029 statement.SetReadOnly(true); | |
2030 statement.SetParameterType("id", ValueType_Integer64); | |
2031 | |
2032 Dictionary args; | |
2033 args.SetIntegerValue("id", id); | |
2034 | |
2035 statement.Execute(args); | |
2036 | |
2037 result.clear(); | |
2038 | |
2039 if (!statement.IsDone()) | |
2040 { | |
2041 if (statement.GetResultFieldsCount() != 2) | |
2042 { | |
2043 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
2044 } | |
2045 | |
2046 statement.SetResultFieldType(0, ValueType_Integer64); | |
2047 statement.SetResultFieldType(1, ValueType_Utf8String); | |
2048 | |
2049 while (!statement.IsDone()) | |
2050 { | |
2051 result[ReadInteger32(statement, 0)] = ReadString(statement, 1); | |
2052 statement.Next(); | |
2053 } | |
2054 } | |
2055 } | |
2056 # endif | |
2057 #endif | |
1954 } | 2058 } |