OpenTREP Logo  0.08.01
C++ Open Travel Request Parsing Library
Loading...
Searching...
No Matches
DBManager.cpp
Go to the documentation of this file.
1// //////////////////////////////////////////////////////////////////////
2// Import section
3// //////////////////////////////////////////////////////////////////////
4// STL
5#include <cassert>
6#include <sstream>
7// Boost
8#include <boost/lexical_cast.hpp>
9#include <boost/date_time/gregorian/gregorian.hpp>
10#include <boost/filesystem.hpp>
11#include <boost/algorithm/string.hpp>
12// SOCI
13#include <soci/soci.h>
14#include <soci/sqlite3/soci-sqlite3.h>
15#include <soci/mysql/soci-mysql.h>
16#include <soci/postgresql/soci-postgresql.h>
17// OpenTrep
18#include <opentrep/Location.hpp>
31
32namespace OPENTREP {
33
34 // //////////////////////////////////////////////////////////////////////
36 const DeploymentNumber_T& iDeploymentNumber) {
37 bool oCreationSuccessful = true;
38 try {
39
40 // Retrieve the full file-path of the SQLite3 directory
41 boost::filesystem::path lSQLiteDBFullPath (iSQLDBConnStr.begin(),
42 iSQLDBConnStr.end());
43 // Retrieve the directory hosting the SQLite3 database
44 boost::filesystem::path lSQLiteDBParentPath =
45 lSQLiteDBFullPath.parent_path();
46
47 // DEBUG
48 OPENTREP_LOG_DEBUG ("The SQLite database file ('" << lSQLiteDBFullPath
49 << "') will be cleared and re-created");
50
51 // Delete the SQL database/file and its directory
52 boost::filesystem::remove_all (lSQLiteDBFullPath);
53
54 // Re-create the SQLite3 directory
55 boost::filesystem::create_directories (lSQLiteDBParentPath);
56
57 // Check whether the just created directory exists and is a directory.
58 //boost::filesystem::path lSQLiteDBFilename=lSQLiteDBFullPath.filename();
59 if (!(boost::filesystem::exists (lSQLiteDBParentPath)
60 && boost::filesystem::is_directory (lSQLiteDBParentPath))) {
61 std::ostringstream oStr;
62 oStr << "Error. The path to the SQLite3 database directory ('"
63 << lSQLiteDBParentPath
64 << "') does not exist or is not a directory.";
65 OPENTREP_LOG_ERROR (oStr.str());
66 throw FileNotFoundException (oStr.str());
67 }
68
69 } catch (std::exception const& lException) {
70 std::ostringstream errorStr;
71 errorStr << "Error when trying to create " << iSQLDBConnStr
72 << " SQLite3 database file: " << lException.what();
73 errorStr << ". Check that the program has got write permission on the "
74 << "corresponding parent directories.";
75 OPENTREP_LOG_ERROR (errorStr.str());
76 throw SQLDatabaseFileCannotBeCreatedException (errorStr.str());
77 }
78
79 // DEBUG
80 OPENTREP_LOG_DEBUG ("The SQLite database ('" << iSQLDBConnStr
81 << "') has been cleared and re-created");
82
83 //
84 return oCreationSuccessful;
85 }
86
87 // //////////////////////////////////////////////////////////////////////
89 const DeploymentNumber_T& iDeploymentNumber) {
90 bool oCreationSuccessful = true;
91
92 // DEBUG
93 OPENTREP_LOG_DEBUG ("Create the '"
95 << "' user and '" << DEFAULT_OPENTREP_MYSQL_DB_DBNAME
96 << iDeploymentNumber
97 << "' database in MySQL/MariaDB ('" << iSQLDBConnStr
98 << "')");
99
100 // Connection to the MySQL/MariaDB database
101 soci::session* lSociSession_ptr = NULL;
102 try {
103
104 // Connect to the SQL database/file
105 lSociSession_ptr = DBManager::initSQLDBSession (DBType::MYSQL,
106 iSQLDBConnStr);
107 if (lSociSession_ptr == NULL) {
108 oCreationSuccessful = false;
109 return oCreationSuccessful;
110 }
111
112 } catch (soci::mysql_soci_error const& lSociException) {
113 std::ostringstream errorStr;
114 errorStr << "SOCI-related error when trying to connect to the "
115 << "MySQL/MariaDB database ('" << iSQLDBConnStr
116 << "'). SOCI error message: " << lSociException.what();
117 OPENTREP_LOG_ERROR (errorStr.str());
118 std::cerr << errorStr.str() << std::endl;
119 oCreationSuccessful = false;
120 return oCreationSuccessful;
121 }
122 assert (lSociSession_ptr != NULL);
123 soci::session& lSociSession = *lSociSession_ptr;
124
152
153 try {
154 // Drop user 'trep'@'localhost'
155 std::ostringstream lSQLDropTrepLocalStr;
156 lSQLDropTrepLocalStr << "drop user '"
159 lSociSession << lSQLDropTrepLocalStr.str();
160
161 // Drop user 'trep'@'%'
162 std::ostringstream lSQLDropTrepAllStr;
163 lSQLDropTrepAllStr << "drop user '"
164 << DEFAULT_OPENTREP_MYSQL_DB_USER << "'@'%';";
165 lSociSession << lSQLDropTrepAllStr.str();
166
167 } catch (soci::mysql_soci_error const& lSociException) {
168 std::ostringstream issueStr;
169 issueStr << "Issue when trying to drop MySQL/MariaDB '"
170 << DEFAULT_OPENTREP_MYSQL_DB_USER << "' user. "
171 << "Most probably the user did not exist before. " << std::endl
172 << "SOCI error message: " << lSociException.what() << std::endl
173 << "The database users should however be created without "
174 << "any issue ";
175 OPENTREP_LOG_DEBUG (issueStr.str());
176 std::cout << issueStr.str() << std::endl;
177 }
178
179 try {
180 // Create user 'trep'@'localhost'
181 std::ostringstream lSQLCreateTrepLocalStr;
182 lSQLCreateTrepLocalStr << "create user '"
185 lSQLCreateTrepLocalStr << "identified by '"
187 lSociSession << lSQLCreateTrepLocalStr.str();
188
189 // Grant privileges to 'trep'@'localhost'
190 std::ostringstream lSQLGrantTrepLocalStr;
191 lSQLGrantTrepLocalStr << "grant SELECT, INSERT, UPDATE, DELETE, ";
192 lSQLGrantTrepLocalStr << "CREATE, DROP, FILE, INDEX, ALTER, ";
193 lSQLGrantTrepLocalStr << "CREATE TEMPORARY TABLES, CREATE VIEW, EVENT, ";
194 lSQLGrantTrepLocalStr << "TRIGGER, SHOW VIEW, CREATE ROUTINE, ";
195 lSQLGrantTrepLocalStr << "ALTER ROUTINE, EXECUTE ON *.*";
196 lSQLGrantTrepLocalStr << " to '" << DEFAULT_OPENTREP_MYSQL_DB_USER
197 << "'@'" << DEFAULT_OPENTREP_MYSQL_DB_HOST << "';";
198 lSociSession << lSQLGrantTrepLocalStr.str();
199
200 // Create user 'trep'@'%'
201 std::ostringstream lSQLCreateTrepAllStr;
202 lSQLCreateTrepAllStr << "create user '"
204 << "'@'%' identified by '"
206 lSociSession << lSQLCreateTrepAllStr.str();
207
208 // Grant privileges to 'trep'@'%'
209 std::ostringstream lSQLGrantTrepAllStr;
210 lSQLGrantTrepAllStr << "grant SELECT, INSERT, UPDATE, DELETE, ";
211 lSQLGrantTrepAllStr << "CREATE, DROP, FILE, INDEX, ALTER, ";
212 lSQLGrantTrepAllStr << "CREATE TEMPORARY TABLES, CREATE VIEW, EVENT, ";
213 lSQLGrantTrepAllStr << "TRIGGER, SHOW VIEW, CREATE ROUTINE, ";
214 lSQLGrantTrepAllStr << "ALTER ROUTINE, EXECUTE ON *.*";
215 lSQLGrantTrepAllStr << " to '" << DEFAULT_OPENTREP_MYSQL_DB_USER
216 << "'@'%';";
217 lSociSession << lSQLGrantTrepAllStr.str();
218
219 // Flush privileges
220 std::ostringstream lSQLFlushPrivilegesStr;
221 lSQLFlushPrivilegesStr << "flush privileges;";
222 lSociSession << lSQLFlushPrivilegesStr.str();
223
224 } catch (soci::mysql_soci_error const& lSociException) {
225 oCreationSuccessful = false;
226 std::ostringstream errorStr;
227 errorStr << "SOCI-related error when trying to create MySQL/MariaDB "
229 << "' user. Error message: " << lSociException.what();
230 OPENTREP_LOG_ERROR (errorStr.str());
231 std::cerr << errorStr.str() << std::endl;
232 oCreationSuccessful = false;
233 return oCreationSuccessful;
234 }
235
244 try {
245 // Drop the 'trep_trep' database, if existing
246 std::ostringstream lSQLDropDBStr;
247 lSQLDropDBStr << "drop database if exists "
248 << DEFAULT_OPENTREP_MYSQL_DB_DBNAME << iDeploymentNumber
249 << ";";
250 lSociSession << lSQLDropDBStr.str();
251
252 // Create the 'trep_trep' database
253 std::ostringstream lSQLCreateDBStr;
254 lSQLCreateDBStr << "create database if not exists "
255 << DEFAULT_OPENTREP_MYSQL_DB_DBNAME << iDeploymentNumber;
256 lSQLCreateDBStr << " default character set utf8mb4";
257 lSQLCreateDBStr << " collate utf8mb4_unicode_ci;";
258 lSociSession << lSQLCreateDBStr.str();
259
260 } catch (soci::mysql_soci_error const& lSociException) {
261 oCreationSuccessful = false;
262 std::ostringstream errorStr;
263 errorStr << "SOCI-related error when trying to create MySQL/MariaDB "
264 << "'" << DEFAULT_OPENTREP_MYSQL_DB_DBNAME << iDeploymentNumber
265 << "' database with 'utf8mb4' as character set. "
266 << "Error message: " << lSociException.what();
267 OPENTREP_LOG_ERROR (errorStr.str());
268 std::cerr << errorStr.str() << std::endl;
269 }
270 if (oCreationSuccessful == false) {
271 try {
272 // Drop the 'trep_trep' database, if existing
273 std::ostringstream lSQLDropDBStr;
274 lSQLDropDBStr << "drop database if exists "
275 << DEFAULT_OPENTREP_MYSQL_DB_DBNAME << iDeploymentNumber
276 << ";";
277 lSociSession << lSQLDropDBStr.str();
278
279 // Create the 'trep_trep' database
280 std::ostringstream lSQLCreateDBStr;
281 lSQLCreateDBStr << "create database if not exists "
283 << iDeploymentNumber;
284 lSQLCreateDBStr << " default character set utf8";
285 lSQLCreateDBStr << " collate utf8_unicode_ci;";
286 lSociSession << lSQLCreateDBStr.str();
287
288 } catch (soci::mysql_soci_error const& lSociException) {
289 oCreationSuccessful = false;
290 std::ostringstream errorStr;
291 errorStr << "SOCI-related error when trying to create MySQL/MariaDB "
293 << iDeploymentNumber
294 << "' database. Error message: " << lSociException.what();
295 OPENTREP_LOG_ERROR (errorStr.str());
296 std::cerr << errorStr.str() << std::endl;
297 oCreationSuccessful = false;
298 return oCreationSuccessful;
299 }
300 }
301
302 // DEBUG
304 << "' user and '" << DEFAULT_OPENTREP_MYSQL_DB_DBNAME
305 << iDeploymentNumber
306 << "' database have been created in MySQL/MariaDB ('"
307 << iSQLDBConnStr << "')");
308 //
309 return oCreationSuccessful;
310 }
311
312 // //////////////////////////////////////////////////////////////////////
314 const DeploymentNumber_T& iDeploymentNumber) {
315 bool oCreationSuccessful = true;
316
317
318 // DEBUG
319 OPENTREP_LOG_DEBUG ("Create the '"
321 << "' user and '" << DEFAULT_OPENTREP_PG_DB_DBNAME
322 << iDeploymentNumber
323 << "' database in PostgreSQL ('" << iSQLDBConnStr
324 << "')");
325
326 // Connection to the PostgreSQL database
327 soci::session* lSociSession_ptr = NULL;
328 try {
329
330 // Connect to the SQL database/file
331 lSociSession_ptr = DBManager::initSQLDBSession (DBType::PG,
332 iSQLDBConnStr);
333 if (lSociSession_ptr == NULL) {
334 oCreationSuccessful = false;
335 return oCreationSuccessful;
336 }
337
338 } catch (soci::postgresql_soci_error const& lSociException) {
339 std::ostringstream errorStr;
340 errorStr << "SOCI-related error when trying to connect to the "
341 << "PostgreSQL database ('" << iSQLDBConnStr
342 << "'). SOCI error message: " << lSociException.what();
343 OPENTREP_LOG_ERROR (errorStr.str());
344 std::cerr << errorStr.str() << std::endl;
345 oCreationSuccessful = false;
346 return oCreationSuccessful;
347 }
348 assert (lSociSession_ptr != NULL);
349 soci::session& lSociSession = *lSociSession_ptr;
350
366
367 try {
368 // Drop role 'trep' if it already exists
369 std::ostringstream lSQLDropRoleStr;
370 lSQLDropRoleStr << "DROP ROLE IF EXISTS "
372 lSociSession << lSQLDropRoleStr.str();
373
374 // Create role 'trep' with login and password
375 std::ostringstream lSQLCreateRoleStr;
376 lSQLCreateRoleStr << "CREATE ROLE " << DEFAULT_OPENTREP_PG_DB_USER
377 << " WITH LOGIN ENCRYPTED PASSWORD '"
379 lSociSession << lSQLCreateRoleStr.str();
380
381 } catch (soci::postgresql_soci_error const& lSociException) {
382 oCreationSuccessful = false;
383 std::ostringstream errorStr;
384 errorStr << "SOCI-related error when trying to create PostgreSQL role '"
386 << "'. Error message: " << lSociException.what();
387 OPENTREP_LOG_ERROR (errorStr.str());
388 std::cerr << errorStr.str() << std::endl;
389 return oCreationSuccessful;
390 }
391
392 try {
393 // Drop the 'trep_trep<N>' database if it exists
394 std::ostringstream lSQLDropDBStr;
395 lSQLDropDBStr << "DROP DATABASE IF EXISTS "
396 << DEFAULT_OPENTREP_PG_DB_DBNAME << iDeploymentNumber
397 << ";";
398 lSociSession << lSQLDropDBStr.str();
399
400 // Create the 'trep_trep<N>' database
401 std::ostringstream lSQLCreateDBStr;
402 lSQLCreateDBStr << "CREATE DATABASE "
403 << DEFAULT_OPENTREP_PG_DB_DBNAME << iDeploymentNumber
404 << " WITH OWNER " << DEFAULT_OPENTREP_PG_DB_USER
405 << " ENCODING 'UTF8' TEMPLATE template0;";
406 lSociSession << lSQLCreateDBStr.str();
407
408 } catch (soci::postgresql_soci_error const& lSociException) {
409 oCreationSuccessful = false;
410 std::ostringstream errorStr;
411 errorStr << "SOCI-related error when trying to create PostgreSQL database '"
412 << DEFAULT_OPENTREP_PG_DB_DBNAME << iDeploymentNumber
413 << "'. Error message: " << lSociException.what();
414 OPENTREP_LOG_ERROR (errorStr.str());
415 std::cerr << errorStr.str() << std::endl;
416 return oCreationSuccessful;
417 }
418
419 // DEBUG
421 << "' role and '"
422 << DEFAULT_OPENTREP_PG_DB_DBNAME << iDeploymentNumber
423 << "' database have been created in PostgreSQL ('"
424 << iSQLDBConnStr << "')");
425 //
426 return oCreationSuccessful;
427 }
428
429 // //////////////////////////////////////////////////////////////////////
431 createSQLDBUser (const DBType& iDBType,
432 const SQLDBConnectionString_T& iSQLDBConnStr,
433 const DeploymentNumber_T& iDeploymentNumber) {
434 bool oCreationSuccessful = true;
435
436 // Retrieve the enum, so that the switch-case statement works
437 const DBType::EN_DBType& dbType = iDBType.getType();
438
439 switch (dbType) {
440 case DBType::SQLITE3: {
441 oCreationSuccessful = createSQLDBUserOnSQLite(iSQLDBConnStr,
442 iDeploymentNumber);
443 break;
444 }
445
446 case DBType::MYSQL: {
447 oCreationSuccessful = createSQLDBUserOnMySQL(iSQLDBConnStr,
448 iDeploymentNumber);
449
450 break;
451 }
452
453 case DBType::PG: {
454 oCreationSuccessful = createSQLDBUserOnPG(iSQLDBConnStr,
455 iDeploymentNumber);
456
457 break;
458 }
459
460 default: {
461 break;
462 }
463 }
464
465 return oCreationSuccessful;
466 }
467
468 // //////////////////////////////////////////////////////////////////////
469 soci::session* DBManager::
470 initSQLDBSession (const DBType& iDBType,
471 const SQLDBConnectionString_T& iSQLDBConnStr) {
472 soci::session* oSociSession_ptr = NULL;
473
474 // Retrieve the enum, so that the switch-case statement works
475 const DBType::EN_DBType& dbType = iDBType.getType();
476
477 // DEBUG
478 if (dbType != DBType::NODB) {
479 OPENTREP_LOG_DEBUG ("Connecting to the " << iDBType.describe()
480 << " SQL database/file ('" << iSQLDBConnStr << "')");
481 }
482
483 switch (dbType) {
484 case DBType::SQLITE3: {
485 // Check that the directory hosting the SQLite database exists
486 const bool existSQLDBDir =
487 FileManager::checkSQLiteDirectory (iSQLDBConnStr);
488 if (existSQLDBDir == false) {
489 std::ostringstream errorStr;
490 errorStr << "Error when trying to connect to the '" << iSQLDBConnStr
491 << "' SQLite3 database; the directory hosting that "
492 << "database does not exist or is not readable";
493 OPENTREP_LOG_ERROR (errorStr.str());
494 throw SQLDatabaseImpossibleConnectionException (errorStr.str());
495 }
496
497 try {
498
499 // Connect to the SQL database.
500 oSociSession_ptr = new soci::session();
501 assert (oSociSession_ptr != NULL);
502 soci::session& lSociSession = *oSociSession_ptr;
503 lSociSession.open (soci::sqlite3, iSQLDBConnStr);
504
505 // DEBUG
506 OPENTREP_LOG_DEBUG ("The SQLite3 database/file ('" << iSQLDBConnStr
507 << "') has been checked and opened");
508
509 } catch (std::exception const& lException) {
510 std::ostringstream errorStr;
511 errorStr << "Error when trying to connect to the '" << iSQLDBConnStr
512 << "' SQLite3 database: " << lException.what();
513 OPENTREP_LOG_ERROR (errorStr.str());
514 throw SQLDatabaseImpossibleConnectionException (errorStr.str());
515 }
516
517 // The SQLite3 connection is assumed to have been successful
518 assert (oSociSession_ptr != NULL);
519
520 break;
521 }
522
523 case DBType::MYSQL: {
524 try {
525
526 // Connect to the SQL database.
527 oSociSession_ptr = new soci::session();
528 assert (oSociSession_ptr != NULL);
529 soci::session& lSociSession = *oSociSession_ptr;
530 lSociSession.open (soci::mysql, iSQLDBConnStr);
531
532 // DEBUG
533 OPENTREP_LOG_DEBUG ("The " << iDBType.describe() << " database ("
534 << iSQLDBConnStr << ") is accessible");
535
536 } catch (std::exception const& lException) {
537 std::ostringstream errorStr;
538 errorStr << "Error when trying to connect to the '" << iSQLDBConnStr
539 << "' MySQL/MariaDB database: " << lException.what();
540 OPENTREP_LOG_ERROR (errorStr.str());
541 throw SQLDatabaseImpossibleConnectionException (errorStr.str());
542 }
543
544 // The MySQL/MariaDB connection is assumed to have been successful
545 assert (oSociSession_ptr != NULL);
546
547 break;
548 }
549
550 case DBType::PG: {
551 try {
552
553 // Connect to the SQL database.
554 oSociSession_ptr = new soci::session();
555 assert (oSociSession_ptr != NULL);
556 soci::session& lSociSession = *oSociSession_ptr;
557 lSociSession.open (soci::postgresql, iSQLDBConnStr);
558
559 // DEBUG
560 OPENTREP_LOG_DEBUG ("The " << iDBType.describe() << " database ("
561 << iSQLDBConnStr << ") is accessible");
562
563 } catch (std::exception const& lException) {
564 std::ostringstream errorStr;
565 errorStr << "Error when trying to connect to the '" << iSQLDBConnStr
566 << "' PostgreSQL database: " << lException.what();
567 OPENTREP_LOG_ERROR (errorStr.str());
568 throw SQLDatabaseImpossibleConnectionException (errorStr.str());
569 }
570
571 // The PostgreSQL connection is assumed to have been successful
572 assert (oSociSession_ptr != NULL);
573
574 break;
575 }
576
577 case DBType::NODB: {
578 // Do nothing
579
580 break;
581 }
582
583 default: {
584 std::ostringstream errorStr;
585 errorStr << "Error: the '" << iDBType.describe()
586 << "' SQL database type is not supported";
587 OPENTREP_LOG_ERROR (errorStr.str());
588 throw SQLDatabaseTableCreationException (errorStr.str());
589 break;
590 }
591 }
592
593 return oSociSession_ptr;
594 }
595
596 // //////////////////////////////////////////////////////////////////////
598 terminateSQLDBSession (const DBType& iDBType,
599 const SQLDBConnectionString_T& iSQLDBConnStr,
600 soci::session& ioSociSession) {
601 // Retrieve the enum, so that the switch-case statement works
602 const DBType::EN_DBType& dbType = iDBType.getType();
603
604 // DEBUG
605 if (dbType != DBType::NODB) {
606 OPENTREP_LOG_DEBUG ("Connecting to the " << iDBType.describe()
607 << " SQL database/file ('" << iSQLDBConnStr << "')");
608 }
609
610 switch (dbType) {
611 case DBType::SQLITE3: {
612 try {
613
614 // Release the SQL database connection
615 ioSociSession.close();
616
617 } catch (std::exception const& lException) {
618 std::ostringstream errorStr;
619 errorStr << "Error when trying to release the connection ('"
620 << iSQLDBConnStr
621 << "') to the SQLite3 database: " << lException.what();
622 OPENTREP_LOG_ERROR (errorStr.str());
623 throw SQLDatabaseConnectionReleaseException (errorStr.str());
624 }
625
626 break;
627 }
628
629 case DBType::PG: {
630 try {
631
632 // Release the SQL database connection
633 ioSociSession.close();
634
635 } catch (std::exception const& lException) {
636 std::ostringstream errorStr;
637 errorStr << "Error when trying to release the connection ('"
638 << iSQLDBConnStr
639 << "') to the PostgreSQL database: " << lException.what();
640 OPENTREP_LOG_ERROR (errorStr.str());
641 throw SQLDatabaseConnectionReleaseException (errorStr.str());
642 }
643
644 break;
645 }
646
647 case DBType::MYSQL: {
648 try {
649
650 // Release the SQL database connection
651 ioSociSession.close();
652
653 } catch (std::exception const& lException) {
654 std::ostringstream errorStr;
655 errorStr << "Error when trying to release the connection ('"
656 << iSQLDBConnStr
657 << "') to the MySQL/MariaDB database: " << lException.what();
658 OPENTREP_LOG_ERROR (errorStr.str());
659 throw SQLDatabaseConnectionReleaseException (errorStr.str());
660 }
661 break;
662 }
663
664 case DBType::NODB: {
665 // Do nothing
666
667 break;
668 }
669
670 default: {
671 std::ostringstream errorStr;
672 errorStr << "Error: the '" << iDBType.describe()
673 << "' SQL database type is not supported";
674 OPENTREP_LOG_ERROR (errorStr.str());
675 throw SQLDatabaseTableCreationException (errorStr.str());
676 }
677 }
678 }
679
680 // //////////////////////////////////////////////////////////////////////
681 void DBManager::createSQLDBTables (soci::session& ioSociSession) {
682 const std::string& lDBName = ioSociSession.get_backend_name();
683 const DBType lDBType (lDBName);
684
685 // Retrieve the enum, so that the switch-case statement works
686 const DBType::EN_DBType& dbType = lDBType.getType();
687
688 // DEBUG
689 if (dbType != DBType::NODB) {
690 OPENTREP_LOG_DEBUG ("The tables of the " << lDBType.describe()
691 << " SQL database/file will be created/reset");
692 }
693
694 switch (dbType) {
695 case DBType::SQLITE3: {
696 // DEBUG
697 OPENTREP_LOG_DEBUG ("Create the optd_por table in the SQLite3 database");
698
699 try {
700
720
721 ioSociSession << "drop table if exists optd_por;";
722 std::ostringstream lSQLTableCreationStr;
723 lSQLTableCreationStr << "create table optd_por (";
724 lSQLTableCreationStr << "pk varchar(20) NOT NULL, ";
725 lSQLTableCreationStr << "location_type varchar(4) default NULL, ";
726 lSQLTableCreationStr << "iata_code varchar(3) default NULL, ";
727 lSQLTableCreationStr << "icao_code varchar(4) default NULL, ";
728 lSQLTableCreationStr << "faa_code varchar(4) default NULL, ";
729 lSQLTableCreationStr << "unlocode_code varchar(5) default NULL, ";
730 lSQLTableCreationStr << "uic_code int(11) default NULL, ";
731 lSQLTableCreationStr << "is_geonames varchar(1) default NULL, ";
732 lSQLTableCreationStr << "geoname_id int(11) default NULL, ";
733 lSQLTableCreationStr << "envelope_id int(11) default NULL, ";
734 lSQLTableCreationStr << "date_from date default NULL, ";
735 lSQLTableCreationStr << "date_until date default NULL, ";
736 lSQLTableCreationStr << "serialised_place varchar(12000) default NULL);";
737 ioSociSession << lSQLTableCreationStr.str();
738
739 } catch (std::exception const& lException) {
740 std::ostringstream errorStr;
741 errorStr << "Error when trying to create SQLite3 tables: "
742 << lException.what();
743 OPENTREP_LOG_ERROR (errorStr.str());
744 throw SQLDatabaseTableCreationException (errorStr.str());
745 }
746
747 // DEBUG
748 OPENTREP_LOG_DEBUG ("The optd_por table has been created in the SQLite3 database");
749 break;
750 }
751
752 case DBType::PG: {
753 // DEBUG
754 OPENTREP_LOG_DEBUG ("Create the optd_por table in the PostgreSQL database");
755
756 try {
757
777
778 ioSociSession << "drop table if exists optd_por;";
779 std::ostringstream lSQLTableCreationStr;
780 lSQLTableCreationStr << "create table optd_por (";
781 lSQLTableCreationStr << "pk varchar(20) NOT NULL, ";
782 lSQLTableCreationStr << "location_type varchar(4) default NULL, ";
783 lSQLTableCreationStr << "iata_code varchar(3) default NULL, ";
784 lSQLTableCreationStr << "icao_code varchar(4) default NULL, ";
785 lSQLTableCreationStr << "faa_code varchar(4) default NULL, ";
786 lSQLTableCreationStr << "unlocode_code varchar(5) default NULL, ";
787 lSQLTableCreationStr << "uic_code integer default NULL, ";
788 lSQLTableCreationStr << "is_geonames varchar(1) default NULL, ";
789 lSQLTableCreationStr << "geoname_id integer default NULL, ";
790 lSQLTableCreationStr << "envelope_id integer default NULL, ";
791 lSQLTableCreationStr << "date_from date default NULL, ";
792 lSQLTableCreationStr << "date_until date default NULL, ";
793 lSQLTableCreationStr << "serialised_place varchar(12000) default NULL);";
794 ioSociSession << lSQLTableCreationStr.str();
795
796 } catch (std::exception const& lException) {
797 std::ostringstream errorStr;
798 errorStr << "Error when trying to create PostgreSQL tables: "
799 << lException.what();
800 OPENTREP_LOG_ERROR (errorStr.str());
801 throw SQLDatabaseTableCreationException (errorStr.str());
802 }
803
804 // DEBUG
805 OPENTREP_LOG_DEBUG ("The optd_por table has been created in the "
806 "PostgreSQL database");
807 break;
808 }
809
810 case DBType::MYSQL: {
811 // DEBUG
812 OPENTREP_LOG_DEBUG ("Create the optd_por table in the MySQL database");
813
814 try {
815
835
836 ioSociSession << "drop table if exists optd_por;";
837 std::ostringstream lSQLTableCreationStr;
838 lSQLTableCreationStr << "create table optd_por (";
839 lSQLTableCreationStr << "pk varchar(20) NOT NULL, ";
840 lSQLTableCreationStr << "location_type varchar(4) default NULL, ";
841 lSQLTableCreationStr << "iata_code varchar(3) default NULL, ";
842 lSQLTableCreationStr << "icao_code varchar(4) default NULL, ";
843 lSQLTableCreationStr << "faa_code varchar(4) default NULL, ";
844 lSQLTableCreationStr << "unlocode_code varchar(5) default NULL, ";
845 lSQLTableCreationStr << "uic_code int(11) default NULL, ";
846 lSQLTableCreationStr << "is_geonames varchar(1) default NULL, ";
847 lSQLTableCreationStr << "geoname_id int(11) default NULL, ";
848 lSQLTableCreationStr << "envelope_id int(11) default NULL, ";
849 lSQLTableCreationStr << "date_from date default NULL, ";
850 lSQLTableCreationStr << "date_until date default NULL, ";
851 lSQLTableCreationStr << "serialised_place varchar(12000) default NULL); ";
852 ioSociSession << lSQLTableCreationStr.str();
853
854 } catch (std::exception const& lException) {
855 std::ostringstream errorStr;
856 errorStr << "Error when trying to create MySQL/MariaDB tables: "
857 << lException.what();
858 OPENTREP_LOG_ERROR (errorStr.str());
859 throw SQLDatabaseTableCreationException (errorStr.str());
860 }
861
862 // DEBUG
863 OPENTREP_LOG_DEBUG ("The optd_por table has been created in the MySQL database");
864
865 break;
866 }
867
868 case DBType::NODB: {
869 // Do nothing
870
871 break;
872 }
873
874 default: {
875 std::ostringstream errorStr;
876 errorStr << "Error: the '" << lDBName
877 << "' SQL database type is not supported";
878 OPENTREP_LOG_ERROR (errorStr.str());
879 throw SQLDatabaseTableCreationException (errorStr.str());
880 break;
881 }
882 }
883 }
884
885 // //////////////////////////////////////////////////////////////////////
886 void DBManager::createSQLDBIndexes (soci::session& ioSociSession) {
887 const std::string& lDBName = ioSociSession.get_backend_name();
888 const DBType lDBType (lDBName);
889
890 // Retrieve the enum, so that the switch-case statement works
891 const DBType::EN_DBType& dbType = lDBType.getType();
892
893 // DEBUG
894 if (dbType != DBType::NODB) {
895 OPENTREP_LOG_DEBUG ("The indexes of the " << lDBType.describe()
896 << " SQL database/file will be created/reset");
897 }
898
899 switch (dbType) {
900 case DBType::SQLITE3: {
901 // DEBUG
902 OPENTREP_LOG_DEBUG ("Create the indices for the SQLite3 database");
903
904 try {
905
916
917 ioSociSession
918 << "create index optd_por_iata_code on optd_por (iata_code);";
919 ioSociSession
920 << "create index optd_por_iata_date on optd_por (iata_code, date_from, date_until);";
921 ioSociSession
922 << "create index optd_por_icao_code on optd_por (icao_code);";
923 ioSociSession
924 << "create index optd_por_geonameid on optd_por (geoname_id);";
925 ioSociSession
926 << "create index optd_por_unlocode_code on optd_por (unlocode_code);";
927 ioSociSession
928 << "create index optd_por_uic_code on optd_por (uic_code);";
929
930 } catch (std::exception const& lException) {
931 std::ostringstream errorStr;
932 errorStr << "Error when trying to create SQLite3 indexes: "
933 << lException.what();
934 OPENTREP_LOG_ERROR (errorStr.str());
935 throw SQLDatabaseIndexCreationException (errorStr.str());
936 }
937
938 // DEBUG
939 OPENTREP_LOG_DEBUG ("The indices have been created "
940 "for the SQLite3 database");
941 break;
942 }
943
944 case DBType::PG: {
945 // DEBUG
946 OPENTREP_LOG_DEBUG ("Create the indices for the PostgreSQL database");
947
948 try {
949
961
962 ioSociSession
963 << "create unique index optd_por_pk on optd_por (pk);";
964 ioSociSession
965 << "create index optd_por_iata_code on optd_por (iata_code asc);";
966 ioSociSession
967 << "create index optd_por_iata_date on optd_por (iata_code asc, date_from asc, date_until asc);";
968 ioSociSession
969 << "create index optd_por_icao_code on optd_por (icao_code asc);";
970 ioSociSession
971 << "create index optd_por_geonameid on optd_por (geoname_id asc);";
972 ioSociSession
973 << "create index optd_por_unlocode_code on optd_por (unlocode_code asc);";
974 ioSociSession
975 << "create index optd_por_uic_code on optd_por (uic_code asc);";
976
977 } catch (std::exception const& lException) {
978 std::ostringstream errorStr;
979 errorStr << "Error when trying to create PostgreSQL indices: "
980 << lException.what();
981 OPENTREP_LOG_ERROR (errorStr.str());
982 throw SQLDatabaseIndexCreationException (errorStr.str());
983 }
984
985 // DEBUG
986 OPENTREP_LOG_DEBUG ("The indices have been created "
987 "for the PostgreSQL database");
988 break;
989 }
990
991 case DBType::MYSQL: {
992 // DEBUG
993 OPENTREP_LOG_DEBUG ("Create the indices for the MySQL database");
994
995 try {
996
1009
1010 ioSociSession
1011 << "alter table optd_por add unique index optd_por_pk (pk asc);";
1012 ioSociSession
1013 << "alter table optd_por add index optd_por_iata_code (iata_code asc);";
1014 ioSociSession
1015 << "alter table optd_por add index optd_por_iata_date (iata_code asc, date_from asc, date_until asc);";
1016 ioSociSession
1017 << "alter table optd_por add index optd_por_icao_code (icao_code asc);";
1018 ioSociSession
1019 << "alter table optd_por add index optd_por_geonameid (geoname_id asc);";
1020 ioSociSession
1021 << "alter table optd_por add index optd_por_unlocode_code (unlocode_code asc);";
1022 ioSociSession
1023 << "alter table optd_por add index optd_por_uic_code (uic_code asc);";
1024
1025 } catch (std::exception const& lException) {
1026 std::ostringstream errorStr;
1027 errorStr << "Error when trying to create MySQL/MariaDB indices: "
1028 << lException.what();
1029 OPENTREP_LOG_ERROR (errorStr.str());
1030 throw SQLDatabaseIndexCreationException (errorStr.str());
1031 }
1032
1033 // DEBUG
1034 OPENTREP_LOG_DEBUG ("The indices have been created "
1035 "for the MySQL/MariaDB database");
1036
1037 break;
1038 }
1039
1040 case DBType::NODB: {
1041 // Do nothing
1042 break;
1043 }
1044
1045 default: {
1046 std::ostringstream errorStr;
1047 errorStr << "Error: the '" << lDBName
1048 << "' SQL database type is not supported";
1049 OPENTREP_LOG_ERROR (errorStr.str());
1050 throw SQLDatabaseIndexCreationException (errorStr.str());
1051 break;
1052 }
1053 }
1054 }
1055
1056 // //////////////////////////////////////////////////////////////////////
1057 std::string DBManager::
1058 prepareSelectAllBlobStatement (soci::session& ioSociSession,
1059 soci::statement& ioSelectStatement) {
1060 std::string oSerialisedPlaceStr;
1061
1062 try {
1063
1064 // Instanciate a SQL statement (no request is performed at that stage)
1068
1069 ioSelectStatement = (ioSociSession.prepare
1070 << "select serialised_place from optd_por",
1071 soci::into (oSerialisedPlaceStr));
1072
1073 // Execute the SQL query
1074 ioSelectStatement.execute();
1075
1076 } catch (std::exception const& lException) {
1077 std::ostringstream errorStr;
1078 errorStr
1079 << "Error in the 'select serialised_place from optd_por' SQL request: "
1080 << lException.what();
1081 OPENTREP_LOG_ERROR (errorStr.str());
1082 throw SQLDatabaseException (errorStr.str());
1083 }
1084
1085 //
1086 return oSerialisedPlaceStr;
1087 }
1088
1089 // //////////////////////////////////////////////////////////////////////
1090 void DBManager::
1091 prepareSelectBlobOnIataCodeStatement (soci::session& ioSociSession,
1092 soci::statement& ioSelectStatement,
1093 const std::string& iIataCode,
1094 std::string& ioSerialisedPlaceStr) {
1095
1096 try {
1097
1098 // Instanciate a SQL statement (no request is performed at that stage)
1102 ioSelectStatement = (ioSociSession.prepare
1103 << "select serialised_place from optd_por "
1104 << "where iata_code = :place_iata_code",
1105 soci::use (iIataCode),
1106 soci::into (ioSerialisedPlaceStr));
1107
1108 // Execute the SQL query
1109 ioSelectStatement.execute();
1110
1111 } catch (std::exception const& lException) {
1112 std::ostringstream errorStr;
1113 errorStr
1114 << "Error in the 'select serialised_place from optd_por' SQL request: "
1115 << lException.what();
1116 OPENTREP_LOG_ERROR (errorStr.str());
1117 throw SQLDatabaseException (errorStr.str());
1118 }
1119 }
1120
1121 // //////////////////////////////////////////////////////////////////////
1122 void DBManager::
1123 prepareSelectBlobOnIcaoCodeStatement (soci::session& ioSociSession,
1124 soci::statement& ioSelectStatement,
1125 const std::string& iIcaoCode,
1126 std::string& ioSerialisedPlaceStr) {
1127
1128 try {
1129
1130 // Instanciate a SQL statement (no request is performed at that stage)
1134 ioSelectStatement = (ioSociSession.prepare
1135 << "select serialised_place from optd_por "
1136 << "where icao_code = :place_icao_code",
1137 soci::use (iIcaoCode),
1138 soci::into (ioSerialisedPlaceStr));
1139
1140 // Execute the SQL query
1141 ioSelectStatement.execute();
1142
1143 } catch (std::exception const& lException) {
1144 std::ostringstream errorStr;
1145 errorStr
1146 << "Error in the 'select serialised_place from optd_por' SQL request: "
1147 << lException.what();
1148 OPENTREP_LOG_ERROR (errorStr.str());
1149 throw SQLDatabaseException (errorStr.str());
1150 }
1151 }
1152
1153 // //////////////////////////////////////////////////////////////////////
1154 void DBManager::
1155 prepareSelectBlobOnFaaCodeStatement (soci::session& ioSociSession,
1156 soci::statement& ioSelectStatement,
1157 const std::string& iFaaCode,
1158 std::string& ioSerialisedPlaceStr) {
1159
1160 try {
1161
1162 // Instanciate a SQL statement (no request is performed at that stage)
1166 ioSelectStatement = (ioSociSession.prepare
1167 << "select serialised_place from optd_por "
1168 << "where faa_code = :place_faa_code",
1169 soci::use (iFaaCode),
1170 soci::into (ioSerialisedPlaceStr));
1171
1172 // Execute the SQL query
1173 ioSelectStatement.execute();
1174
1175 } catch (std::exception const& lException) {
1176 std::ostringstream errorStr;
1177 errorStr
1178 << "Error in the 'select serialised_place from optd_por' SQL request: "
1179 << lException.what();
1180 OPENTREP_LOG_ERROR (errorStr.str());
1181 throw SQLDatabaseException (errorStr.str());
1182 }
1183 }
1184
1185 // //////////////////////////////////////////////////////////////////////
1186 void DBManager::
1187 prepareSelectBlobOnUNLOCodeStatement (soci::session& ioSociSession,
1188 soci::statement& ioSelectStatement,
1189 const std::string& iUNLOCode,
1190 std::string& ioSerialisedPlaceStr) {
1191
1192 try {
1193
1194 // Instanciate a SQL statement (no request is performed at that stage)
1198 ioSelectStatement = (ioSociSession.prepare
1199 << "select serialised_place from optd_por "
1200 << "where unlocode_code = :place_unlocode_code",
1201 soci::use (iUNLOCode),
1202 soci::into (ioSerialisedPlaceStr));
1203
1204 // Execute the SQL query
1205 ioSelectStatement.execute();
1206
1207 } catch (std::exception const& lException) {
1208 std::ostringstream errorStr;
1209 errorStr
1210 << "Error in the 'select serialised_place from optd_por' SQL request: "
1211 << lException.what();
1212 OPENTREP_LOG_ERROR (errorStr.str());
1213 throw SQLDatabaseException (errorStr.str());
1214 }
1215 }
1216
1217 // //////////////////////////////////////////////////////////////////////
1218 void DBManager::
1219 prepareSelectBlobOnUICCodeStatement (soci::session& ioSociSession,
1220 soci::statement& ioSelectStatement,
1221 const UICCode_T& iUICCode,
1222 std::string& ioSerialisedPlaceStr) {
1223
1224 try {
1225
1226 // Instanciate a SQL statement (no request is performed at that stage)
1230 ioSelectStatement = (ioSociSession.prepare
1231 << "select serialised_place from optd_por "
1232 << "where uic_code = :place_uic_code",
1233 soci::use (iUICCode),
1234 soci::into (ioSerialisedPlaceStr));
1235
1236 // Execute the SQL query
1237 ioSelectStatement.execute();
1238
1239 } catch (std::exception const& lException) {
1240 std::ostringstream errorStr;
1241 errorStr
1242 << "Error in the 'select serialised_place from optd_por' SQL request: "
1243 << lException.what();
1244 OPENTREP_LOG_ERROR (errorStr.str());
1245 throw SQLDatabaseException (errorStr.str());
1246 }
1247 }
1248
1249 // //////////////////////////////////////////////////////////////////////
1250 void DBManager::
1251 prepareSelectBlobOnPlaceGeoIDStatement (soci::session& ioSociSession,
1252 soci::statement& ioSelectStatement,
1253 const GeonamesID_T& iGeonameID,
1254 std::string& ioSerialisedPlaceStr) {
1255
1256 try {
1257
1258 // Instanciate a SQL statement (no request is performed at that stage)
1262 ioSelectStatement = (ioSociSession.prepare
1263 << "select serialised_place from optd_por "
1264 << "where geoname_id = :place_geoname_id",
1265 soci::use (iGeonameID),
1266 soci::into (ioSerialisedPlaceStr));
1267
1268 // Execute the SQL query
1269 ioSelectStatement.execute();
1270
1271 } catch (std::exception const& lException) {
1272 std::ostringstream errorStr;
1273 errorStr
1274 << "Error in the 'select serialised_place from optd_por' SQL request: "
1275 << lException.what();
1276 OPENTREP_LOG_ERROR (errorStr.str());
1277 throw SQLDatabaseException (errorStr.str());
1278 }
1279 }
1280
1281 // //////////////////////////////////////////////////////////////////////
1282 bool DBManager::iterateOnStatement (soci::statement& ioStatement,
1283 const std::string& iSerialisedPlaceStr) {
1284 bool hasStillData = false;
1285
1286 try {
1287
1288 // Retrieve the next row of Place object
1289 hasStillData = ioStatement.fetch();
1290
1291 } catch (std::exception const& lException) {
1292 std::ostringstream errorStr;
1293 errorStr << "Error when iterating on the SQL fetch: " << lException.what();
1294 errorStr << ". The current place is: " << iSerialisedPlaceStr;
1295 OPENTREP_LOG_ERROR (errorStr.str());
1296 throw SQLDatabaseException (errorStr.str());
1297 }
1298
1299 return hasStillData;
1300 }
1301
1302 // //////////////////////////////////////////////////////////////////////
1303 void DBManager::insertPlaceInDB (soci::session& ioSociSession,
1304 const Place& iPlace) {
1305
1306 try {
1307
1308 // Begin a transaction on the database
1309 ioSociSession.begin();
1310
1311 // Instanciate a SQL statement (no request is performed at that stage)
1312 const LocationKey& lLocationKey = iPlace.getKey();
1313 const std::string lPK (lLocationKey.toString());
1314 const IATAType& lIataType = iPlace.getIataType();
1315 const std::string lLocationType (lIataType.getTypeAsString());
1316 const std::string lIataCode (iPlace.getIataCode());
1317 const std::string lIcaoCode (iPlace.getIcaoCode());
1318 const std::string lFaaCode (iPlace.getFaaCode());
1319 const std::string lIsGeonames ((iPlace.isGeonames())?"Y":"N");
1320 const std::string lGeonameID =
1321 boost::lexical_cast<std::string> (iPlace.getGeonamesID());
1322 const std::string lEnvID =
1323 boost::lexical_cast<std::string> (iPlace.getEnvelopeID());
1324 const std::string lDateFrom =
1325 boost::gregorian::to_iso_extended_string (iPlace.getDateFrom());
1326 const std::string lDateEnd =
1327 boost::gregorian::to_iso_extended_string (iPlace.getDateEnd());
1328 const std::string lRawDataString (iPlace.getRawDataString());
1329
1354 const UNLOCodeList_T& lUNLOCodeList = iPlace.getUNLOCodeList();
1355 std::string lUNLOCodeStr ("");
1356 if (lUNLOCodeList.empty() == false) {
1357 const UNLOCode_T& lUNLOCode = lUNLOCodeList.front();
1358 lUNLOCodeStr = static_cast<const std::string> (lUNLOCode);
1359 }
1360
1365 const UICCodeList_T& lUICCodeList = iPlace.getUICCodeList();
1366 UICCode_T lUICCodeInt = 0;
1367 if (lUICCodeList.empty() == false) {
1368 const UICCode_T& lUICCode = lUICCodeList.front();
1369 lUICCodeInt = static_cast<const UICCode_T> (lUICCode);
1370 }
1371
1372
1373 // DEBUG
1374 /*
1375 std::ostringstream oStr;
1376 oStr << "insert into optd_por values (" << lPK << ", ";
1377 oStr << lLocationType << ", ";
1378 oStr << lIataCode << ", " << lIcaoCode << ", " << lFaaCode << ", ";
1379 oStr << lUNLOCode << ", ";
1380 oStr << lUICCode << ", ";
1381 oStr << lIsGeonames << ", " << lGeonameID << ", ";
1382 oStr << lEnvID << ", " << lDateFrom << ", " << lDateEnd << ", ";
1383 oStr << lRawDataString << ")";
1384 OPENTREP_LOG_DEBUG ("Full SQL statement: '" << oStr.str() << "'");
1385 */
1386
1387 ioSociSession << "insert into optd_por values (:pk, "
1388 << ":location_type, :iata_code, :icao_code, :faa_code, "
1389 << ":unlocode_code, :uic_code, "
1390 << ":is_geonames, :geoname_id, "
1391 << ":envelope_id, :date_from, :date_until, "
1392 << ":serialised_place)",
1393 soci::use (lPK), soci::use (lLocationType), soci::use (lIataCode),
1394 soci::use (lIcaoCode), soci::use (lFaaCode),
1395 soci::use (lUNLOCodeStr), soci::use (lUICCodeInt),
1396 soci::use (lIsGeonames), soci::use (lGeonameID),
1397 soci::use (lEnvID), soci::use (lDateFrom), soci::use (lDateEnd),
1398 soci::use (lRawDataString);
1399
1400 // Commit the transaction on the database
1401 ioSociSession.commit();
1402
1403 // Debug
1404 // OPENTREP_LOG_DEBUG ("[" << lDocID << "] " << iPlace);
1405
1406 } catch (std::exception const& lException) {
1407 std::ostringstream errorStr;
1408 errorStr << "Error when updating " << iPlace.toString() << ": "
1409 << lException.what();
1410 OPENTREP_LOG_ERROR (errorStr.str());
1411 throw SQLDatabaseException (errorStr.str());
1412 }
1413 }
1414
1415 // //////////////////////////////////////////////////////////////////////
1416 void DBManager::updatePlaceInDB (soci::session& ioSociSession,
1417 const Place& iPlace) {
1418
1419 try {
1420
1421 // Begin a transaction on the database
1422 ioSociSession.begin();
1423
1424 // Instanciate a SQL statement (no request is performed at that stage)
1425 XapianDocID_T lDocID;
1426 std::string lIataCode;
1427 soci::statement lUpdateStatement =
1428 (ioSociSession.prepare
1429 << "update place_details "
1430 << "set xapian_docid = :xapian_docid "
1431 << "where iata_code = :iata_code",
1432 soci::use (lDocID), soci::use (lIataCode));
1433
1434 // Execute the SQL query
1435 lDocID = iPlace.getDocID();
1436 lIataCode = iPlace.getIataCode();
1437 lUpdateStatement.execute (true);
1438
1439 // Commit the transaction on the database
1440 ioSociSession.commit();
1441
1442 // Debug
1443 // OPENTREP_LOG_DEBUG ("[" << lDocID << "] " << iPlace);
1444
1445 } catch (std::exception const& lException) {
1446 std::ostringstream errorStr;
1447 errorStr << "Error when updating " << iPlace.toString() << ": "
1448 << lException.what();
1449 OPENTREP_LOG_ERROR (errorStr.str());
1450 throw SQLDatabaseException (errorStr.str());
1451 }
1452 }
1453
1454 // //////////////////////////////////////////////////////////////////////
1455 NbOfDBEntries_T DBManager::displayCount (soci::session& ioSociSession) {
1456 NbOfDBEntries_T oNbOfEntries = 0;
1457
1458 try {
1459
1465
1466 ioSociSession << "select count(1) from optd_por;", soci::into(oNbOfEntries);
1467
1468 } catch (std::exception const& lException) {
1469 std::ostringstream errorStr;
1470 errorStr
1471 << "Error when trying to count the number of rows in the optd_por table: "
1472 << lException.what();
1473 OPENTREP_LOG_ERROR (errorStr.str());
1474 throw SQLDatabaseIndexCreationException (errorStr.str());
1475 }
1476
1477 return oNbOfEntries;
1478 }
1479
1480 // //////////////////////////////////////////////////////////////////////
1481 NbOfDBEntries_T DBManager::displayAll (soci::session& ioSociSession) {
1482 NbOfDBEntries_T oNbOfEntries = 0;
1483
1484 try {
1485
1486 // Prepare the SQL request corresponding to the select statement
1487 soci::statement lSelectStatement (ioSociSession);
1488 std::string lPlace =
1490 lSelectStatement);
1491
1496 bool hasStillData = true;
1497 while (hasStillData == true) {
1498 hasStillData = iterateOnStatement (lSelectStatement, lPlace);
1499
1500 // It is enough to have (at least) one database retrieved row
1501 if (hasStillData == true) {
1502 ++oNbOfEntries;
1503
1504 // Debug
1505 OPENTREP_LOG_DEBUG ("[" << oNbOfEntries << "] " << lPlace);
1506 }
1507 }
1508
1509 } catch (std::exception const& lException) {
1510 std::ostringstream errorStr;
1511 errorStr << "Error when trying to retrieve " << oNbOfEntries
1512 << "-th row from the SQL database: " << lException.what();
1513 OPENTREP_LOG_ERROR (errorStr.str());
1514 throw SQLDatabaseException (errorStr.str());
1515 }
1516
1517 return oNbOfEntries;
1518 }
1519
1520 // //////////////////////////////////////////////////////////////////////
1521 NbOfDBEntries_T DBManager::getPORByIATACode (soci::session& ioSociSession,
1522 const IATACode_T& iIataCode,
1523 LocationList_T& ioLocationList,
1524 const bool iUniqueEntry) {
1525 NbOfDBEntries_T oNbOfEntries = 0;
1526 LocationList_T lLocationList;
1527
1528 try {
1529
1530 // Convert the code into uppercase. That way, one can search for codes
1531 // irrespective of the case (knwing that codes are stored uppercase
1532 // in the database)
1533 const std::string& lCode = static_cast<const std::string&> (iIataCode);
1534 const std::string lCodeUpper = boost::algorithm::to_upper_copy (lCode);
1535
1536 // Prepare the SQL request corresponding to the select statement
1537 soci::statement lSelectStatement (ioSociSession);
1538 std::string lPlaceRawDataString;
1539 DBManager::prepareSelectBlobOnIataCodeStatement (ioSociSession,
1540 lSelectStatement,
1541 lCodeUpper,
1542 lPlaceRawDataString);
1543
1548 bool hasStillData = true;
1549 while (hasStillData == true) {
1550 hasStillData = iterateOnStatement (lSelectStatement,
1551 lPlaceRawDataString);
1552
1553 // DEBUG
1554 const std::string lFoundStr = hasStillData?"more; see below":"no more";
1555 OPENTREP_LOG_DEBUG ("Checked whether there are more locations "
1556 << "corresponding to '" << iIataCode
1557 << "' IATA code. Result: " << lFoundStr);
1558
1559 if (hasStillData == true) {
1560 //
1561 ++oNbOfEntries;
1562
1563 // Parse the POR details and create the corresponding
1564 // Location structure
1565 const RawDataString_T lPlaceRawData (lPlaceRawDataString);
1566 Location lLocation = Result::retrieveLocation (lPlaceRawData);
1567 lLocation.setCorrectedKeywords (iIataCode);
1568
1569 // Add the new found location to the list
1570 lLocationList.push_back (lLocation);
1571
1572 // Debug
1573 OPENTREP_LOG_DEBUG ("[" << oNbOfEntries << "] " << lLocation);
1574 }
1575 }
1576
1577 } catch (std::exception const& lException) {
1578 std::ostringstream errorStr;
1579 errorStr << "Error when trying to retrieve a POR for " << iIataCode
1580 << " from the SQL database: " << lException.what();
1581 OPENTREP_LOG_ERROR (errorStr.str());
1582 throw SQLDatabaseException (errorStr.str());
1583 }
1584
1585 // Add the just retrieved Location structure(s) to the list given
1586 // as parameter
1587 const Location* lHighestPRLocation_ptr = NULL;
1588 PageRank_T lHighestPRValue = 0.0;
1589 for (LocationList_T::const_iterator itLoc = lLocationList.begin();
1590 itLoc != lLocationList.end(); ++itLoc) {
1591 const Location& lLocation = *itLoc;
1592 const PageRank_T& lPRValue = lLocation.getPageRank();
1593
1594 // Store (a pointer on) the Location structure with the highest Page Rank.
1595 // Normally, when there is no PageRank value, the field should be empty
1596 // (empty string). In some rare cases, actually when OPTD is buggy,
1597 // the PageRank value may be zero. While it is a bug from OPTD, there is
1598 // no reason it should trigger a bug from OpenTREP in turn. So, rather
1599 // then ignoring any POR with zero PageRank value, rather the first one
1600 // is (randomly) selected
1601 if (lPRValue >= lHighestPRValue) {
1602 lHighestPRLocation_ptr = &lLocation;
1603 lHighestPRValue = lPRValue;
1604 }
1605
1606 // Add the Location structure now, only when a unique solution
1607 // is not expected
1608 if (iUniqueEntry == false) {
1609 ioLocationList.push_back (lLocation);
1610 }
1611 }
1612
1613 // Add the Location structure with the highest Page Rank value
1614 if (iUniqueEntry == true && lHighestPRLocation_ptr != NULL) {
1615 assert (lHighestPRLocation_ptr != NULL);
1616 ioLocationList.push_back (*lHighestPRLocation_ptr);
1617
1618 // DEBUG
1619 OPENTREP_LOG_DEBUG("Kept the location with the highest PageRank value ("
1620 << lHighestPRValue << ") for '" << iIataCode
1621 << "' IATA code: " << lHighestPRLocation_ptr->getKey());
1622 }
1623
1624 // Make the number of retrieved locations consistent with the unicity
1625 // requirement (if set)
1626 if (oNbOfEntries > 0 && iUniqueEntry == true) {
1627 oNbOfEntries = 1;
1628 }
1629
1630 //
1631 return oNbOfEntries;
1632 }
1633
1634 // //////////////////////////////////////////////////////////////////////
1635 NbOfDBEntries_T DBManager::getPORByICAOCode (soci::session& ioSociSession,
1636 const ICAOCode_T& iIcaoCode,
1637 LocationList_T& ioLocationList) {
1638 NbOfDBEntries_T oNbOfEntries = 0;
1639
1640 try {
1641
1642 // Convert the code into uppercase. That way, one can search for codes
1643 // irrespective of the case (knwing that codes are stored uppercase
1644 // in the database)
1645 const std::string& lCode = static_cast<const std::string&> (iIcaoCode);
1646 const std::string lCodeUpper = boost::algorithm::to_upper_copy (lCode);
1647
1648 // Prepare the SQL request corresponding to the select statement
1649 soci::statement lSelectStatement (ioSociSession);
1650 std::string lPlaceRawDataString;
1651 DBManager::prepareSelectBlobOnIcaoCodeStatement (ioSociSession,
1652 lSelectStatement,
1653 lCodeUpper,
1654 lPlaceRawDataString);
1655
1660 bool hasStillData = true;
1661 while (hasStillData == true) {
1662 hasStillData = iterateOnStatement (lSelectStatement,
1663 lPlaceRawDataString);
1664
1665 // DEBUG
1666 const std::string lFoundStr = hasStillData?"Yes":"No";
1667 OPENTREP_LOG_DEBUG ("Checked locations corresponding to "
1668 << iIcaoCode << " ICAO code. Found: " << lFoundStr);
1669
1670 if (hasStillData == true) {
1671 //
1672 ++oNbOfEntries;
1673
1674 // Parse the POR details and create the corresponding
1675 // Location structure
1676 const RawDataString_T lPlaceRawData (lPlaceRawDataString);
1677 Location lLocation = Result::retrieveLocation (lPlaceRawData);
1678 lLocation.setCorrectedKeywords (iIcaoCode);
1679
1680 // Add the new found location to the list
1681 ioLocationList.push_back (lLocation);
1682
1683 // Debug
1684 OPENTREP_LOG_DEBUG ("[" << oNbOfEntries << "] " << lLocation);
1685 }
1686 }
1687
1688 } catch (std::exception const& lException) {
1689 std::ostringstream errorStr;
1690 errorStr << "Error when trying to retrieve a POR for " << iIcaoCode
1691 << " from the SQL database: " << lException.what();
1692 OPENTREP_LOG_ERROR (errorStr.str());
1693 throw SQLDatabaseException (errorStr.str());
1694 }
1695
1696 //
1697 return oNbOfEntries;
1698 }
1699
1700 // //////////////////////////////////////////////////////////////////////
1701 NbOfDBEntries_T DBManager::getPORByFAACode (soci::session& ioSociSession,
1702 const FAACode_T& iFaaCode,
1703 LocationList_T& ioLocationList) {
1704 NbOfDBEntries_T oNbOfEntries = 0;
1705
1706 try {
1707
1708 // Convert the code into uppercase. That way, one can search for codes
1709 // irrespective of the case (knwing that codes are stored uppercase
1710 // in the database)
1711 const std::string& lCode = static_cast<const std::string&> (iFaaCode);
1712 const std::string lCodeUpper = boost::algorithm::to_upper_copy (lCode);
1713
1714 // Prepare the SQL request corresponding to the select statement
1715 soci::statement lSelectStatement (ioSociSession);
1716 std::string lPlaceRawDataString;
1717 DBManager::prepareSelectBlobOnFaaCodeStatement (ioSociSession,
1718 lSelectStatement,
1719 lCodeUpper,
1720 lPlaceRawDataString);
1721
1726 bool hasStillData = true;
1727 while (hasStillData == true) {
1728 hasStillData = iterateOnStatement (lSelectStatement,
1729 lPlaceRawDataString);
1730
1731 // DEBUG
1732 const std::string lFoundStr = hasStillData?"Yes":"No";
1733 OPENTREP_LOG_DEBUG ("Checked locations corresponding to "
1734 << iFaaCode << " FAA code. Found: " << lFoundStr);
1735
1736 if (hasStillData == true) {
1737 //
1738 ++oNbOfEntries;
1739
1740 // Parse the POR details and create the corresponding
1741 // Location structure
1742 const RawDataString_T lPlaceRawData (lPlaceRawDataString);
1743 Location lLocation = Result::retrieveLocation (lPlaceRawData);
1744 lLocation.setCorrectedKeywords (iFaaCode);
1745
1746 // Add the new found location to the list
1747 ioLocationList.push_back (lLocation);
1748
1749 // Debug
1750 OPENTREP_LOG_DEBUG ("[" << oNbOfEntries << "] " << lLocation);
1751 }
1752 }
1753
1754 } catch (std::exception const& lException) {
1755 std::ostringstream errorStr;
1756 errorStr << "Error when trying to retrieve a POR for " << iFaaCode
1757 << " from the SQL database: " << lException.what();
1758 OPENTREP_LOG_ERROR (errorStr.str());
1759 throw SQLDatabaseException (errorStr.str());
1760 }
1761
1762 //
1763 return oNbOfEntries;
1764 }
1765
1766 // //////////////////////////////////////////////////////////////////////
1767 NbOfDBEntries_T DBManager::getPORByUNLOCode (soci::session& ioSociSession,
1768 const UNLOCode_T& iUNLOCode,
1769 LocationList_T& ioLocationList,
1770 const bool iUniqueEntry) {
1771 NbOfDBEntries_T oNbOfEntries = 0;
1772 LocationList_T lLocationList;
1773
1774 try {
1775
1776 // Convert the code into uppercase. That way, one can search for codes
1777 // irrespective of the case (knwing that codes are stored uppercase
1778 // in the database)
1779 const std::string& lCode = static_cast<const std::string&> (iUNLOCode);
1780 const std::string lCodeUpper = boost::algorithm::to_upper_copy (lCode);
1781
1782 // Prepare the SQL request corresponding to the select statement
1783 soci::statement lSelectStatement (ioSociSession);
1784 std::string lPlaceRawDataString;
1785 DBManager::prepareSelectBlobOnUNLOCodeStatement (ioSociSession,
1786 lSelectStatement,
1787 lCodeUpper,
1788 lPlaceRawDataString);
1789
1794 bool hasStillData = true;
1795 while (hasStillData == true) {
1796 hasStillData = iterateOnStatement (lSelectStatement,
1797 lPlaceRawDataString);
1798
1799 // DEBUG
1800 const std::string lFoundStr = hasStillData?"Yes":"No";
1801 OPENTREP_LOG_DEBUG ("Checked locations corresponding to "
1802 << iUNLOCode << " UN/LOCODE code. Found: "
1803 << lFoundStr);
1804
1805 if (hasStillData == true) {
1806 //
1807 ++oNbOfEntries;
1808
1809 // Parse the POR details and create the corresponding
1810 // Location structure
1811 const RawDataString_T lPlaceRawData (lPlaceRawDataString);
1812 Location lLocation = Result::retrieveLocation (lPlaceRawData);
1813 lLocation.setCorrectedKeywords (iUNLOCode);
1814
1815 // Add the new found location to the list
1816 lLocationList.push_back (lLocation);
1817
1818 // Debug
1819 OPENTREP_LOG_DEBUG ("[" << oNbOfEntries << "] " << lLocation);
1820 }
1821 }
1822
1823 } catch (std::exception const& lException) {
1824 std::ostringstream errorStr;
1825 errorStr << "Error when trying to retrieve a POR for " << iUNLOCode
1826 << " from the SQL database: " << lException.what();
1827 OPENTREP_LOG_ERROR (errorStr.str());
1828 throw SQLDatabaseException (errorStr.str());
1829 }
1830
1831 // Add the just retrieved Location structure(s) to the list given
1832 // as parameter
1833 const Location* lHighestPRLocation_ptr = NULL;
1834 PageRank_T lHighestPRValue = 0.0;
1835 for (LocationList_T::const_iterator itLoc = lLocationList.begin();
1836 itLoc != lLocationList.end(); ++itLoc) {
1837 const Location& lLocation = *itLoc;
1838 const PageRank_T& lPRValue = lLocation.getPageRank();
1839
1840 // Store (a pointer on) the Location structure with the highest Page Rank
1841 if (lPRValue > lHighestPRValue) {
1842 lHighestPRLocation_ptr = &lLocation;
1843 lHighestPRValue = lPRValue;
1844 }
1845
1846 // Add the Location structure now, only when
1847 if (iUniqueEntry == false) {
1848 ioLocationList.push_back (lLocation);
1849 }
1850 }
1851
1852 // Add the Location structure with the highest Page Rank value
1853 if (iUniqueEntry == true && lHighestPRLocation_ptr != NULL) {
1854 assert (lHighestPRLocation_ptr != NULL);
1855 ioLocationList.push_back (*lHighestPRLocation_ptr);
1856
1857 // DEBUG
1858 OPENTREP_LOG_DEBUG("Kept the location with the highest PageRank value ("
1859 << lHighestPRValue << ") for '" << iUNLOCode
1860 << "' IATA code: " << lHighestPRLocation_ptr->getKey());
1861 }
1862
1863 // Make the number of retrieved locations consistent with the unicity
1864 // requirement (if set)
1865 if (oNbOfEntries > 0 && iUniqueEntry == true) {
1866 oNbOfEntries = 1;
1867 }
1868
1869 //
1870 return oNbOfEntries;
1871 }
1872
1873 // //////////////////////////////////////////////////////////////////////
1874 NbOfDBEntries_T DBManager::getPORByUICCode (soci::session& ioSociSession,
1875 const UICCode_T& iUICCode,
1876 LocationList_T& ioLocationList) {
1877 NbOfDBEntries_T oNbOfEntries = 0;
1878
1879 try {
1880
1881 // Prepare the SQL request corresponding to the select statement
1882 soci::statement lSelectStatement (ioSociSession);
1883 std::string lPlaceRawDataString;
1884 DBManager::prepareSelectBlobOnUICCodeStatement (ioSociSession,
1885 lSelectStatement,
1886 iUICCode,
1887 lPlaceRawDataString);
1888
1893 bool hasStillData = true;
1894 while (hasStillData == true) {
1895 hasStillData = iterateOnStatement (lSelectStatement,
1896 lPlaceRawDataString);
1897
1898 // DEBUG
1899 const std::string lFoundStr = hasStillData?"Yes":"No";
1900 OPENTREP_LOG_DEBUG ("Checked locations corresponding to "
1901 << iUICCode << " UIC code. Found: "
1902 << lFoundStr);
1903
1904 if (hasStillData == true) {
1905 //
1906 ++oNbOfEntries;
1907
1908 // Parse the POR details and create the corresponding
1909 // Location structure
1910 const RawDataString_T lPlaceRawData (lPlaceRawDataString);
1911 Location lLocation = Result::retrieveLocation (lPlaceRawData);
1912 const std::string lUICCodeStr =
1913 boost::lexical_cast<std::string> (iUICCode);
1914 lLocation.setCorrectedKeywords (lUICCodeStr);
1915
1916 // Add the new found location to the list
1917 ioLocationList.push_back (lLocation);
1918
1919 // Debug
1920 OPENTREP_LOG_DEBUG ("[" << oNbOfEntries << "] " << lLocation);
1921 }
1922 }
1923
1924 } catch (std::exception const& lException) {
1925 std::ostringstream errorStr;
1926 errorStr << "Error when trying to retrieve a POR for " << iUICCode
1927 << " from the SQL database: " << lException.what();
1928 OPENTREP_LOG_ERROR (errorStr.str());
1929 throw SQLDatabaseException (errorStr.str());
1930 }
1931
1932 //
1933 return oNbOfEntries;
1934 }
1935
1936 // //////////////////////////////////////////////////////////////////////
1937 NbOfDBEntries_T DBManager::getPORByGeonameID (soci::session& ioSociSession,
1938 const GeonamesID_T& iGeonameID,
1939 LocationList_T& ioLocationList) {
1940 NbOfDBEntries_T oNbOfEntries = 0;
1941
1942 try {
1943
1944 // Prepare the SQL request corresponding to the select statement
1945 soci::statement lSelectStatement (ioSociSession);
1946 std::string lPlaceRawDataString;
1947 DBManager::prepareSelectBlobOnPlaceGeoIDStatement (ioSociSession,
1948 lSelectStatement,
1949 iGeonameID,
1950 lPlaceRawDataString);
1951
1956 bool hasStillData = true;
1957 while (hasStillData == true) {
1958 hasStillData = iterateOnStatement (lSelectStatement,
1959 lPlaceRawDataString);
1960
1961 // DEBUG
1962 const std::string lFoundStr = hasStillData?"Yes":"No";
1963 OPENTREP_LOG_DEBUG ("Checked locations corresponding to "
1964 << iGeonameID<< " Geonames ID. Found: "<< lFoundStr);
1965
1966 if (hasStillData == true) {
1967 //
1968 ++oNbOfEntries;
1969
1970 // Parse the POR details and create the corresponding
1971 // Location structure
1972 const RawDataString_T lPlaceRawData (lPlaceRawDataString);
1973 Location lLocation = Result::retrieveLocation (lPlaceRawData);
1974 const std::string lGeonamesIDStr =
1975 boost::lexical_cast<std::string> (iGeonameID);
1976 lLocation.setCorrectedKeywords (lGeonamesIDStr);
1977
1978 // Add the new found location to the list
1979 ioLocationList.push_back (lLocation);
1980
1981 // Debug
1982 OPENTREP_LOG_DEBUG ("[" << oNbOfEntries << "] " << lLocation);
1983 }
1984 }
1985
1986 } catch (std::exception const& lException) {
1987 std::ostringstream errorStr;
1988 errorStr << "Error when trying to retrieve a POR for " << iGeonameID
1989 << " from the SQL database: " << lException.what();
1990 OPENTREP_LOG_ERROR (errorStr.str());
1991 throw SQLDatabaseException (errorStr.str());
1992 }
1993
1994 //
1995 return oNbOfEntries;
1996 }
1997
1998}
#define OPENTREP_LOG_ERROR(iToBeLogged)
Definition Logger.hpp:24
#define OPENTREP_LOG_DEBUG(iToBeLogged)
Definition Logger.hpp:33
static void terminateSQLDBSession(const DBType &, const SQLDBConnectionString_T &, soci::session &)
static void createSQLDBTables(soci::session &)
static std::string prepareSelectAllBlobStatement(soci::session &, soci::statement &)
static NbOfDBEntries_T getPORByUICCode(soci::session &, const UICCode_T &, LocationList_T &)
static NbOfDBEntries_T getPORByICAOCode(soci::session &, const ICAOCode_T &, LocationList_T &)
static soci::session * initSQLDBSession(const DBType &, const SQLDBConnectionString_T &)
static NbOfDBEntries_T getPORByFAACode(soci::session &, const FAACode_T &, LocationList_T &)
static void createSQLDBIndexes(soci::session &)
static NbOfDBEntries_T displayCount(soci::session &)
static NbOfDBEntries_T displayAll(soci::session &)
static NbOfDBEntries_T getPORByUNLOCode(soci::session &, const UNLOCode_T &, LocationList_T &, const bool iUniqueEntry)
static NbOfDBEntries_T getPORByGeonameID(soci::session &, const GeonamesID_T &, LocationList_T &)
static NbOfDBEntries_T getPORByIATACode(soci::session &, const IATACode_T &, LocationList_T &, const bool iUniqueEntry)
static void updatePlaceInDB(soci::session &, const Place &)
static bool iterateOnStatement(soci::statement &, const std::string &)
static bool createSQLDBUser(const DBType &, const SQLDBConnectionString_T &, const DeploymentNumber_T &)
static void insertPlaceInDB(soci::session &, const Place &)
static bool checkSQLiteDirectory(const std::string &iSQLDBConnStr)
Class modelling a place/POR (point of reference).
Definition Place.hpp:29
const IsGeonames_T & isGeonames() const
Definition Place.hpp:87
const ICAOCode_T & getIcaoCode() const
Definition Place.hpp:94
const RawDataString_T & getRawDataString() const
Definition Place.hpp:467
const FAACode_T & getFaaCode() const
Definition Place.hpp:101
const Date_T & getDateEnd() const
Definition Place.hpp:158
const GeonamesID_T & getGeonamesID() const
Definition Place.hpp:80
const XapianDocID_T & getDocID() const
Definition Place.hpp:474
const IATACode_T & getIataCode() const
Definition Place.hpp:66
const Date_T & getDateFrom() const
Definition Place.hpp:151
const EnvelopeID_T & getEnvelopeID() const
Definition Place.hpp:144
const UNLOCodeList_T & getUNLOCodeList() const
Definition Place.hpp:108
std::string toString() const
Definition Place.cpp:85
const IATAType & getIataType() const
Definition Place.hpp:73
const LocationKey & getKey() const
Definition Place.hpp:59
const UICCodeList_T & getUICCodeList() const
Definition Place.hpp:115
static Location retrieveLocation(const Xapian::Document &)
Definition Result.cpp:272
unsigned int UICCode_T
bool createSQLDBUserOnPG(const SQLDBConnectionString_T &iSQLDBConnStr, const DeploymentNumber_T &iDeploymentNumber)
bool createSQLDBUserOnMySQL(const SQLDBConnectionString_T &iSQLDBConnStr, const DeploymentNumber_T &iDeploymentNumber)
Definition DBManager.cpp:88
unsigned int NbOfDBEntries_T
const std::string DEFAULT_OPENTREP_MYSQL_DB_DBNAME
const std::string DEFAULT_OPENTREP_MYSQL_DB_USER
double PageRank_T
const std::string DEFAULT_OPENTREP_MYSQL_DB_PASSWD
std::list< Location > LocationList_T
std::list< UICCode_T > UICCodeList_T
const std::string DEFAULT_OPENTREP_MYSQL_DB_HOST
std::list< UNLOCode_T > UNLOCodeList_T
const std::string DEFAULT_OPENTREP_PG_DB_USER
bool createSQLDBUserOnSQLite(const SQLDBConnectionString_T &iSQLDBConnStr, const DeploymentNumber_T &iDeploymentNumber)
Definition DBManager.cpp:35
const std::string DEFAULT_OPENTREP_PG_DB_PASSWD
unsigned short DeploymentNumber_T
unsigned int GeonamesID_T
const std::string DEFAULT_OPENTREP_PG_DB_DBNAME
unsigned int XapianDocID_T
Enumeration of database types.
Definition DBType.hpp:17
const std::string describe() const
Definition DBType.cpp:135
static EN_DBType getType(const char)
Definition DBType.cpp:35
Enumeration of place/location types with respect to their use for transportation purposes.
Definition IATAType.hpp:42
std::string getTypeAsString() const
Definition IATAType.cpp:174
Class modelling the primary key of a location/POR (point of reference).
std::string toString() const
Structure modelling a (geographical) location.
Definition Location.hpp:25
const LocationKey & getKey() const
Definition Location.hpp:31
const PageRank_T & getPageRank() const
Definition Location.hpp:354
void setCorrectedKeywords(const std::string &iCorrectedKeywords)
Definition Location.hpp:846