21#ifndef KICAD_DATABASE_CONNECTION_H
22#define KICAD_DATABASE_CONNECTION_H
45 typedef std::map<std::string, std::any>
ROW;
90 bool CacheTableInfo(
const std::string& aTable,
const std::set<std::string>& aRequiredColumns,
91 const std::set<std::string>& aOptionalColumns = {} );
102 bool SelectOne(
const std::string& aTable,
const std::pair<std::string, std::string>& aWhere,
126 std::optional<TABLE_FAILURE>
GetTableFailure(
const std::string& aTable )
const;
136 bool SelectAll(
const std::string& aTable,
const std::string& aKey, std::vector<ROW>& aResults,
147 bool SelectSample(
const std::string& aTable,
size_t aMaxRows, std::vector<std::string>& aColumns,
148 std::vector<ROW>& aRows );
153 bool GetTables( std::vector<std::string>& aTables );
158 bool GetColumns(
const std::string& aTable, std::vector<std::string>& aColumns );
187 static std::optional<size_t>
findLabel(
const std::vector<std::string>& aLabels,
const std::string& aKey );
190 static ROW makeRow(
const std::vector<std::string>& aLabels, std::vector<DB_VALUE>&& aValues );
std::map< std::string, ROW > CACHE_VALUE
LOAD_CYCLE(const LOAD_CYCLE &)=delete
DATABASE_CONNECTION & m_connection
LOAD_CYCLE(DATABASE_CONNECTION &aConnection, DB_STOP_CHECK aStopped)
LOAD_CYCLE & operator=(const LOAD_CYCLE &)=delete
DB_FAILURE GetLastFailure() const
bool SelectAll(const std::string &aTable, const std::string &aKey, std::vector< ROW > &aResults, QUERY_STATUS *aStatus=nullptr)
Retrieves all rows from a database table.
DATABASE_CONNECTION(std::unique_ptr< DATABASE_BACKEND > aBackend, bool aConnectNow=true)
bool GetColumns(const std::string &aTable, std::vector< std::string > &aColumns)
Lists the columns of a table in catalog order.
std::map< std::string, std::any > ROW
std::unique_ptr< DATABASE_BACKEND > m_backend
static ROW makeRow(const std::vector< std::string > &aLabels, std::vector< DB_VALUE > &&aValues)
Converts one row delivered by the backend to text keyed by result-column label.
std::map< std::string, TABLE_STATE > m_tables
void SetCacheParams(int aMaxSize, int aMaxAge)
std::unique_ptr< DB_CACHE_TYPE > m_cache
std::map< std::string, TABLE_FAILURE > m_tableFailures
Why CacheTableInfo could not describe each table, so a later query on it reports that table's own fai...
static std::vector< std::string > columnNames(const TABLE_STATE &aTable)
void ClearCache(const std::string &aTable)
bool GetTables(std::vector< std::string > &aTables)
Lists the tables and views visible through this connection, sorted by name.
bool SelectSample(const std::string &aTable, size_t aMaxRows, std::vector< std::string > &aColumns, std::vector< ROW > &aRows)
Reads the first rows of a table, bypassing the row cache.
DATABASE_CACHE< std::map< std::string, ROW > > DB_CACHE_TYPE
bool SelectOne(const std::string &aTable, const std::pair< std::string, std::string > &aWhere, ROW &aResult)
Retrieves a single row from a database table.
static std::optional< size_t > findLabel(const std::vector< std::string > &aLabels, const std::string &aKey)
std::string GetLastError() const
bool readAndCache(const std::string &aTable, const std::string &aKey, DB_CACHE_TYPE::CACHE_VALUE &aEntry)
Reads a whole table into aEntry and offers it to the row cache.
std::optional< TABLE_FAILURE > GetTableFailure(const std::string &aTable) const
bool CacheTableInfo(const std::string &aTable, const std::set< std::string > &aRequiredColumns, const std::set< std::string > &aOptionalColumns={})
Caches schema information for a table so that subsequent queries know which columns exist.
std::function< bool()> DB_STOP_CHECK
True once the caller no longer wants what a read would deliver.
DB_FAILURE
Why a connection attempt failed, as far as the backend's report tells.
What a failed query left behind, copied before another thread's query can replace it.
Why CacheTableInfo could not describe a table.
std::set< std::string > columns
Lowercase columns the failed lookups asked for; only a lookup asking for all of them clears the failu...
A table the backend described, with the columns queries against it read.
std::set< std::string > columns
The column spellings queries read. Spellings differing only in case are distinct columns.