Banking_System_Server  1.0.0
Qt-based banking app for user/admin account management, transactions, secure server communication via PostgreSQL/Supabase.
DB::DatabaseManager Class Reference

Manages database connections and SQL operations. More...

#include <db.h>

Collaboration diagram for DB::DatabaseManager:
Collaboration graph

Public Member Functions

 ~DatabaseManager ()
 Destructor for DatabaseManager.
 
DatabaseManagerreset ()
 Resets the query settings. More...
 
DatabaseManagerselect (const QString &value)
 Selects columns for the query. More...
 
DatabaseManagertable (const QString &value)
 Sets the table for the query. More...
 
DatabaseManagerwhere (const QString &value, const QVariant &val=QVariant())
 Adds a WHERE clause to the query. More...
 
DatabaseManagerlike (const QString &value, const QString &val)
 Adds a LIKE clause to the query. More...
 
DatabaseManagerlikePost (const QString &value, const QString &val)
 Adds a LIKE clause with a postfix wildcard to the query. More...
 
DatabaseManagerlikeNative (const QString &value, const QString &val)
 Adds a native LIKE clause to the query. More...
 
DatabaseManagerwhereOr (const QString &value)
 Adds an OR condition to the WHERE clause. More...
 
DatabaseManagerjoin (const QString &value)
 Adds a JOIN clause to the query. More...
 
DatabaseManagerlimit (int limit)
 Adds a LIMIT clause to the query. More...
 
DatabaseManagerstart (int start)
 Adds an OFFSET clause to the query. More...
 
DatabaseManagersort (const QString &sort)
 Adds an ORDER BY clause to the query. More...
 
DatabaseManagergroup (const QString &group)
 Adds a GROUP BY clause to the query. More...
 
QString getSelectQuery (const QString &select=QString())
 Gets the SQL SELECT query. More...
 
QSqlError lastError ()
 Gets the last error occurred. More...
 
QVariant lastInsertedId ()
 Gets the ID of the last inserted record. More...
 
QString lastQuery ()
 Gets the last executed query. More...
 
DbResult exec ()
 Executes the built query. More...
 
DbResult execResult (const QString &sql)
 Executes a SQL query. More...
 
DbResult get (const QString &tableName)
 Executes a SELECT query on a specified table. More...
 
bool exec (const QString &sqlcommand)
 Executes a SQL command. More...
 
bool insert (const QString &table, const QVariantMap &data)
 Inserts data into a specified table. More...
 
bool update (const QString &table, const QVariantMap &data)
 Updates data in a specified table. More...
 
bool del (const QString &table)
 Deletes data from a specified table. More...
 
int count ()
 Gets the count of records matching the query criteria. More...
 
DatabaseManagerclone ()
 Clones the current DatabaseManager instance. More...
 
bool beginTransaction ()
 Begins a transaction. More...
 
bool commit ()
 Commits a transaction. More...
 
bool rollback ()
 Rolls back a transaction. More...
 
bool isSupportTransaction ()
 Checks if transactions are supported. More...
 
DatabaseManagerclearSelect ()
 Clears the SELECT clause. More...
 
bool truncateTable (const QString &table)
 Truncates a specified table. More...
 

Static Public Member Functions

static DatabaseManagercreateInstance (bool checkDBName=false, bool newConnection=false, QString *err=nullptr)
 Creates an instance of DatabaseManager. More...
 
static bool setDbSetting (const QString &host, int port, const QString &username, const QString &password, const QString &dbname)
 Sets the database settings. More...
 
static bool checkConnection (QString &error)
 Checks the database connection. More...
 

Detailed Description

Manages database connections and SQL operations.

This class provides methods for managing database connections, executing SQL queries, and handling transactions.

Member Function Documentation

◆ beginTransaction()

bool DatabaseManager::beginTransaction ( )

Begins a transaction.

Returns
True if the transaction started successfully, false otherwise.

