OpenTREP Logo  0.08.02
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
963
972 long long lNbOfDuplicatedPKs = 0;
973 ioSociSession
974 << "select count(*) from "
975 "(select pk from optd_por group by pk having count(*) > 1) "
976 "as duplicated_pk;", soci::into (lNbOfDuplicatedPKs);
977 if (lNbOfDuplicatedPKs > 0) {
978 std::ostringstream warningStr;
979 warningStr << lNbOfDuplicatedPKs << " duplicated primary key(s) "
980 << "have been found in the 'optd_por' table (the "
981 << "upstream OPTD POR data file contains a few rows "
982 << "sharing the same key). For each duplicated key, "
983 << "all but the last-inserted row will be removed "
984 << "before creating the unique index.";
985 OPENTREP_LOG_WARNING (warningStr.str());
986
987 ioSociSession
988 << "delete from optd_por a using optd_por b "
989 "where a.pk = b.pk and a.ctid < b.ctid;";
990 }
991
992 ioSociSession
993 << "create unique index optd_por_pk on optd_por (pk);";
994 ioSociSession
995 << "create index optd_por_iata_code on optd_por (iata_code asc);";
996 ioSociSession
997 << "create index optd_por_iata_date on optd_por (iata_code asc, date_from asc, date_until asc);";
998 ioSociSession
999 << "create index optd_por_icao_code on optd_por (icao_code asc);";
1000 ioSociSession
1001 << "create index optd_por_geonameid on optd_por (geoname_id asc);";
1002 ioSociSession
1003 << "create index optd_por_unlocode_code on optd_por (unlocode_code asc);";
1004 ioSociSession
1005 << "create index optd_por_uic_code on optd_por (uic_code asc);";
1006
1007 } catch (std::exception const& lException) {
1008 std::ostringstream errorStr;
1009 errorStr << "Error when trying to create PostgreSQL indices: "
1010 << lException.what();
1011 OPENTREP_LOG_ERROR (errorStr.str());
1012 throw SQLDatabaseIndexCreationException (errorStr.str());
1013 }
1014
1015 // DEBUG
1016 OPENTREP_LOG_DEBUG ("The indices have been created "
1017 "for the PostgreSQL database");
1018 break;
1019 }
1020
1021 case DBType::MYSQL: {
1022 // DEBUG
1023 OPENTREP_LOG_DEBUG ("Create the indices for the MySQL database");
1024
1025 try {
1026
1039
1040 ioSociSession
1041 << "alter table optd_por add unique index optd_por_pk (pk asc);";
1042 ioSociSession
1043 << "alter table optd_por add index optd_por_iata_code (iata_code asc);";
1044 ioSociSession
1045 << "alter table optd_por add index optd_por_iata_date (iata_code asc, date_from asc, date_until asc);";
1046 ioSociSession
1047 << "alter table optd_por add index optd_por_icao_code (icao_code asc);";
1048 ioSociSession
1049 << "alter table optd_por add index optd_por_geonameid (geoname_id asc);";
1050 ioSociSession
1051 << "alter table optd_por add index optd_por_unlocode_code (unlocode_code asc);";
1052 ioSociSession
1053 << "alter table optd_por add index optd_por_uic_code (uic_code asc);";
1054
1055 } catch (std::exception const& lException) {
1056 std::ostringstream errorStr;
1057 errorStr << "Error when trying to create MySQL/MariaDB indices: "
1058 << lException.what();
1059 OPENTREP_LOG_ERROR (errorStr.str());
1060 throw SQLDatabaseIndexCreationException (errorStr.str());
1061 }
1062
1063 // DEBUG
1064 OPENTREP_LOG_DEBUG ("The indices have been created "
1065 "for the MySQL/MariaDB database");
1066
1067 break;
1068 }
1069
1070 case DBType::NODB: {
1071 // Do nothing
1072 break;
1073 }
1074
1075 default: {
1076 std::ostringstream errorStr;
1077 errorStr << "Error: the '" << lDBName
1078 << "' SQL database type is not supported";
1079 OPENTREP_LOG_ERROR (errorStr.str());
1080 throw SQLDatabaseIndexCreationException (errorStr.str());
1081 break;
1082 }
1083 }
1084 }
1085
1086 // //////////////////////////////////////////////////////////////////////
1087 std::string DBManager::
1088 prepareSelectAllBlobStatement (soci::session& ioSociSession,
1089 soci::statement& ioSelectStatement) {
1090 std::string oSerialisedPlaceStr;
1091
1092 try {
1093
1094 // Instanciate a SQL statement (no request is performed at that stage)
1098
1099 ioSelectStatement = (ioSociSession.prepare
1100 << "select serialised_place from optd_por",
1101 soci::into (oSerialisedPlaceStr));
1102
1103 // Execute the SQL query
1104 ioSelectStatement.execute();
1105
1106 } catch (std::exception const& lException) {
1107 std::ostringstream errorStr;
1108 errorStr
1109 << "Error in the 'select serialised_place from optd_por' SQL request: "
1110 << lException.what();
1111 OPENTREP_LOG_ERROR (errorStr.str());
1112 throw SQLDatabaseException (errorStr.str());
1113 }
1114
1115 //
1116 return oSerialisedPlaceStr;
1117 }
1118
1119 // //////////////////////////////////////////////////////////////////////
1120 void DBManager::
1121 prepareSelectBlobOnIataCodeStatement (soci::session& ioSociSession,
1122 soci::statement& ioSelectStatement,
1123 const std::string& iIataCode,
1124 std::string& ioSerialisedPlaceStr) {
1125
1126 try {
1127
1128 // Instanciate a SQL statement (no request is performed at that stage)
1132 ioSelectStatement = (ioSociSession.prepare
1133 << "select serialised_place from optd_por "
1134 << "where iata_code = :place_iata_code",
1135 soci::use (iIataCode),
1136 soci::into (ioSerialisedPlaceStr));
1137
1138 // Execute the SQL query
1139 ioSelectStatement.execute();
1140
1141 } catch (std::exception const& lException) {
1142 std::ostringstream errorStr;
1143 errorStr
1144 << "Error in the 'select serialised_place from optd_por' SQL request: "
1145 << lException.what();
1146 OPENTREP_LOG_ERROR (errorStr.str());
1147 throw SQLDatabaseException (errorStr.str());
1148 }
1149 }
1150
1151 // //////////////////////////////////////////////////////////////////////
1152 void DBManager::
1153 prepareSelectBlobOnIcaoCodeStatement (soci::session& ioSociSession,
1154 soci::statement& ioSelectStatement,
1155 const std::string& iIcaoCode,
1156 std::string& ioSerialisedPlaceStr) {
1157
1158 try {
1159
1160 // Instanciate a SQL statement (no request is performed at that stage)
1164 ioSelectStatement = (ioSociSession.prepare
1165 << "select serialised_place from optd_por "
1166 << "where icao_code = :place_icao_code",
1167 soci::use (iIcaoCode),
1168 soci::into (ioSerialisedPlaceStr));
1169
1170 // Execute the SQL query
1171 ioSelectStatement.execute();
1172
1173 } catch (std::exception const& lException) {
1174 std::ostringstream errorStr;
1175 errorStr
1176 << "Error in the 'select serialised_place from optd_por' SQL request: "
1177 << lException.what();
1178 OPENTREP_LOG_ERROR (errorStr.str());
1179 throw SQLDatabaseException (errorStr.str());
1180 }
1181 }
1182
1183 // //////////////////////////////////////////////////////////////////////
1184 void DBManager::
1185 prepareSelectBlobOnFaaCodeStatement (soci::session& ioSociSession,
1186 soci::statement& ioSelectStatement,
1187 const std::string& iFaaCode,
1188 std::string& ioSerialisedPlaceStr) {
1189
1190 try {
1191
1192 // Instanciate a SQL statement (no request is performed at that stage)
1196 ioSelectStatement = (ioSociSession.prepare
1197 << "select serialised_place from optd_por "
1198 << "where faa_code = :place_faa_code",
1199 soci::use (iFaaCode),
1200 soci::into (ioSerialisedPlaceStr));
1201
1202 // Execute the SQL query
1203 ioSelectStatement.execute();
1204
1205 } catch (std::exception const& lException) {
1206 std::ostringstream errorStr;
1207 errorStr
1208 << "Error in the 'select serialised_place from optd_por' SQL request: "
1209 << lException.what();
1210 OPENTREP_LOG_ERROR (errorStr.str());
1211 throw SQLDatabaseException (errorStr.str());
1212 }
1213 }
1214
1215 // //////////////////////////////////////////////////////////////////////
1216 void DBManager::
1217 prepareSelectBlobOnUNLOCodeStatement (soci::session& ioSociSession,
1218 soci::statement& ioSelectStatement,
1219 const std::string& iUNLOCode,
1220 std::string& ioSerialisedPlaceStr) {
1221
1222 try {
1223
1224 // Instanciate a SQL statement (no request is performed at that stage)
1228 ioSelectStatement = (ioSociSession.prepare
1229 << "select serialised_place from optd_por "
1230 << "where unlocode_code = :place_unlocode_code",
1231 soci::use (iUNLOCode),
1232 soci::into (ioSerialisedPlaceStr));
1233
1234 // Execute the SQL query
1235 ioSelectStatement.execute();
1236
1237 } catch (std::exception const& lException) {
1238 std::ostringstream errorStr;
1239 errorStr
1240 << "Error in the 'select serialised_place from optd_por' SQL request: "
1241 << lException.what();
1242 OPENTREP_LOG_ERROR (errorStr.str());
1243 throw SQLDatabaseException (errorStr.str());
1244 }
1245 }
1246
1247 // //////////////////////////////////////////////////////////////////////
1248 void DBManager::
1249 prepareSelectBlobOnUICCodeStatement (soci::session& ioSociSession,
1250 soci::statement& ioSelectStatement,
1251 const UICCode_T& iUICCode,
1252 std::string& ioSerialisedPlaceStr) {
1253
1254 try {
1255
1256 // Instanciate a SQL statement (no request is performed at that stage)
1260 ioSelectStatement = (ioSociSession.prepare
1261 << "select serialised_place from optd_por "
1262 << "where uic_code = :place_uic_code",
1263 soci::use (iUICCode),
1264 soci::into (ioSerialisedPlaceStr));
1265
1266 // Execute the SQL query
1267 ioSelectStatement.execute();
1268
1269 } catch (std::exception const& lException) {
1270 std::ostringstream errorStr;
1271 errorStr
1272 << "Error in the 'select serialised_place from optd_por' SQL request: "
1273 << lException.what();
1274 OPENTREP_LOG_ERROR (errorStr.str());
1275 throw SQLDatabaseException (errorStr.str());
1276 }
1277 }
1278
1279 // //////////////////////////////////////////////////////////////////////
1280 void DBManager::
1281 prepareSelectBlobOnPlaceGeoIDStatement (soci::session& ioSociSession,
1282 soci::statement& ioSelectStatement,
1283 const GeonamesID_T& iGeonameID,
1284 std::string& ioSerialisedPlaceStr) {
1285
1286 try {
1287
1288 // Instanciate a SQL statement (no request is performed at that stage)
1292 ioSelectStatement = (ioSociSession.prepare
1293 << "select serialised_place from optd_por "
1294 << "where geoname_id = :place_geoname_id",
1295 soci::use (iGeonameID),
1296 soci::into (ioSerialisedPlaceStr));
1297
1298 // Execute the SQL query
1299 ioSelectStatement.execute();
1300
1301 } catch (std::exception const& lException) {
1302 std::ostringstream errorStr;
1303 errorStr
1304 << "Error in the 'select serialised_place from optd_por' SQL request: "
1305 << lException.what();
1306 OPENTREP_LOG_ERROR (errorStr.str());
1307 throw SQLDatabaseException (errorStr.str());
1308 }
1309 }
1310
1311 // //////////////////////////////////////////////////////////////////////
1312 bool DBManager::iterateOnStatement (soci::statement& ioStatement,
1313 const std::string& iSerialisedPlaceStr) {
1314 bool hasStillData = false;
1315
1316 try {
1317
1318 // Retrieve the next row of Place object
1319 hasStillData = ioStatement.fetch();
1320
1321 } catch (std::exception const& lException) {
1322 std::ostringstream errorStr;
1323 errorStr << "Error when iterating on the SQL fetch: " << lException.what();
1324 errorStr << ". The current place is: " << iSerialisedPlaceStr;
1325 OPENTREP_LOG_ERROR (errorStr.str());
1326 throw SQLDatabaseException (errorStr.str());
1327 }
1328
1329 return hasStillData;
1330 }
1331
1332 // //////////////////////////////////////////////////////////////////////
1333 void DBManager::insertPlaceInDB (soci::session& ioSociSession,
1334 const Place& iPlace) {
1335
1336 try {
1337
1338 // Begin a transaction on the database
1339 ioSociSession.begin();
1340
1341 // Instanciate a SQL statement (no request is performed at that stage)
1342 const LocationKey& lLocationKey = iPlace.getKey();
1343 const std::string lPK (lLocationKey.toString());
1344 const IATAType& lIataType = iPlace.getIataType();
1345 const std::string lLocationType (lIataType.getTypeAsString());
1346 const std::string lIataCode (iPlace.getIataCode());
1347 const std::string lIcaoCode (iPlace.getIcaoCode());
1348 const std::string lFaaCode (iPlace.getFaaCode());
1349 const std::string lIsGeonames ((iPlace.isGeonames())?"Y":"N");
1350 const std::string lGeonameID =
1351 boost::lexical_cast<std::string> (iPlace.getGeonamesID());
1352 const std::string lEnvID =
1353 boost::lexical_cast<std::string> (iPlace.getEnvelopeID());
1354 const std::string lDateFrom =
1355 boost::gregorian::to_iso_extended_string (iPlace.getDateFrom());
1356 const std::string lDateEnd =
1357 boost::gregorian::to_iso_extended_string (iPlace.getDateEnd());
1358 const std::string lRawDataString (iPlace.getRawDataString());
1359
1384 const UNLOCodeList_T& lUNLOCodeList = iPlace.getUNLOCodeList();
1385 std::string lUNLOCodeStr ("");
1386 if (lUNLOCodeList.empty() == false) {
1387 const UNLOCode_T& lUNLOCode = lUNLOCodeList.front();
1388 lUNLOCodeStr = static_cast<const std::string> (lUNLOCode);
1389 }
1390
1395 const UICCodeList_T& lUICCodeList = iPlace.getUICCodeList();
1396 UICCode_T lUICCodeInt = 0;
1397 if (lUICCodeList.empty() == false) {
1398 const UICCode_T& lUICCode = lUICCodeList.front();
1399 lUICCodeInt = static_cast<const UICCode_T> (lUICCode);
1400 }
1401
1402
1403 // DEBUG
1404 /*
1405 std::ostringstream oStr;
1406 oStr << "insert into optd_por values (" << lPK << ", ";
1407 oStr << lLocationType << ", ";
1408 oStr << lIataCode << ", " << lIcaoCode << ", " << lFaaCode << ", ";
1409 oStr << lUNLOCode << ", ";
1410 oStr << lUICCode << ", ";
1411 oStr << lIsGeonames << ", " << lGeonameID << ", ";
1412 oStr << lEnvID << ", " << lDateFrom << ", " << lDateEnd << ", ";
1413 oStr << lRawDataString << ")";
1414 OPENTREP_LOG_DEBUG ("Full SQL statement: '" << oStr.str() << "'");
1415 */
1416
1417 ioSociSession << "insert into optd_por values (:pk, "
1418 << ":location_type, :iata_code, :icao_code, :faa_code, "
1419 << ":unlocode_code, :uic_code, "
1420 << ":is_geonames, :geoname_id, "
1421 << ":envelope_id, :date_from, :date_until, "
1422 << ":serialised_place)",
1423 soci::use (lPK), soci::use (lLocationType), soci::use (lIataCode),
1424 soci::use (lIcaoCode), soci::use (lFaaCode),
1425 soci::use (lUNLOCodeStr), soci::use (lUICCodeInt),
1426 soci::use (lIsGeonames), soci::use (lGeonameID),
1427 soci::use (lEnvID), soci::use (lDateFrom), soci::use (lDateEnd),
1428 soci::use (lRawDataString);
1429
1430 // Commit the transaction on the database
1431 ioSociSession.commit();
1432
1433 // Debug
1434 // OPENTREP_LOG_DEBUG ("[" << lDocID << "] " << iPlace);
1435
1436 } catch (std::exception const& lException) {
1437 std::ostringstream errorStr;
1438 errorStr << "Error when updating " << iPlace.toString() << ": "
1439 << lException.what();
1440 OPENTREP_LOG_ERROR (errorStr.str());
1441 throw SQLDatabaseException (errorStr.str());
1442 }
1443 }
1444
1445 // //////////////////////////////////////////////////////////////////////
1446 void DBManager::updatePlaceInDB (soci::session& ioSociSession,
1447 const Place& iPlace) {
1448
1449 try {
1450
1451 // Begin a transaction on the database
1452 ioSociSession.begin();
1453
1454 // Instanciate a SQL statement (no request is performed at that stage)
1455 XapianDocID_T lDocID;
1456 std::string lIataCode;
1457 soci::statement lUpdateStatement =
1458 (ioSociSession.prepare
1459 << "update place_details "
1460 << "set xapian_docid = :xapian_docid "
1461 << "where iata_code = :iata_code",
1462 soci::use (lDocID), soci::use (lIataCode));
1463
1464 // Execute the SQL query
1465 lDocID = iPlace.getDocID();
1466 lIataCode = iPlace.getIataCode();
1467 lUpdateStatement.execute (true);
1468
1469 // Commit the transaction on the database
1470 ioSociSession.commit();
1471
1472 // Debug
1473 // OPENTREP_LOG_DEBUG ("[" << lDocID << "] " << iPlace);
1474
1475 } catch (std::exception const& lException) {
1476 std::ostringstream errorStr;
1477 errorStr << "Error when updating " << iPlace.toString() << ": "
1478 << lException.what();
1479 OPENTREP_LOG_ERROR (errorStr.str());
1480 throw SQLDatabaseException (errorStr.str());
1481 }
1482 }
1483
1484 // //////////////////////////////////////////////////////////////////////
1485 NbOfDBEntries_T DBManager::displayCount (soci::session& ioSociSession) {
1486 NbOfDBEntries_T oNbOfEntries = 0;
1487
1488 try {
1489
1495
1496 ioSociSession << "select count(1) from optd_por;", soci::into(oNbOfEntries);
1497
1498 } catch (std::exception const& lException) {
1499 std::ostringstream errorStr;
1500 errorStr
1501 << "Error when trying to count the number of rows in the optd_por table: "
1502 << lException.what();
1503 OPENTREP_LOG_ERROR (errorStr.str());
1504 throw SQLDatabaseIndexCreationException (errorStr.str());
1505 }
1506
1507 return oNbOfEntries;
1508 }
1509
1510 // //////////////////////////////////////////////////////////////////////
1511 NbOfDBEntries_T DBManager::displayAll (soci::session& ioSociSession) {
1512 NbOfDBEntries_T oNbOfEntries = 0;
1513
1514 try {
1515
1516 // Prepare the SQL request corresponding to the select statement
1517 soci::statement lSelectStatement (ioSociSession);
1518 std::string lPlace =
1520 lSelectStatement);
1521
1526 bool hasStillData = true;
1527 while (hasStillData == true) {
1528 hasStillData = iterateOnStatement (lSelectStatement, lPlace);
1529
1530 // It is enough to have (at least) one database retrieved row
1531 if (hasStillData == true) {
1532 ++oNbOfEntries;
1533
1534 // Debug
1535 OPENTREP_LOG_DEBUG ("[" << oNbOfEntries << "] " << lPlace);
1536 }
1537 }
1538
1539 } catch (std::exception const& lException) {
1540 std::ostringstream errorStr;
1541 errorStr << "Error when trying to retrieve " << oNbOfEntries
1542 << "-th row from the SQL database: " << lException.what();
1543 OPENTREP_LOG_ERROR (errorStr.str());
1544 throw SQLDatabaseException (errorStr.str());
1545 }
1546
1547 return oNbOfEntries;
1548 }
1549
1550 // //////////////////////////////////////////////////////////////////////
1551 NbOfDBEntries_T DBManager::getPORByIATACode (soci::session& ioSociSession,
1552 const IATACode_T& iIataCode,
1553 LocationList_T& ioLocationList,
1554 const bool iUniqueEntry) {
1555 NbOfDBEntries_T oNbOfEntries = 0;
1556 LocationList_T lLocationList;
1557
1558 try {
1559
1560 // Convert the code into uppercase. That way, one can search for codes
1561 // irrespective of the case (knwing that codes are stored uppercase
1562 // in the database)
1563 const std::string& lCode = static_cast<const std::string&> (iIataCode);
1564 const std::string lCodeUpper = boost::algorithm::to_upper_copy (lCode);
1565
1566 // Prepare the SQL request corresponding to the select statement
1567 soci::statement lSelectStatement (ioSociSession);
1568 std::string lPlaceRawDataString;
1569 DBManager::prepareSelectBlobOnIataCodeStatement (ioSociSession,
1570 lSelectStatement,
1571 lCodeUpper,
1572 lPlaceRawDataString);
1573
1578 bool hasStillData = true;
1579 while (hasStillData == true) {
1580 hasStillData = iterateOnStatement (lSelectStatement,
1581 lPlaceRawDataString);
1582
1583 // DEBUG
1584 const std::string lFoundStr = hasStillData?"more; see below":"no more";
1585 OPENTREP_LOG_DEBUG ("Checked whether there are more locations "
1586 << "corresponding to '" << iIataCode
1587 << "' IATA code. Result: " << lFoundStr);
1588
1589 if (hasStillData == true) {
1590 //
1591 ++oNbOfEntries;
1592
1593 // Parse the POR details and create the corresponding
1594 // Location structure
1595 const RawDataString_T lPlaceRawData (lPlaceRawDataString);
1596 Location lLocation = Result::retrieveLocation (lPlaceRawData);
1597 lLocation.setCorrectedKeywords (iIataCode);
1598
1599 // Add the new found location to the list
1600 lLocationList.push_back (lLocation);
1601
1602 // Debug
1603 OPENTREP_LOG_DEBUG ("[" << oNbOfEntries << "] " << lLocation);
1604 }
1605 }
1606
1607 } catch (std::exception const& lException) {
1608 std::ostringstream errorStr;
1609 errorStr << "Error when trying to retrieve a POR for " << iIataCode
1610 << " from the SQL database: " << lException.what();
1611 OPENTREP_LOG_ERROR (errorStr.str());
1612 throw SQLDatabaseException (errorStr.str());
1613 }
1614
1615 // Add the just retrieved Location structure(s) to the list given
1616 // as parameter
1617 const Location* lHighestPRLocation_ptr = NULL;
1618 PageRank_T lHighestPRValue = 0.0;
1619 for (LocationList_T::const_iterator itLoc = lLocationList.begin();
1620 itLoc != lLocationList.end(); ++itLoc) {
1621 const Location& lLocation = *itLoc;
1622 const PageRank_T& lPRValue = lLocation.getPageRank();
1623
1624 // Store (a pointer on) the Location structure with the highest Page Rank.
1625 // Normally, when there is no PageRank value, the field should be empty
1626 // (empty string). In some rare cases, actually when OPTD is buggy,
1627 // the PageRank value may be zero. While it is a bug from OPTD, there is
1628 // no reason it should trigger a bug from OpenTREP in turn. So, rather
1629 // then ignoring any POR with zero PageRank value, rather the first one
1630 // is (randomly) selected
1631 if (lPRValue >= lHighestPRValue) {
1632 lHighestPRLocation_ptr = &lLocation;
1633 lHighestPRValue = lPRValue;
1634 }
1635
1636 // Add the Location structure now, only when a unique solution
1637 // is not expected
1638 if (iUniqueEntry == false) {
1639 ioLocationList.push_back (lLocation);
1640 }
1641 }
1642
1643 // Add the Location structure with the highest Page Rank value
1644 if (iUniqueEntry == true && lHighestPRLocation_ptr != NULL) {
1645 assert (lHighestPRLocation_ptr != NULL);
1646 ioLocationList.push_back (*lHighestPRLocation_ptr);
1647
1648 // DEBUG
1649 OPENTREP_LOG_DEBUG("Kept the location with the highest PageRank value ("
1650 << lHighestPRValue << ") for '" << iIataCode
1651 << "' IATA code: " << lHighestPRLocation_ptr->getKey());
1652 }
1653
1654 // Make the number of retrieved locations consistent with the unicity
1655 // requirement (if set)
1656 if (oNbOfEntries > 0 && iUniqueEntry == true) {
1657 oNbOfEntries = 1;
1658 }
1659
1660 //
1661 return oNbOfEntries;
1662 }
1663
1664 // //////////////////////////////////////////////////////////////////////
1665 NbOfDBEntries_T DBManager::getPORByICAOCode (soci::session& ioSociSession,
1666 const ICAOCode_T& iIcaoCode,
1667 LocationList_T& ioLocationList) {
1668 NbOfDBEntries_T oNbOfEntries = 0;
1669
1670 try {
1671
1672 // Convert the code into uppercase. That way, one can search for codes
1673 // irrespective of the case (knwing that codes are stored uppercase
1674 // in the database)
1675 const std::string& lCode = static_cast<const std::string&> (iIcaoCode);
1676 const std::string lCodeUpper = boost::algorithm::to_upper_copy (lCode);
1677
1678 // Prepare the SQL request corresponding to the select statement
1679 soci::statement lSelectStatement (ioSociSession);
1680 std::string lPlaceRawDataString;
1681 DBManager::prepareSelectBlobOnIcaoCodeStatement (ioSociSession,
1682 lSelectStatement,
1683 lCodeUpper,
1684 lPlaceRawDataString);
1685
1690 bool hasStillData = true;
1691 while (hasStillData == true) {
1692 hasStillData = iterateOnStatement (lSelectStatement,
1693 lPlaceRawDataString);
1694
1695 // DEBUG
1696 const std::string lFoundStr = hasStillData?"Yes":"No";
1697 OPENTREP_LOG_DEBUG ("Checked locations corresponding to "
1698 << iIcaoCode << " ICAO code. Found: " << lFoundStr);
1699
1700 if (hasStillData == true) {
1701 //
1702 ++oNbOfEntries;
1703
1704 // Parse the POR details and create the corresponding
1705 // Location structure
1706 const RawDataString_T lPlaceRawData (lPlaceRawDataString);
1707 Location lLocation = Result::retrieveLocation (lPlaceRawData);
1708 lLocation.setCorrectedKeywords (iIcaoCode);
1709
1710 // Add the new found location to the list
1711 ioLocationList.push_back (lLocation);
1712
1713 // Debug
1714 OPENTREP_LOG_DEBUG ("[" << oNbOfEntries << "] " << lLocation);
1715 }
1716 }
1717
1718 } catch (std::exception const& lException) {
1719 std::ostringstream errorStr;
1720 errorStr << "Error when trying to retrieve a POR for " << iIcaoCode
1721 << " from the SQL database: " << lException.what();
1722 OPENTREP_LOG_ERROR (errorStr.str());
1723 throw SQLDatabaseException (errorStr.str());
1724 }
1725
1726 //
1727 return oNbOfEntries;
1728 }
1729
1730 // //////////////////////////////////////////////////////////////////////
1731 NbOfDBEntries_T DBManager::getPORByFAACode (soci::session& ioSociSession,
1732 const FAACode_T& iFaaCode,
1733 LocationList_T& ioLocationList) {
1734 NbOfDBEntries_T oNbOfEntries = 0;
1735
1736 try {
1737
1738 // Convert the code into uppercase. That way, one can search for codes
1739 // irrespective of the case (knwing that codes are stored uppercase
1740 // in the database)
1741 const std::string& lCode = static_cast<const std::string&> (iFaaCode);
1742 const std::string lCodeUpper = boost::algorithm::to_upper_copy (lCode);
1743
1744 // Prepare the SQL request corresponding to the select statement
1745 soci::statement lSelectStatement (ioSociSession);
1746 std::string lPlaceRawDataString;
1747 DBManager::prepareSelectBlobOnFaaCodeStatement (ioSociSession,
1748 lSelectStatement,
1749 lCodeUpper,
1750 lPlaceRawDataString);
1751
1756 bool hasStillData = true;
1757 while (hasStillData == true) {
1758 hasStillData = iterateOnStatement (lSelectStatement,
1759 lPlaceRawDataString);
1760
1761 // DEBUG
1762 const std::string lFoundStr = hasStillData?"Yes":"No";
1763 OPENTREP_LOG_DEBUG ("Checked locations corresponding to "
1764 << iFaaCode << " FAA code. Found: " << lFoundStr);
1765
1766 if (hasStillData == true) {
1767 //
1768 ++oNbOfEntries;
1769
1770 // Parse the POR details and create the corresponding
1771 // Location structure
1772 const RawDataString_T lPlaceRawData (lPlaceRawDataString);
1773 Location lLocation = Result::retrieveLocation (lPlaceRawData);
1774 lLocation.setCorrectedKeywords (iFaaCode);
1775
1776 // Add the new found location to the list
1777 ioLocationList.push_back (lLocation);
1778
1779 // Debug
1780 OPENTREP_LOG_DEBUG ("[" << oNbOfEntries << "] " << lLocation);
1781 }
1782 }
1783
1784 } catch (std::exception const& lException) {
1785 std::ostringstream errorStr;
1786 errorStr << "Error when trying to retrieve a POR for " << iFaaCode
1787 << " from the SQL database: " << lException.what();
1788 OPENTREP_LOG_ERROR (errorStr.str());
1789 throw SQLDatabaseException (errorStr.str());
1790 }
1791
1792 //
1793 return oNbOfEntries;
1794 }
1795
1796 // //////////////////////////////////////////////////////////////////////
1797 NbOfDBEntries_T DBManager::getPORByUNLOCode (soci::session& ioSociSession,
1798 const UNLOCode_T& iUNLOCode,
1799 LocationList_T& ioLocationList,
1800 const bool iUniqueEntry) {
1801 NbOfDBEntries_T oNbOfEntries = 0;
1802 LocationList_T lLocationList;
1803
1804 try {
1805
1806 // Convert the code into uppercase. That way, one can search for codes
1807 // irrespective of the case (knwing that codes are stored uppercase
1808 // in the database)
1809 const std::string& lCode = static_cast<const std::string&> (iUNLOCode);
1810 const std::string lCodeUpper = boost::algorithm::to_upper_copy (lCode);
1811
1812 // Prepare the SQL request corresponding to the select statement
1813 soci::statement lSelectStatement (ioSociSession);
1814 std::string lPlaceRawDataString;
1815 DBManager::prepareSelectBlobOnUNLOCodeStatement (ioSociSession,
1816 lSelectStatement,
1817 lCodeUpper,
1818 lPlaceRawDataString);
1819
1824 bool hasStillData = true;
1825 while (hasStillData == true) {
1826 hasStillData = iterateOnStatement (lSelectStatement,
1827 lPlaceRawDataString);
1828
1829 // DEBUG
1830 const std::string lFoundStr = hasStillData?"Yes":"No";
1831 OPENTREP_LOG_DEBUG ("Checked locations corresponding to "
1832 << iUNLOCode << " UN/LOCODE code. Found: "
1833 << lFoundStr);
1834
1835 if (hasStillData == true) {
1836 //
1837 ++oNbOfEntries;
1838
1839 // Parse the POR details and create the corresponding
1840 // Location structure
1841 const RawDataString_T lPlaceRawData (lPlaceRawDataString);
1842 Location lLocation = Result::retrieveLocation (lPlaceRawData);
1843 lLocation.setCorrectedKeywords (iUNLOCode);
1844
1845 // Add the new found location to the list
1846 lLocationList.push_back (lLocation);
1847
1848 // Debug
1849 OPENTREP_LOG_DEBUG ("[" << oNbOfEntries << "] " << lLocation);
1850 }
1851 }
1852
1853 } catch (std::exception const& lException) {
1854 std::ostringstream errorStr;
1855 errorStr << "Error when trying to retrieve a POR for " << iUNLOCode
1856 << " from the SQL database: " << lException.what();
1857 OPENTREP_LOG_ERROR (errorStr.str());
1858 throw SQLDatabaseException (errorStr.str());
1859 }
1860
1861 // Add the just retrieved Location structure(s) to the list given
1862 // as parameter
1863 const Location* lHighestPRLocation_ptr = NULL;
1864 PageRank_T lHighestPRValue = 0.0;
1865 for (LocationList_T::const_iterator itLoc = lLocationList.begin();
1866 itLoc != lLocationList.end(); ++itLoc) {
1867 const Location& lLocation = *itLoc;
1868 const PageRank_T& lPRValue = lLocation.getPageRank();
1869
1870 // Store (a pointer on) the Location structure with the highest Page Rank
1871 if (lPRValue > lHighestPRValue) {
1872 lHighestPRLocation_ptr = &lLocation;
1873 lHighestPRValue = lPRValue;
1874 }
1875
1876 // Add the Location structure now, only when
1877 if (iUniqueEntry == false) {
1878 ioLocationList.push_back (lLocation);
1879 }
1880 }
1881
1882 // Add the Location structure with the highest Page Rank value
1883 if (iUniqueEntry == true && lHighestPRLocation_ptr != NULL) {
1884 assert (lHighestPRLocation_ptr != NULL);
1885 ioLocationList.push_back (*lHighestPRLocation_ptr);
1886
1887 // DEBUG
1888 OPENTREP_LOG_DEBUG("Kept the location with the highest PageRank value ("
1889 << lHighestPRValue << ") for '" << iUNLOCode
1890 << "' IATA code: " << lHighestPRLocation_ptr->getKey());
1891 }
1892
1893 // Make the number of retrieved locations consistent with the unicity
1894 // requirement (if set)
1895 if (oNbOfEntries > 0 && iUniqueEntry == true) {
1896 oNbOfEntries = 1;
1897 }
1898
1899 //
1900 return oNbOfEntries;
1901 }
1902
1903 // //////////////////////////////////////////////////////////////////////
1904 NbOfDBEntries_T DBManager::getPORByUICCode (soci::session& ioSociSession,
1905 const UICCode_T& iUICCode,
1906 LocationList_T& ioLocationList) {
1907 NbOfDBEntries_T oNbOfEntries = 0;
1908
1909 try {
1910
1911 // Prepare the SQL request corresponding to the select statement
1912 soci::statement lSelectStatement (ioSociSession);
1913 std::string lPlaceRawDataString;
1914 DBManager::prepareSelectBlobOnUICCodeStatement (ioSociSession,
1915 lSelectStatement,
1916 iUICCode,
1917 lPlaceRawDataString);
1918
1923 bool hasStillData = true;
1924 while (hasStillData == true) {
1925 hasStillData = iterateOnStatement (lSelectStatement,
1926 lPlaceRawDataString);
1927
1928 // DEBUG
1929 const std::string lFoundStr = hasStillData?"Yes":"No";
1930 OPENTREP_LOG_DEBUG ("Checked locations corresponding to "
1931 << iUICCode << " UIC code. Found: "
1932 << lFoundStr);
1933
1934 if (hasStillData == true) {
1935 //
1936 ++oNbOfEntries;
1937
1938 // Parse the POR details and create the corresponding
1939 // Location structure
1940 const RawDataString_T lPlaceRawData (lPlaceRawDataString);
1941 Location lLocation = Result::retrieveLocation (lPlaceRawData);
1942 const std::string lUICCodeStr =
1943 boost::lexical_cast<std::string> (iUICCode);
1944 lLocation.setCorrectedKeywords (lUICCodeStr);
1945
1946 // Add the new found location to the list
1947 ioLocationList.push_back (lLocation);
1948
1949 // Debug
1950 OPENTREP_LOG_DEBUG ("[" << oNbOfEntries << "] " << lLocation);
1951 }
1952 }
1953
1954 } catch (std::exception const& lException) {
1955 std::ostringstream errorStr;
1956 errorStr << "Error when trying to retrieve a POR for " << iUICCode
1957 << " from the SQL database: " << lException.what();
1958 OPENTREP_LOG_ERROR (errorStr.str());
1959 throw SQLDatabaseException (errorStr.str());
1960 }
1961
1962 //
1963 return oNbOfEntries;
1964 }
1965
1966 // //////////////////////////////////////////////////////////////////////
1967 NbOfDBEntries_T DBManager::getPORByGeonameID (soci::session& ioSociSession,
1968 const GeonamesID_T& iGeonameID,
1969 LocationList_T& ioLocationList) {
1970 NbOfDBEntries_T oNbOfEntries = 0;
1971
1972 try {
1973
1974 // Prepare the SQL request corresponding to the select statement
1975 soci::statement lSelectStatement (ioSociSession);
1976 std::string lPlaceRawDataString;
1977 DBManager::prepareSelectBlobOnPlaceGeoIDStatement (ioSociSession,
1978 lSelectStatement,
1979 iGeonameID,
1980 lPlaceRawDataString);
1981
1986 bool hasStillData = true;
1987 while (hasStillData == true) {
1988 hasStillData = iterateOnStatement (lSelectStatement,
1989 lPlaceRawDataString);
1990
1991 // DEBUG
1992 const std::string lFoundStr = hasStillData?"Yes":"No";
1993 OPENTREP_LOG_DEBUG ("Checked locations corresponding to "
1994 << iGeonameID<< " Geonames ID. Found: "<< lFoundStr);
1995
1996 if (hasStillData == true) {
1997 //
1998 ++oNbOfEntries;
1999
2000 // Parse the POR details and create the corresponding
2001 // Location structure
2002 const RawDataString_T lPlaceRawData (lPlaceRawDataString);
2003 Location lLocation = Result::retrieveLocation (lPlaceRawData);
2004 const std::string lGeonamesIDStr =
2005 boost::lexical_cast<std::string> (iGeonameID);
2006 lLocation.setCorrectedKeywords (lGeonamesIDStr);
2007
2008 // Add the new found location to the list
2009 ioLocationList.push_back (lLocation);
2010
2011 // Debug
2012 OPENTREP_LOG_DEBUG ("[" << oNbOfEntries << "] " << lLocation);
2013 }
2014 }
2015
2016 } catch (std::exception const& lException) {
2017 std::ostringstream errorStr;
2018 errorStr << "Error when trying to retrieve a POR for " << iGeonameID
2019 << " from the SQL database: " << lException.what();
2020 OPENTREP_LOG_ERROR (errorStr.str());
2021 throw SQLDatabaseException (errorStr.str());
2022 }
2023
2024 //
2025 return oNbOfEntries;
2026 }
2027
2028}
#define OPENTREP_LOG_ERROR(iToBeLogged)
Definition Logger.hpp:24
#define OPENTREP_LOG_DEBUG(iToBeLogged)
Definition Logger.hpp:33
#define OPENTREP_LOG_WARNING(iToBeLogged)
Definition Logger.hpp:30
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