123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- #include "dbairport.h"
- #include "dbapi.h"
- QString dbAirport::retreiveAirportNameFromIcaoOrIata(QString identifier)
- {
- QString result = "";
- QSqlQuery query;
- query.prepare("SELECT name "
- "FROM airports WHERE icao LIKE ? OR iata LIKE ?");
- identifier.append("%");
- identifier.prepend("%");
- query.addBindValue(identifier);
- query.addBindValue(identifier);
- query.exec();
- if(query.first())
- {
- result.append(query.value(0).toString());
- return result;
- }else
- {
- result = result.left(result.length()-1);
- result.append("No matching airport found.");
- return result;
- }
- }
- QString dbAirport::retreiveAirportIdFromIcao(QString identifier)
- {
- QString result;
- QSqlQuery query;
- query.prepare("SELECT airport_id FROM airports WHERE icao = ?");
- query.addBindValue(identifier);
- query.exec();
- while(query.next())
- {
- result.append(query.value(0).toString());
-
- }
- return result;
- }
- QStringList dbAirport::completeIcaoOrIata(QString icaoStub)
- {
- QStringList result;
- QSqlQuery query;
- query.prepare("SELECT icao FROM airports WHERE icao LIKE ? OR iata LIKE ?");
- icaoStub.prepend("%"); icaoStub.append("%");
- query.addBindValue(icaoStub);
- query.addBindValue(icaoStub);
- query.exec();
- while(query.next())
- {
- result.append(query.value(0).toString());
- qDebug() << "db::CompleteIcaoOrIata says... Result:" << result;
- }
- return result;
- }
- QStringList dbAirport::retreiveIataIcaoList()
- {
- QSqlQuery query;
- query.prepare("SELECT icao, iata from airports");
- query.exec();
- QStringList result;
- while(query.next())
- {
- result.append(query.value(0).toString());
- result.append(query.value(1).toString());
- }
- result.removeAll(QString(""));
- return result;
- }
- bool dbAirport::checkICAOValid(QString identifier)
- {
- if(identifier.length() == 4)
- {
- QString check = retreiveAirportIdFromIcao(identifier);
- if(check.length() > 0)
- {
- return true;
- }else
- {
- return false;
- }
- }else
- {
- return false;
- }
- }
- QVector<double> dbAirport::retreiveIcaoCoordinates(QString icao)
- {
- QSqlQuery query;
- query.prepare("SELECT lat, long "
- "FROM airports "
- "WHERE icao = ?");
- query.addBindValue(icao);
- query.exec();
- QVector<double> result;
- while(query.next()) {
- result.append(query.value(0).toDouble());
- result.append(query.value(1).toDouble());
- }
- return result;
- }
- QVector<QPair<QString, QString>> dbAirport::retreiveTimezonesIATA()
- {
- QSqlQuery query;
- query.prepare("SELECT iata, tzolson "
- "FROM airports "
- "WHERE tzolson IS NOT NULL AND iata IS NOT NULL");
- query.exec();
- QVector<QPair<QString, QString>> result;
- while(query.next()) {
- result.append(QPair<QString, QString>(query.value(0).toString(),query.value(1).toString()));
- }
- return result;
- }
|