GCC Code Coverage Report


Directory: libimgdoc2/
File: libimgdoc2/src/db/database_creator.cpp
Date: 2025-02-03 12:41:04
Exec Total Coverage
Lines: 250 263 95.1%
Functions: 18 18 100.0%
Branches: 488 956 51.0%

Line Branch Exec Source
1 // SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH
2 //
3 // SPDX-License-Identifier: MIT
4
5 #include <sstream>
6 #include <string>
7 #include <gsl/gsl>
8 #include <imgdoc2.h>
9 #include "database_creator.h"
10 #include "database_configuration.h"
11 #include "database_constants.h"
12 #include "DbFactory.h"
13 #include "database_discovery.h"
14 #include "database_utilities.h"
15 #include "utilities.h"
16
17 using namespace std;
18 using namespace imgdoc2;
19
20 184 std::shared_ptr<DatabaseConfiguration2D> DbCreator::CreateTables2d(const imgdoc2::ICreateOptions* create_options)
21 {
22
1/2
✓ Branch 1 taken 184 times.
✗ Branch 2 not taken.
184 DbCreator::ThrowIfDocumentTypeIsNotAsSpecified(create_options, imgdoc2::DocumentType::kImage2d);
23
24 // construct the "database configuration" based on the the create_options
25
1/2
✓ Branch 1 taken 184 times.
✗ Branch 2 not taken.
184 auto database_configuration = make_shared<DatabaseConfiguration2D>();
26
1/2
✓ Branch 2 taken 184 times.
✗ Branch 3 not taken.
184 this->Initialize2dConfigurationFromCreateOptions(database_configuration.get(), create_options);
27
28 // TODO(JBL): make those operations a transaction
29
1/2
✓ Branch 2 taken 184 times.
✗ Branch 3 not taken.
184 auto sql_statement = this->GenerateSqlStatementForCreatingGeneralTable_Sqlite(database_configuration.get());
30
1/2
✓ Branch 2 taken 184 times.
✗ Branch 3 not taken.
184 this->db_connection_->Execute(sql_statement);
31
32
1/2
✓ Branch 2 taken 184 times.
✗ Branch 3 not taken.
184 sql_statement = this->GenerateSqlStatementForFillingGeneralTable_Sqlite(database_configuration.get());
33
1/2
✓ Branch 2 taken 184 times.
✗ Branch 3 not taken.
184 this->db_connection_->Execute(sql_statement);
34
35
1/2
✓ Branch 2 taken 184 times.
✗ Branch 3 not taken.
184 sql_statement = this->GenerateSqlStatementForCreatingTilesDataTable_Sqlite(database_configuration.get());
36
1/2
✓ Branch 2 taken 184 times.
✗ Branch 3 not taken.
184 this->db_connection_->Execute(sql_statement);
37
38
1/2
✓ Branch 2 taken 184 times.
✗ Branch 3 not taken.
184 sql_statement = this->GenerateSqlStatementForCreatingTilesInfoTable_Sqlite(database_configuration.get());
39
1/2
✓ Branch 2 taken 184 times.
✗ Branch 3 not taken.
184 this->db_connection_->Execute(sql_statement);
40
41
1/2
✓ Branch 2 taken 184 times.
✗ Branch 3 not taken.
184 sql_statement = this->GenerateSqlStatementForCreatingMetadataTable_Sqlite(database_configuration.get());
42
1/2
✓ Branch 2 taken 184 times.
✗ Branch 3 not taken.
184 this->db_connection_->Execute(sql_statement);
43
44
3/4
✓ Branch 1 taken 184 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 176 times.
184 if (create_options->GetUseSpatialIndex())
45 {
46
1/2
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
8 sql_statement = this->GenerateSqlStatementForCreatingSpatialTilesIndex_Sqlite(database_configuration.get());
47
1/2
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
8 this->db_connection_->Execute(sql_statement);
48
49 // and, add its name to the "General" table
50
1/2
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
8 this->SetGeneralTableInfoForSpatialIndex(database_configuration.get());
51 }
52
53
3/4
✓ Branch 1 taken 184 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 38 times.
✓ Branch 4 taken 146 times.
184 if (create_options->GetCreateBlobTable())
54 {
55
1/2
✓ Branch 2 taken 38 times.
✗ Branch 3 not taken.
38 sql_statement = GenerateSqlStatementForCreatingBlobTable_Sqlite(database_configuration.get());
56
1/2
✓ Branch 2 taken 38 times.
✗ Branch 3 not taken.
38 this->db_connection_->Execute(sql_statement);
57
1/2
✓ Branch 2 taken 38 times.
✗ Branch 3 not taken.
38 this->SetBlobTableNameInGeneralTable(database_configuration.get());
58 }
59
60 368 return database_configuration;
61 184 }
62
63 74 std::shared_ptr<DatabaseConfiguration3D> DbCreator::CreateTables3d(const imgdoc2::ICreateOptions* create_options)
64 {
65
1/2
✓ Branch 1 taken 74 times.
✗ Branch 2 not taken.
74 DbCreator::ThrowIfDocumentTypeIsNotAsSpecified(create_options, imgdoc2::DocumentType::kImage3d);
66
67 // construct the "database configuration" based on the the create_options
68
1/2
✓ Branch 1 taken 74 times.
✗ Branch 2 not taken.
74 auto database_configuration = make_shared<DatabaseConfiguration3D>();
69
1/2
✓ Branch 2 taken 74 times.
✗ Branch 3 not taken.
74 this->Initialize3dConfigurationFromCreateOptions(database_configuration.get(), create_options);
70
71 // TODO(JBL): make those operations a transaction
72
1/2
✓ Branch 2 taken 74 times.
✗ Branch 3 not taken.
74 auto sql_statement = this->GenerateSqlStatementForCreatingGeneralTable_Sqlite(database_configuration.get());
73
1/2
✓ Branch 2 taken 74 times.
✗ Branch 3 not taken.
74 this->db_connection_->Execute(sql_statement);
74
75
1/2
✓ Branch 2 taken 74 times.
✗ Branch 3 not taken.
74 sql_statement = this->GenerateSqlStatementForFillingGeneralTable_Sqlite(database_configuration.get());
76
1/2
✓ Branch 2 taken 74 times.
✗ Branch 3 not taken.
74 this->db_connection_->Execute(sql_statement);
77
78
1/2
✓ Branch 2 taken 74 times.
✗ Branch 3 not taken.
74 sql_statement = this->GenerateSqlStatementForCreatingTilesDataTable_Sqlite(database_configuration.get());
79
1/2
✓ Branch 2 taken 74 times.
✗ Branch 3 not taken.
74 this->db_connection_->Execute(sql_statement);
80
81
1/2
✓ Branch 2 taken 74 times.
✗ Branch 3 not taken.
74 sql_statement = this->GenerateSqlStatementForCreatingTilesInfoTable_Sqlite(database_configuration.get());
82
1/2
✓ Branch 2 taken 74 times.
✗ Branch 3 not taken.
74 this->db_connection_->Execute(sql_statement);
83
84
1/2
✓ Branch 2 taken 74 times.
✗ Branch 3 not taken.
74 sql_statement = this->GenerateSqlStatementForCreatingMetadataTable_Sqlite(database_configuration.get());
85
1/2
✓ Branch 2 taken 74 times.
✗ Branch 3 not taken.
74 this->db_connection_->Execute(sql_statement);
86
87
3/4
✓ Branch 1 taken 74 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 20 times.
✓ Branch 4 taken 54 times.
74 if (create_options->GetUseSpatialIndex())
88 {
89
1/2
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
20 sql_statement = this->GenerateSqlStatementForCreatingSpatialTilesIndex_Sqlite(database_configuration.get());
90
1/2
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
20 this->db_connection_->Execute(sql_statement);
91
92 // and, add its name to the "General" table
93
1/2
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
20 this->SetGeneralTableInfoForSpatialIndex(database_configuration.get());
94 }
95
96
3/4
✓ Branch 1 taken 74 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 48 times.
✓ Branch 4 taken 26 times.
74 if (create_options->GetCreateBlobTable())
97 {
98
1/2
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
48 sql_statement = GenerateSqlStatementForCreatingBlobTable_Sqlite(database_configuration.get());
99
1/2
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
48 this->db_connection_->Execute(sql_statement);
100
1/2
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
48 this->SetBlobTableNameInGeneralTable(database_configuration.get());
101 }
102
103 148 return database_configuration;
104 74 }
105
106 184 std::string DbCreator::GenerateSqlStatementForCreatingTilesDataTable_Sqlite(const DatabaseConfiguration2D* database_configuration)
107 {
108
1/2
✓ Branch 1 taken 184 times.
✗ Branch 2 not taken.
184 stringstream string_stream;
109 string_stream << "CREATE TABLE[" << database_configuration->GetTableNameForTilesDataOrThrow() << "](" <<
110 184 "[" << database_configuration->GetColumnNameOfTilesDataTableOrThrow(DatabaseConfiguration2D::kTilesDataTable_Column_Pk) << "] INTEGER PRIMARY KEY," <<
111 184 "[" << database_configuration->GetColumnNameOfTilesDataTableOrThrow(DatabaseConfiguration2D::kTilesDataTable_Column_PixelWidth) << "] INTEGER(4) NOT NULL," <<
112 184 "[" << database_configuration->GetColumnNameOfTilesDataTableOrThrow(DatabaseConfiguration2D::kTilesDataTable_Column_PixelHeight) << "] INTEGER(4) NOT NULL," <<
113 184 "[" << database_configuration->GetColumnNameOfTilesDataTableOrThrow(DatabaseConfiguration2D::kTilesDataTable_Column_PixelType) << "] INTEGER(1) NOT NULL," <<
114 184 "[" << database_configuration->GetColumnNameOfTilesDataTableOrThrow(DatabaseConfiguration2D::kTilesDataTable_Column_TileDataType) << "] INTEGER(1) NOT NULL," <<
115 184 "[" << database_configuration->GetColumnNameOfTilesDataTableOrThrow(DatabaseConfiguration2D::kTilesDataTable_Column_BinDataStorageType) << "] INTEGER(1)," <<
116
32/64
✓ Branch 1 taken 184 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 184 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 184 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 184 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 184 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 184 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 184 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 184 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 184 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 184 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 184 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 184 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 184 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 184 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 184 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 184 times.
✗ Branch 47 not taken.
✓ Branch 49 taken 184 times.
✗ Branch 50 not taken.
✓ Branch 52 taken 184 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 184 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 184 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 184 times.
✗ Branch 62 not taken.
✓ Branch 64 taken 184 times.
✗ Branch 65 not taken.
✓ Branch 67 taken 184 times.
✗ Branch 68 not taken.
✓ Branch 70 taken 184 times.
✗ Branch 71 not taken.
✓ Branch 73 taken 184 times.
✗ Branch 74 not taken.
✓ Branch 76 taken 184 times.
✗ Branch 77 not taken.
✓ Branch 79 taken 184 times.
✗ Branch 80 not taken.
✓ Branch 82 taken 184 times.
✗ Branch 83 not taken.
✓ Branch 85 taken 184 times.
✗ Branch 86 not taken.
✓ Branch 88 taken 184 times.
✗ Branch 89 not taken.
✓ Branch 91 taken 184 times.
✗ Branch 92 not taken.
✓ Branch 94 taken 184 times.
✗ Branch 95 not taken.
184 "[" << database_configuration->GetColumnNameOfTilesDataTableOrThrow(DatabaseConfiguration2D::kTilesDataTable_Column_BinDataId) << "] INTEGER(8)";
117
1/2
✓ Branch 1 taken 184 times.
✗ Branch 2 not taken.
184 string_stream << ");";
118
119
1/2
✓ Branch 1 taken 184 times.
✗ Branch 2 not taken.
368 return string_stream.str();
120 184 }
121
122 74 std::string DbCreator::GenerateSqlStatementForCreatingTilesDataTable_Sqlite(const DatabaseConfiguration3D* database_configuration)
123 {
124
1/2
✓ Branch 1 taken 74 times.
✗ Branch 2 not taken.
74 stringstream string_stream;
125 string_stream << "CREATE TABLE[" << database_configuration->GetTableNameForTilesDataOrThrow() << "](" <<
126 74 "[" << database_configuration->GetColumnNameOfTilesDataTableOrThrow(DatabaseConfiguration3D::kTilesDataTable_Column_Pk) << "] INTEGER PRIMARY KEY," <<
127 74 "[" << database_configuration->GetColumnNameOfTilesDataTableOrThrow(DatabaseConfiguration3D::kTilesDataTable_Column_PixelWidth) << "] INTEGER(4) NOT NULL," <<
128 74 "[" << database_configuration->GetColumnNameOfTilesDataTableOrThrow(DatabaseConfiguration3D::kTilesDataTable_Column_PixelHeight) << "] INTEGER(4) NOT NULL," <<
129 74 "[" << database_configuration->GetColumnNameOfTilesDataTableOrThrow(DatabaseConfiguration3D::kTilesDataTable_Column_PixelDepth) << "] INTEGER(4) NOT NULL," <<
130 74 "[" << database_configuration->GetColumnNameOfTilesDataTableOrThrow(DatabaseConfiguration3D::kTilesDataTable_Column_PixelType) << "] INTEGER(1) NOT NULL," <<
131 74 "[" << database_configuration->GetColumnNameOfTilesDataTableOrThrow(DatabaseConfiguration3D::kTilesDataTable_Column_TileDataType) << "] INTEGER(1) NOT NULL," <<
132 74 "[" << database_configuration->GetColumnNameOfTilesDataTableOrThrow(DatabaseConfiguration3D::kTilesDataTable_Column_BinDataStorageType) << "] INTEGER(1)," <<
133
36/72
✓ Branch 1 taken 74 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 74 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 74 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 74 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 74 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 74 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 74 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 74 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 74 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 74 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 74 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 74 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 74 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 74 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 74 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 74 times.
✗ Branch 47 not taken.
✓ Branch 49 taken 74 times.
✗ Branch 50 not taken.
✓ Branch 52 taken 74 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 74 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 74 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 74 times.
✗ Branch 62 not taken.
✓ Branch 64 taken 74 times.
✗ Branch 65 not taken.
✓ Branch 67 taken 74 times.
✗ Branch 68 not taken.
✓ Branch 70 taken 74 times.
✗ Branch 71 not taken.
✓ Branch 73 taken 74 times.
✗ Branch 74 not taken.
✓ Branch 76 taken 74 times.
✗ Branch 77 not taken.
✓ Branch 79 taken 74 times.
✗ Branch 80 not taken.
✓ Branch 82 taken 74 times.
✗ Branch 83 not taken.
✓ Branch 85 taken 74 times.
✗ Branch 86 not taken.
✓ Branch 88 taken 74 times.
✗ Branch 89 not taken.
✓ Branch 91 taken 74 times.
✗ Branch 92 not taken.
✓ Branch 94 taken 74 times.
✗ Branch 95 not taken.
✓ Branch 97 taken 74 times.
✗ Branch 98 not taken.
✓ Branch 100 taken 74 times.
✗ Branch 101 not taken.
✓ Branch 103 taken 74 times.
✗ Branch 104 not taken.
✓ Branch 106 taken 74 times.
✗ Branch 107 not taken.
74 "[" << database_configuration->GetColumnNameOfTilesDataTableOrThrow(DatabaseConfiguration3D::kTilesDataTable_Column_BinDataId) << "] INTEGER(8)";
134
1/2
✓ Branch 1 taken 74 times.
✗ Branch 2 not taken.
74 string_stream << ");";
135
136
1/2
✓ Branch 1 taken 74 times.
✗ Branch 2 not taken.
148 return string_stream.str();
137 74 }
138
139 184 std::string DbCreator::GenerateSqlStatementForCreatingTilesInfoTable_Sqlite(const DatabaseConfiguration2D* database_configuration)
140 {
141
1/2
✓ Branch 1 taken 184 times.
✗ Branch 2 not taken.
184 stringstream string_stream;
142 // Notes:
143 // * "INTEGER PRIMARY KEY" makes the column-name an alias for the RowId-column
144 string_stream << "CREATE TABLE[" << database_configuration->GetTableNameForTilesInfoOrThrow() << "](" <<
145 184 "[" << database_configuration->GetColumnNameOfTilesInfoTableOrThrow(DatabaseConfiguration2D::kTilesInfoTable_Column_Pk) << "] INTEGER PRIMARY KEY," <<
146 184 "[" << database_configuration->GetColumnNameOfTilesInfoTableOrThrow(DatabaseConfiguration2D::kTilesInfoTable_Column_TileX) << "] DOUBLE NOT NULL," <<
147 184 "[" << database_configuration->GetColumnNameOfTilesInfoTableOrThrow(DatabaseConfiguration2D::kTilesInfoTable_Column_TileY) << "] DOUBLE NOT NULL," <<
148 184 "[" << database_configuration->GetColumnNameOfTilesInfoTableOrThrow(DatabaseConfiguration2D::kTilesInfoTable_Column_TileW) << "] DOUBLE NOT NULL," <<
149 184 "[" << database_configuration->GetColumnNameOfTilesInfoTableOrThrow(DatabaseConfiguration2D::kTilesInfoTable_Column_TileH) << "] DOUBLE NOT NULL," <<
150
28/56
✓ Branch 1 taken 184 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 184 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 184 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 184 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 184 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 184 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 184 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 184 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 184 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 184 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 184 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 184 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 184 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 184 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 184 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 184 times.
✗ Branch 47 not taken.
✓ Branch 49 taken 184 times.
✗ Branch 50 not taken.
✓ Branch 52 taken 184 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 184 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 184 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 184 times.
✗ Branch 62 not taken.
✓ Branch 64 taken 184 times.
✗ Branch 65 not taken.
✓ Branch 67 taken 184 times.
✗ Branch 68 not taken.
✓ Branch 70 taken 184 times.
✗ Branch 71 not taken.
✓ Branch 73 taken 184 times.
✗ Branch 74 not taken.
✓ Branch 76 taken 184 times.
✗ Branch 77 not taken.
✓ Branch 79 taken 184 times.
✗ Branch 80 not taken.
✓ Branch 82 taken 184 times.
✗ Branch 83 not taken.
184 "[" << database_configuration->GetColumnNameOfTilesInfoTableOrThrow(DatabaseConfiguration2D::kTilesInfoTable_Column_PyramidLevel) << "] INTEGER(1) NOT NULL,";
151
152
4/8
✓ Branch 1 taken 184 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 184 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 184 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 184 times.
✗ Branch 11 not taken.
184 string_stream << "[" << database_configuration->GetColumnNameOfTilesInfoTableOrThrow(DatabaseConfiguration2D::kTilesInfoTable_Column_TileDataId) << "] INTEGER(8) NOT NULL";
153
154
2/2
✓ Branch 6 taken 224 times.
✓ Branch 7 taken 184 times.
408 for (const auto dim : database_configuration->GetTileDimensions())
155 {
156
1/2
✓ Branch 2 taken 224 times.
✗ Branch 3 not taken.
224 string colName = database_configuration->GetDimensionsColumnPrefix() + dim;
157
3/6
✓ Branch 1 taken 224 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 224 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 224 times.
✗ Branch 8 not taken.
224 string_stream << ", [" << colName << "] INTEGER(4) NOT NULL";
158 224 }
159
160
1/2
✓ Branch 1 taken 184 times.
✗ Branch 2 not taken.
184 string_stream << ");";
161
162 // create the indices for the "dimension tables"
163
2/2
✓ Branch 5 taken 12 times.
✓ Branch 6 taken 184 times.
196 for (const auto dim : database_configuration->GetIndexedTileDimensions())
164 {
165 12 string_stream << "CREATE INDEX [" << database_configuration->GetIndexForDimensionColumnPrefix() << dim << "] ON "
166 12 << "[" << database_configuration->GetTableNameForTilesInfoOrThrow() << "] "
167
12/24
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 12 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 12 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 12 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 12 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 12 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 12 times.
✗ Branch 21 not taken.
✓ Branch 23 taken 12 times.
✗ Branch 24 not taken.
✓ Branch 26 taken 12 times.
✗ Branch 27 not taken.
✓ Branch 30 taken 12 times.
✗ Branch 31 not taken.
✓ Branch 33 taken 12 times.
✗ Branch 34 not taken.
✓ Branch 36 taken 12 times.
✗ Branch 37 not taken.
12 << "( [" << database_configuration->GetDimensionsColumnPrefix() << dim << "]);";
168 }
169
170
1/2
✓ Branch 1 taken 184 times.
✗ Branch 2 not taken.
368 return string_stream.str();
171 184 }
172
173 74 std::string DbCreator::GenerateSqlStatementForCreatingTilesInfoTable_Sqlite(const DatabaseConfiguration3D* database_configuration)
174 {
175
1/2
✓ Branch 1 taken 74 times.
✗ Branch 2 not taken.
74 stringstream string_stream;
176 // Notes:
177 // * "INTEGER PRIMARY KEY" makes the column-name an alias for the RowId-column
178 string_stream << "CREATE TABLE[" << database_configuration->GetTableNameForTilesInfoOrThrow() << "](" <<
179 74 "[" << database_configuration->GetColumnNameOfTilesInfoTableOrThrow(DatabaseConfiguration3D::kTilesInfoTable_Column_Pk) << "] INTEGER PRIMARY KEY," <<
180 74 "[" << database_configuration->GetColumnNameOfTilesInfoTableOrThrow(DatabaseConfiguration3D::kTilesInfoTable_Column_TileX) << "] DOUBLE NOT NULL," <<
181 74 "[" << database_configuration->GetColumnNameOfTilesInfoTableOrThrow(DatabaseConfiguration3D::kTilesInfoTable_Column_TileY) << "] DOUBLE NOT NULL," <<
182 74 "[" << database_configuration->GetColumnNameOfTilesInfoTableOrThrow(DatabaseConfiguration3D::kTilesInfoTable_Column_TileZ) << "] DOUBLE NOT NULL," <<
183 74 "[" << database_configuration->GetColumnNameOfTilesInfoTableOrThrow(DatabaseConfiguration3D::kTilesInfoTable_Column_TileW) << "] DOUBLE NOT NULL," <<
184 74 "[" << database_configuration->GetColumnNameOfTilesInfoTableOrThrow(DatabaseConfiguration3D::kTilesInfoTable_Column_TileH) << "] DOUBLE NOT NULL," <<
185 74 "[" << database_configuration->GetColumnNameOfTilesInfoTableOrThrow(DatabaseConfiguration3D::kTilesInfoTable_Column_TileD) << "] DOUBLE NOT NULL," <<
186
36/72
✓ Branch 1 taken 74 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 74 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 74 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 74 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 74 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 74 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 74 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 74 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 74 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 74 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 74 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 74 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 74 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 74 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 74 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 74 times.
✗ Branch 47 not taken.
✓ Branch 49 taken 74 times.
✗ Branch 50 not taken.
✓ Branch 52 taken 74 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 74 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 74 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 74 times.
✗ Branch 62 not taken.
✓ Branch 64 taken 74 times.
✗ Branch 65 not taken.
✓ Branch 67 taken 74 times.
✗ Branch 68 not taken.
✓ Branch 70 taken 74 times.
✗ Branch 71 not taken.
✓ Branch 73 taken 74 times.
✗ Branch 74 not taken.
✓ Branch 76 taken 74 times.
✗ Branch 77 not taken.
✓ Branch 79 taken 74 times.
✗ Branch 80 not taken.
✓ Branch 82 taken 74 times.
✗ Branch 83 not taken.
✓ Branch 85 taken 74 times.
✗ Branch 86 not taken.
✓ Branch 88 taken 74 times.
✗ Branch 89 not taken.
✓ Branch 91 taken 74 times.
✗ Branch 92 not taken.
✓ Branch 94 taken 74 times.
✗ Branch 95 not taken.
✓ Branch 97 taken 74 times.
✗ Branch 98 not taken.
✓ Branch 100 taken 74 times.
✗ Branch 101 not taken.
✓ Branch 103 taken 74 times.
✗ Branch 104 not taken.
✓ Branch 106 taken 74 times.
✗ Branch 107 not taken.
74 "[" << database_configuration->GetColumnNameOfTilesInfoTableOrThrow(DatabaseConfiguration3D::kTilesInfoTable_Column_PyramidLevel) << "] INTEGER(1) NOT NULL,";
187
188
4/8
✓ Branch 1 taken 74 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 74 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 74 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 74 times.
✗ Branch 11 not taken.
74 string_stream << "[" << database_configuration->GetColumnNameOfTilesInfoTableOrThrow(DatabaseConfiguration3D::kTilesInfoTable_Column_TileDataId) << "] INTEGER(8) NOT NULL";
189
190 // TODO(JBL): the code below can be refactored to be shared with the 2D case
191
2/2
✓ Branch 6 taken 84 times.
✓ Branch 7 taken 74 times.
158 for (const auto dim : database_configuration->GetTileDimensions())
192 {
193
1/2
✓ Branch 2 taken 84 times.
✗ Branch 3 not taken.
84 string colName = database_configuration->GetDimensionsColumnPrefix() + dim;
194
3/6
✓ Branch 1 taken 84 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 84 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 84 times.
✗ Branch 8 not taken.
84 string_stream << ", [" << colName << "] INTEGER(4) NOT NULL";
195 84 }
196
197
1/2
✓ Branch 1 taken 74 times.
✗ Branch 2 not taken.
74 string_stream << ");";
198
199 // create the indices for the "dimension tables"
200
2/2
✓ Branch 5 taken 8 times.
✓ Branch 6 taken 74 times.
82 for (const auto dim : database_configuration->GetIndexedTileDimensions())
201 {
202 8 string_stream << "CREATE INDEX [" << database_configuration->GetIndexForDimensionColumnPrefix() << dim << "] ON "
203 8 << "[" << database_configuration->GetTableNameForTilesInfoOrThrow() << "] "
204
12/24
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 8 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 8 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 8 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 8 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 8 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 8 times.
✗ Branch 21 not taken.
✓ Branch 23 taken 8 times.
✗ Branch 24 not taken.
✓ Branch 26 taken 8 times.
✗ Branch 27 not taken.
✓ Branch 30 taken 8 times.
✗ Branch 31 not taken.
✓ Branch 33 taken 8 times.
✗ Branch 34 not taken.
✓ Branch 36 taken 8 times.
✗ Branch 37 not taken.
8 << "( [" << database_configuration->GetDimensionsColumnPrefix() << dim << "]);";
205 }
206
207
1/2
✓ Branch 1 taken 74 times.
✗ Branch 2 not taken.
148 return string_stream.str();
208 74 }
209
210 258 std::string DbCreator::GenerateSqlStatementForCreatingGeneralTable_Sqlite(const DatabaseConfigurationCommon* database_configuration_common)
211 {
212
1/2
✓ Branch 1 taken 258 times.
✗ Branch 2 not taken.
258 stringstream string_stream;
213 string_stream << "CREATE TABLE[" << database_configuration_common->GetTableNameForGeneralTableOrThrow() << "](" <<
214 258 "[" << database_configuration_common->GetColumnNameOfGeneralInfoTableOrThrow(DatabaseConfigurationCommon::kGeneralInfoTable_Column_Key) << "] TEXT(40) UNIQUE," <<
215
12/24
✓ Branch 1 taken 258 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 258 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 258 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 258 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 258 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 258 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 258 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 258 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 258 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 258 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 258 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 258 times.
✗ Branch 35 not taken.
258 "[" << database_configuration_common->GetColumnNameOfGeneralInfoTableOrThrow(DatabaseConfigurationCommon::kGeneralInfoTable_Column_ValueString) << "] TEXT);";
216
217
1/2
✓ Branch 1 taken 258 times.
✗ Branch 2 not taken.
516 return string_stream.str();
218 258 }
219
220 28 void DbCreator::SetGeneralTableInfoForSpatialIndex(const DatabaseConfigurationCommon* database_configuration_common)
221 {
222
3/6
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 28 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 28 times.
28 Expects(database_configuration_common != nullptr && database_configuration_common->GetIsUsingSpatialIndex() == true);
223
224 // insert an item into the "General"-table where we notify about the name of the "tiles-spatial-table"
225
3/6
✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 28 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 28 times.
✗ Branch 9 not taken.
56 Utilities::WriteStringIntoPropertyBag(
226 this->db_connection_.get(),
227
1/2
✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
56 database_configuration_common->GetTableNameForGeneralTableOrThrow(),
228
1/2
✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
56 database_configuration_common->GetColumnNameOfGeneralInfoTableOrThrow(DatabaseConfigurationCommon::kGeneralInfoTable_Column_Key),
229
1/2
✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
56 database_configuration_common->GetColumnNameOfGeneralInfoTableOrThrow(DatabaseConfigurationCommon::kGeneralInfoTable_Column_ValueString),
230 DbConstants::GetGeneralTable_ItemKey(GeneralTableItems::kSpatialIndexTable),
231
1/2
✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
56 database_configuration_common->GetTableNameForTilesSpatialIndexTableOrThrow());
232 28 }
233
234 258 std::string DbCreator::GenerateSqlStatementForFillingGeneralTable_Sqlite(const DatabaseConfigurationCommon* database_configuration_common)
235 {
236
1/2
✓ Branch 1 taken 258 times.
✗ Branch 2 not taken.
258 stringstream string_stream;
237 string_stream << "INSERT INTO [" << database_configuration_common->GetTableNameForGeneralTableOrThrow() << "]" <<
238 258 "([" << database_configuration_common->GetColumnNameOfGeneralInfoTableOrThrow(DatabaseConfigurationCommon::kGeneralInfoTable_Column_Key) << "], " <<
239 258 "[" << database_configuration_common->GetColumnNameOfGeneralInfoTableOrThrow(DatabaseConfigurationCommon::kGeneralInfoTable_Column_ValueString) << "])" <<
240 " VALUES('" << DbConstants::GetGeneralTable_ItemKey(GeneralTableItems::kVersion) << "','" << "0.0.1-alpha" << "')," <<
241 258 "('" << DbConstants::GetGeneralTable_ItemKey(GeneralTableItems::kTilesDataTable) << "','" << database_configuration_common->GetTableNameForTilesDataOrThrow() << "')," <<
242 258 "('" << DbConstants::GetGeneralTable_ItemKey(GeneralTableItems::kTilesInfoTable) << "','" << database_configuration_common->GetTableNameForTilesInfoOrThrow() << "')," <<
243 258 "('" << DbConstants::GetGeneralTable_ItemKey(GeneralTableItems::kMetadataTable) << "','" << database_configuration_common->GetTableNameForMetadataTableOrThrow() << "')," <<
244
47/94
✓ Branch 1 taken 258 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 258 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 258 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 258 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 258 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 258 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 258 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 258 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 258 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 258 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 258 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 258 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 258 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 258 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 258 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 258 times.
✗ Branch 47 not taken.
✓ Branch 49 taken 258 times.
✗ Branch 50 not taken.
✓ Branch 52 taken 258 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 258 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 258 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 258 times.
✗ Branch 62 not taken.
✓ Branch 64 taken 258 times.
✗ Branch 65 not taken.
✓ Branch 67 taken 258 times.
✗ Branch 68 not taken.
✓ Branch 70 taken 258 times.
✗ Branch 71 not taken.
✓ Branch 73 taken 258 times.
✗ Branch 74 not taken.
✓ Branch 76 taken 258 times.
✗ Branch 77 not taken.
✓ Branch 79 taken 258 times.
✗ Branch 80 not taken.
✓ Branch 82 taken 258 times.
✗ Branch 83 not taken.
✓ Branch 85 taken 258 times.
✗ Branch 86 not taken.
✓ Branch 88 taken 258 times.
✗ Branch 89 not taken.
✓ Branch 91 taken 258 times.
✗ Branch 92 not taken.
✓ Branch 94 taken 258 times.
✗ Branch 95 not taken.
✓ Branch 97 taken 258 times.
✗ Branch 98 not taken.
✓ Branch 100 taken 258 times.
✗ Branch 101 not taken.
✓ Branch 103 taken 258 times.
✗ Branch 104 not taken.
✓ Branch 106 taken 258 times.
✗ Branch 107 not taken.
✓ Branch 109 taken 258 times.
✗ Branch 110 not taken.
✓ Branch 112 taken 258 times.
✗ Branch 113 not taken.
✓ Branch 115 taken 258 times.
✗ Branch 116 not taken.
✓ Branch 118 taken 258 times.
✗ Branch 119 not taken.
✓ Branch 121 taken 258 times.
✗ Branch 122 not taken.
✓ Branch 124 taken 258 times.
✗ Branch 125 not taken.
✓ Branch 127 taken 258 times.
✗ Branch 128 not taken.
✓ Branch 130 taken 258 times.
✗ Branch 131 not taken.
✓ Branch 133 taken 258 times.
✗ Branch 134 not taken.
✓ Branch 136 taken 258 times.
✗ Branch 137 not taken.
✓ Branch 139 taken 258 times.
✗ Branch 140 not taken.
258 "('" << DbConstants::GetGeneralTable_ItemKey(GeneralTableItems::kDocType) << "','" << DbUtilities::GetDocTypeValueForDocumentType(database_configuration_common->GetDocumentType()) << "');";
245
246
1/2
✓ Branch 1 taken 258 times.
✗ Branch 2 not taken.
516 return string_stream.str();
247 258 }
248
249 184 void DbCreator::Initialize2dConfigurationFromCreateOptions(DatabaseConfiguration2D* database_configuration, const imgdoc2::ICreateOptions* create_options)
250 {
251 184 database_configuration->SetDimensionColumnPrefix(DbConstants::kDimensionColumnPrefix_Default/*"Dim_"*/);
252 184 database_configuration->SetIndexForDimensionColumnPrefix(DbConstants::kIndexForDimensionColumnPrefix_Default/*"IndexForDim_"*/);
253 184 database_configuration->SetTableName(DatabaseConfigurationCommon::TableTypeCommon::GeneralInfo, DbConstants::kGeneralTable_Name/*"GENERAL"*/);
254 184 database_configuration->SetTableName(DatabaseConfigurationCommon::TableTypeCommon::TilesData, DbConstants::kTilesDataTable_DefaultName/*"TILESDATA"*/);
255 184 database_configuration->SetTableName(DatabaseConfigurationCommon::TableTypeCommon::TilesInfo, DbConstants::kTilesInfoTable_DefaultName/*"TILESINFO"*/);
256 184 database_configuration->SetTableName(DatabaseConfigurationCommon::TableTypeCommon::Metadata, DbConstants::kMetadataTable_DefaultName);
257 184 database_configuration->SetDefaultColumnNamesForMetadataTable();// TODO(JBl): should we make the metadata-table optional?
258 184 database_configuration->SetDefaultColumnNamesForTilesDataTable();
259 184 database_configuration->SetDefaultColumnNamesForTilesInfoTable();
260 184 database_configuration->SetTileDimensions(create_options->GetDimensions().cbegin(), create_options->GetDimensions().cend());
261 184 database_configuration->SetIndexedTileDimensions(create_options->GetIndexedDimensions().cbegin(), create_options->GetIndexedDimensions().cend());
262
263
2/2
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 176 times.
184 if (create_options->GetUseSpatialIndex())
264 {
265 8 database_configuration->SetTableName(DatabaseConfigurationCommon::TableTypeCommon::TilesSpatialIndex, DbConstants::kTilesSpatialIndexTable_DefaultName/*"TILESSPATIALINDEX"*/);
266 8 database_configuration->SetColumnNameForTilesSpatialIndexTable(DatabaseConfiguration2D::kTilesSpatialIndexTable_Column_Pk, DbConstants::kSqliteSpatialIndexTable_Column_Pk_DefaultName/*"id"*/);
267 8 database_configuration->SetColumnNameForTilesSpatialIndexTable(DatabaseConfiguration2D::kTilesSpatialIndexTable_Column_MinX, DbConstants::kSqliteSpatialIndexTable_Column_minX_DefaultName /*"minX"*/);
268 8 database_configuration->SetColumnNameForTilesSpatialIndexTable(DatabaseConfiguration2D::kTilesSpatialIndexTable_Column_MaxX, DbConstants::kSqliteSpatialIndexTable_Column_maxX_DefaultName /*"maxX"*/);
269 8 database_configuration->SetColumnNameForTilesSpatialIndexTable(DatabaseConfiguration2D::kTilesSpatialIndexTable_Column_MinY, DbConstants::kSqliteSpatialIndexTable_Column_minY_DefaultName /*"minY"*/);
270 8 database_configuration->SetColumnNameForTilesSpatialIndexTable(DatabaseConfiguration2D::kTilesSpatialIndexTable_Column_MaxY, DbConstants::kSqliteSpatialIndexTable_Column_maxY_DefaultName /*"maxY"*/);
271 }
272
273
2/2
✓ Branch 1 taken 38 times.
✓ Branch 2 taken 146 times.
184 if (create_options->GetCreateBlobTable())
274 {
275 38 database_configuration->SetTableName(DatabaseConfigurationCommon::TableTypeCommon::Blobs, DbConstants::kBlobTable_DefaultName);
276 38 database_configuration->SetColumnNameForBlobTable(DatabaseConfiguration2D::kBlobTable_Column_Pk, DbConstants::kBlobTable_Column_Pk_DefaultName);
277 38 database_configuration->SetColumnNameForBlobTable(DatabaseConfiguration2D::kBlobTable_Column_Data, DbConstants::kBlobTable_Column_Data_DefaultName);
278 }
279 184 }
280
281 74 void DbCreator::Initialize3dConfigurationFromCreateOptions(DatabaseConfiguration3D* database_configuration, const imgdoc2::ICreateOptions* create_options)
282 {
283 74 database_configuration->SetDimensionColumnPrefix(DbConstants::kDimensionColumnPrefix_Default/*"Dim_"*/);
284 74 database_configuration->SetIndexForDimensionColumnPrefix(DbConstants::kIndexForDimensionColumnPrefix_Default/*"IndexForDim_"*/);
285 74 database_configuration->SetTableName(DatabaseConfigurationCommon::TableTypeCommon::GeneralInfo, DbConstants::kGeneralTable_Name/*"GENERAL"*/);
286 74 database_configuration->SetTableName(DatabaseConfigurationCommon::TableTypeCommon::TilesData, DbConstants::kTilesDataTable_DefaultName/*"TILESDATA"*/);
287 74 database_configuration->SetTableName(DatabaseConfigurationCommon::TableTypeCommon::TilesInfo, DbConstants::kTilesInfoTable_DefaultName/*"TILESINFO"*/);
288 74 database_configuration->SetTableName(DatabaseConfigurationCommon::TableTypeCommon::Metadata, DbConstants::kMetadataTable_DefaultName);
289 74 database_configuration->SetDefaultColumnNamesForMetadataTable();// TODO(JBl): should we make the metadata-table optional?
290 74 database_configuration->SetDefaultColumnNamesForTilesDataTable();
291
292 74 database_configuration->SetDefaultColumnNamesForTilesInfoTable();
293 74 database_configuration->SetTileDimensions(create_options->GetDimensions().cbegin(), create_options->GetDimensions().cend());
294 74 database_configuration->SetIndexedTileDimensions(create_options->GetIndexedDimensions().cbegin(), create_options->GetIndexedDimensions().cend());
295
296
2/2
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 54 times.
74 if (create_options->GetUseSpatialIndex())
297 {
298 20 database_configuration->SetTableName(DatabaseConfigurationCommon::TableTypeCommon::TilesSpatialIndex, DbConstants::kTilesSpatialIndexTable_DefaultName/*"TILESSPATIALINDEX"*/);
299 20 database_configuration->SetColumnNameForTilesSpatialIndexTable(DatabaseConfiguration3D::kTilesSpatialIndexTable_Column_Pk, DbConstants::kSqliteSpatialIndexTable_Column_Pk_DefaultName/*"id"*/);
300 20 database_configuration->SetColumnNameForTilesSpatialIndexTable(DatabaseConfiguration3D::kTilesSpatialIndexTable_Column_MinX, DbConstants::kSqliteSpatialIndexTable_Column_minX_DefaultName /*"minX"*/);
301 20 database_configuration->SetColumnNameForTilesSpatialIndexTable(DatabaseConfiguration3D::kTilesSpatialIndexTable_Column_MaxX, DbConstants::kSqliteSpatialIndexTable_Column_maxX_DefaultName /*"maxX"*/);
302 20 database_configuration->SetColumnNameForTilesSpatialIndexTable(DatabaseConfiguration3D::kTilesSpatialIndexTable_Column_MinY, DbConstants::kSqliteSpatialIndexTable_Column_minY_DefaultName /*"minY"*/);
303 20 database_configuration->SetColumnNameForTilesSpatialIndexTable(DatabaseConfiguration3D::kTilesSpatialIndexTable_Column_MaxY, DbConstants::kSqliteSpatialIndexTable_Column_maxY_DefaultName /*"maxY"*/);
304 20 database_configuration->SetColumnNameForTilesSpatialIndexTable(DatabaseConfiguration3D::kTilesSpatialIndexTable_Column_MinZ, DbConstants::kSqliteSpatialIndexTable_Column_minZ_DefaultName /*"minZ"*/);
305 20 database_configuration->SetColumnNameForTilesSpatialIndexTable(DatabaseConfiguration3D::kTilesSpatialIndexTable_Column_MaxZ, DbConstants::kSqliteSpatialIndexTable_Column_maxZ_DefaultName /*"maxZ"*/);
306 }
307
308
2/2
✓ Branch 1 taken 48 times.
✓ Branch 2 taken 26 times.
74 if (create_options->GetCreateBlobTable())
309 {
310 48 database_configuration->SetTableName(DatabaseConfigurationCommon::TableTypeCommon::Blobs, DbConstants::kBlobTable_DefaultName);
311 48 database_configuration->SetColumnNameForBlobTable(DatabaseConfiguration2D::kBlobTable_Column_Pk, DbConstants::kBlobTable_Column_Pk_DefaultName);
312 48 database_configuration->SetColumnNameForBlobTable(DatabaseConfiguration2D::kBlobTable_Column_Data, DbConstants::kBlobTable_Column_Data_DefaultName);
313 }
314 74 }
315
316 8 std::string DbCreator::GenerateSqlStatementForCreatingSpatialTilesIndex_Sqlite(const DatabaseConfiguration2D* database_configuration)
317 {
318
4/8
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 8 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 8 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 8 times.
8 Expects(database_configuration != nullptr && database_configuration->GetIsUsingSpatialIndex() == true);
319
320
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 auto string_stream = ostringstream();
321 string_stream << "CREATE VIRTUAL TABLE " << database_configuration->GetTableNameForTilesSpatialIndexTableOrThrow() << " USING rtree(" <<
322 8 database_configuration->GetColumnNameOfTilesSpatialIndexTableOrThrow(DatabaseConfiguration2D::kTilesSpatialIndexTable_Column_Pk) << "," << // Integer primary key
323 8 database_configuration->GetColumnNameOfTilesSpatialIndexTableOrThrow(DatabaseConfiguration2D::kTilesSpatialIndexTable_Column_MinX) << "," << // Minimum X coordinate"
324 8 database_configuration->GetColumnNameOfTilesSpatialIndexTableOrThrow(DatabaseConfiguration2D::kTilesSpatialIndexTable_Column_MaxX) << "," << // Maximum X coordinate"
325 8 database_configuration->GetColumnNameOfTilesSpatialIndexTableOrThrow(DatabaseConfiguration2D::kTilesSpatialIndexTable_Column_MinY) << "," << // Minimum Y coordinate"
326
19/38
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 8 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 8 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 8 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 8 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 8 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 8 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 8 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 8 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 8 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 8 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 8 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 8 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 8 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 8 times.
✗ Branch 47 not taken.
✓ Branch 49 taken 8 times.
✗ Branch 50 not taken.
✓ Branch 52 taken 8 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 8 times.
✗ Branch 56 not taken.
8 database_configuration->GetColumnNameOfTilesSpatialIndexTableOrThrow(DatabaseConfiguration2D::kTilesSpatialIndexTable_Column_MaxY) << ");"; // Maximum Y coordinate"
327
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
16 return string_stream.str();
328 8 }
329
330 20 std::string DbCreator::GenerateSqlStatementForCreatingSpatialTilesIndex_Sqlite(const DatabaseConfiguration3D* database_configuration)
331 {
332
4/8
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 20 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 20 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 20 times.
20 Expects(database_configuration != nullptr && database_configuration->GetIsUsingSpatialIndex() == true);
333
334
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 ostringstream string_stream;
335 string_stream << "CREATE VIRTUAL TABLE " << database_configuration->GetTableNameForTilesSpatialIndexTableOrThrow() << " USING rtree(" <<
336 20 database_configuration->GetColumnNameOfTilesSpatialIndexTableOrThrow(DatabaseConfiguration3D::kTilesSpatialIndexTable_Column_Pk) << "," << // Integer primary key
337 20 database_configuration->GetColumnNameOfTilesSpatialIndexTableOrThrow(DatabaseConfiguration3D::kTilesSpatialIndexTable_Column_MinX) << "," << // Minimum X coordinate"
338 20 database_configuration->GetColumnNameOfTilesSpatialIndexTableOrThrow(DatabaseConfiguration3D::kTilesSpatialIndexTable_Column_MaxX) << "," << // Maximum X coordinate"
339 20 database_configuration->GetColumnNameOfTilesSpatialIndexTableOrThrow(DatabaseConfiguration3D::kTilesSpatialIndexTable_Column_MinY) << "," << // Minimum Y coordinate"
340 20 database_configuration->GetColumnNameOfTilesSpatialIndexTableOrThrow(DatabaseConfiguration3D::kTilesSpatialIndexTable_Column_MaxY) << "," << // Maximum Y coordinate"
341 20 database_configuration->GetColumnNameOfTilesSpatialIndexTableOrThrow(DatabaseConfiguration3D::kTilesSpatialIndexTable_Column_MinZ) << "," << // Minimum Z coordinate"
342
25/50
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 20 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 20 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 20 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 20 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 20 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 20 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 20 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 20 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 20 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 20 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 20 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 20 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 20 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 20 times.
✗ Branch 47 not taken.
✓ Branch 49 taken 20 times.
✗ Branch 50 not taken.
✓ Branch 52 taken 20 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 20 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 20 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 20 times.
✗ Branch 62 not taken.
✓ Branch 64 taken 20 times.
✗ Branch 65 not taken.
✓ Branch 67 taken 20 times.
✗ Branch 68 not taken.
✓ Branch 70 taken 20 times.
✗ Branch 71 not taken.
✓ Branch 73 taken 20 times.
✗ Branch 74 not taken.
20 database_configuration->GetColumnNameOfTilesSpatialIndexTableOrThrow(DatabaseConfiguration3D::kTilesSpatialIndexTable_Column_MaxZ) << ");"; // Maximum Z coordinate"
343
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
40 return string_stream.str();
344 20 }
345
346 38 std::string DbCreator::GenerateSqlStatementForCreatingBlobTable_Sqlite(const DatabaseConfiguration2D* database_configuration)
347 {
348
4/8
✓ Branch 0 taken 38 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 38 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 38 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 38 times.
38 Expects(database_configuration != nullptr && database_configuration->GetHasBlobsTable() == true);
349
350
1/2
✓ Branch 1 taken 38 times.
✗ Branch 2 not taken.
38 ostringstream string_stream;
351 string_stream << "CREATE TABLE [" << database_configuration->GetTableNameForBlobTableOrThrow() << "] (" <<
352 38 "[" << database_configuration->GetColumnNameOfBlobTableOrThrow(DatabaseConfiguration2D::kBlobTable_Column_Pk) << "] INTEGER PRIMARY KEY," <<
353
12/24
✓ Branch 1 taken 38 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 38 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 38 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 38 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 38 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 38 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 38 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 38 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 38 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 38 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 38 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 38 times.
✗ Branch 35 not taken.
38 "[" << database_configuration->GetColumnNameOfBlobTableOrThrow(DatabaseConfiguration2D::kBlobTable_Column_Data) << "] BLOB );";
354
355
1/2
✓ Branch 1 taken 38 times.
✗ Branch 2 not taken.
76 return string_stream.str();
356 38 }
357
358 48 std::string DbCreator::GenerateSqlStatementForCreatingBlobTable_Sqlite(const DatabaseConfiguration3D* database_configuration)
359 {
360
4/8
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 48 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 48 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 48 times.
48 Expects(database_configuration != nullptr && database_configuration->GetHasBlobsTable() == true);
361
362
1/2
✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
48 ostringstream string_stream;
363 string_stream << "CREATE TABLE [" << database_configuration->GetTableNameForBlobTableOrThrow() << "] (" <<
364 48 "[" << database_configuration->GetColumnNameOfBlobTableOrThrow(DatabaseConfiguration3D::kBlobTable_Column_Pk) << "] INTEGER PRIMARY KEY," <<
365
12/24
✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 48 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 48 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 48 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 48 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 48 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 48 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 48 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 48 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 48 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 48 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 48 times.
✗ Branch 35 not taken.
48 "[" << database_configuration->GetColumnNameOfBlobTableOrThrow(DatabaseConfiguration3D::kBlobTable_Column_Data) << "] BLOB );";
366
367
1/2
✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
96 return string_stream.str();
368 48 }
369
370 86 void DbCreator::SetBlobTableNameInGeneralTable(const DatabaseConfigurationCommon* database_configuration_common)
371 {
372
1/2
✓ Branch 1 taken 86 times.
✗ Branch 2 not taken.
86 ostringstream string_stream;
373 string_stream << "INSERT INTO [" << database_configuration_common->GetTableNameForGeneralTableOrThrow() << "]" <<
374 86 "([" << database_configuration_common->GetColumnNameOfGeneralInfoTableOrThrow(DatabaseConfigurationCommon::kGeneralInfoTable_Column_Key) << "], " <<
375 86 "[" << database_configuration_common->GetColumnNameOfGeneralInfoTableOrThrow(DatabaseConfigurationCommon::kGeneralInfoTable_Column_ValueString) << "])" <<
376
18/36
✓ Branch 1 taken 86 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 86 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 86 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 86 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 86 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 86 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 86 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 86 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 86 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 86 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 86 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 86 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 86 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 86 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 86 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 86 times.
✗ Branch 47 not taken.
✓ Branch 49 taken 86 times.
✗ Branch 50 not taken.
✓ Branch 52 taken 86 times.
✗ Branch 53 not taken.
86 " VALUES('" << "BlobTable" << "','" << database_configuration_common->GetTableNameForBlobTableOrThrow() << "');";
377
2/4
✓ Branch 2 taken 86 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 86 times.
✗ Branch 6 not taken.
86 this->db_connection_->Execute(string_stream.str());
378 86 }
379
380 258 /*static*/void DbCreator::ThrowIfDocumentTypeIsNotAsSpecified(const imgdoc2::ICreateOptions* create_options, imgdoc2::DocumentType document_type)
381 {
382
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 258 times.
258 if (create_options->GetDocumentType() != document_type)
383 {
384 throw internal_error_exception("Document type is not as expected");
385 }
386 258 }
387
388 258 std::string DbCreator::GenerateSqlStatementForCreatingMetadataTable_Sqlite(const DatabaseConfigurationCommon* database_configuration_common)
389 {
390
1/2
✓ Branch 1 taken 258 times.
✗ Branch 2 not taken.
258 ostringstream string_stream;
391 string_stream << "CREATE TABLE [" << database_configuration_common->GetTableNameForMetadataTableOrThrow() << "] (" <<
392 258 "[" << database_configuration_common->GetColumnNameOfMetadataTableOrThrow(DatabaseConfigurationCommon::kMetadataTable_Column_Pk) << "] INTEGER PRIMARY KEY," <<
393 258 "[" << database_configuration_common->GetColumnNameOfMetadataTableOrThrow(DatabaseConfigurationCommon::kMetadataTable_Column_Name) << "] TEXT NOT NULL," <<
394 258 "[" << database_configuration_common->GetColumnNameOfMetadataTableOrThrow(DatabaseConfigurationCommon::kMetadataTable_Column_AncestorId) << "] INTEGER," <<
395 258 "[" << database_configuration_common->GetColumnNameOfMetadataTableOrThrow(DatabaseConfigurationCommon::kMetadataTable_Column_TypeDiscriminator) << "] INTEGER," <<
396 258 "[" << database_configuration_common->GetColumnNameOfMetadataTableOrThrow(DatabaseConfigurationCommon::kMetadataTable_Column_ValueDouble) << "] REAL," <<
397 258 "[" << database_configuration_common->GetColumnNameOfMetadataTableOrThrow(DatabaseConfigurationCommon::kMetadataTable_Column_ValueInteger) << "] INTEGER," <<
398 258 "[" << database_configuration_common->GetColumnNameOfMetadataTableOrThrow(DatabaseConfigurationCommon::kMetadataTable_Column_ValueString) << "] TEXT," <<
399 258 "FOREIGN KEY(" << database_configuration_common->GetColumnNameOfMetadataTableOrThrow(DatabaseConfigurationCommon::kMetadataTable_Column_AncestorId) << ") REFERENCES " <<
400 258 database_configuration_common->GetTableNameForMetadataTableOrThrow() << "(" << database_configuration_common->GetColumnNameOfMetadataTableOrThrow(DatabaseConfigurationCommon::kMetadataTable_Column_Pk) << "),"
401 258 "UNIQUE(" << database_configuration_common->GetColumnNameOfMetadataTableOrThrow(DatabaseConfigurationCommon::kMetadataTable_Column_Name) << "," <<
402
49/98
✓ Branch 1 taken 258 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 258 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 258 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 258 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 258 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 258 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 258 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 258 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 258 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 258 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 258 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 258 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 258 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 258 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 258 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 258 times.
✗ Branch 47 not taken.
✓ Branch 49 taken 258 times.
✗ Branch 50 not taken.
✓ Branch 52 taken 258 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 258 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 258 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 258 times.
✗ Branch 62 not taken.
✓ Branch 64 taken 258 times.
✗ Branch 65 not taken.
✓ Branch 67 taken 258 times.
✗ Branch 68 not taken.
✓ Branch 70 taken 258 times.
✗ Branch 71 not taken.
✓ Branch 73 taken 258 times.
✗ Branch 74 not taken.
✓ Branch 76 taken 258 times.
✗ Branch 77 not taken.
✓ Branch 79 taken 258 times.
✗ Branch 80 not taken.
✓ Branch 82 taken 258 times.
✗ Branch 83 not taken.
✓ Branch 85 taken 258 times.
✗ Branch 86 not taken.
✓ Branch 88 taken 258 times.
✗ Branch 89 not taken.
✓ Branch 91 taken 258 times.
✗ Branch 92 not taken.
✓ Branch 94 taken 258 times.
✗ Branch 95 not taken.
✓ Branch 97 taken 258 times.
✗ Branch 98 not taken.
✓ Branch 100 taken 258 times.
✗ Branch 101 not taken.
✓ Branch 103 taken 258 times.
✗ Branch 104 not taken.
✓ Branch 106 taken 258 times.
✗ Branch 107 not taken.
✓ Branch 109 taken 258 times.
✗ Branch 110 not taken.
✓ Branch 112 taken 258 times.
✗ Branch 113 not taken.
✓ Branch 115 taken 258 times.
✗ Branch 116 not taken.
✓ Branch 118 taken 258 times.
✗ Branch 119 not taken.
✓ Branch 121 taken 258 times.
✗ Branch 122 not taken.
✓ Branch 124 taken 258 times.
✗ Branch 125 not taken.
✓ Branch 127 taken 258 times.
✗ Branch 128 not taken.
✓ Branch 130 taken 258 times.
✗ Branch 131 not taken.
✓ Branch 133 taken 258 times.
✗ Branch 134 not taken.
✓ Branch 136 taken 258 times.
✗ Branch 137 not taken.
✓ Branch 139 taken 258 times.
✗ Branch 140 not taken.
✓ Branch 142 taken 258 times.
✗ Branch 143 not taken.
✓ Branch 145 taken 258 times.
✗ Branch 146 not taken.
258 database_configuration_common->GetColumnNameOfMetadataTableOrThrow(DatabaseConfigurationCommon::kMetadataTable_Column_AncestorId) << ") )" << ";";
403 // the combination of Name and AncestorId must be unique, in other words, the names of items with the same ancestor must be unique
404
405
1/2
✓ Branch 1 taken 258 times.
✗ Branch 2 not taken.
516 return string_stream.str();
406 258 }
407