123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- #include "dbairport.h"
- #include "dbman.cpp"
- 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;
- }
- bool dbAirport::checkICAOValid(QString identifier)
- {
- if(identifier.length() == 4)
- {
- QString check = retreiveAirportIdFromIcao(identifier);
- if(check.length() > 0)
- {
-
- return 1;
- }else
- {
-
- return 0;
- }
- }else
- {
-
- return 0;
- }
- }
- 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;
- }
|