File: DatabaseConnectionHandle.h

package info (click to toggle)
tango 10.0.2%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 89,484 kB
  • sloc: cpp: 201,245; sh: 1,645; python: 953; java: 800; perl: 467; javascript: 447; xml: 325; makefile: 269; sql: 72; ruby: 24
file content (30 lines) | stat: -rw-r--r-- 913 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#ifndef DATABASECONNECTIONMANAGER_H
#define DATABASECONNECTIONMANAGER_H

#include "DatabaseConnectionPool.h"
#include "common.h"

/// @brief RAII class for database connections
class DatabaseConnectionHandle
{
public:
  DatabaseConnectionHandle(DatabaseConnectionPoolPtr dcp);
  ~DatabaseConnectionHandle();

  DatabaseConnectionHandle(const DatabaseConnectionHandle&) = delete;
  DatabaseConnectionHandle& operator=(const DatabaseConnectionHandle&) = delete;
  DatabaseConnectionHandle(DatabaseConnectionHandle&&) = delete;
  DatabaseConnectionHandle& operator=(DatabaseConnectionHandle&&) = delete;

  /// Allow access to the database class itself
  /// This pointer must *never* stored in a variable as it's lifetime is tied to the lifetime
  /// of this class.
  MYSQL* db() noexcept;

private:
  DatabaseConnectionPoolPtr m_dcp;
  int m_id;
  MYSQL* m_db = nullptr;
};

#endif // DATABASECONNECTIONMANAGER_H