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>
14#include <soci/sqlite3/soci-sqlite3.h>
15#include <soci/mysql/soci-mysql.h>
38 bool oCreationSuccessful =
true;
50 boost::filesystem::path lSQLiteDBFullPath (iSQLDBConnStr.begin(),
53 boost::filesystem::path lSQLiteDBParentPath =
54 lSQLiteDBFullPath.parent_path();
58 <<
"') will be cleared and re-created");
61 boost::filesystem::remove_all (lSQLiteDBFullPath);
64 boost::filesystem::create_directories (lSQLiteDBParentPath);
68 if (!(boost::filesystem::exists (lSQLiteDBParentPath)
69 && boost::filesystem::is_directory (lSQLiteDBParentPath))) {
70 std::ostringstream oStr;
71 oStr <<
"Error. The path to the SQLite3 database directory ('"
72 << lSQLiteDBParentPath
73 <<
"') does not exist or is not a directory.";
78 }
catch (std::exception
const& lException) {
79 std::ostringstream errorStr;
80 errorStr <<
"Error when trying to create " << iSQLDBConnStr
81 <<
" SQLite3 database file: " << lException.what();
82 errorStr <<
". Check that the program has got write permission on the "
83 <<
"corresponding parent directories.";
90 <<
"') has been cleared and re-created");
98 <<
"' database in MySQL/MariaDB ('" << iSQLDBConnStr
102 soci::session* lSociSession_ptr = NULL;
107 if (lSociSession_ptr == NULL) {
108 oCreationSuccessful =
false;
109 return oCreationSuccessful;
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();
118 std::cerr << errorStr.str() << std::endl;
119 oCreationSuccessful =
false;
120 return oCreationSuccessful;
122 assert (lSociSession_ptr != NULL);
123 soci::session& lSociSession = *lSociSession_ptr;
155 std::ostringstream lSQLDropTrepLocalStr;
156 lSQLDropTrepLocalStr <<
"drop user '"
159 lSociSession << lSQLDropTrepLocalStr.str();
162 std::ostringstream lSQLDropTrepAllStr;
163 lSQLDropTrepAllStr <<
"drop user '"
165 lSociSession << lSQLDropTrepAllStr.str();
167 }
catch (soci::mysql_soci_error
const& lSociException) {
168 std::ostringstream issueStr;
169 issueStr <<
"Issue when trying to drop MySQL/MariaDB '"
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 "
176 std::cout << issueStr.str() << std::endl;
181 std::ostringstream lSQLCreateTrepLocalStr;
182 lSQLCreateTrepLocalStr <<
"create user '"
185 lSQLCreateTrepLocalStr <<
"identified by '"
187 lSociSession << lSQLCreateTrepLocalStr.str();
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 *.*";
198 lSociSession << lSQLGrantTrepLocalStr.str();
201 std::ostringstream lSQLCreateTrepAllStr;
202 lSQLCreateTrepAllStr <<
"create user '"
204 <<
"'@'%' identified by '"
206 lSociSession << lSQLCreateTrepAllStr.str();
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 *.*";
217 lSociSession << lSQLGrantTrepAllStr.str();
220 std::ostringstream lSQLFlushPrivilegesStr;
221 lSQLFlushPrivilegesStr <<
"flush privileges;";
222 lSociSession << lSQLFlushPrivilegesStr.str();
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();
231 std::cerr << errorStr.str() << std::endl;
232 oCreationSuccessful =
false;
233 return oCreationSuccessful;
246 std::ostringstream lSQLDropDBStr;
247 lSQLDropDBStr <<
"drop database if exists "
250 lSociSession << lSQLDropDBStr.str();
253 std::ostringstream lSQLCreateDBStr;
254 lSQLCreateDBStr <<
"create database if not exists "
256 lSQLCreateDBStr <<
" default character set utf8mb4";
257 lSQLCreateDBStr <<
" collate utf8mb4_unicode_ci;";
258 lSociSession << lSQLCreateDBStr.str();
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 "
265 <<
"' database with 'utf8mb4' as character set. "
266 <<
"Error message: " << lSociException.what();
268 std::cerr << errorStr.str() << std::endl;
270 if (oCreationSuccessful ==
false) {
273 std::ostringstream lSQLDropDBStr;
274 lSQLDropDBStr <<
"drop database if exists "
277 lSociSession << lSQLDropDBStr.str();
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();
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 "
294 <<
"' database. Error message: " << lSociException.what();
296 std::cerr << errorStr.str() << std::endl;
297 oCreationSuccessful =
false;
298 return oCreationSuccessful;
306 <<
"' database have been created in MySQL/MariaDB ('"
307 << iSQLDBConnStr <<
"')");
313 return oCreationSuccessful;
320 soci::session* oSociSession_ptr = NULL;
325 <<
" SQL database/file ('" << iSQLDBConnStr <<
"')");
331 const bool existSQLDBDir =
333 if (existSQLDBDir ==
false) {
334 std::ostringstream errorStr;
335 errorStr <<
"Error when trying to connect to the '" << iSQLDBConnStr
336 <<
"' SQLite3 database; the directory hosting that "
337 <<
"database does not exist or is not readable";
345 oSociSession_ptr =
new soci::session();
346 assert (oSociSession_ptr != NULL);
347 soci::session& lSociSession = *oSociSession_ptr;
348 lSociSession.open (soci::sqlite3, iSQLDBConnStr);
352 <<
"') has been checked and opened");
354 }
catch (std::exception
const& lException) {
355 std::ostringstream errorStr;
356 errorStr <<
"Error when trying to connect to the '" << iSQLDBConnStr
357 <<
"' SQLite3 database: " << lException.what();
363 assert (oSociSession_ptr != NULL);
370 oSociSession_ptr =
new soci::session();
371 assert (oSociSession_ptr != NULL);
372 soci::session& lSociSession = *oSociSession_ptr;
373 lSociSession.open (soci::mysql, iSQLDBConnStr);
377 << iSQLDBConnStr <<
") is accessible");
379 }
catch (std::exception
const& lException) {
380 std::ostringstream errorStr;
381 errorStr <<
"Error when trying to connect to the '" << iSQLDBConnStr
382 <<
"' MySQL/MariaDB database: " << lException.what();
388 assert (oSociSession_ptr != NULL);
394 std::ostringstream errorStr;
395 errorStr <<
"Error: the '" << iDBType.
describe()
396 <<
"' SQL database type is not supported";
401 return oSociSession_ptr;
408 soci::session& ioSociSession) {
412 <<
" SQL database/file ('" << iSQLDBConnStr <<
"')");
420 ioSociSession.close();
422 }
catch (std::exception
const& lException) {
423 std::ostringstream errorStr;
424 errorStr <<
"Error when trying to release the connection ('"
426 <<
"') to the SQLite3 database: " << lException.what();
436 ioSociSession.close();
438 }
catch (std::exception
const& lException) {
439 std::ostringstream errorStr;
440 errorStr <<
"Error when trying to release the connection ('"
442 <<
"') to the MySQL/MariaDB database: " << lException.what();
451 std::ostringstream errorStr;
452 errorStr <<
"Error: the '" << iDBType.
describe()
453 <<
"' SQL database type is not supported";
461 const std::string& lDBName = ioSociSession.get_backend_name();
462 const DBType lDBType (lDBName);
467 <<
" SQL database/file will be created/reset");
497 ioSociSession <<
"drop table if exists optd_por;";
498 std::ostringstream lSQLTableCreationStr;
499 lSQLTableCreationStr <<
"create table optd_por (";
500 lSQLTableCreationStr <<
"pk varchar(20) NOT NULL, ";
501 lSQLTableCreationStr <<
"location_type varchar(4) default NULL, ";
502 lSQLTableCreationStr <<
"iata_code varchar(3) default NULL, ";
503 lSQLTableCreationStr <<
"icao_code varchar(4) default NULL, ";
504 lSQLTableCreationStr <<
"faa_code varchar(4) default NULL, ";
505 lSQLTableCreationStr <<
"unlocode_code varchar(5) default NULL, ";
506 lSQLTableCreationStr <<
"uic_code int(11) default NULL, ";
507 lSQLTableCreationStr <<
"is_geonames varchar(1) default NULL, ";
508 lSQLTableCreationStr <<
"geoname_id int(11) default NULL, ";
509 lSQLTableCreationStr <<
"envelope_id int(11) default NULL, ";
510 lSQLTableCreationStr <<
"date_from date default NULL, ";
511 lSQLTableCreationStr <<
"date_until date default NULL, ";
512 lSQLTableCreationStr <<
"serialised_place varchar(12000) default NULL);";
513 ioSociSession << lSQLTableCreationStr.str();
515 }
catch (std::exception
const& lException) {
516 std::ostringstream errorStr;
517 errorStr <<
"Error when trying to create SQLite3 tables: "
518 << lException.what();
553 ioSociSession <<
"drop table if exists optd_por;";
554 std::ostringstream lSQLTableCreationStr;
555 lSQLTableCreationStr <<
"create table optd_por (";
556 lSQLTableCreationStr <<
"pk varchar(20) NOT NULL, ";
557 lSQLTableCreationStr <<
"location_type varchar(4) default NULL, ";
558 lSQLTableCreationStr <<
"iata_code varchar(3) default NULL, ";
559 lSQLTableCreationStr <<
"icao_code varchar(4) default NULL, ";
560 lSQLTableCreationStr <<
"faa_code varchar(4) default NULL, ";
561 lSQLTableCreationStr <<
"unlocode_code varchar(5) default NULL, ";
562 lSQLTableCreationStr <<
"uic_code int(11) default NULL, ";
563 lSQLTableCreationStr <<
"is_geonames varchar(1) default NULL, ";
564 lSQLTableCreationStr <<
"geoname_id int(11) default NULL, ";
565 lSQLTableCreationStr <<
"envelope_id int(11) default NULL, ";
566 lSQLTableCreationStr <<
"date_from date default NULL, ";
567 lSQLTableCreationStr <<
"date_until date default NULL, ";
568 lSQLTableCreationStr <<
"serialised_place varchar(12000) default NULL); ";
569 ioSociSession << lSQLTableCreationStr.str();
571 }
catch (std::exception
const& lException) {
572 std::ostringstream errorStr;
573 errorStr <<
"Error when trying to create MySQL/MariaDB tables: "
574 << lException.what();
586 std::ostringstream errorStr;
587 errorStr <<
"Error: the '" << lDBName
588 <<
"' SQL database type is not supported";
596 const std::string& lDBName = ioSociSession.get_backend_name();
597 const DBType lDBType (lDBName);
602 <<
" SQL database/file will be created/reset");
624 <<
"create index optd_por_iata_code on optd_por (iata_code);";
626 <<
"create index optd_por_iata_date on optd_por (iata_code, date_from, date_until);";
628 <<
"create index optd_por_icao_code on optd_por (icao_code);";
630 <<
"create index optd_por_geonameid on optd_por (geoname_id);";
632 <<
"create index optd_por_unlocode_code on optd_por (unlocode_code);";
634 <<
"create index optd_por_uic_code on optd_por (uic_code);";
636 }
catch (std::exception
const& lException) {
637 std::ostringstream errorStr;
638 errorStr <<
"Error when trying to create SQLite3 indexes: "
639 << lException.what();
646 "for the SQLite3 database");
669 <<
"alter table optd_por add unique index optd_por_pk (pk asc);";
671 <<
"alter table optd_por add index optd_por_iata_code (iata_code asc);";
673 <<
"alter table optd_por add index optd_por_iata_date (iata_code asc, date_from asc, date_until asc);";
675 <<
"alter table optd_por add index optd_por_icao_code (icao_code asc);";
677 <<
"alter table optd_por add index optd_por_geonameid (geoname_id asc);";
679 <<
"alter table optd_por add index optd_por_unlocode_code (unlocode_code asc);";
681 <<
"alter table optd_por add index optd_por_uic_code (uic_code asc);";
683 }
catch (std::exception
const& lException) {
684 std::ostringstream errorStr;
685 errorStr <<
"Error when trying to create MySQL/MariaDB indices: "
686 << lException.what();
693 "for the MySQL/MariaDB database");
699 std::ostringstream errorStr;
700 errorStr <<
"Error: the '" << lDBName
701 <<
"' SQL database type is not supported";
710 soci::statement& ioSelectStatement) {
711 std::string oSerialisedPlaceStr;
720 ioSelectStatement = (ioSociSession.prepare
721 <<
"select serialised_place from optd_por",
722 soci::into (oSerialisedPlaceStr));
725 ioSelectStatement.execute();
727 }
catch (std::exception
const& lException) {
728 std::ostringstream errorStr;
730 <<
"Error in the 'select serialised_place from optd_por' SQL request: "
731 << lException.what();
737 return oSerialisedPlaceStr;
742 prepareSelectBlobOnIataCodeStatement (soci::session& ioSociSession,
743 soci::statement& ioSelectStatement,
744 const std::string& iIataCode,
745 std::string& ioSerialisedPlaceStr) {
753 ioSelectStatement = (ioSociSession.prepare
754 <<
"select serialised_place from optd_por "
755 <<
"where iata_code = :place_iata_code",
756 soci::use (iIataCode),
757 soci::into (ioSerialisedPlaceStr));
760 ioSelectStatement.execute();
762 }
catch (std::exception
const& lException) {
763 std::ostringstream errorStr;
765 <<
"Error in the 'select serialised_place from optd_por' SQL request: "
766 << lException.what();
768 throw SQLDatabaseException (errorStr.str());
774 prepareSelectBlobOnIcaoCodeStatement (soci::session& ioSociSession,
775 soci::statement& ioSelectStatement,
776 const std::string& iIcaoCode,
777 std::string& ioSerialisedPlaceStr) {
785 ioSelectStatement = (ioSociSession.prepare
786 <<
"select serialised_place from optd_por "
787 <<
"where icao_code = :place_icao_code",
788 soci::use (iIcaoCode),
789 soci::into (ioSerialisedPlaceStr));
792 ioSelectStatement.execute();
794 }
catch (std::exception
const& lException) {
795 std::ostringstream errorStr;
797 <<
"Error in the 'select serialised_place from optd_por' SQL request: "
798 << lException.what();
800 throw SQLDatabaseException (errorStr.str());
806 prepareSelectBlobOnFaaCodeStatement (soci::session& ioSociSession,
807 soci::statement& ioSelectStatement,
808 const std::string& iFaaCode,
809 std::string& ioSerialisedPlaceStr) {
817 ioSelectStatement = (ioSociSession.prepare
818 <<
"select serialised_place from optd_por "
819 <<
"where faa_code = :place_faa_code",
820 soci::use (iFaaCode),
821 soci::into (ioSerialisedPlaceStr));
824 ioSelectStatement.execute();
826 }
catch (std::exception
const& lException) {
827 std::ostringstream errorStr;
829 <<
"Error in the 'select serialised_place from optd_por' SQL request: "
830 << lException.what();
832 throw SQLDatabaseException (errorStr.str());
838 prepareSelectBlobOnUNLOCodeStatement (soci::session& ioSociSession,
839 soci::statement& ioSelectStatement,
840 const std::string& iUNLOCode,
841 std::string& ioSerialisedPlaceStr) {
849 ioSelectStatement = (ioSociSession.prepare
850 <<
"select serialised_place from optd_por "
851 <<
"where unlocode_code = :place_unlocode_code",
852 soci::use (iUNLOCode),
853 soci::into (ioSerialisedPlaceStr));
856 ioSelectStatement.execute();
858 }
catch (std::exception
const& lException) {
859 std::ostringstream errorStr;
861 <<
"Error in the 'select serialised_place from optd_por' SQL request: "
862 << lException.what();
864 throw SQLDatabaseException (errorStr.str());
870 prepareSelectBlobOnUICCodeStatement (soci::session& ioSociSession,
871 soci::statement& ioSelectStatement,
873 std::string& ioSerialisedPlaceStr) {
881 ioSelectStatement = (ioSociSession.prepare
882 <<
"select serialised_place from optd_por "
883 <<
"where uic_code = :place_uic_code",
884 soci::use (iUICCode),
885 soci::into (ioSerialisedPlaceStr));
888 ioSelectStatement.execute();
890 }
catch (std::exception
const& lException) {
891 std::ostringstream errorStr;
893 <<
"Error in the 'select serialised_place from optd_por' SQL request: "
894 << lException.what();
896 throw SQLDatabaseException (errorStr.str());
902 prepareSelectBlobOnPlaceGeoIDStatement (soci::session& ioSociSession,
903 soci::statement& ioSelectStatement,
905 std::string& ioSerialisedPlaceStr) {
913 ioSelectStatement = (ioSociSession.prepare
914 <<
"select serialised_place from optd_por "
915 <<
"where geoname_id = :place_geoname_id",
916 soci::use (iGeonameID),
917 soci::into (ioSerialisedPlaceStr));
920 ioSelectStatement.execute();
922 }
catch (std::exception
const& lException) {
923 std::ostringstream errorStr;
925 <<
"Error in the 'select serialised_place from optd_por' SQL request: "
926 << lException.what();
928 throw SQLDatabaseException (errorStr.str());
934 const std::string& iSerialisedPlaceStr) {
935 bool hasStillData =
false;
940 hasStillData = ioStatement.fetch();
942 }
catch (std::exception
const& lException) {
943 std::ostringstream errorStr;
944 errorStr <<
"Error when iterating on the SQL fetch: " << lException.what();
945 errorStr <<
". The current place is: " << iSerialisedPlaceStr;
955 const Place& iPlace) {
960 ioSociSession.begin();
964 const std::string lPK (lLocationKey.
toString());
967 const std::string lIataCode (iPlace.
getIataCode());
968 const std::string lIcaoCode (iPlace.
getIcaoCode());
969 const std::string lFaaCode (iPlace.
getFaaCode());
970 const std::string lIsGeonames ((iPlace.
isGeonames())?
"Y":
"N");
971 const std::string lGeonameID =
973 const std::string lEnvID =
975 const std::string lDateFrom =
976 boost::gregorian::to_iso_extended_string (iPlace.
getDateFrom());
977 const std::string lDateEnd =
978 boost::gregorian::to_iso_extended_string (iPlace.
getDateEnd());
1006 std::string lUNLOCodeStr (
"");
1007 if (lUNLOCodeList.empty() ==
false) {
1008 const UNLOCode_T& lUNLOCode = lUNLOCodeList.front();
1009 lUNLOCodeStr =
static_cast<const std::string
> (lUNLOCode);
1018 if (lUICCodeList.empty() ==
false) {
1019 const UICCode_T& lUICCode = lUICCodeList.front();
1020 lUICCodeInt =
static_cast<const UICCode_T> (lUICCode);
1038 ioSociSession <<
"insert into optd_por values (:pk, "
1039 <<
":location_type, :iata_code, :icao_code, :faa_code, "
1040 <<
":unlocode_code, :uic_code, "
1041 <<
":is_geonames, :geoname_id, "
1042 <<
":envelope_id, :date_from, :date_until, "
1043 <<
":serialised_place)",
1044 soci::use (lPK), soci::use (lLocationType), soci::use (lIataCode),
1045 soci::use (lIcaoCode), soci::use (lFaaCode),
1046 soci::use (lUNLOCodeStr), soci::use (lUICCodeInt),
1047 soci::use (lIsGeonames), soci::use (lGeonameID),
1048 soci::use (lEnvID), soci::use (lDateFrom), soci::use (lDateEnd),
1049 soci::use (lRawDataString);
1052 ioSociSession.commit();
1057 }
catch (std::exception
const& lException) {
1058 std::ostringstream errorStr;
1059 errorStr <<
"Error when updating " << iPlace.
toString() <<
": "
1060 << lException.what();
1068 const Place& iPlace) {
1073 ioSociSession.begin();
1077 std::string lIataCode;
1078 soci::statement lUpdateStatement =
1079 (ioSociSession.prepare
1080 <<
"update place_details "
1081 <<
"set xapian_docid = :xapian_docid "
1082 <<
"where iata_code = :iata_code",
1083 soci::use (lDocID), soci::use (lIataCode));
1088 lUpdateStatement.execute (
true);
1091 ioSociSession.commit();
1096 }
catch (std::exception
const& lException) {
1097 std::ostringstream errorStr;
1098 errorStr <<
"Error when updating " << iPlace.
toString() <<
": "
1099 << lException.what();
1117 ioSociSession <<
"select count(1) from optd_por;", soci::into(oNbOfEntries);
1119 }
catch (std::exception
const& lException) {
1120 std::ostringstream errorStr;
1122 <<
"Error when trying to count the number of rows in the optd_por table: "
1123 << lException.what();
1128 return oNbOfEntries;
1138 soci::statement lSelectStatement (ioSociSession);
1139 std::string lPlace =
1147 bool hasStillData =
true;
1148 while (hasStillData ==
true) {
1152 if (hasStillData ==
true) {
1160 }
catch (std::exception
const& lException) {
1161 std::ostringstream errorStr;
1162 errorStr <<
"Error when trying to retrieve " << oNbOfEntries
1163 <<
"-th row from the SQL database: " << lException.what();
1168 return oNbOfEntries;
1175 const bool iUniqueEntry) {
1184 const std::string& lCode =
static_cast<const std::string&
> (iIataCode);
1185 const std::string lCodeUpper = boost::algorithm::to_upper_copy (lCode);
1188 soci::statement lSelectStatement (ioSociSession);
1189 std::string lPlaceRawDataString;
1190 DBManager::prepareSelectBlobOnIataCodeStatement (ioSociSession,
1193 lPlaceRawDataString);
1199 bool hasStillData =
true;
1200 while (hasStillData ==
true) {
1202 lPlaceRawDataString);
1205 const std::string lFoundStr = hasStillData?
"more; see below":
"no more";
1207 <<
"corresponding to '" << iIataCode
1208 <<
"' IATA code. Result: " << lFoundStr);
1210 if (hasStillData ==
true) {
1221 lLocationList.push_back (lLocation);
1228 }
catch (std::exception
const& lException) {
1229 std::ostringstream errorStr;
1230 errorStr <<
"Error when trying to retrieve a POR for " << iIataCode
1231 <<
" from the SQL database: " << lException.what();
1238 const Location* lHighestPRLocation_ptr = NULL;
1240 for (LocationList_T::const_iterator itLoc = lLocationList.begin();
1241 itLoc != lLocationList.end(); ++itLoc) {
1242 const Location& lLocation = *itLoc;
1252 if (lPRValue >= lHighestPRValue) {
1253 lHighestPRLocation_ptr = &lLocation;
1254 lHighestPRValue = lPRValue;
1259 if (iUniqueEntry ==
false) {
1260 ioLocationList.push_back (lLocation);
1265 if (iUniqueEntry ==
true && lHighestPRLocation_ptr != NULL) {
1266 assert (lHighestPRLocation_ptr != NULL);
1267 ioLocationList.push_back (*lHighestPRLocation_ptr);
1271 << lHighestPRValue <<
") for '" << iIataCode
1272 <<
"' IATA code: " << lHighestPRLocation_ptr->
getKey());
1277 if (oNbOfEntries > 0 && iUniqueEntry ==
true) {
1282 return oNbOfEntries;
1296 const std::string& lCode =
static_cast<const std::string&
> (iIcaoCode);
1297 const std::string lCodeUpper = boost::algorithm::to_upper_copy (lCode);
1300 soci::statement lSelectStatement (ioSociSession);
1301 std::string lPlaceRawDataString;
1302 DBManager::prepareSelectBlobOnIcaoCodeStatement (ioSociSession,
1305 lPlaceRawDataString);
1311 bool hasStillData =
true;
1312 while (hasStillData ==
true) {
1314 lPlaceRawDataString);
1317 const std::string lFoundStr = hasStillData?
"Yes":
"No";
1319 << iIcaoCode <<
" ICAO code. Found: " << lFoundStr);
1321 if (hasStillData ==
true) {
1332 ioLocationList.push_back (lLocation);
1339 }
catch (std::exception
const& lException) {
1340 std::ostringstream errorStr;
1341 errorStr <<
"Error when trying to retrieve a POR for " << iIcaoCode
1342 <<
" from the SQL database: " << lException.what();
1348 return oNbOfEntries;
1362 const std::string& lCode =
static_cast<const std::string&
> (iFaaCode);
1363 const std::string lCodeUpper = boost::algorithm::to_upper_copy (lCode);
1366 soci::statement lSelectStatement (ioSociSession);
1367 std::string lPlaceRawDataString;
1368 DBManager::prepareSelectBlobOnFaaCodeStatement (ioSociSession,
1371 lPlaceRawDataString);
1377 bool hasStillData =
true;
1378 while (hasStillData ==
true) {
1380 lPlaceRawDataString);
1383 const std::string lFoundStr = hasStillData?
"Yes":
"No";
1385 << iFaaCode <<
" FAA code. Found: " << lFoundStr);
1387 if (hasStillData ==
true) {
1398 ioLocationList.push_back (lLocation);
1405 }
catch (std::exception
const& lException) {
1406 std::ostringstream errorStr;
1407 errorStr <<
"Error when trying to retrieve a POR for " << iFaaCode
1408 <<
" from the SQL database: " << lException.what();
1414 return oNbOfEntries;
1421 const bool iUniqueEntry) {
1430 const std::string& lCode =
static_cast<const std::string&
> (iUNLOCode);
1431 const std::string lCodeUpper = boost::algorithm::to_upper_copy (lCode);
1434 soci::statement lSelectStatement (ioSociSession);
1435 std::string lPlaceRawDataString;
1436 DBManager::prepareSelectBlobOnUNLOCodeStatement (ioSociSession,
1439 lPlaceRawDataString);
1445 bool hasStillData =
true;
1446 while (hasStillData ==
true) {
1448 lPlaceRawDataString);
1451 const std::string lFoundStr = hasStillData?
"Yes":
"No";
1453 << iUNLOCode <<
" UN/LOCODE code. Found: "
1456 if (hasStillData ==
true) {
1467 lLocationList.push_back (lLocation);
1474 }
catch (std::exception
const& lException) {
1475 std::ostringstream errorStr;
1476 errorStr <<
"Error when trying to retrieve a POR for " << iUNLOCode
1477 <<
" from the SQL database: " << lException.what();
1484 const Location* lHighestPRLocation_ptr = NULL;
1486 for (LocationList_T::const_iterator itLoc = lLocationList.begin();
1487 itLoc != lLocationList.end(); ++itLoc) {
1488 const Location& lLocation = *itLoc;
1492 if (lPRValue > lHighestPRValue) {
1493 lHighestPRLocation_ptr = &lLocation;
1494 lHighestPRValue = lPRValue;
1498 if (iUniqueEntry ==
false) {
1499 ioLocationList.push_back (lLocation);
1504 if (iUniqueEntry ==
true && lHighestPRLocation_ptr != NULL) {
1505 assert (lHighestPRLocation_ptr != NULL);
1506 ioLocationList.push_back (*lHighestPRLocation_ptr);
1510 << lHighestPRValue <<
") for '" << iUNLOCode
1511 <<
"' IATA code: " << lHighestPRLocation_ptr->
getKey());
1516 if (oNbOfEntries > 0 && iUniqueEntry ==
true) {
1521 return oNbOfEntries;
1533 soci::statement lSelectStatement (ioSociSession);
1534 std::string lPlaceRawDataString;
1535 DBManager::prepareSelectBlobOnUICCodeStatement (ioSociSession,
1538 lPlaceRawDataString);
1544 bool hasStillData =
true;
1545 while (hasStillData ==
true) {
1547 lPlaceRawDataString);
1550 const std::string lFoundStr = hasStillData?
"Yes":
"No";
1552 << iUICCode <<
" UIC code. Found: "
1555 if (hasStillData ==
true) {
1563 const std::string lUICCodeStr =
1564 boost::lexical_cast<std::string> (iUICCode);
1568 ioLocationList.push_back (lLocation);
1575 }
catch (std::exception
const& lException) {
1576 std::ostringstream errorStr;
1577 errorStr <<
"Error when trying to retrieve a POR for " << iUICCode
1578 <<
" from the SQL database: " << lException.what();
1584 return oNbOfEntries;
1596 soci::statement lSelectStatement (ioSociSession);
1597 std::string lPlaceRawDataString;
1598 DBManager::prepareSelectBlobOnPlaceGeoIDStatement (ioSociSession,
1601 lPlaceRawDataString);
1607 bool hasStillData =
true;
1608 while (hasStillData ==
true) {
1610 lPlaceRawDataString);
1613 const std::string lFoundStr = hasStillData?
"Yes":
"No";
1615 << iGeonameID<<
" Geonames ID. Found: "<< lFoundStr);
1617 if (hasStillData ==
true) {
1625 const std::string lGeonamesIDStr =
1626 boost::lexical_cast<std::string> (iGeonameID);
1630 ioLocationList.push_back (lLocation);
1637 }
catch (std::exception
const& lException) {
1638 std::ostringstream errorStr;
1639 errorStr <<
"Error when trying to retrieve a POR for " << iGeonameID
1640 <<
" from the SQL database: " << lException.what();
1646 return oNbOfEntries;
#define OPENTREP_LOG_ERROR(iToBeLogged)
#define OPENTREP_LOG_DEBUG(iToBeLogged)
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).
const IsGeonames_T & isGeonames() const
const ICAOCode_T & getIcaoCode() const
const RawDataString_T & getRawDataString() const
const FAACode_T & getFaaCode() const
const Date_T & getDateEnd() const
const GeonamesID_T & getGeonamesID() const
const XapianDocID_T & getDocID() const
const IATACode_T & getIataCode() const
const Date_T & getDateFrom() const
const EnvelopeID_T & getEnvelopeID() const
const UNLOCodeList_T & getUNLOCodeList() const
std::string toString() const
const IATAType & getIataType() const
const LocationKey & getKey() const
const UICCodeList_T & getUICCodeList() const
static Location retrieveLocation(const Xapian::Document &)
unsigned int NbOfDBEntries_T
const std::string DEFAULT_OPENTREP_MYSQL_DB_DBNAME
const std::string DEFAULT_OPENTREP_MYSQL_DB_USER
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
unsigned short DeploymentNumber_T
unsigned int GeonamesID_T
unsigned int XapianDocID_T
Enumeration of database types.
const std::string describe() const
Enumeration of place/location types with respect to their use for transportation purposes.
std::string getTypeAsString() const
Class modelling the primary key of a location/POR (point of reference).
std::string toString() const
Structure modelling a (geographical) location.
const LocationKey & getKey() const
const PageRank_T & getPageRank() const
void setCorrectedKeywords(const std::string &iCorrectedKeywords)