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> 13 #include <soci/soci.h> 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();
668 <<
"alter table optd_por add unique index optd_por_pk (pk asc);";
670 <<
"alter table optd_por add index optd_por_iata_code (iata_code asc);";
672 <<
"alter table optd_por add index optd_por_iata_date (iata_code asc, date_from asc, date_until asc);";
674 <<
"alter table optd_por add index optd_por_icao_code (icao_code asc);";
676 <<
"alter table optd_por add index optd_por_geonameid (geoname_id asc);";
678 <<
"alter table optd_por add index optd_por_unlocode_code (unlocode_code asc);";
680 <<
"alter table optd_por add index optd_por_uic_code (uic_code asc);";
682 }
catch (std::exception
const& lException) {
683 std::ostringstream errorStr;
684 errorStr <<
"Error when trying to create MySQL/MariaDB indices: " 685 << lException.what();
697 std::ostringstream errorStr;
698 errorStr <<
"Error: the '" << lDBName
699 <<
"' SQL database type is not supported";
708 soci::statement& ioSelectStatement) {
709 std::string oSerialisedPlaceStr;
718 ioSelectStatement = (ioSociSession.prepare
719 <<
"select serialised_place from optd_por",
720 soci::into (oSerialisedPlaceStr));
723 ioSelectStatement.execute();
725 }
catch (std::exception
const& lException) {
726 std::ostringstream errorStr;
728 <<
"Error in the 'select serialised_place from optd_por' SQL request: " 729 << lException.what();
735 return oSerialisedPlaceStr;
740 prepareSelectBlobOnIataCodeStatement (soci::session& ioSociSession,
741 soci::statement& ioSelectStatement,
743 std::string& ioSerialisedPlaceStr) {
744 std::string oSerialisedPlaceStr;
752 const std::string lCode =
static_cast<std::string
> (iIataCode);
753 const std::string lCodeUpper = boost::algorithm::to_upper_copy (lCode);
755 ioSelectStatement = (ioSociSession.prepare
756 <<
"select serialised_place from optd_por " 757 <<
"where iata_code = :place_iata_code",
758 soci::into (ioSerialisedPlaceStr),
759 soci::use (lCodeUpper));
762 ioSelectStatement.execute();
764 }
catch (std::exception
const& lException) {
765 std::ostringstream errorStr;
767 <<
"Error in the 'select serialised_place from optd_por' SQL request: " 768 << lException.what();
770 throw SQLDatabaseException (errorStr.str());
776 prepareSelectBlobOnIcaoCodeStatement (soci::session& ioSociSession,
777 soci::statement& ioSelectStatement,
778 const ICAOCode_T& iIcaoCode,
779 std::string& ioSerialisedPlaceStr) {
780 std::string oSerialisedPlaceStr;
788 const std::string lCode =
static_cast<std::string
> (iIcaoCode);
789 const std::string lCodeUpper = boost::algorithm::to_upper_copy (lCode);
791 ioSelectStatement = (ioSociSession.prepare
792 <<
"select serialised_place from optd_por " 793 <<
"where icao_code = :place_icao_code",
794 soci::into (ioSerialisedPlaceStr),
795 soci::use (lCodeUpper));
798 ioSelectStatement.execute();
800 }
catch (std::exception
const& lException) {
801 std::ostringstream errorStr;
803 <<
"Error in the 'select serialised_place from optd_por' SQL request: " 804 << lException.what();
806 throw SQLDatabaseException (errorStr.str());
812 prepareSelectBlobOnFaaCodeStatement (soci::session& ioSociSession,
813 soci::statement& ioSelectStatement,
814 const FAACode_T& iFaaCode,
815 std::string& ioSerialisedPlaceStr) {
816 std::string oSerialisedPlaceStr;
824 const std::string lCode =
static_cast<std::string
> (iFaaCode);
825 const std::string lCodeUpper = boost::algorithm::to_upper_copy (lCode);
827 ioSelectStatement = (ioSociSession.prepare
828 <<
"select serialised_place from optd_por " 829 <<
"where faa_code = :place_faa_code",
830 soci::into (ioSerialisedPlaceStr),
831 soci::use (lCodeUpper));
834 ioSelectStatement.execute();
836 }
catch (std::exception
const& lException) {
837 std::ostringstream errorStr;
839 <<
"Error in the 'select serialised_place from optd_por' SQL request: " 840 << lException.what();
842 throw SQLDatabaseException (errorStr.str());
848 prepareSelectBlobOnUNLOCodeStatement (soci::session& ioSociSession,
849 soci::statement& ioSelectStatement,
850 const UNLOCode_T& iUNLOCode,
851 std::string& ioSerialisedPlaceStr) {
852 std::string oSerialisedPlaceStr;
860 const std::string lCode =
static_cast<std::string
> (iUNLOCode);
861 const std::string lCodeUpper = boost::algorithm::to_upper_copy (lCode);
863 ioSelectStatement = (ioSociSession.prepare
864 <<
"select serialised_place from optd_por " 865 <<
"where unlocode_code = :place_unlocode_code",
866 soci::into (ioSerialisedPlaceStr),
867 soci::use (lCodeUpper));
870 ioSelectStatement.execute();
872 }
catch (std::exception
const& lException) {
873 std::ostringstream errorStr;
875 <<
"Error in the 'select serialised_place from optd_por' SQL request: " 876 << lException.what();
878 throw SQLDatabaseException (errorStr.str());
884 prepareSelectBlobOnUICCodeStatement (soci::session& ioSociSession,
885 soci::statement& ioSelectStatement,
887 std::string& ioSerialisedPlaceStr) {
888 std::string oSerialisedPlaceStr;
897 ioSelectStatement = (ioSociSession.prepare
898 <<
"select serialised_place from optd_por " 899 <<
"where uic_code = :place_uic_code",
900 soci::into (ioSerialisedPlaceStr),
901 soci::use (iUICCode));
904 ioSelectStatement.execute();
906 }
catch (std::exception
const& lException) {
907 std::ostringstream errorStr;
909 <<
"Error in the 'select serialised_place from optd_por' SQL request: " 910 << lException.what();
912 throw SQLDatabaseException (errorStr.str());
918 prepareSelectBlobOnPlaceGeoIDStatement (soci::session& ioSociSession,
919 soci::statement& ioSelectStatement,
921 std::string& ioSerialisedPlaceStr) {
922 std::string oSerialisedPlaceStr;
931 ioSelectStatement = (ioSociSession.prepare
932 <<
"select serialised_place from optd_por " 933 <<
"where geoname_id = :place_geoname_id",
934 soci::into (ioSerialisedPlaceStr),
935 soci::use (iGeonameID));
938 ioSelectStatement.execute();
940 }
catch (std::exception
const& lException) {
941 std::ostringstream errorStr;
943 <<
"Error in the 'select serialised_place from optd_por' SQL request: " 944 << lException.what();
946 throw SQLDatabaseException (errorStr.str());
952 const std::string& iSerialisedPlaceStr) {
953 bool hasStillData =
false;
958 hasStillData = ioStatement.fetch();
960 }
catch (std::exception
const& lException) {
961 std::ostringstream errorStr;
962 errorStr <<
"Error when iterating on the SQL fetch: " << lException.what();
963 errorStr <<
". The current place is: " << iSerialisedPlaceStr;
973 const Place& iPlace) {
978 ioSociSession.begin();
982 const std::string lPK (lLocationKey.
toString());
984 const std::string lLocationType (lIataType.getTypeAsString());
985 const std::string lIataCode (iPlace.
getIataCode());
986 const std::string lIcaoCode (iPlace.
getIcaoCode());
987 const std::string lFaaCode (iPlace.
getFaaCode());
988 const std::string lIsGeonames ((iPlace.
isGeonames())?
"Y":
"N");
989 const std::string lGeonameID =
991 const std::string lEnvID =
993 const std::string lDateFrom =
994 boost::gregorian::to_iso_extended_string (iPlace.
getDateFrom());
995 const std::string lDateEnd =
996 boost::gregorian::to_iso_extended_string (iPlace.
getDateEnd());
1024 std::string lUNLOCodeStr (
"");
1025 if (lUNLOCodeList.empty() ==
false) {
1026 const UNLOCode_T& lUNLOCode = lUNLOCodeList.front();
1027 lUNLOCodeStr =
static_cast<const std::string
> (lUNLOCode);
1036 if (lUICCodeList.empty() ==
false) {
1037 const UICCode_T& lUICCode = lUICCodeList.front();
1038 lUICCodeInt =
static_cast<const UICCode_T> (lUICCode);
1056 ioSociSession <<
"insert into optd_por values (:pk, " 1057 <<
":location_type, :iata_code, :icao_code, :faa_code, " 1058 <<
":unlocode_code, :uic_code, " 1059 <<
":is_geonames, :geoname_id, " 1060 <<
":envelope_id, :date_from, :date_until, " 1061 <<
":serialised_place)",
1062 soci::use (lPK), soci::use (lLocationType), soci::use (lIataCode),
1063 soci::use (lIcaoCode), soci::use (lFaaCode),
1064 soci::use (lUNLOCodeStr), soci::use (lUICCodeInt),
1065 soci::use (lIsGeonames), soci::use (lGeonameID),
1066 soci::use (lEnvID), soci::use (lDateFrom), soci::use (lDateEnd),
1067 soci::use (lRawDataString);
1070 ioSociSession.commit();
1075 }
catch (std::exception
const& lException) {
1076 std::ostringstream errorStr;
1077 errorStr <<
"Error when updating " << iPlace.
toString() <<
": " 1078 << lException.what();
1086 const Place& iPlace) {
1091 ioSociSession.begin();
1095 std::string lIataCode;
1096 soci::statement lUpdateStatement =
1097 (ioSociSession.prepare
1098 <<
"update place_details " 1099 <<
"set xapian_docid = :xapian_docid " 1100 <<
"where iata_code = :iata_code",
1101 soci::use (lDocID), soci::use (lIataCode));
1106 lUpdateStatement.execute (
true);
1109 ioSociSession.commit();
1114 }
catch (std::exception
const& lException) {
1115 std::ostringstream errorStr;
1116 errorStr <<
"Error when updating " << iPlace.
toString() <<
": " 1117 << lException.what();
1135 ioSociSession <<
"select count(1) from optd_por;", soci::into(oNbOfEntries);
1137 }
catch (std::exception
const& lException) {
1138 std::ostringstream errorStr;
1140 <<
"Error when trying to count the number of rows in the optd_por table: " 1141 << lException.what();
1146 return oNbOfEntries;
1156 soci::statement lSelectStatement (ioSociSession);
1157 std::string lPlace =
1165 bool hasStillData =
true;
1166 while (hasStillData ==
true) {
1170 if (hasStillData ==
true) {
1178 }
catch (std::exception
const& lException) {
1179 std::ostringstream errorStr;
1180 errorStr <<
"Error when trying to retrieve " << oNbOfEntries
1181 <<
"-th row from the SQL database: " << lException.what();
1186 return oNbOfEntries;
1193 const bool iUniqueEntry) {
1200 soci::statement lSelectStatement (ioSociSession);
1201 std::string lPlaceRawDataString;
1202 DBManager::prepareSelectBlobOnIataCodeStatement (ioSociSession,
1205 lPlaceRawDataString);
1211 bool hasStillData =
true;
1212 while (hasStillData ==
true) {
1214 lPlaceRawDataString);
1217 const std::string lFoundStr = hasStillData?
"more; see below":
"no more";
1219 <<
"corresponding to '" << iIataCode
1220 <<
"' IATA code. Result: " << lFoundStr);
1222 if (hasStillData ==
true) {
1233 lLocationList.push_back (lLocation);
1240 }
catch (std::exception
const& lException) {
1241 std::ostringstream errorStr;
1242 errorStr <<
"Error when trying to retrieve a POR for " << iIataCode
1243 <<
" from the SQL database: " << lException.what();
1250 const Location* lHighestPRLocation_ptr = NULL;
1252 for (LocationList_T::const_iterator itLoc = lLocationList.begin();
1253 itLoc != lLocationList.end(); ++itLoc) {
1254 const Location& lLocation = *itLoc;
1258 if (lPRValue > lHighestPRValue) {
1259 lHighestPRLocation_ptr = &lLocation;
1260 lHighestPRValue = lPRValue;
1264 if (iUniqueEntry ==
false) {
1265 ioLocationList.push_back (lLocation);
1270 if (iUniqueEntry ==
true && lHighestPRLocation_ptr != NULL) {
1271 assert (lHighestPRLocation_ptr != NULL);
1272 ioLocationList.push_back (*lHighestPRLocation_ptr);
1276 << lHighestPRValue <<
") for '" << iIataCode
1277 <<
"' IATA code: " << lHighestPRLocation_ptr->
getKey());
1281 return oNbOfEntries;
1293 soci::statement lSelectStatement (ioSociSession);
1294 std::string lPlaceRawDataString;
1295 DBManager::prepareSelectBlobOnIcaoCodeStatement (ioSociSession,
1298 lPlaceRawDataString);
1304 bool hasStillData =
true;
1305 while (hasStillData ==
true) {
1307 lPlaceRawDataString);
1310 const std::string lFoundStr = hasStillData?
"Yes":
"No";
1312 << iIcaoCode <<
" ICAO code. Found: " << lFoundStr);
1314 if (hasStillData ==
true) {
1325 ioLocationList.push_back (lLocation);
1332 }
catch (std::exception
const& lException) {
1333 std::ostringstream errorStr;
1334 errorStr <<
"Error when trying to retrieve a POR for " << iIcaoCode
1335 <<
" from the SQL database: " << lException.what();
1341 return oNbOfEntries;
1353 soci::statement lSelectStatement (ioSociSession);
1354 std::string lPlaceRawDataString;
1355 DBManager::prepareSelectBlobOnFaaCodeStatement (ioSociSession,
1358 lPlaceRawDataString);
1364 bool hasStillData =
true;
1365 while (hasStillData ==
true) {
1367 lPlaceRawDataString);
1370 const std::string lFoundStr = hasStillData?
"Yes":
"No";
1372 << iFaaCode <<
" FAA code. Found: " << lFoundStr);
1374 if (hasStillData ==
true) {
1385 ioLocationList.push_back (lLocation);
1392 }
catch (std::exception
const& lException) {
1393 std::ostringstream errorStr;
1394 errorStr <<
"Error when trying to retrieve a POR for " << iFaaCode
1395 <<
" from the SQL database: " << lException.what();
1401 return oNbOfEntries;
1413 soci::statement lSelectStatement (ioSociSession);
1414 std::string lPlaceRawDataString;
1415 DBManager::prepareSelectBlobOnUNLOCodeStatement (ioSociSession,
1418 lPlaceRawDataString);
1424 bool hasStillData =
true;
1425 while (hasStillData ==
true) {
1427 lPlaceRawDataString);
1430 const std::string lFoundStr = hasStillData?
"Yes":
"No";
1432 << iUNLOCode <<
" UN/LOCODE code. Found: " 1435 if (hasStillData ==
true) {
1446 ioLocationList.push_back (lLocation);
1453 }
catch (std::exception
const& lException) {
1454 std::ostringstream errorStr;
1455 errorStr <<
"Error when trying to retrieve a POR for " << iUNLOCode
1456 <<
" from the SQL database: " << lException.what();
1462 return oNbOfEntries;
1474 soci::statement lSelectStatement (ioSociSession);
1475 std::string lPlaceRawDataString;
1476 DBManager::prepareSelectBlobOnUICCodeStatement (ioSociSession,
1479 lPlaceRawDataString);
1485 bool hasStillData =
true;
1486 while (hasStillData ==
true) {
1488 lPlaceRawDataString);
1491 const std::string lFoundStr = hasStillData?
"Yes":
"No";
1493 << iUICCode <<
" UIC code. Found: " 1496 if (hasStillData ==
true) {
1504 const std::string lUICCodeStr =
1505 boost::lexical_cast<std::string> (iUICCode);
1509 ioLocationList.push_back (lLocation);
1516 }
catch (std::exception
const& lException) {
1517 std::ostringstream errorStr;
1518 errorStr <<
"Error when trying to retrieve a POR for " << iUICCode
1519 <<
" from the SQL database: " << lException.what();
1525 return oNbOfEntries;
1537 soci::statement lSelectStatement (ioSociSession);
1538 std::string lPlaceRawDataString;
1539 DBManager::prepareSelectBlobOnPlaceGeoIDStatement (ioSociSession,
1542 lPlaceRawDataString);
1548 bool hasStillData =
true;
1549 while (hasStillData ==
true) {
1551 lPlaceRawDataString);
1554 const std::string lFoundStr = hasStillData?
"Yes":
"No";
1556 << iGeonameID<<
" Geonames ID. Found: "<< lFoundStr);
1558 if (hasStillData ==
true) {
1566 const std::string lGeonamesIDStr =
1567 boost::lexical_cast<std::string> (iGeonameID);
1571 ioLocationList.push_back (lLocation);
1578 }
catch (std::exception
const& lException) {
1579 std::ostringstream errorStr;
1580 errorStr <<
"Error when trying to retrieve a POR for " << iGeonameID
1581 <<
" from the SQL database: " << lException.what();
1587 return oNbOfEntries;
const EnvelopeID_T & getEnvelopeID() const
Class modelling the primary key of a location/POR (point of reference).
const Date_T & getDateEnd() const
#define OPENTREP_LOG_ERROR(iToBeLogged)
#define OPENTREP_LOG_DEBUG(iToBeLogged)
std::list< UNLOCode_T > UNLOCodeList_T
unsigned int GeonamesID_T
void setCorrectedKeywords(const std::string &iCorrectedKeywords)
const GeonamesID_T & getGeonamesID() const
static void updatePlaceInDB(soci::session &, const Place &)
const Date_T & getDateFrom() const
const IATACode_T & getIataCode() const
Structure modelling a (geographical) location.
const std::string DEFAULT_OPENTREP_MYSQL_DB_HOST
std::string toString() const
static NbOfDBEntries_T getPORByFAACode(soci::session &, const FAACode_T &, LocationList_T &)
std::list< UICCode_T > UICCodeList_T
static Location retrieveLocation(const Xapian::Document &)
const std::string DEFAULT_OPENTREP_MYSQL_DB_USER
static bool checkSQLiteDirectory(const std::string &iSQLDBConnStr)
unsigned int NbOfDBEntries_T
const std::string DEFAULT_OPENTREP_MYSQL_DB_DBNAME
const UNLOCodeList_T & getUNLOCodeList() const
static bool createSQLDBUser(const DBType &, const SQLDBConnectionString_T &, const DeploymentNumber_T &)
static std::string prepareSelectAllBlobStatement(soci::session &, soci::statement &)
static void createSQLDBTables(soci::session &)
const PageRank_T & getPageRank() const
static void terminateSQLDBSession(const DBType &, const SQLDBConnectionString_T &, soci::session &)
static NbOfDBEntries_T getPORByUICCode(soci::session &, const UICCode_T &, LocationList_T &)
Enumeration of database types.
const UICCodeList_T & getUICCodeList() const
const ICAOCode_T & getIcaoCode() const
static NbOfDBEntries_T getPORByIATACode(soci::session &, const IATACode_T &, LocationList_T &, const bool iUniqueEntry)
static NbOfDBEntries_T displayCount(soci::session &)
std::string toString() const
const std::string describe() const
Class modelling a place/POR (point of reference).
unsigned int XapianDocID_T
std::list< Location > LocationList_T
const FAACode_T & getFaaCode() const
const LocationKey & getKey() const
static NbOfDBEntries_T getPORByUNLOCode(soci::session &, const UNLOCode_T &, LocationList_T &)
const RawDataString_T & getRawDataString() const
static bool iterateOnStatement(soci::statement &, const std::string &)
const IATAType & getIataType() const
const std::string DEFAULT_OPENTREP_MYSQL_DB_PASSWD
const IsGeonames_T & isGeonames() const
static NbOfDBEntries_T displayAll(soci::session &)
static NbOfDBEntries_T getPORByGeonameID(soci::session &, const GeonamesID_T &, LocationList_T &)
const XapianDocID_T & getDocID() const
const LocationKey & getKey() const
Enumeration of place/location types with respect to their use for transportation purposes.
static NbOfDBEntries_T getPORByICAOCode(soci::session &, const ICAOCode_T &, LocationList_T &)
static void createSQLDBIndexes(soci::session &)
static soci::session * initSQLDBSession(const DBType &, const SQLDBConnectionString_T &)
unsigned short DeploymentNumber_T
static void insertPlaceInDB(soci::session &, const Place &)