KanoopDatabaseQt 1.1.1
Qt database abstraction library
Loading...
Searching...
No Matches
databasecredentials.h
1/**
2 * DatabaseCredentials
3 *
4 * Represents a set of database credentials for use by the DataSource class
5 *
6 * Stephen Punak, January 11 2025
7 */
8#ifndef DATABASECREDENTIALS_H
9#define DATABASECREDENTIALS_H
10
11#include <QString>
12
13/** @brief Represents a set of database connection credentials for use by the DataSource class. */
15{
16public:
17 /** @brief Construct default (empty) credentials. */
19
20 /** @brief Construct credentials with all connection parameters.
21 * @param host The database server hostname or IP address.
22 * @param schema The database/schema name.
23 * @param username The database username.
24 * @param password The database password.
25 * @param engine The database engine identifier (e.g. SQLENG_SQLITE, SQLENG_MYSQL).
26 */
27 DatabaseCredentials(const QString& host, const QString& schema, const QString& username, const QString& password, const QString& engine) :
28 _host(host), _schema(schema), _username(username), _password(password), _engine(engine) {}
29
30 /** @brief Construct SQLite credentials with only a schema (file path).
31 * @param schema The SQLite database file path.
32 */
33 DatabaseCredentials(const QString& schema) :
34 _schema(schema), _engine(SQLENG_SQLITE) {}
35
36 /** @brief Get the database server hostname.
37 * @return The hostname or IP address.
38 */
39 QString host() const { return _host; }
40 /** @brief Set the database server hostname.
41 * @param value The hostname or IP address.
42 */
43 void setHost(const QString& value) { _host = value; }
44
45 /** @brief Get the database/schema name.
46 * @return The schema name or SQLite file path.
47 */
48 QString schema() const { return _schema; }
49 /** @brief Set the database/schema name.
50 * @param value The schema name or SQLite file path.
51 */
52 void setSchema(const QString& value) { _schema = value; }
53
54 /** @brief Get the database username.
55 * @return The username string.
56 */
57 QString username() const { return _username; }
58 /** @brief Set the database username.
59 * @param value The username.
60 */
61 void setUsername(const QString& value) { _username = value; }
62
63 /** @brief Get the database password.
64 * @return The password string.
65 */
66 QString password() const { return _password; }
67 /** @brief Set the database password.
68 * @param value The password.
69 */
70 void setPassword(const QString& value) { _password = value; }
71
72 /** @brief Get the database engine identifier.
73 * @return The engine string (e.g. SQLENG_SQLITE, SQLENG_MYSQL).
74 */
75 QString engine() const { return _engine; }
76 /** @brief Set the database engine identifier.
77 * @param value The engine string (e.g. SQLENG_SQLITE).
78 */
79 void setEngine(const QString& value) { _engine = value; }
80
81 /** @brief Return true if the engine is SQLite.
82 * @return true if the engine is SQLite.
83 */
84 bool isSqlite() const { return _engine == SQLENG_SQLITE; }
85 /** @brief Return true if the credentials have a non-empty schema.
86 * @return true if a schema has been set.
87 */
88 bool isValid() const { return _schema.isEmpty() == false; }
89
90 /** @brief Engine identifier string for SQLite. */
91 static const QString SQLENG_SQLITE;
92 /** @brief Engine identifier string for MySQL. */
93 static const QString SQLENG_MYSQL;
94 /** @brief Engine identifier string for PostgreSQL. */
95 static const QString SQLENG_PGSQL;
96
97private:
98 QString _host;
99 QString _schema;
100 QString _username;
101 QString _password;
102 QString _engine;
103};
104
105#endif // DATABASECREDENTIALS_H
DatabaseCredentials.
QString username() const
Get the database username.
bool isValid() const
Return true if the credentials have a non-empty schema.
void setPassword(const QString &value)
Set the database password.
bool isSqlite() const
Return true if the engine is SQLite.
void setEngine(const QString &value)
Set the database engine identifier.
QString password() const
Get the database password.
static const QString SQLENG_PGSQL
Engine identifier string for PostgreSQL.
QString schema() const
Get the database/schema name.
QString engine() const
Get the database engine identifier.
DatabaseCredentials(const QString &host, const QString &schema, const QString &username, const QString &password, const QString &engine)
Construct credentials with all connection parameters.
DatabaseCredentials(const QString &schema)
Construct SQLite credentials with only a schema (file path).
void setHost(const QString &value)
Set the database server hostname.
DatabaseCredentials()
Construct default (empty) credentials.
void setUsername(const QString &value)
Set the database username.
void setSchema(const QString &value)
Set the database/schema name.
static const QString SQLENG_SQLITE
Engine identifier string for SQLite.
QString host() const
Get the database server hostname.
static const QString SQLENG_MYSQL
Engine identifier string for MySQL.