Lightweight 0.20261105.1
Loading...
Searching...
No Matches
Catalog.hpp File Reference
#include "../../Api.hpp"
#include "../../SqlBindingTypes.hpp"
#include "../../SqlError.hpp"
#include "../Concept.hpp"
#include "Handles.hpp"
#include "SqlOdbcPrelude.hpp"
#include <expected>
#include <string>
#include <string_view>
#include <sql.h>
#include <sqlext.h>

Go to the source code of this file.

Classes

struct  Lightweight::Driver::Odbc::CatalogObjectName
 The three-part name of a catalog object (a table, or a search pattern for tables), so that the parts are passed by name rather than as adjacent strings that could be swapped silently. More...
 

Functions

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Odbc::OpenTablesCatalog (Statement const &stmt, CatalogObjectName const &tables, bool wideText)
 Opens the SQLTables result set of the tables of tables' catalog and schema, narrowed to its name search pattern. No table type is passed (null pointer, length 0).
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Odbc::OpenColumnsCatalog (Statement const &stmt, CatalogObjectName const &table, bool wideText)
 Opens the SQLColumns result set of every column of table (no column name: null pointer, length 0).
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Odbc::OpenPrimaryKeysCatalog (Statement const &stmt, CatalogObjectName const &table, bool wideText)
 Opens the SQLPrimaryKeys result set of table.
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Odbc::OpenForeignKeysCatalog (Statement const &stmt, CatalogObjectName const &primaryKeyTable, CatalogObjectName const &foreignKeyTable, bool wideText)
 Opens the SQLForeignKeys result set of the foreign keys between the primary-key table and the foreign-key table; an empty table name leaves that side open.
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Odbc::OpenStatisticsCatalog (Statement const &stmt, CatalogObjectName const &table, bool uniqueOnly, bool wideText)
 Opens the SQLStatistics result set of the indexes of table, with SQL_ENSURE.
 
LIGHTWEIGHT_API std::expected< std::string, SqlErrorInfo > Lightweight::Driver::Odbc::SearchPatternEscape (Connection const &connection)
 Reads the driver's SQL_SEARCH_PATTERN_ESCAPE string through the ANSI SQLGetInfo, into a 32-byte buffer.
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Odbc::OpenCatalog (Statement const &stmt, SqlCatalogRequest const &request)
 Opens the catalog result set request names: calls OpenTablesCatalog, OpenColumnsCatalog, OpenPrimaryKeysCatalog, OpenForeignKeysCatalog or OpenStatisticsCatalog with its arguments.
 

Detailed Description

The catalog operations of the ODBC driver: the ODBC catalog functions (SQLTables, SQLColumns, SQLPrimaryKeys, SQLForeignKeys, SQLStatistics) that SqlSchema runs to read a database's schema. Each opens the catalog result set on the statement and leaves it there; the caller reads it by column position, as the ODBC specification lays it out.

Every function is a thin wrapper: the same ODBC call with the same arguments as the code it was moved from, and the return code handed back as Lightweight::SqlResult so that the caller keeps its check at the same point. Text arguments go to the W entry point as UTF-16 when wideText is set, otherwise to the ANSI entry point with the UTF-8 bytes unchanged (see SqlConnection::AcceptsWideQueryText()). An empty text argument is passed as a null pointer with length 0.

Definition in file Catalog.hpp.

Function Documentation

◆ OpenTablesCatalog()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Odbc::OpenTablesCatalog ( Statement const &  stmt,
CatalogObjectName const &  tables,
bool  wideText 
)

Opens the SQLTables result set of the tables of tables' catalog and schema, narrowed to its name search pattern. No table type is passed (null pointer, length 0).

Parameters
stmtThe statement to open the result set on.
tablesThe catalog name, the schema name and the table name search pattern (empty for all tables).
wideTextWhether to call SQLTablesW rather than SQLTables.
Returns
The result of SQLTables.
Note
Reached through the concept's OpenCatalog (see OpenCatalog below), which shared code calls with a Lightweight::Driver::SqlCatalogRequest.

References Lightweight::Driver::Odbc::OpenTablesCatalog().

Referenced by Lightweight::Driver::Odbc::OpenTablesCatalog().

◆ OpenColumnsCatalog()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Odbc::OpenColumnsCatalog ( Statement const &  stmt,
CatalogObjectName const &  table,
bool  wideText 
)

Opens the SQLColumns result set of every column of table (no column name: null pointer, length 0).

Parameters
stmtThe statement to open the result set on.
tableThe catalog name, the schema name and the table name.
wideTextWhether to call SQLColumnsW rather than SQLColumns.
Returns
The result of SQLColumns.
Note
Reached through the concept's OpenCatalog (see OpenCatalog below), which shared code calls with a Lightweight::Driver::SqlCatalogRequest.

