9 #include <soci/sqlite3/soci-sqlite3.h>
23 soci::statement& ioSelectStatement,
62 (ioSociSession.prepare
63 <<
"select dts.iata_code as iata_code, "
64 <<
" dts.location_type as location_type, "
65 <<
" dts.geoname_id as geoname_id, "
66 <<
" icao_code, faa_code, "
67 <<
" envelope_id, dts.name as utf_name, asciiname, "
68 <<
" latitude, longitude, fclass, fcode, "
70 <<
" date(date_from) as date_from, date(date_until) as date_until, "
72 <<
" country_code, cc2, country_name, continent_name, "
73 <<
" admin1_code, admin1_UTF8_name, admin1_ASCII_name, "
74 <<
" admin2_code, admin2_UTF8_name, admin2_ASCII_name, "
75 <<
" admin3_code, admin4_code, "
76 <<
" population, elevation, gtopo30, "
77 <<
" time_zone, gmt_offset, dst_offset, raw_offset, "
78 <<
" date(moddate) as moddate, "
79 <<
" state_code, wiki_link, "
80 <<
" alt.lang_code as alt_lang_code, alt.name as alt_name, "
81 <<
" alt.specifiers as alt_spec, "
82 <<
" city_iata_code, city_location_type, city_geoname_id, "
83 <<
" city_UTF8_name, city_ASCII_name "
84 <<
"from ori_por_public_details dts, ori_por_public_alt_names alt, "
85 <<
" ori_por_public_served_cities cty "
86 <<
"where dts.iata_code = alt.iata_code "
87 <<
" and dts.location_type = alt.location_type "
88 <<
" and dts.geoname_id = alt.geoname_id "
89 <<
" and dts.iata_code = cty.iata_code "
90 <<
" and dts.location_type = cty.location_type "
91 <<
" and dts.geoname_id = cty.geoname_id "
92 <<
"order by dts.iata_code, dts.location_type, dts.geoname_id",
93 soci::into (ioPlace));
96 ioSelectStatement.execute();
98 }
catch (std::exception
const& lException) {
99 std::ostringstream errorStr;
100 errorStr <<
"Error in the 'select * from ori_por_public_xxx' SQL request: "
101 << lException.what();
110 soci::statement& ioSelectStatement,
138 (ioSociSession.prepare
139 <<
"select rpd.iata_code, xapian_docid, icao_code, "
140 <<
"is_geonames, geonameid, "
141 <<
"latitude, longitude, fclass, fcode, "
142 <<
"country_code, cc2, admin1, admin2, admin3, admin4, "
143 <<
"population, elevation, gtopo30, "
144 <<
"timezone, gmt_offset, dst_offset, raw_offset, moddate, "
145 <<
"is_airport, is_commercial, "
146 <<
"city_code, state_code, region_code, location_type, wiki_link, "
147 <<
"language_code, ascii_name, utf_name, "
148 <<
"alternate_name1, alternate_name2, alternate_name3, "
149 <<
"alternate_name4, alternate_name5, alternate_name6, "
150 <<
"alternate_name7, alternate_name8, alternate_name9, "
151 <<
"alternate_name10, "
152 <<
"page_rank, por_type "
153 <<
"from place_names as pn, place_details as rpd "
154 <<
"left join airport_pageranked pr on pr.iata_code = rpd.iata_code "
155 <<
"where rpd.iata_code = pn.iata_code "
156 <<
"order by rpd.iata_code, icao_code, geonameid", soci::into(ioPlace));
159 ioSelectStatement.execute();
161 }
catch (std::exception
const& lException) {
162 std::ostringstream errorStr;
163 errorStr <<
"Error in the 'select * from place_details' SQL request: "
164 << lException.what();
173 soci::statement& ioSelectStatement,
174 const double& iLatitude,
175 const double& iLongitude) {
204 const double K_ERROR = 2.0;
205 const double lLowerBoundLatitude = iLatitude - K_ERROR;
206 const double lUpperBoundLatitude = iLatitude + K_ERROR;
207 const double lLowerBoundLongitude = iLongitude - K_ERROR;
208 const double lUpperBoundLongitude = iLongitude + K_ERROR;
211 (ioSociSession.prepare
212 <<
"select rpd.iata_code, xapian_docid, icao_code, "
213 <<
"is_geonames, geonameid, "
214 <<
"latitude, longitude, fclass, fcode, "
215 <<
"country_code, cc2, admin1, admin2, admin3, admin4, "
216 <<
"population, elevation, gtopo30, "
217 <<
"timezone, gmt_offset, dst_offset, raw_offset, moddate, "
218 <<
"is_airport, is_commercial, "
219 <<
"city_code, state_code, region_code, location_type, wiki_link, "
220 <<
"language_code, ascii_name, utf_name, "
221 <<
"alternate_name1, alternate_name2, alternate_name3, "
222 <<
"alternate_name4, alternate_name5, alternate_name6, "
223 <<
"alternate_name7, alternate_name8, alternate_name9, "
224 <<
"alternate_name10, "
225 <<
"page_rank, por_type "
226 <<
"from place_names as pn, place_details as rpd "
227 <<
"left join airport_pageranked pr on pr.iata_code = rpd.iata_code "
228 <<
"where latitude >= :lower_latitude "
229 <<
" and latitude <= :upper_latitude "
230 <<
" and longitude >= :lower_longitude "
231 <<
" and longitude <= :upper_longitude "
232 <<
" and rpd.iata_code = pn.iata_code",
233 soci::into (lPlace), soci::use (lLowerBoundLatitude),
234 soci::use (lUpperBoundLatitude), soci::use (lLowerBoundLongitude),
235 soci::use (lUpperBoundLongitude));
238 ioSelectStatement.execute();
240 }
catch (std::exception
const& lException) {
241 std::ostringstream errorStr;
242 errorStr <<
"Error in the 'select * from place_details' SQL request: "
243 << lException.what();
251 prepareSelectOnPlaceCodeStatement (soci::session& ioSociSession,
252 soci::statement& ioSelectStatement,
253 const std::string& iIataCode,
254 const std::string& iIcaoCode,
285 (ioSociSession.prepare
286 <<
"select rpd.iata_code, xapian_docid, icao_code, "
287 <<
"is_geonames, geonameid, "
288 <<
"latitude, longitude, fclass, fcode, "
289 <<
"country_code, cc2, admin1, admin2, admin3, admin4, "
290 <<
"population, elevation, gtopo30, "
291 <<
"timezone, gmt_offset, dst_offset, raw_offset, moddate, "
292 <<
"is_airport, is_commercial, "
293 <<
"city_code, state_code, region_code, location_type, wiki_link, "
294 <<
"language_code, ascii_name, utf_name, "
295 <<
"alternate_name1, alternate_name2, alternate_name3, "
296 <<
"alternate_name4, alternate_name5, alternate_name6, "
297 <<
"alternate_name7, alternate_name8, alternate_name9, "
298 <<
"alternate_name10, "
299 <<
"page_rank, por_type "
300 <<
"from place_names as pn, place_details as rpd "
301 <<
"left join airport_pageranked pr on pr.iata_code = rpd.iata_code "
302 <<
"where rpd.iata_code = :place_iata_code "
303 <<
" and rpd.icao_code = :place_icao_code "
304 <<
" and rpd.geonameid = :place_geonameid "
305 <<
" and rpd.iata_code = pn.iata_code",
306 soci::into (ioPlace), soci::use (iIataCode), soci::use (iIcaoCode),
307 soci::use (iGeonamesID));
310 ioSelectStatement.execute();
312 }
catch (std::exception
const& lException) {
313 std::ostringstream errorStr;
314 errorStr <<
"Error in the 'select * from place_details' SQL request: "
315 << lException.
what();
317 throw SQLDatabaseException (errorStr.str());
323 prepareSelectOnDocIDStatement (soci::session& ioSociSession,
324 soci::statement& ioSelectStatement,
354 (ioSociSession.prepare
355 <<
"select rpd.iata_code, xapian_docid, icao_code, "
356 <<
"is_geonames, geonameid, "
357 <<
"latitude, longitude, fclass, fcode, "
358 <<
"country_code, cc2, admin1, admin2, admin3, admin4, "
359 <<
"population, elevation, gtopo30, "
360 <<
"timezone, gmt_offset, dst_offset, raw_offset, moddate, "
361 <<
"is_airport, is_commercial, "
362 <<
"city_code, state_code, region_code, location_type, wiki_link, "
363 <<
"language_code, ascii_name, utf_name, "
364 <<
"alternate_name1, alternate_name2, alternate_name3, "
365 <<
"alternate_name4, alternate_name5, alternate_name6, "
366 <<
"alternate_name7, alternate_name8, alternate_name9, "
367 <<
"alternate_name10, "
368 <<
"page_rank, por_type "
369 <<
"from place_names as pn, place_details as rpd "
370 <<
"left join airport_pageranked pr on pr.iata_code = rpd.iata_code "
371 <<
"where rpd.xapian_docid = :xapian_docid "
372 <<
" and rpd.iata_code = pn.iata_code "
373 <<
" and rpd.iata_code = pr.iata_code",
374 soci::into (ioPlace), soci::use (iDocID));
377 ioSelectStatement.execute();
379 }
catch (std::exception
const& lException) {
380 std::ostringstream errorStr;
381 errorStr <<
"Error: " << lException.what();
383 throw SQLDatabaseException (errorStr.str());
390 bool hasStillData =
false;
395 hasStillData = ioStatement.fetch();
397 }
catch (std::exception
const& lException) {
398 std::ostringstream errorStr;
399 errorStr <<
"Error when iterating on the SQL fetch: " << lException.what();
400 errorStr <<
". The current place key is: " << ioPlace.
describeKey()
401 <<
" (it may be mis-leading, though, if the key could not be retrieved).";
411 const Place& iPlace) {
416 ioSociSession.begin();
420 std::string lIataCode;
421 soci::statement lUpdateStatement =
422 (ioSociSession.prepare
423 <<
"update place_details "
424 <<
"set xapian_docid = :xapian_docid "
425 <<
"where iata_code = :iata_code",
426 soci::use (lDocID), soci::use (lIataCode));
431 lUpdateStatement.execute (
true);
434 ioSociSession.commit();
439 }
catch (std::exception
const& lException) {
440 std::ostringstream errorStr;
441 errorStr <<
"Error when updating " << iPlace.
toString() <<
": "
442 << lException.what();
451 bool oHasRetrievedPlace =
false;
456 soci::statement lSelectStatement (ioSociSession);
457 const std::string& lIataCode = iPlaceKey.
getIataCode();
461 DBManager::prepareSelectOnPlaceCodeStatement (ioSociSession,
463 lIataCode, lIataTypeStr,
464 lGeonamesID, ioPlace);
469 bool hasStillData =
true;
470 while (hasStillData ==
true) {
474 if (hasStillData ==
true) {
475 oHasRetrievedPlace =
true;
482 }
catch (std::exception
const& lException) {
483 std::ostringstream errorStr;
484 errorStr <<
"Error when trying to retrieve " << iPlaceKey
485 <<
" from the SQLite3 database: " << lException.what();
490 return oHasRetrievedPlace;
495 const double& iLatitude,
496 const double& iLongitude,
498 bool oHasRetrievedPlace =
false;
503 }
catch (std::exception
const& lException) {
504 std::ostringstream errorStr;
505 errorStr <<
"Error when trying to retrieve the closest places for "
506 << iLatitude <<
" / " << iLongitude <<
": " << lException.what();
511 return oHasRetrievedPlace;
523 soci::session* lSociSession_ptr =
new soci::session();
524 assert (lSociSession_ptr != NULL);
525 soci::session& lSociSession = *lSociSession_ptr;
526 lSociSession.open (soci::sqlite3, iSQLiteDBFilePath);
529 soci::statement lSelectStatement (lSociSession);
537 bool hasStillData =
true;
538 while (hasStillData ==
true) {
542 if (hasStillData ==
true) {
551 }
catch (std::exception
const& lException) {
552 std::ostringstream errorStr;
553 errorStr <<
"Error when trying to retrieve " << oNbOfEntries
554 <<
"-th row from the SQLite3 database: " << lException.what();
Class modelling the primary key of a location/POR (point of reference).
#define OPENTREP_LOG_ERROR(iToBeLogged)
#define OPENTREP_LOG_DEBUG(iToBeLogged)
const IATAType & getIataType() const
static FacPlace & instance()
static void updatePlaceInDB(soci::session &, const Place &)
static NbOfDBEntries_T buildSQLDB(const PORFilePath_T &, const SQLiteDBFilePath_T &)
static void prepareSelectFromCodeStatement(soci::session &, soci::statement &, Place &)
unsigned int NbOfDBEntries_T
static void prepareSelectFromCoordStatement(soci::session &, soci::statement &, const double &iLatitude, const double &iLongitude)
Class modelling a place/POR (point of reference).
std::string describeKey() const
const GeonamesID_T & getGeonamesID() const
const XapianDocID_T & getDocID() const
static bool iterateOnStatement(soci::statement &, Place &)
std::string getTypeAsString() const
static void prepareSelectAllStatement(soci::session &, soci::statement &, Place &)
static bool retrievePlace(soci::session &, const LocationKey &, Place &)
std::list< Place * > PlaceOrderedList_T
std::string toString() const
Enumeration of output types.
const LocationKey & getKey() const
const IATACode_T & getIataCode() const
const IATACode_T & getIataCode() const
static bool retrieveClosestPlaces(soci::session &, const double &iLatitude, const double &iLongitude, PlaceOrderedList_T &)
const char * what() const