Db(3)

NAME
Db - The Db class provides a basic API for accessing the database programatically. It is used to set up the initial connection and various basic queries can be executed using a set of static functions. When interfacing with the database for the purpose of adding, deleting or updating entries, the use of the entry class and its subclasses is recommended. This clas is not supposed to be instantiated, if you need a database object, use QSqlDatabase::database('qt_sql_default_connection');.

SYNOPSIS

#include <db.h>

  Public Types
enum editRole { createNew, editExisting }
The editRole enum {createNew, editExisting} is used to differentiate between creating a new entry in the database vs editing an existing one.
enum matchType { exactMatch, partialMatch }
The matchType enum {exactMatch, partialMatch} is used to determine the matching when using a WHERE sql statement. exactMatch results in a '=' operator, whereas partiasMatch results in a 'LIKE' operator.

  Public Member Functions
Db (Db const &)=delete
void operator= (Db const &)=delete

  Static Public Member Functions
static Db & get ()
static void connect ()
connect establishes the database connection. Only needs to be called once within the application. Database is available thereafter, objects can be instantiated with QSqlDatabase::database('qt_sql_default_connection') as required.
static void disconnect ()
disconnect Closes and removes the default database connection.
static QSqlDatabase Database ()
Can be used to access the database connection.
static bool exists (QString column, QString table, QString checkColumn, QString value, Db::matchType match)
Db::exists checks if a certain value exists in the database with a sqlite WHERE statement.
static bool singleUpdate (QString table, QString column, QString value, QString checkColumn, QString checkvalue, Db::matchType match)
Db::singleUpdate Updates a single value in the database. Query format: UPDATE table SET column = value WHERE checkcolumn =/LIKE checkvalue.
static QString singleSelect (QString column, QString table, QString checkColumn, QString value, Db::matchType match)
singleSelect Returns a single value from the database with a sqlite WHERE statement
static QVector< QString > multiSelect (QVector< QString > columns, QString table, QString checkColumn, QString value, Db::matchType match)
Db::multiSelect Returns multiple values from the database with a sqlite WHERE statement.
static QVector< QString > multiSelect (QVector< QString > columns, QString table)
Db::multiSelect Returns a complete column(s) for a given table.
static QVector< QString > customQuery (QString query, int returnValues)
Db::customQuery Can be used to send a complex query to the database.

Detailed Description

The Db class provides a basic API for accessing the database programatically. It is used to set up the initial connection and various basic queries can be executed using a set of static functions. When interfacing with the database for the purpose of adding, deleting or updating entries, the use of the entry class and its subclasses is recommended. This clas is not supposed to be instantiated, if you need a database object, use QSqlDatabase::database('qt_sql_default_connection');.

Member Function Documentation

  static QVector<QString> Db::customQuery (QString query, int returnValues) [inline], [static]

Db::customQuery Can be used to send a complex query to the database.

Parameters
    query - the full sql query statement
    returnValues - the number of expected return values

Returns
    QVector<QString> of results

  static QSqlDatabase Db::Database () [inline], [static]

Can be used to access the database connection.

Returns
    a pointer to the default database connection

  static bool Db::exists (QString column, QString table, QString checkColumn, QString value, Db::matchType match) [inline], [static]

Db::exists checks if a certain value exists in the database with a sqlite WHERE statement.

Parameters
    table - Name of the table
    column - Name of the column
    value - The value to be checked

Returns

  static QVector<QString> Db::multiSelect (QVector< QString > columns, QString table) [inline], [static]

Db::multiSelect Returns a complete column(s) for a given table.

Parameters
    column - QVector<QString> Names of the columns to be queried
    table - QString Name of the table

Returns

  static QVector<QString> Db::multiSelect (QVector< QString > columns, QString table, QString checkColumn, QString value, Db::matchType match) [inline], [static]

Db::multiSelect Returns multiple values from the database with a sqlite WHERE statement.

Parameters
    table - Name of the table
    columns - QVector<QString> Names of the columns to be queried
    value - Identifier for WHERE statement
    checkColumn - column to match value to
    match - enum Db::exactMatch or Db::partialMatch

Returns
    QVector<QString>

  static QString Db::singleSelect (QString column, QString table, QString checkColumn, QString value, Db::matchType match) [inline], [static]

singleSelect Returns a single value from the database with a sqlite WHERE statement

Parameters
    table - Name of the table
    column - Name of the column
    value - Identifier for WHERE statement
    match - enum Db::exactMatch or Db::partialMatch

Returns
    QString

  static bool Db::singleUpdate (QString table, QString column, QString value, QString checkColumn, QString checkvalue, Db::matchType match) [inline], [static]

Db::singleUpdate Updates a single value in the database. Query format: UPDATE table SET column = value WHERE checkcolumn =/LIKE checkvalue.

Parameters
    table Name of the table to be updated
    column Name of the column to be updated
    checkColumn Name of the column for WHERE statement
    value The value to be set
    checkvalue The value for the WHERE statement
    match enum Db::exactMatch or Db::partialMatch

Returns
    true on success, otherwise error messages in debug out

Author

Generated automatically by Doxygen for openPilotLog from the source code.