| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: MIT | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <string> | ||
| 8 | #include <variant> | ||
| 9 | #include <cstdint> | ||
| 10 | #include <tuple> | ||
| 11 | #include <vector> | ||
| 12 | #include "IDimCoordinateQueryClause.h" | ||
| 13 | #include "ITIleInfoQueryClause.h" | ||
| 14 | #include "database_configuration.h" | ||
| 15 | #include "IDbConnection.h" | ||
| 16 | #include "IDbStatement.h" | ||
| 17 | |||
| 18 | class Utilities | ||
| 19 | { | ||
| 20 | public: | ||
| 21 | struct DataBindInfo | ||
| 22 | { | ||
| 23 | 94 | explicit DataBindInfo(int v) : value(v) | |
| 24 | 94 | {} | |
| 25 | |||
| 26 | explicit DataBindInfo(std::int64_t v) : value(v) | ||
| 27 | {} | ||
| 28 | |||
| 29 | 98 | explicit DataBindInfo(double v) : value(v) | |
| 30 | 98 | {} | |
| 31 | |||
| 32 | std::variant<int, std::int64_t, double> value; | ||
| 33 | }; | ||
| 34 | public: | ||
| 35 | static std::tuple<std::string, std::vector<DataBindInfo>> CreateWhereStatement(const imgdoc2::IDimCoordinateQueryClause* dim_coordinate_query_clause, const imgdoc2::ITileInfoQueryClause* tileInfo_query_clause, const DatabaseConfiguration2D& database_configuration); | ||
| 36 | static std::tuple<std::string, std::vector<DataBindInfo>> CreateWhereStatement(const imgdoc2::IDimCoordinateQueryClause* dim_coordinate_query_clause, const imgdoc2::ITileInfoQueryClause* tileInfo_query_clause, const DatabaseConfiguration3D& database_configuration); | ||
| 37 | |||
| 38 | static std::tuple<std::string, std::vector<DataBindInfo>> CreateWhereConditionForDimQueryClause(const imgdoc2::IDimCoordinateQueryClause* clause, const std::function<void(imgdoc2::Dimension, std::string&)>& funcGetColumnNameForDimension); | ||
| 39 | |||
| 40 | static std::tuple<std::string, std::vector<DataBindInfo>> CreateWhereConditionForTileInfoQueryClause(const imgdoc2::ITileInfoQueryClause* clause, const std::string& column_name_pyramidlevel); | ||
| 41 | |||
| 42 | /// Attempts to read from the table with the specified name the value of the column 'value_common_name' from the row | ||
| 43 | /// where the value in 'key_column_name' is equal to 'key'. If successful, the string (from column 'value_common_name') is put | ||
| 44 | /// into 'output' (if 'output' is non-null) and true is returned. If the key is not found, the method returns false. | ||
| 45 | /// It is not checked whether there are multiple hits, in such case an arbitrary hit is returned. | ||
| 46 | /// Note that in case of a database-error, this method will throw an exception. | ||
| 47 | /// | ||
| 48 | /// \param [in] db_connection The database connection. | ||
| 49 | /// \param table_name Name of the table. | ||
| 50 | /// \param key_column_name Name of the key column. | ||
| 51 | /// \param value_column_name Name of the value column. | ||
| 52 | /// \param key The key to search for. | ||
| 53 | /// \param [out] output If non-null and successful, the result is put here. | ||
| 54 | /// | ||
| 55 | /// \returns True if it succeeds, false if it fails. | ||
| 56 | [[nodiscard]] static bool TryReadStringFromPropertyBag(IDbConnection* db_connection, const std::string& table_name, const std::string& key_column_name, const std::string& value_column_name, const std::string& key, std::string* output); | ||
| 57 | |||
| 58 | static void WriteStringIntoPropertyBag(IDbConnection* db_connection, const std::string& table_name, const std::string& key_column_name, const std::string& value_column_name, const std::string& key, const std::string& value); | ||
| 59 | |||
| 60 | static void DeleteItemFromPropertyBag(IDbConnection* db_connection, const std::string& table_name, const std::string& key_column_name, const std::string& value_column_name, const std::string& key); | ||
| 61 | |||
| 62 | /// <summary> | ||
| 63 | /// Creates a condition-clause for "does the tile intersect with the specified plane". The condition is constructed for | ||
| 64 | /// the tiles-info-table. Note that this condition does **not** leverage the spatial index (so - this clause is to be used | ||
| 65 | /// if there is no spatial-index available). | ||
| 66 | /// </summary> | ||
| 67 | /// <param name="plane"> The plane. </param> | ||
| 68 | /// <param name="database_configuration"> The database configuration. </param> | ||
| 69 | /// <returns> SQL-fragment containing the conditional clause, and the corresponding data-binding-values. </returns> | ||
| 70 | static std::tuple<std::string, std::vector<DataBindInfo>> CreateWhereConditionForIntersectingWithPlaneClause(const imgdoc2::Plane_NormalAndDistD& plane, const DatabaseConfiguration3D& database_configuration); | ||
| 71 | |||
| 72 | /// <summary> | ||
| 73 | /// Add the data from the specified 'data_bind_info'-list to the specified Db-statement, starting with the index given | ||
| 74 | /// with 'binding_index'. The method returns the index of the next free binding-index (or - it returns the binding-index | ||
| 75 | /// for the next parameter, in other words "binding-index + data_bind_info.size()"). | ||
| 76 | /// </summary> | ||
| 77 | /// <param name="data_bind_info"> Information describing the data bind. </param> | ||
| 78 | /// <param name="db_statement"> [in] The database statement where the data is to be bound to. </param> | ||
| 79 | /// <param name="binding_index"> The index where to start the binding. </param> | ||
| 80 | /// <returns> The index for the next binding, or - the specified 'binding_index' incremented as many times as we bound data. </returns> | ||
| 81 | static int AddDataBindInfoListToDbStatement(const std::vector<DataBindInfo>& data_bind_info, IDbStatement* db_statement, int binding_index); | ||
| 82 | private: | ||
| 83 | static const char* ComparisonOperatorToString(imgdoc2::ComparisonOperation comparison_operator); | ||
| 84 | static const char* LogicalOperatorToString(imgdoc2::LogicalOperator logical_operator); | ||
| 85 | |||
| 86 | static bool ProcessRangeClause(const std::string& column_name_for_dimension, const imgdoc2::IDimCoordinateQueryClause::RangeClause& rangeClause, std::vector<Utilities::DataBindInfo>& databind_info, std::ostringstream& string_stream); | ||
| 87 | |||
| 88 | struct CreateWhereInfo | ||
| 89 | { | ||
| 90 | std::string dimension_column_prefix; | ||
| 91 | std::string column_name_pyramid_level; | ||
| 92 | }; | ||
| 93 | static std::tuple<std::string, std::vector<DataBindInfo>> CreateWhereStatement( | ||
| 94 | const imgdoc2::IDimCoordinateQueryClause* dim_coordinate_query_clause, | ||
| 95 | const imgdoc2::ITileInfoQueryClause* tileInfo_query_clause, | ||
| 96 | const CreateWhereInfo& create_where_info); | ||
| 97 | }; | ||
| 98 | |||
| 99 |