References Lightweight::Driver::Odbc::OpenColumnsCatalog().

Referenced by Lightweight::Driver::Odbc::OpenColumnsCatalog().

◆ OpenPrimaryKeysCatalog()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Odbc::OpenPrimaryKeysCatalog ( Statement const &  stmt,
CatalogObjectName const &  table,
bool  wideText 
)

Opens the SQLPrimaryKeys result set of table.

Parameters
stmtThe statement to open the result set on.
tableThe catalog name, the schema name and the table name.
wideTextWhether to call SQLPrimaryKeysW rather than SQLPrimaryKeys.
Returns
The result of SQLPrimaryKeys.
Note
Reached through the concept's OpenCatalog (see OpenCatalog below), which shared code calls with a Lightweight::Driver::SqlCatalogRequest.

References Lightweight::Driver::Odbc::OpenPrimaryKeysCatalog().

Referenced by Lightweight::Driver::Odbc::OpenPrimaryKeysCatalog().

◆ OpenForeignKeysCatalog()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Odbc::OpenForeignKeysCatalog ( Statement const &  stmt,
CatalogObjectName const &  primaryKeyTable,
CatalogObjectName const &  foreignKeyTable,
bool  wideText 
)

Opens the SQLForeignKeys result set of the foreign keys between the primary-key table and the foreign-key table; an empty table name leaves that side open.

Parameters
stmtThe statement to open the result set on.
primaryKeyTableThe catalog name, the schema name and the name (empty for any) of the primary-key table.
foreignKeyTableThe catalog name, the schema name and the name (empty for any) of the foreign-key table.
wideTextWhether to call SQLForeignKeysW rather than SQLForeignKeys.
Returns
The result of SQLForeignKeys.
Note
Reached through the concept's OpenCatalog (see OpenCatalog below), which shared code calls with a Lightweight::Driver::SqlCatalogRequest.

References Lightweight::Driver::Odbc::OpenForeignKeysCatalog().

Referenced by Lightweight::Driver::Odbc::OpenForeignKeysCatalog().

◆ OpenStatisticsCatalog()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Odbc::OpenStatisticsCatalog ( Statement const &  stmt,
CatalogObjectName const &  table,
bool  uniqueOnly,
bool  wideText 
)

Opens the SQLStatistics result set of the indexes of table, with SQL_ENSURE.

Parameters
stmtThe statement to open the result set on.
tableThe catalog name, the schema name and the table name.
uniqueOnlySQL_INDEX_UNIQUE when set, otherwise SQL_INDEX_ALL.
wideTextWhether to call SQLStatisticsW rather than SQLStatistics.
Returns
The result of SQLStatistics.
Note
Reached through the concept's OpenCatalog (see OpenCatalog below), which shared code calls with a Lightweight::Driver::SqlCatalogRequest.

References Lightweight::Driver::Odbc::OpenStatisticsCatalog().

Referenced by Lightweight::Driver::Odbc::OpenStatisticsCatalog().

◆ SearchPatternEscape()

LIGHTWEIGHT_API std::expected< std::string, SqlErrorInfo > Lightweight::Driver::Odbc::SearchPatternEscape ( Connection const &  connection)

Reads the driver's SQL_SEARCH_PATTERN_ESCAPE string through the ANSI SQLGetInfo, into a 32-byte buffer.

Parameters
connectionThe connection to ask.
Returns
The escape string, or an empty string when the driver does not report it; never an error.
Note
Part of the Lightweight::Driver::SqlDriver concept, which every driver implements: it escapes the search patterns of the catalog functions above. A driver without catalog functions (Driver::HasCatalogFunctions is false) answers with the not-supported error: SqlSchema reads its catalog with SQL, and the dialect's SqlCatalogQueries::searchPatternEscape states the escape, see SqlQueryFormatter::CatalogQueries().

◆ OpenCatalog()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Odbc::OpenCatalog ( Statement const &  stmt,
SqlCatalogRequest const &  request 
)

Opens the catalog result set request names: calls OpenTablesCatalog, OpenColumnsCatalog, OpenPrimaryKeysCatalog, OpenForeignKeysCatalog or OpenStatisticsCatalog with its arguments.

Parameters
stmtThe statement to open the result set on.
requestThe catalog function and its arguments; wideText chooses the W entry point.
Returns
The result of the catalog function.
Note
Part of the Lightweight::Driver::SqlDriver concept, which every driver implements: shared code reaches the catalog functions only through it. A driver without catalog functions (Driver::HasCatalogFunctions is false) fails it with the not-supported error; SqlSchema reads that driver's catalog with SQL instead, see SqlQueryFormatter::CatalogQueries().

References Lightweight::Driver::OpenCatalog().