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>
16#include <soci/postgresql/soci-postgresql.h>
37 bool oCreationSuccessful =
true;
41 boost::filesystem::path lSQLiteDBFullPath (iSQLDBConnStr.begin(),
44 boost::filesystem::path lSQLiteDBParentPath =
45 lSQLiteDBFullPath.parent_path();
49 <<
"') will be cleared and re-created");
52 boost::filesystem::remove_all (lSQLiteDBFullPath);
55 boost::filesystem::create_directories (lSQLiteDBParentPath);
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.";
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.";
81 <<
"') has been cleared and re-created");
84 return oCreationSuccessful;
90 bool oCreationSuccessful =
true;
97 <<
"' database in MySQL/MariaDB ('" << iSQLDBConnStr
101 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 <<
"')");
309 return oCreationSuccessful;
315 bool oCreationSuccessful =
true;
323 <<
"' database in PostgreSQL ('" << iSQLDBConnStr
327 soci::session* lSociSession_ptr = NULL;
333 if (lSociSession_ptr == NULL) {
334 oCreationSuccessful =
false;
335 return oCreationSuccessful;
338 }
catch (soci::mysql_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();
344 std::cerr << errorStr.str() << std::endl;
345 oCreationSuccessful =
false;
346 return oCreationSuccessful;
348 assert (lSociSession_ptr != NULL);
356 return oCreationSuccessful;
364 bool oCreationSuccessful =
true;
395 return oCreationSuccessful;
402 soci::session* oSociSession_ptr = NULL;
410 <<
" SQL database/file ('" << iSQLDBConnStr <<
"')");
416 const bool existSQLDBDir =
418 if (existSQLDBDir ==
false) {
419 std::ostringstream errorStr;
420 errorStr <<
"Error when trying to connect to the '" << iSQLDBConnStr
421 <<
"' SQLite3 database; the directory hosting that "
422 <<
"database does not exist or is not readable";
430 oSociSession_ptr =
new soci::session();
431 assert (oSociSession_ptr != NULL);
432 soci::session& lSociSession = *oSociSession_ptr;
433 lSociSession.open (soci::sqlite3, iSQLDBConnStr);
437 <<
"') has been checked and opened");
439 }
catch (std::exception
const& lException) {
440 std::ostringstream errorStr;
441 errorStr <<
"Error when trying to connect to the '" << iSQLDBConnStr
442 <<
"' SQLite3 database: " << lException.what();
448 assert (oSociSession_ptr != NULL);
457 oSociSession_ptr =
new soci::session();
458 assert (oSociSession_ptr != NULL);
459 soci::session& lSociSession = *oSociSession_ptr;
460 lSociSession.open (soci::mysql, iSQLDBConnStr);
464 << iSQLDBConnStr <<
") is accessible");
466 }
catch (std::exception
const& lException) {
467 std::ostringstream errorStr;
468 errorStr <<
"Error when trying to connect to the '" << iSQLDBConnStr
469 <<
"' MySQL/MariaDB database: " << lException.what();
475 assert (oSociSession_ptr != NULL);
484 oSociSession_ptr =
new soci::session();
485 assert (oSociSession_ptr != NULL);
486 soci::session& lSociSession = *oSociSession_ptr;
487 lSociSession.open (soci::postgresql, iSQLDBConnStr);
491 << iSQLDBConnStr <<
") is accessible");
493 }
catch (std::exception
const& lException) {
494 std::ostringstream errorStr;
495 errorStr <<
"Error when trying to connect to the '" << iSQLDBConnStr
496 <<
"' PostgreSQL database: " << lException.what();
502 assert (oSociSession_ptr != NULL);
514 std::ostringstream errorStr;
515 errorStr <<
"Error: the '" << iDBType.
describe()
516 <<
"' SQL database type is not supported";
523 return oSociSession_ptr;
530 soci::session& ioSociSession) {
537 <<
" SQL database/file ('" << iSQLDBConnStr <<
"')");
545 ioSociSession.close();
547 }
catch (std::exception
const& lException) {
548 std::ostringstream errorStr;
549 errorStr <<
"Error when trying to release the connection ('"
551 <<
"') to the SQLite3 database: " << lException.what();
563 ioSociSession.close();
565 }
catch (std::exception
const& lException) {
566 std::ostringstream errorStr;
567 errorStr <<
"Error when trying to release the connection ('"
569 <<
"') to the PostgreSQL database: " << lException.what();
581 ioSociSession.close();
583 }
catch (std::exception
const& lException) {
584 std::ostringstream errorStr;
585 errorStr <<
"Error when trying to release the connection ('"
587 <<
"') to the MySQL/MariaDB database: " << lException.what();
601 std::ostringstream errorStr;
602 errorStr <<
"Error: the '" << iDBType.
describe()
603 <<
"' SQL database type is not supported";
612 const std::string& lDBName = ioSociSession.get_backend_name();
613 const DBType lDBType (lDBName);
621 <<
" SQL database/file will be created/reset");
651 ioSociSession <<
"drop table if exists optd_por;";
652 std::ostringstream lSQLTableCreationStr;
653 lSQLTableCreationStr <<
"create table optd_por (";
654 lSQLTableCreationStr <<
"pk varchar(20) NOT NULL, ";
655 lSQLTableCreationStr <<
"location_type varchar(4) default NULL, ";
656 lSQLTableCreationStr <<
"iata_code varchar(3) default NULL, ";
657 lSQLTableCreationStr <<
"icao_code varchar(4) default NULL, ";
658 lSQLTableCreationStr <<
"faa_code varchar(4) default NULL, ";
659 lSQLTableCreationStr <<
"unlocode_code varchar(5) default NULL, ";
660 lSQLTableCreationStr <<
"uic_code int(11) default NULL, ";
661 lSQLTableCreationStr <<
"is_geonames varchar(1) default NULL, ";
662 lSQLTableCreationStr <<
"geoname_id int(11) default NULL, ";
663 lSQLTableCreationStr <<
"envelope_id int(11) default NULL, ";
664 lSQLTableCreationStr <<
"date_from date default NULL, ";
665 lSQLTableCreationStr <<
"date_until date default NULL, ";
666 lSQLTableCreationStr <<
"serialised_place varchar(12000) default NULL);";
667 ioSociSession << lSQLTableCreationStr.str();
669 }
catch (std::exception
const& lException) {
670 std::ostringstream errorStr;
671 errorStr <<
"Error when trying to create SQLite3 tables: "
672 << lException.what();
713 ioSociSession <<
"drop table if exists optd_por;";
714 std::ostringstream lSQLTableCreationStr;
715 lSQLTableCreationStr <<
"create table optd_por (";
716 lSQLTableCreationStr <<
"pk varchar(20) NOT NULL, ";
717 lSQLTableCreationStr <<
"location_type varchar(4) default NULL, ";
718 lSQLTableCreationStr <<
"iata_code varchar(3) default NULL, ";
719 lSQLTableCreationStr <<
"icao_code varchar(4) default NULL, ";
720 lSQLTableCreationStr <<
"faa_code varchar(4) default NULL, ";
721 lSQLTableCreationStr <<
"unlocode_code varchar(5) default NULL, ";
722 lSQLTableCreationStr <<
"uic_code int(11) default NULL, ";
723 lSQLTableCreationStr <<
"is_geonames varchar(1) default NULL, ";
724 lSQLTableCreationStr <<
"geoname_id int(11) default NULL, ";
725 lSQLTableCreationStr <<
"envelope_id int(11) default NULL, ";
726 lSQLTableCreationStr <<
"date_from date default NULL, ";
727 lSQLTableCreationStr <<
"date_until date default NULL, ";
728 lSQLTableCreationStr <<
"serialised_place varchar(12000) default NULL); ";
729 ioSociSession << lSQLTableCreationStr.str();
731 }
catch (std::exception
const& lException) {
732 std::ostringstream errorStr;
733 errorStr <<
"Error when trying to create MySQL/MariaDB tables: "
734 << lException.what();
752 std::ostringstream errorStr;
753 errorStr <<
"Error: the '" << lDBName
754 <<
"' SQL database type is not supported";
764 const std::string& lDBName = ioSociSession.get_backend_name();
765 const DBType lDBType (lDBName);
773 <<
" SQL database/file will be created/reset");
795 <<
"create index optd_por_iata_code on optd_por (iata_code);";
797 <<
"create index optd_por_iata_date on optd_por (iata_code, date_from, date_until);";
799 <<
"create index optd_por_icao_code on optd_por (icao_code);";
801 <<
"create index optd_por_geonameid on optd_por (geoname_id);";
803 <<
"create index optd_por_unlocode_code on optd_por (unlocode_code);";
805 <<
"create index optd_por_uic_code on optd_por (uic_code);";
807 }
catch (std::exception
const& lException) {
808 std::ostringstream errorStr;
809 errorStr <<
"Error when trying to create SQLite3 indexes: "
810 << lException.what();
817 "for the SQLite3 database");
847 <<
"alter table optd_por add unique index optd_por_pk (pk asc);";
849 <<
"alter table optd_por add index optd_por_iata_code (iata_code asc);";
851 <<
"alter table optd_por add index optd_por_iata_date (iata_code asc, date_from asc, date_until asc);";
853 <<
"alter table optd_por add index optd_por_icao_code (icao_code asc);";
855 <<
"alter table optd_por add index optd_por_geonameid (geoname_id asc);";
857 <<
"alter table optd_por add index optd_por_unlocode_code (unlocode_code asc);";
859 <<
"alter table optd_por add index optd_por_uic_code (uic_code asc);";
861 }
catch (std::exception
const& lException) {
862 std::ostringstream errorStr;
863 errorStr <<
"Error when trying to create MySQL/MariaDB indices: "
864 << lException.what();
871 "for the MySQL/MariaDB database");
882 std::ostringstream errorStr;
883 errorStr <<
"Error: the '" << lDBName
884 <<
"' SQL database type is not supported";
895 soci::statement& ioSelectStatement) {
896 std::string oSerialisedPlaceStr;
905 ioSelectStatement = (ioSociSession.prepare
906 <<
"select serialised_place from optd_por",
907 soci::into (oSerialisedPlaceStr));
910 ioSelectStatement.execute();
912 }
catch (std::exception
const& lException) {
913 std::ostringstream errorStr;
915 <<
"Error in the 'select serialised_place from optd_por' SQL request: "
916 << lException.what();
922 return oSerialisedPlaceStr;
927 prepareSelectBlobOnIataCodeStatement (soci::session& ioSociSession,
928 soci::statement& ioSelectStatement,
929 const std::string& iIataCode,
930 std::string& ioSerialisedPlaceStr) {
938 ioSelectStatement = (ioSociSession.prepare
939 <<
"select serialised_place from optd_por "
940 <<
"where iata_code = :place_iata_code",
941 soci::use (iIataCode),
942 soci::into (ioSerialisedPlaceStr));
945 ioSelectStatement.execute();
947 }
catch (std::exception
const& lException) {
948 std::ostringstream errorStr;
950 <<
"Error in the 'select serialised_place from optd_por' SQL request: "
951 << lException.what();
953 throw SQLDatabaseException (errorStr.str());
959 prepareSelectBlobOnIcaoCodeStatement (soci::session& ioSociSession,
960 soci::statement& ioSelectStatement,
961 const std::string& iIcaoCode,
962 std::string& ioSerialisedPlaceStr) {
970 ioSelectStatement = (ioSociSession.prepare
971 <<
"select serialised_place from optd_por "
972 <<
"where icao_code = :place_icao_code",
973 soci::use (iIcaoCode),
974 soci::into (ioSerialisedPlaceStr));
977 ioSelectStatement.execute();
979 }
catch (std::exception
const& lException) {
980 std::ostringstream errorStr;
982 <<
"Error in the 'select serialised_place from optd_por' SQL request: "
983 << lException.what();
985 throw SQLDatabaseException (errorStr.str());
991 prepareSelectBlobOnFaaCodeStatement (soci::session& ioSociSession,
992 soci::statement& ioSelectStatement,
993 const std::string& iFaaCode,
994 std::string& ioSerialisedPlaceStr) {
1002 ioSelectStatement = (ioSociSession.prepare
1003 <<
"select serialised_place from optd_por "
1004 <<
"where faa_code = :place_faa_code",
1005 soci::use (iFaaCode),
1006 soci::into (ioSerialisedPlaceStr));
1009 ioSelectStatement.execute();
1011 }
catch (std::exception
const& lException) {
1012 std::ostringstream errorStr;
1014 <<
"Error in the 'select serialised_place from optd_por' SQL request: "
1015 << lException.what();
1017 throw SQLDatabaseException (errorStr.str());
1023 prepareSelectBlobOnUNLOCodeStatement (soci::session& ioSociSession,
1024 soci::statement& ioSelectStatement,
1025 const std::string& iUNLOCode,
1026 std::string& ioSerialisedPlaceStr) {
1034 ioSelectStatement = (ioSociSession.prepare
1035 <<
"select serialised_place from optd_por "
1036 <<
"where unlocode_code = :place_unlocode_code",
1037 soci::use (iUNLOCode),
1038 soci::into (ioSerialisedPlaceStr));
1041 ioSelectStatement.execute();
1043 }
catch (std::exception
const& lException) {
1044 std::ostringstream errorStr;
1046 <<
"Error in the 'select serialised_place from optd_por' SQL request: "
1047 << lException.what();
1049 throw SQLDatabaseException (errorStr.str());
1055 prepareSelectBlobOnUICCodeStatement (soci::session& ioSociSession,
1056 soci::statement& ioSelectStatement,
1058 std::string& ioSerialisedPlaceStr) {
1066 ioSelectStatement = (ioSociSession.prepare
1067 <<
"select serialised_place from optd_por "
1068 <<
"where uic_code = :place_uic_code",
1069 soci::use (iUICCode),
1070 soci::into (ioSerialisedPlaceStr));
1073 ioSelectStatement.execute();
1075 }
catch (std::exception
const& lException) {
1076 std::ostringstream errorStr;
1078 <<
"Error in the 'select serialised_place from optd_por' SQL request: "
1079 << lException.what();
1081 throw SQLDatabaseException (errorStr.str());
1087 prepareSelectBlobOnPlaceGeoIDStatement (soci::session& ioSociSession,
1088 soci::statement& ioSelectStatement,
1090 std::string& ioSerialisedPlaceStr) {
1098 ioSelectStatement = (ioSociSession.prepare
1099 <<
"select serialised_place from optd_por "
1100 <<
"where geoname_id = :place_geoname_id",
1101 soci::use (iGeonameID),
1102 soci::into (ioSerialisedPlaceStr));
1105 ioSelectStatement.execute();
1107 }
catch (std::exception
const& lException) {
1108 std::ostringstream errorStr;
1110 <<
"Error in the 'select serialised_place from optd_por' SQL request: "
1111 << lException.what();
1113 throw SQLDatabaseException (errorStr.str());
1119 const std::string& iSerialisedPlaceStr) {
1120 bool hasStillData =
false;
1125 hasStillData = ioStatement.fetch();
1127 }
catch (std::exception
const& lException) {
1128 std::ostringstream errorStr;
1129 errorStr <<
"Error when iterating on the SQL fetch: " << lException.what();
1130 errorStr <<
". The current place is: " << iSerialisedPlaceStr;
1135 return hasStillData;
1140 const Place& iPlace) {
1145 ioSociSession.begin();
1149 const std::string lPK (lLocationKey.
toString());
1152 const std::string lIataCode (iPlace.
getIataCode());
1153 const std::string lIcaoCode (iPlace.
getIcaoCode());
1154 const std::string lFaaCode (iPlace.
getFaaCode());
1155 const std::string lIsGeonames ((iPlace.
isGeonames())?
"Y":
"N");
1156 const std::string lGeonameID =
1158 const std::string lEnvID =
1160 const std::string lDateFrom =
1161 boost::gregorian::to_iso_extended_string (iPlace.
getDateFrom());
1162 const std::string lDateEnd =
1163 boost::gregorian::to_iso_extended_string (iPlace.
getDateEnd());
1191 std::string lUNLOCodeStr (
"");
1192 if (lUNLOCodeList.empty() ==
false) {
1193 const UNLOCode_T& lUNLOCode = lUNLOCodeList.front();
1194 lUNLOCodeStr =
static_cast<const std::string
> (lUNLOCode);
1203 if (lUICCodeList.empty() ==
false) {
1204 const UICCode_T& lUICCode = lUICCodeList.front();
1205 lUICCodeInt =
static_cast<const UICCode_T> (lUICCode);
1223 ioSociSession <<
"insert into optd_por values (:pk, "
1224 <<
":location_type, :iata_code, :icao_code, :faa_code, "
1225 <<
":unlocode_code, :uic_code, "
1226 <<
":is_geonames, :geoname_id, "
1227 <<
":envelope_id, :date_from, :date_until, "
1228 <<
":serialised_place)",
1229 soci::use (lPK), soci::use (lLocationType), soci::use (lIataCode),
1230 soci::use (lIcaoCode), soci::use (lFaaCode),
1231 soci::use (lUNLOCodeStr), soci::use (lUICCodeInt),
1232 soci::use (lIsGeonames), soci::use (lGeonameID),
1233 soci::use (lEnvID), soci::use (lDateFrom), soci::use (lDateEnd),
1234 soci::use (lRawDataString);
1237 ioSociSession.commit();
1242 }
catch (std::exception
const& lException) {
1243 std::ostringstream errorStr;
1244 errorStr <<
"Error when updating " << iPlace.
toString() <<
": "
1245 << lException.what();
1253 const Place& iPlace) {
1258 ioSociSession.begin();
1262 std::string lIataCode;
1263 soci::statement lUpdateStatement =
1264 (ioSociSession.prepare
1265 <<
"update place_details "
1266 <<
"set xapian_docid = :xapian_docid "
1267 <<
"where iata_code = :iata_code",
1268 soci::use (lDocID), soci::use (lIataCode));
1273 lUpdateStatement.execute (
true);
1276 ioSociSession.commit();
1281 }
catch (std::exception
const& lException) {
1282 std::ostringstream errorStr;
1283 errorStr <<
"Error when updating " << iPlace.
toString() <<
": "
1284 << lException.what();
1302 ioSociSession <<
"select count(1) from optd_por;", soci::into(oNbOfEntries);
1304 }
catch (std::exception
const& lException) {
1305 std::ostringstream errorStr;
1307 <<
"Error when trying to count the number of rows in the optd_por table: "
1308 << lException.what();
1313 return oNbOfEntries;
1323 soci::statement lSelectStatement (ioSociSession);
1324 std::string lPlace =
1332 bool hasStillData =
true;
1333 while (hasStillData ==
true) {
1337 if (hasStillData ==
true) {
1345 }
catch (std::exception
const& lException) {
1346 std::ostringstream errorStr;
1347 errorStr <<
"Error when trying to retrieve " << oNbOfEntries
1348 <<
"-th row from the SQL database: " << lException.what();
1353 return oNbOfEntries;
1360 const bool iUniqueEntry) {
1369 const std::string& lCode =
static_cast<const std::string&
> (iIataCode);
1370 const std::string lCodeUpper = boost::algorithm::to_upper_copy (lCode);
1373 soci::statement lSelectStatement (ioSociSession);
1374 std::string lPlaceRawDataString;
1375 DBManager::prepareSelectBlobOnIataCodeStatement (ioSociSession,
1378 lPlaceRawDataString);
1384 bool hasStillData =
true;
1385 while (hasStillData ==
true) {
1387 lPlaceRawDataString);
1390 const std::string lFoundStr = hasStillData?
"more; see below":
"no more";
1392 <<
"corresponding to '" << iIataCode
1393 <<
"' IATA code. Result: " << lFoundStr);
1395 if (hasStillData ==
true) {
1406 lLocationList.push_back (lLocation);
1413 }
catch (std::exception
const& lException) {
1414 std::ostringstream errorStr;
1415 errorStr <<
"Error when trying to retrieve a POR for " << iIataCode
1416 <<
" from the SQL database: " << lException.what();
1423 const Location* lHighestPRLocation_ptr = NULL;
1425 for (LocationList_T::const_iterator itLoc = lLocationList.begin();
1426 itLoc != lLocationList.end(); ++itLoc) {
1427 const Location& lLocation = *itLoc;
1437 if (lPRValue >= lHighestPRValue) {
1438 lHighestPRLocation_ptr = &lLocation;
1439 lHighestPRValue = lPRValue;
1444 if (iUniqueEntry ==
false) {
1445 ioLocationList.push_back (lLocation);
1450 if (iUniqueEntry ==
true && lHighestPRLocation_ptr != NULL) {
1451 assert (lHighestPRLocation_ptr != NULL);
1452 ioLocationList.push_back (*lHighestPRLocation_ptr);
1456 << lHighestPRValue <<
") for '" << iIataCode
1457 <<
"' IATA code: " << lHighestPRLocation_ptr->
getKey());
1462 if (oNbOfEntries > 0 && iUniqueEntry ==
true) {
1467 return oNbOfEntries;
1481 const std::string& lCode =
static_cast<const std::string&
> (iIcaoCode);
1482 const std::string lCodeUpper = boost::algorithm::to_upper_copy (lCode);
1485 soci::statement lSelectStatement (ioSociSession);
1486 std::string lPlaceRawDataString;
1487 DBManager::prepareSelectBlobOnIcaoCodeStatement (ioSociSession,
1490 lPlaceRawDataString);
1496 bool hasStillData =
true;
1497 while (hasStillData ==
true) {
1499 lPlaceRawDataString);
1502 const std::string lFoundStr = hasStillData?
"Yes":
"No";
1504 << iIcaoCode <<
" ICAO code. Found: " << lFoundStr);
1506 if (hasStillData ==
true) {
1517 ioLocationList.push_back (lLocation);
1524 }
catch (std::exception
const& lException) {
1525 std::ostringstream errorStr;
1526 errorStr <<
"Error when trying to retrieve a POR for " << iIcaoCode
1527 <<
" from the SQL database: " << lException.what();
1533 return oNbOfEntries;
1547 const std::string& lCode =
static_cast<const std::string&
> (iFaaCode);
1548 const std::string lCodeUpper = boost::algorithm::to_upper_copy (lCode);
1551 soci::statement lSelectStatement (ioSociSession);
1552 std::string lPlaceRawDataString;
1553 DBManager::prepareSelectBlobOnFaaCodeStatement (ioSociSession,
1556 lPlaceRawDataString);
1562 bool hasStillData =
true;
1563 while (hasStillData ==
true) {
1565 lPlaceRawDataString);
1568 const std::string lFoundStr = hasStillData?
"Yes":
"No";
1570 << iFaaCode <<
" FAA code. Found: " << lFoundStr);
1572 if (hasStillData ==
true) {
1583 ioLocationList.push_back (lLocation);
1590 }
catch (std::exception
const& lException) {
1591 std::ostringstream errorStr;
1592 errorStr <<
"Error when trying to retrieve a POR for " << iFaaCode
1593 <<
" from the SQL database: " << lException.what();
1599 return oNbOfEntries;
1606 const bool iUniqueEntry) {
1615 const std::string& lCode =
static_cast<const std::string&
> (iUNLOCode);
1616 const std::string lCodeUpper = boost::algorithm::to_upper_copy (lCode);
1619 soci::statement lSelectStatement (ioSociSession);
1620 std::string lPlaceRawDataString;
1621 DBManager::prepareSelectBlobOnUNLOCodeStatement (ioSociSession,
1624 lPlaceRawDataString);
1630 bool hasStillData =
true;
1631 while (hasStillData ==
true) {
1633 lPlaceRawDataString);
1636 const std::string lFoundStr = hasStillData?
"Yes":
"No";
1638 << iUNLOCode <<
" UN/LOCODE code. Found: "
1641 if (hasStillData ==
true) {
1652 lLocationList.push_back (lLocation);
1659 }
catch (std::exception
const& lException) {
1660 std::ostringstream errorStr;
1661 errorStr <<
"Error when trying to retrieve a POR for " << iUNLOCode
1662 <<
" from the SQL database: " << lException.what();
1669 const Location* lHighestPRLocation_ptr = NULL;
1671 for (LocationList_T::const_iterator itLoc = lLocationList.begin();
1672 itLoc != lLocationList.end(); ++itLoc) {
1673 const Location& lLocation = *itLoc;
1677 if (lPRValue > lHighestPRValue) {
1678 lHighestPRLocation_ptr = &lLocation;
1679 lHighestPRValue = lPRValue;
1683 if (iUniqueEntry ==
false) {
1684 ioLocationList.push_back (lLocation);
1689 if (iUniqueEntry ==
true && lHighestPRLocation_ptr != NULL) {
1690 assert (lHighestPRLocation_ptr != NULL);
1691 ioLocationList.push_back (*lHighestPRLocation_ptr);
1695 << lHighestPRValue <<
") for '" << iUNLOCode
1696 <<
"' IATA code: " << lHighestPRLocation_ptr->
getKey());
1701 if (oNbOfEntries > 0 && iUniqueEntry ==
true) {
1706 return oNbOfEntries;
1718 soci::statement lSelectStatement (ioSociSession);
1719 std::string lPlaceRawDataString;
1720 DBManager::prepareSelectBlobOnUICCodeStatement (ioSociSession,
1723 lPlaceRawDataString);
1729 bool hasStillData =
true;
1730 while (hasStillData ==
true) {
1732 lPlaceRawDataString);
1735 const std::string lFoundStr = hasStillData?
"Yes":
"No";
1737 << iUICCode <<
" UIC code. Found: "
1740 if (hasStillData ==
true) {
1748 const std::string lUICCodeStr =
1749 boost::lexical_cast<std::string> (iUICCode);
1753 ioLocationList.push_back (lLocation);
1760 }
catch (std::exception
const& lException) {
1761 std::ostringstream errorStr;
1762 errorStr <<
"Error when trying to retrieve a POR for " << iUICCode
1763 <<
" from the SQL database: " << lException.what();
1769 return oNbOfEntries;
1781 soci::statement lSelectStatement (ioSociSession);
1782 std::string lPlaceRawDataString;
1783 DBManager::prepareSelectBlobOnPlaceGeoIDStatement (ioSociSession,
1786 lPlaceRawDataString);
1792 bool hasStillData =
true;
1793 while (hasStillData ==
true) {
1795 lPlaceRawDataString);
1798 const std::string lFoundStr = hasStillData?
"Yes":
"No";
1800 << iGeonameID<<
" Geonames ID. Found: "<< lFoundStr);
1802 if (hasStillData ==
true) {
1810 const std::string lGeonamesIDStr =
1811 boost::lexical_cast<std::string> (iGeonameID);
1815 ioLocationList.push_back (lLocation);
1822 }
catch (std::exception
const& lException) {
1823 std::ostringstream errorStr;
1824 errorStr <<
"Error when trying to retrieve a POR for " << iGeonameID
1825 <<
" from the SQL database: " << lException.what();
1831 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 &)
bool createSQLDBUserOnPG(const SQLDBConnectionString_T &iSQLDBConnStr, const DeploymentNumber_T &iDeploymentNumber)
bool createSQLDBUserOnMySQL(const SQLDBConnectionString_T &iSQLDBConnStr, const DeploymentNumber_T &iDeploymentNumber)
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
const std::string DEFAULT_OPENTREP_PG_DB_USER
bool createSQLDBUserOnSQLite(const SQLDBConnectionString_T &iSQLDBConnStr, const DeploymentNumber_T &iDeploymentNumber)
unsigned short DeploymentNumber_T
unsigned int GeonamesID_T
const std::string DEFAULT_OPENTREP_PG_DB_DBNAME
unsigned int XapianDocID_T
Enumeration of database types.
const std::string describe() const
static EN_DBType getType(const char)
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)