◆ checkConnection()

bool DatabaseManager::checkConnection ( QString &  error)
static

Checks the database connection.

Parameters
errorReference to store error message.
Returns
True if connection is successful, false otherwise.

Referenced by Request::isDBConnectionValid().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clearSelect()

DatabaseManager* DB::DatabaseManager::clearSelect ( )
inline

Clears the SELECT clause.

Returns
Pointer to the DatabaseManager instance.

◆ clone()

DatabaseManager * DatabaseManager::clone ( )

Clones the current DatabaseManager instance.

Returns
Pointer to the cloned DatabaseManager instance.

Referenced by count().

Here is the caller graph for this function:

◆ commit()

bool DatabaseManager::commit ( )

Commits a transaction.

Returns
True if the transaction was committed successfully, false otherwise.

◆ count()

int DatabaseManager::count ( )

Gets the count of records matching the query criteria.

Returns
Count of records.
Here is the call graph for this function:

◆ createInstance()

DatabaseManager * DatabaseManager::createInstance ( bool  checkDBName = false,
bool  newConnection = false,
QString *  err = nullptr 
)
static

Creates an instance of DatabaseManager.

Parameters
checkDBNameFlag to check database name.
newConnectionFlag to create a new connection.
errPointer to store error message.
Returns
Pointer to DatabaseManager instance.

Referenced by checkConnection().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ del()

bool DatabaseManager::del ( const QString &  table)

Deletes data from a specified table.

Parameters
tableName of the table.
Returns
True if the data was deleted successfully, false otherwise.

Referenced by DeleteUserRequest::execute(), and UpdateUserRequest::execute().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ exec() [1/2]

◆ exec() [2/2]

bool DatabaseManager::exec ( const QString &  sqlcommand)

Executes a SQL command.

Parameters
sqlcommandSQL command to execute.
Returns
True if the command executed successfully, false otherwise.
Here is the call graph for this function:

◆ execResult()

DbResult DatabaseManager::execResult ( const QString &  sql)

Executes a SQL query.

Parameters
sqlSQL query to execute.
Returns
DbResult object containing the result of the query.
Here is the call graph for this function:

◆ get()

DbResult DatabaseManager::get ( const QString &  tableName)

Executes a SELECT query on a specified table.

Parameters
tableNameName of the table.
Returns
DbResult object containing the result of the query.
Here is the call graph for this function:

◆ getSelectQuery()

QString DatabaseManager::getSelectQuery ( const QString &  select = QString())

Gets the SQL SELECT query.

Parameters
selectOptional select clause.
Returns
SQL SELECT query as a string.

Referenced by count(), and exec().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ group()

DatabaseManager * DatabaseManager::group ( const QString &  group)

Adds a GROUP BY clause to the query.

Parameters
groupGrouping criteria.
Returns
Pointer to the DatabaseManager instance.

◆ insert()

bool DatabaseManager::insert ( const QString &  table,
const QVariantMap &  data 
)

Inserts data into a specified table.

Parameters
tableName of the table.
dataData to insert.
Returns
True if the data was inserted successfully, false otherwise.

Referenced by CreateNewUserRequest::execute(), and MakeTransactionRequest::execute().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isSupportTransaction()

bool DB::DatabaseManager::isSupportTransaction ( )
inline

Checks if transactions are supported.

Returns
True if transactions are supported, false otherwise.

◆ join()

DatabaseManager * DatabaseManager::join ( const QString &  value)

Adds a JOIN clause to the query.

Parameters
valueJOIN clause.
Returns
Pointer to the DatabaseManager instance.

Referenced by GetAccountNumberRequest::execute(), GetDatabaseRequest::execute(), GetTransactionsHistoryRequest::execute(), and MakeTransactionRequest::execute().

Here is the caller graph for this function:

◆ lastError()

QSqlError DatabaseManager::lastError ( )

Gets the last error occurred.

Returns
QSqlError object containing the last error.

