KiCad PCB EDA Suite
|
#include <database_connection.h>
Public Types | |
typedef std::map< std::string, std::any > | ROW |
Public Member Functions | |
DATABASE_CONNECTION (const std::string &aDataSourceName, const std::string &aUsername, const std::string &aPassword, int aTimeoutSeconds=DEFAULT_TIMEOUT, bool aConnectNow=true) | |
DATABASE_CONNECTION (const std::string &aConnectionString, int aTimeoutSeconds=DEFAULT_TIMEOUT, bool aConnectNow=true) | |
~DATABASE_CONNECTION () | |
void | SetCacheParams (int aMaxSize, int aMaxAge) |
bool | Connect () |
bool | Disconnect () |
bool | IsConnected () const |
bool | CacheTableInfo (const std::string &aTable, const std::set< std::string > &aColumns) |
bool | SelectOne (const std::string &aTable, const std::pair< std::string, std::string > &aWhere, ROW &aResult) |
Retrieves a single row from a database table. | |
bool | SelectAll (const std::string &aTable, const std::string &aKey, std::vector< ROW > &aResults) |
Retrieves all rows from a database table. | |
std::string | GetLastError () const |
Static Public Attributes | |
static const long | DEFAULT_TIMEOUT = 10 |
Private Types | |
typedef DATABASE_CACHE< std::map< std::string, ROW > > | DB_CACHE_TYPE |
Private Member Functions | |
void | init () |
bool | getQuoteChar () |
std::string | columnsFor (const std::string &aTable) |
bool | selectAllAndCache (const std::string &aTable, const std::string &aKey) |
Private Attributes | |
std::unique_ptr< nanodbc::connection > | m_conn |
std::string | m_dsn |
std::string | m_user |
std::string | m_pass |
std::string | m_connectionString |
std::string | m_lastError |
std::map< std::string, std::string > | m_tables |
std::map< std::string, std::map< std::string, int > > | m_columnCache |
Map of table -> map of column name -> data type. | |
long | m_timeout |
char | m_quoteChar |
std::unique_ptr< DB_CACHE_TYPE > | m_cache |
Definition at line 41 of file database_connection.h.
|
private |
Definition at line 119 of file database_connection.h.
typedef std::map<std::string, std::any> DATABASE_CONNECTION::ROW |
Definition at line 46 of file database_connection.h.
DATABASE_CONNECTION::DATABASE_CONNECTION | ( | const std::string & | aDataSourceName, |
const std::string & | aUsername, | ||
const std::string & | aPassword, | ||
int | aTimeoutSeconds = DEFAULT_TIMEOUT , |
||
bool | aConnectNow = true |
||
) |
DATABASE_CONNECTION::DATABASE_CONNECTION | ( | const std::string & | aConnectionString, |
int | aTimeoutSeconds = DEFAULT_TIMEOUT , |
||
bool | aConnectNow = true |
||
) |
DATABASE_CONNECTION::~DATABASE_CONNECTION | ( | ) |
Definition at line 114 of file database_connection.cpp.
References Disconnect(), and m_conn.
bool DATABASE_CONNECTION::CacheTableInfo | ( | const std::string & | aTable, |
const std::set< std::string > & | aColumns | ||
) |
Definition at line 209 of file database_connection.cpp.
References fromUTF8(), m_columnCache, m_conn, m_lastError, m_tables, toUTF8(), and traceDatabase.
Referenced by BOOST_AUTO_TEST_CASE().
|
private |
Definition at line 289 of file database_connection.cpp.
References empty(), m_columnCache, m_quoteChar, and traceDatabase.
Referenced by selectAllAndCache(), and SelectOne().
bool DATABASE_CONNECTION::Connect | ( | ) |
Definition at line 143 of file database_connection.cpp.
References fromUTF8(), getQuoteChar(), IsConnected(), m_conn, m_connectionString, m_dsn, m_lastError, m_pass, m_tables, m_timeout, m_user, and traceDatabase.
Referenced by BOOST_AUTO_TEST_CASE(), and DATABASE_CONNECTION().
bool DATABASE_CONNECTION::Disconnect | ( | ) |
Definition at line 178 of file database_connection.cpp.
References m_conn, and traceDatabase.
Referenced by BOOST_AUTO_TEST_CASE(), and ~DATABASE_CONNECTION().
|
inline |
Definition at line 90 of file database_connection.h.
References m_lastError.
|
private |
Definition at line 263 of file database_connection.cpp.
References m_conn, m_lastError, m_quoteChar, toUTF8(), and traceDatabase.
Referenced by Connect().
|
private |
Definition at line 121 of file database_connection.cpp.
References m_cache.
Referenced by DATABASE_CONNECTION().
bool DATABASE_CONNECTION::IsConnected | ( | ) | const |
Definition at line 200 of file database_connection.cpp.
References m_conn.
Referenced by BOOST_AUTO_TEST_CASE(), and Connect().
bool DATABASE_CONNECTION::SelectAll | ( | const std::string & | aTable, |
const std::string & | aKey, | ||
std::vector< ROW > & | aResults | ||
) |
Retrieves all rows from a database table.
aTable | the name of a table in the database |
aKey | holds the column name of the primary key used for caching results |
aResults | will be filled with all rows in the table |
Definition at line 643 of file database_connection.cpp.
References m_cache, m_conn, m_tables, selectAllAndCache(), and traceDatabase.
|
private |
Definition at line 494 of file database_connection.cpp.
References columnsFor(), fromUTF8(), m_cache, m_conn, m_lastError, m_quoteChar, PROF_TIMER::msecs(), PROF_TIMER::Stop(), toUTF8(), and traceDatabase.
Referenced by SelectAll(), and SelectOne().
bool DATABASE_CONNECTION::SelectOne | ( | const std::string & | aTable, |
const std::pair< std::string, std::string > & | aWhere, | ||
DATABASE_CONNECTION::ROW & | aResult | ||
) |
Retrieves a single row from a database table.
Table and column names are cached when the connection is created, so schema changes to the database won't be recognized unless the connection is recreated.
aTable | the name of a table in the database |
aWhere | column to search, and the value to search for |
aResult | will be filled with a row in the database if one was found |
Definition at line 318 of file database_connection.cpp.
References columnsFor(), fromUTF8(), m_cache, m_columnCache, m_conn, m_lastError, m_quoteChar, m_tables, PROF_TIMER::msecs(), selectAllAndCache(), PROF_TIMER::Stop(), toUTF8(), and traceDatabase.
Referenced by BOOST_AUTO_TEST_CASE().
void DATABASE_CONNECTION::SetCacheParams | ( | int | aMaxSize, |
int | aMaxAge | ||
) |
Definition at line 127 of file database_connection.cpp.
References m_cache.
|
static |
Definition at line 44 of file database_connection.h.
|
private |
Definition at line 121 of file database_connection.h.
Referenced by init(), SelectAll(), selectAllAndCache(), SelectOne(), and SetCacheParams().
|
private |
Map of table -> map of column name -> data type.
Definition at line 113 of file database_connection.h.
Referenced by CacheTableInfo(), columnsFor(), and SelectOne().
|
private |
Definition at line 101 of file database_connection.h.
Referenced by CacheTableInfo(), Connect(), Disconnect(), getQuoteChar(), IsConnected(), SelectAll(), selectAllAndCache(), SelectOne(), and ~DATABASE_CONNECTION().
|
private |
Definition at line 106 of file database_connection.h.
Referenced by Connect().
|
private |
Definition at line 103 of file database_connection.h.
Referenced by Connect(), and DATABASE_CONNECTION().
|
private |
Definition at line 108 of file database_connection.h.
Referenced by CacheTableInfo(), Connect(), GetLastError(), getQuoteChar(), selectAllAndCache(), and SelectOne().
|
private |
Definition at line 105 of file database_connection.h.
Referenced by Connect(), and DATABASE_CONNECTION().
|
private |
Definition at line 117 of file database_connection.h.
Referenced by columnsFor(), getQuoteChar(), selectAllAndCache(), and SelectOne().
|
private |
Definition at line 110 of file database_connection.h.
Referenced by CacheTableInfo(), Connect(), SelectAll(), and SelectOne().
|
private |
Definition at line 115 of file database_connection.h.
Referenced by Connect(), and DATABASE_CONNECTION().
|
private |
Definition at line 104 of file database_connection.h.
Referenced by Connect(), and DATABASE_CONNECTION().