21#ifndef KICAD_ODBC_BACKEND_H
22#define KICAD_ODBC_BACKEND_H
51 ODBC_BACKEND( std::string aDsn, std::string aUser, std::string aPass, std::string aConnectionString,
62 bool ListTables( std::vector<std::string>& aTables )
override;
64 std::optional<DB_TABLE_INFO>
DescribeTable(
const std::string& aTable )
override;
66 bool ListColumns(
const std::string& aTable, std::vector<std::string>& aColumns )
override;
69 std::vector<std::string>& aLabels,
const DB_ROW_SINK& aSink )
override;
72 std::optional<bool>
ReadRow(
const DB_TABLE_INFO& aTable,
const std::vector<std::string>& aColumns,
73 const std::string& aKeyColumn,
const std::string& aKey,
74 std::vector<std::string>& aLabels, std::vector<DB_VALUE>& aRow )
override;
112 using DSN_LOOKUP = std::function<std::optional<std::string>(
const std::string& )>;
121 static bool NeedsDriverLock(
const std::string& aDsn,
const std::string& aConnectionString,
153 const std::string& aKey );
171 std::string
quoted(
const std::string& aIdentifier )
const;
177 std::string
columnList(
const std::vector<std::string>& aColumns )
const;
179 std::unique_ptr<nanodbc::connection>
m_conn;
204 std::map<std::string, std::map<std::string, COLUMN_INFO>>
m_columnInfo;
A read-only source of tables.
std::function< std::optional< std::string >(const std::string &)> DSN_LOOKUP
Resolves a data source name to its driver, or nullopt if it is unknown.
std::string GetLastError() const override
std::optional< DB_TABLE_INFO > DescribeTable(const std::string &aTable) override
DB_FAILURE GetLastFailure() const override
std::map< std::string, std::map< std::string, COLUMN_INFO > > m_columnInfo
Map of table -> map of column name -> column description.
std::optional< std::chrono::steady_clock::time_point > m_engineDeadline
When the wait for the Access driver lock ends, fixed by the first step that finds the lock busy and n...
static std::vector< std::string > ListDrivers()
void Disconnect() override
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) override
Reads rows of a table, handing each to aSink.
std::string m_patternEscape
bool takeAccessDriverLock(std::unique_lock< std::timed_mutex > &aLock)
Takes the lock that keeps the Access driver from initializing or unloading on two threads at once.
std::string quoted(const std::string &aIdentifier) const
Wraps an identifier in the driver's quote character, doubling any it contains.
static bool IsAccessDriver(const std::string &aDriverName)
static DB_FAILURE ClassifyFailure(const std::string &aState, const std::string &aMessage)
Classifies a driver error from its SQLSTATE, falling back to its text since drivers disagree on state...
static KEY_PARAMETER DescribeKeyParameter(int aColumnType, long aColumnSize, short aColumnScale, const std::string &aKey)
Chooses the parameter description for a lookup key from its column's cached ODBC description.
void disconnectLocked()
Closes the connection with the driver lock held by the caller.
bool ListTables(std::vector< std::string > &aTables) override
Lists the tables and views, sorted by name.
ODBC_BACKEND(std::string aDsn, std::string aUser, std::string aPass, std::string aConnectionString, long aTimeout)
static bool IsAccessFileInUse(const std::string &aLowerMessage)
std::string m_connectionString
bool IsConnected() const override
static bool NeedsDriverLock(const std::string &aDsn, const std::string &aConnectionString, const DSN_LOOKUP &aLookup)
Decides whether connecting must be serialized because the effective driver is, or may be,...
static SELECTOR FirstSelector(const std::string &aConnectionString)
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) override
Runs a prepared query whose key parameter is described with the key column's catalog type.
std::string escapePattern(const std::string &aName) const
Escapes catalog search pattern characters so a name matches only itself.
std::unique_ptr< nanodbc::connection > m_conn
bool ListColumns(const std::string &aTable, std::vector< std::string > &aColumns) override
Lists the column names of a table as the catalog reports them, empty if it has none,...
static std::vector< DATA_SOURCE > ListDataSourceDetails()
std::string columnList(const std::vector< std::string > &aColumns) const
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.
This source file implements export and import capabilities to the specctra dsn file format.
ODBC description of a column, so a lookup key can be bound with the type the driver expects.
short scale
Digits right of the decimal point.
long size
Character length or numeric precision, zero or negative when unknown.
A data source configured in the ODBC driver manager.
How ReadRow describes its key parameter to the driver.
short type
ODBC SQL data type.
int64_t integerValue
The key as a number, set when asInteger is true.
bool asInteger
Bind integerValue as a 64-bit integer instead of the key text.
short scale
Digits right of the decimal point.
unsigned long size
Column size or precision.
The keyword ODBC uses to choose where a connection string connects.
std::string value
The keyword's value without braces.