Referenced by createInstance().

Here is the caller graph for this function:

◆ lastInsertedId()

QVariant DatabaseManager::lastInsertedId ( )

Gets the ID of the last inserted record.

Returns
ID of the last inserted record.

◆ lastQuery()

QString DatabaseManager::lastQuery ( )

Gets the last executed query.

Returns
Last executed query as a string.

Referenced by exec().

Here is the caller graph for this function:

◆ like()

DatabaseManager * DatabaseManager::like ( const QString &  value,
const QString &  val 
)

Adds a LIKE clause to the query.

Parameters
valueColumn name.
valValue for the LIKE clause.
Returns
Pointer to the DatabaseManager instance.

◆ likeNative()

DatabaseManager * DatabaseManager::likeNative ( const QString &  value,
const QString &  val 
)

Adds a native LIKE clause to the query.

Parameters
valueColumn name.
valValue for the LIKE clause.
Returns
Pointer to the DatabaseManager instance.

◆ likePost()

DatabaseManager * DatabaseManager::likePost ( const QString &  value,
const QString &  val 
)

Adds a LIKE clause with a postfix wildcard to the query.

Parameters
valueColumn name.
valValue for the LIKE clause.
Returns
Pointer to the DatabaseManager instance.

◆ limit()

DatabaseManager * DatabaseManager::limit ( int  limit)

Adds a LIMIT clause to the query.

Parameters
limitNumber of records to limit.
Returns
Pointer to the DatabaseManager instance.

◆ reset()

DatabaseManager * DatabaseManager::reset ( )

Resets the query settings.

Returns
Pointer to the DatabaseManager instance.

Referenced by del(), exec(), execResult(), insert(), and update().

Here is the caller graph for this function:

◆ rollback()

bool DatabaseManager::rollback ( )

Rolls back a transaction.

Returns
True if the transaction was rolled back successfully, false otherwise.

◆ select()

◆ setDbSetting()

bool DatabaseManager::setDbSetting ( const QString &  host,
int  port,
const QString &  username,
const QString &  password,
const QString &  dbname 
)
static

Sets the database settings.

Parameters
hostDatabase host.
portDatabase port.
usernameDatabase username.
passwordDatabase password.
dbnameDatabase name.
Returns
True if settings are set successfully, false otherwise.
Here is the call graph for this function:

◆ sort()

DatabaseManager * DatabaseManager::sort ( const QString &  sort)

Adds an ORDER BY clause to the query.

Parameters
sortSorting criteria.
Returns
Pointer to the DatabaseManager instance.

◆ start()

DatabaseManager * DatabaseManager::start ( int  start)

Adds an OFFSET clause to the query.

Parameters
startOffset value.
Returns
Pointer to the DatabaseManager instance.

◆ table()

◆ truncateTable()

bool DatabaseManager::truncateTable ( const QString &  table)

Truncates a specified table.

Parameters
tableName of the table.
Returns
True if the table was truncated successfully, false otherwise.
Here is the call graph for this function:

◆ update()

bool DatabaseManager::update ( const QString &  table,
const QVariantMap &  data 
)

Updates data in a specified table.

Parameters
tableName of the table.
dataData to update.
Returns
True if the data was updated successfully, false otherwise.

Referenced by del(), MakeTransactionRequest::execute(), UpdateEmailRequest::execute(), UpdatePasswordRequest::execute(), and UpdateUserRequest::execute().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ where()

DatabaseManager * DatabaseManager::where ( const QString &  value,
const QVariant &  val = QVariant() 
)

◆ whereOr()

DatabaseManager * DatabaseManager::whereOr ( const QString &  value)

Adds an OR condition to the WHERE clause.

Parameters
valueCondition for the OR clause.
Returns
Pointer to the DatabaseManager instance.

Referenced by GetTransactionsHistoryRequest::execute().

Here is the caller graph for this function:

The documentation for this class was generated from the following files: