20#ifndef KICAD_DATABASE_BACKEND_H
21#define KICAD_DATABASE_BACKEND_H
76using DB_ROW_SINK = std::function<void( std::vector<DB_VALUE>&& )>;
91 std::unique_ptr<DATABASE_BACKEND>
backend;
106 static constexpr size_t ALL_ROWS = std::numeric_limits<size_t>::max();
117 virtual bool ListTables( std::vector<std::string>& aTables ) = 0;
120 virtual std::optional<DB_TABLE_INFO>
DescribeTable(
const std::string& aTable ) = 0;
123 virtual bool ListColumns(
const std::string& aTable, std::vector<std::string>& aColumns );
136 std::vector<std::string>& aLabels,
const DB_ROW_SINK& aSink ) = 0;
147 std::vector<std::string>& aLabels,
const DB_ROW_SINK& aSink,
171 const std::string& aKeyColumn,
const std::string& aKey,
172 std::vector<std::string>& aLabels, std::vector<DB_VALUE>& aRow )
A read-only source of tables.
virtual std::optional< DB_TABLE_INFO > DescribeTable(const std::string &aTable)=0
virtual DB_FAILURE GetLastFailure() const =0
virtual bool ListTables(std::vector< std::string > &aTables)=0
Lists the tables and views, sorted by name.
virtual bool ListColumns(const std::string &aTable, std::vector< std::string > &aColumns)
Lists the column names of a table as the catalog reports them, empty if it has none,...
virtual void Disconnect()=0
virtual void EndLoadCycle()
virtual bool IsConnected() const =0
virtual ~DATABASE_BACKEND()=default
virtual std::optional< bool > ReadRow(const DB_TABLE_INFO &aTable, const std::vector< std::string > &aColumns, const std::string &aKeyColumn, const std::string &aKey, std::vector< std::string > &aLabels, std::vector< DB_VALUE > &aRow)
Reads the one row whose key column equals aKey, using an indexed lookup if the backend has one.
virtual bool ReadTable(const DB_TABLE_INFO &aTable, const std::vector< std::string > &aColumns, size_t aMaxRows, std::vector< std::string > &aLabels, const DB_ROW_SINK &aSink)=0
Reads rows of a table, handing each to aSink.
virtual void BeginLoadCycle(const DB_STOP_CHECK &aStopped)
Brackets a load cycle, in which the caller reads each table once.
static constexpr size_t ALL_ROWS
Passed as ReadTable()'s row limit to read every row.
static DB_BACKEND_RESULT Create(const DATABASE_SOURCE &aSource, const wxString &aBasePath)
Builds the backend for a source.
virtual bool ReadAllRows(const DB_TABLE_INFO &aTable, const std::vector< std::string > &aColumns, std::vector< std::string > &aLabels, const DB_ROW_SINK &aSink, const DB_RESTART_SINK &aRestart)
Reads every row of a table for a caller that keeps them, handing each to aSink.
virtual std::string GetLastError() const =0
std::function< bool()> DB_STOP_CHECK
True once the caller no longer wants what a read would deliver.
std::function< void(std::vector< DB_VALUE > &&)> DB_ROW_SINK
Receives one row at a time, in the order of the labels the read produced.
DB_FAILURE
Why a connection attempt failed, as far as the backend's report tells.
@ TIMEOUT
The source did not answer within the timeout.
@ INVALID_TYPE
The source type is not one KiCad knows.
@ NO_DSN
The data source name is not configured.
@ NETWORK_WAL
A write-ahead-log database on a network path cannot be read safely.
@ LOGIN
The server rejected the user name or password.
@ PROVIDER_MISSING
The database engine needed to open the file is not installed.
@ UNREACHABLE
Nothing answered at the server address, or it refused the connection.
@ NOT_SUPPORTED_ON_PLATFORM
No backend for the source type exists on this platform.
@ FILE_IN_USE
The database file is locked by another process.
@ FILE_NOT_FOUND
The database file does not exist.
@ NO_DRIVER
The driver named by the data source could not be loaded.
std::function< void()> DB_RESTART_SINK
Told that the rows delivered so far are void, because the read starts the table again from its first ...
The outcome of building a backend; backend is null when failure and error say why.
std::unique_ptr< DATABASE_BACKEND > backend
A column as the backend reports it.
bool supported
False for columns the backend can never read, such as attachments.
bool columnsUnavailable
True when the table exists but the backend could not read its column list, so only SELECT * works.
std::vector< DB_COLUMN > columns
std::string name
The table's name as the backend spells it.
wxLogTrace helper definitions.