aDbSetup(3)

NAME
aDbSetup - The aDbSetup namespace is responsible for the inital setup of the database when the application is first launched. It creates the database in the specified default location and creates all required tables and views.

SYNOPSIS

  Functions
bool createDatabase ()
createDatabase runs a number of CREATE queries that create the database tables and columns.
bool commitData (const QJsonArray &json_arr, const QString &table_name)
commitData commits the data read from a JSON file into a table in the database.
bool importTemplateData (bool use_local_ressources)
importTemplateData fills an empty database with the template data (Aircraft, Airports, currencies, changelog) as read from the JSON templates.
bool resetUserData ()
Empties all user-generated content in the database.

  Variables
const auto TEMPLATE_URL = QStringLiteral('https://raw.githubusercontent.com/fiffty-50/openpilotlog/develop/assets/database/templates/')
const auto CREATE_TABLE_PILOTS
const auto CREATE_TABLE_TAILS
const auto CREATE_TABLE_FLIGHTS
const auto CREATE_TABLE_AIRPORTS
const auto CREATE_TABLE_AIRCRAFT
const auto CREATE_TABLE_CHANGELOG
const auto CREATE_TABLE_CURRENCIES
const auto CREATE_VIEW_DEFAULT
const auto CREATE_VIEW_EASA
const auto CREATE_VIEW_TAILS
const auto CREATE_VIEW_PILOTS
const auto CREATE_VIEW_QCOMPLETER
const auto CREATE_VIEW_TOTALS
const QList< QLatin1String > DATABASE_TABLES
const QList< QLatin1String > DATABASE_VIEWS
const QList< QLatin1String > USER_TABLES
const QList< QLatin1String > TEMPLATE_TABLES

Detailed Description

The aDbSetup namespace is responsible for the inital setup of the database when the application is first launched. It creates the database in the specified default location and creates all required tables and views.

Function Documentation

  bool aDbSetup::createDatabase ()

createDatabase runs a number of CREATE queries that create the database tables and columns.

Returns

  bool aDbSetup::importTemplateData (bool use_local_ressources)

importTemplateData fills an empty database with the template data (Aircraft, Airports, currencies, changelog) as read from the JSON templates.

Parameters
    use_local_ressources determines whether the included ressource files or a previously downloaded file should be used.

Returns

  bool aDbSetup::resetUserData ()

Empties all user-generated content in the database.

Returns
    true on success

Variable Documentation

  const auto aDbSetup::CREATE_TABLE_AIRCRAFT
Initial value:

= QLatin1String("CREATE TABLE aircraft ("
            " aircraft_id   INTEGER NOT NULL,"
            " make          TEXT,"
            " model         TEXT,"
            " variant       TEXT,"
            " name          TEXT,"
            " iata          TEXT,"
            " icao          TEXT,"
            " multipilot    INTEGER,"
            " multiengine   INTEGER,"
            " engineType    INTEGER,"
            " weightClass   INTEGER,"
            " PRIMARY KEY(aircraft_id AUTOINCREMENT)"
            ")")

  const auto aDbSetup::CREATE_TABLE_AIRPORTS
Initial value:

= QLatin1String("CREATE TABLE airports ( "
            " airport_id     INTEGER NOT NULL, "
            " icao           TEXT NOT NULL, "
            " iata           TEXT, "
            " name           TEXT, "
            " lat            REAL, "
            " long           REAL, "
            " country        TEXT, "
            " alt            INTEGER, "
            " utcoffset      INTEGER, "
            " tzolson        TEXT, "
            " PRIMARY KEY(airport_id AUTOINCREMENT) "
            ")")

  const auto aDbSetup::CREATE_TABLE_CHANGELOG
Initial value:

= QLatin1String("CREATE TABLE changelog ( "
            " revision   INTEGER NOT NULL, "
            " comment    TEXT, "
            " date       NUMERIC, "
            " PRIMARY KEY(revision) "
            ")")

  const auto aDbSetup::CREATE_TABLE_CURRENCIES
Initial value:

= QLatin1String("CREATE TABLE currencies ( "
            " currency_id   INTEGER PRIMARY KEY AUTOINCREMENT, "
            " description   TEXT, "
            " expiryDate     NUMERIC "
            ")"
            )

  const auto aDbSetup::CREATE_TABLE_PILOTS
Initial value:

= QLatin1String("CREATE TABLE pilots ( "
            " pilot_id       INTEGER NOT NULL, "
            " lastname       TEXT    NOT NULL, "
            " firstname      TEXT, "
            " alias          TEXT, "
            " company        TEXT, "
            " employeeid     TEXT, "
            " phone          TEXT, "
            " email          TEXT, "
            " PRIMARY KEY(pilot_id AUTOINCREMENT)"
            ")")

  const auto aDbSetup::CREATE_TABLE_TAILS
Initial value:

= QLatin1String("CREATE TABLE tails ("
            " tail_id        INTEGER NOT NULL,"
            " registration   TEXT NOT NULL,"
            " company        TEXT,"
            " make           TEXT,"
            " model          TEXT,"
            " variant        TEXT,"
            " multipilot     INTEGER,"
            " multiengine    INTEGER,"
            " engineType     INTEGER,"
            " weightClass    INTEGER,"
            " PRIMARY KEY(tail_id AUTOINCREMENT)"
            ")")

  const auto aDbSetup::CREATE_VIEW_DEFAULT
Initial value:

= QLatin1String("CREATE VIEW viewDefault AS "
        " SELECT flight_id, doft as 'Date', "
        " dept AS 'Dept', "
        " printf('%02d',(tofb/60))||':'||printf('%02d',(tofb%60)) AS 'Time', "
        " dest AS 'Dest', printf('%02d',(tonb/60))||':'||printf('%02d',(tonb%60)) AS 'Time ', "
        " printf('%02d',(tblk/60))||':'||printf('%02d',(tblk%60)) AS 'Total', "
        " CASE "
        " WHEN pilot_id = 1 THEN alias "
        " ELSE lastname||', '||substr(firstname, 1, 1)||'.' "
        " END "
        " AS 'Name PIC', "
        " CASE "
        " WHEN variant IS NOT NULL THEN make||' '||model||'-'||variant "
        " ELSE make||' '||model "
        " END "
        " AS 'Type', "
        " registration AS 'Registration', "
        " FlightNumber AS 'Flight #', "
        " remarks AS 'Remarks'"
        " FROM flights "
        " INNER JOIN pilots on flights.pic = pilots.pilot_id "
        " INNER JOIN tails on flights.acft = tails.tail_id "
        " ORDER BY date DESC ")

  const auto aDbSetup::CREATE_VIEW_PILOTS
Initial value:

= QLatin1String("CREATE VIEW viewPilots AS "
        " SELECT "
        " pilot_id AS 'ID', "
        " lastname AS 'Last Name', "
        " firstname AS 'First Name', "
        " company AS 'Company' "
        " FROM pilots")

  const auto aDbSetup::CREATE_VIEW_QCOMPLETER
Initial value:

= QLatin1String("CREATE VIEW viewQCompleter AS "
        " SELECT airport_id, icao, iata, tail_id, registration, pilot_id, "
        " lastname||', '||firstname AS 'pilot_name', alias "
        " FROM airports "
        " LEFT JOIN tails ON airports.airport_id = tails.tail_id "
        " LEFT JOIN pilots ON airports.airport_id = pilots.pilot_id")

  const auto aDbSetup::CREATE_VIEW_TAILS
Initial value:

= QLatin1String("CREATE VIEW viewTails AS "
        " SELECT "
        " tail_id AS 'ID', "
        " registration AS 'Registration', "
        " make||' '||model AS 'Type', "
        " company AS 'Company' "
        " FROM tails WHERE model IS NOT NULL AND variant IS NULL "
        " UNION "
        " SELECT "
        " tail_id AS 'ID', "
        " registration AS 'Registration', "
        " make||' '||model||'-'||variant AS 'Type', "
        " company AS 'Company' "
        " FROM tails WHERE variant IS NOT NULL")

  const auto aDbSetup::CREATE_VIEW_TOTALS
Initial value:

= QLatin1String("CREATE VIEW viewTotals AS "
        " SELECT "
        " printf(
        " printf(
        " printf(
        " printf(
        " printf(
        " printf(
        " printf(
        " printf(
        " printf(
        " printf(
        " printf(
        " printf(
        " CAST(SUM(toDay) AS INT) AS
        " CAST(SUM(ldgDay) AS INT) AS
        " FROM flights")

  const QList<QLatin1String> aDbSetup::DATABASE_TABLES
Initial value:

= {
    CREATE_TABLE_PILOTS,
    CREATE_TABLE_TAILS,
    CREATE_TABLE_FLIGHTS,
    CREATE_TABLE_AIRCRAFT,
    CREATE_TABLE_AIRPORTS,
    CREATE_TABLE_CURRENCIES,
    CREATE_TABLE_CHANGELOG
}

  const QList<QLatin1String> aDbSetup::DATABASE_VIEWS
Initial value:

= {
    CREATE_VIEW_DEFAULT,
    CREATE_VIEW_EASA,
    CREATE_VIEW_TAILS,
    CREATE_VIEW_PILOTS,
    CREATE_VIEW_TOTALS,
    CREATE_VIEW_QCOMPLETER,
}

  const QList<QLatin1String> aDbSetup::TEMPLATE_TABLES
Initial value:

= {
    QLatin1String("aircraft"),
    QLatin1String("airports"),
    QLatin1String("currencies"),
    QLatin1String("changelog")
}

  const QList<QLatin1String> aDbSetup::USER_TABLES
Initial value:

= {
    QLatin1String("flights"),
    QLatin1String("pilots"),
    QLatin1String("tails")
}

Author

Generated automatically by Doxygen for openPilotLog from the source code.