Lightweight 0.20261105.1
Loading...
Searching...
No Matches
Lightweight::SqliteCatalog Namespace Reference

The SQL catalog of SQLite (SqlCatalogQueries), over sqlite_schema and the table-valued pragmas. More...

Variables

constexpr auto DefaultSchema = std::string_view { "main" }
 The schema read when none is named: main, so that a temporary table shadows no table of it.
 
constexpr auto Tables
 
constexpr auto TablesLike
 As Tables, narrowed to the names matching a LIKE pattern (case-insensitive, as SQLite's LIKE is).
 
constexpr auto SchemaNamed
 
constexpr auto SearchPatternEscape = std::string_view { "\\" }
 The escape character of TablesLike's pattern.
 
constexpr auto Columns
 The columns of a table, without generated columns (hidden <> 0).
 
constexpr auto Statistics
 
constexpr auto UniqueStatistics
 As Statistics, unique indexes only.
 
constexpr auto ForeignKeysTo
 
constexpr auto PrimaryKeyColumns
 The columns of a table with their position in its primary key, as PRAGMA table_info lists them.
 
constexpr auto OutgoingForeignKeys
 The foreign keys of a table, as PRAGMA foreign_key_list lists them.
 
constexpr auto Queries
 The whole SQL catalog.
 

Detailed Description

The SQL catalog of SQLite (SqlCatalogQueries), over sqlite_schema and the table-valued pragmas.

Variable Documentation

◆ DefaultSchema

constexpr auto Lightweight::SqliteCatalog::DefaultSchema = std::string_view { "main" }
inlineconstexpr

The schema read when none is named: main, so that a temporary table shadows no table of it.

Definition at line 28 of file SQLiteFormatter.hpp.

◆ Tables

constexpr auto Lightweight::SqliteCatalog::Tables
inlineconstexpr
Initial value:
= std::string_view {
R"(SELECT NULL, NULL, "name", 'TABLE', NULL FROM {0}."sqlite_schema" WHERE "type" = 'table' ORDER BY "rowid")"
}

The tables of the schema's sqlite_schema (its own internal tables included, as the SQLite ODBC driver lists them; views not), in the order they were created.

Definition at line 32 of file SQLiteFormatter.hpp.

◆ TablesLike

constexpr auto Lightweight::SqliteCatalog::TablesLike
inlineconstexpr
Initial value:
=
std::string_view { R"(SELECT NULL, NULL, "name", 'TABLE', NULL FROM {0}."sqlite_schema" WHERE "type" = 'table')"
R"( AND "name" LIKE ? ESCAPE '\' ORDER BY "rowid")" }

As Tables, narrowed to the names matching a LIKE pattern (case-insensitive, as SQLite's LIKE is).

Definition at line 37 of file SQLiteFormatter.hpp.

◆ SchemaNamed

constexpr auto Lightweight::SqliteCatalog::SchemaNamed
inlineconstexpr
Initial value:
=
std::string_view { R"(SELECT "name" FROM pragma_database_list WHERE "name" = ?1 COLLATE NOCASE)"
R"( UNION ALL SELECT 'temp' WHERE ?1 = 'temp' COLLATE NOCASE)"
R"( AND NOT EXISTS (SELECT 1 FROM pragma_database_list WHERE "name" = 'temp'))" }

The schema of a name (case-insensitively) when the connection has one: main, temp or an attached database's.

Definition at line 43 of file SQLiteFormatter.hpp.

◆ SearchPatternEscape

constexpr auto Lightweight::SqliteCatalog::SearchPatternEscape = std::string_view { "\\" }
inlineconstexpr

The escape character of TablesLike's pattern.

Definition at line 49 of file SQLiteFormatter.hpp.

◆ Columns

constexpr auto Lightweight::SqliteCatalog::Columns
inlineconstexpr
Initial value:
= std::string_view {
R"(SELECT "name", "type", "notnull", "dflt_value", "pk" FROM pragma_table_xinfo(?1, ?2) WHERE "hidden" = 0)"
R"( ORDER BY "cid")"
}

The columns of a table, without generated columns (hidden <> 0).

Definition at line 52 of file SQLiteFormatter.hpp.

◆ Statistics

constexpr auto Lightweight::SqliteCatalog::Statistics
inlineconstexpr
Initial value:
= std::string_view {
R"(SELECT NULL, NULL, ?1, NOT "il"."unique", NULL, "il"."name", 3, "ii"."seqno" + 1, "ii"."name",)"
R"( NULL, NULL, NULL, NULL FROM pragma_index_list(?1, ?2) AS "il", pragma_index_info("il"."name", ?2) AS "ii")"
R"( UNION ALL SELECT NULL, NULL, ?1, 0, NULL, 'sqlite_autoindex_0', 3, 1, "ti"."name", NULL, NULL, NULL, NULL)"
R"( FROM pragma_table_info(?1, ?2) AS "ti" WHERE "ti"."pk" = 1)"
R"( AND (SELECT count(*) FROM pragma_table_info(?1, ?2) WHERE "pk" > 0) = 1)"
R"( AND NOT EXISTS (SELECT 1 FROM pragma_index_list(?1, ?2) WHERE "origin" = 'pk'))"
R"( ORDER BY 6, 8)"
}

The columns of every index of a table, in SQLStatistics' layout; an expression's COLUMN_NAME is NULL. A table whose primary key is its rowid (an INTEGER PRIMARY KEY) has no index for it: its key is listed as the unique index sqlite_autoindex_0, the name the SQLite ODBC driver gives it (no user index can have it).

Definition at line 60 of file SQLiteFormatter.hpp.

◆ UniqueStatistics

constexpr auto Lightweight::SqliteCatalog::UniqueStatistics
inlineconstexpr
Initial value:
= std::string_view {
R"(SELECT NULL, NULL, ?1, NOT "il"."unique", NULL, "il"."name", 3, "ii"."seqno" + 1, "ii"."name",)"
R"( NULL, NULL, NULL, NULL FROM pragma_index_list(?1, ?2) AS "il", pragma_index_info("il"."name", ?2) AS "ii")"
R"( WHERE "il"."unique")"
R"( UNION ALL SELECT NULL, NULL, ?1, 0, NULL, 'sqlite_autoindex_0', 3, 1, "ti"."name", NULL, NULL, NULL, NULL)"
R"( FROM pragma_table_info(?1, ?2) AS "ti" WHERE "ti"."pk" = 1)"
R"( AND (SELECT count(*) FROM pragma_table_info(?1, ?2) WHERE "pk" > 0) = 1)"
R"( AND NOT EXISTS (SELECT 1 FROM pragma_index_list(?1, ?2) WHERE "origin" = 'pk'))"
R"( ORDER BY 6, 8)"
}

As Statistics, unique indexes only.

Definition at line 71 of file SQLiteFormatter.hpp.

◆ ForeignKeysTo

constexpr auto Lightweight::SqliteCatalog::ForeignKeysTo
inlineconstexpr
Initial value:
= std::string_view {
R"(SELECT NULL, NULL, "fk"."table",)"
R"( COALESCE("fk"."to", (SELECT "name" FROM pragma_table_info("fk"."table", ?2) WHERE "pk" = "fk"."seq" + 1)),)"
R"( NULL, NULL, "m"."name", "fk"."from", "fk"."seq" + 1,)"
R"( CASE "fk"."on_update" WHEN 'CASCADE' THEN 0 WHEN 'RESTRICT' THEN 1 WHEN 'SET NULL' THEN 2)"
R"( WHEN 'SET DEFAULT' THEN 4 ELSE 3 END,)"
R"( CASE "fk"."on_delete" WHEN 'CASCADE' THEN 0 WHEN 'RESTRICT' THEN 1 WHEN 'SET NULL' THEN 2)"
R"( WHEN 'SET DEFAULT' THEN 4 ELSE 3 END,)"
R"( "fk"."id", NULL, 7)"
R"( FROM {0}."sqlite_schema" AS "m", pragma_foreign_key_list("m"."name", ?2) AS "fk")"
R"( WHERE "m"."type" = 'table' AND "fk"."table" = ?1 COLLATE NOCASE)"
R"( ORDER BY "m"."rowid", "fk"."id", "fk"."seq")"
}

The foreign keys of every table that reference one table, in SQLForeignKeys' layout. A constraint without a column list references the primary key of its table; its UPDATE_RULE and DELETE_RULE are ODBC's codes of the actions (CASCADE 0, RESTRICT 1, SET NULL 2, NO ACTION 3, SET DEFAULT 4), DEFERRABILITY "not deferrable" (7).

Definition at line 85 of file SQLiteFormatter.hpp.

◆ PrimaryKeyColumns

constexpr auto Lightweight::SqliteCatalog::PrimaryKeyColumns
inlineconstexpr
Initial value:
=
std::string_view { R"(SELECT "cid", "name", "type", "notnull", "dflt_value", "pk" FROM pragma_table_info(?1, ?2))" }

The columns of a table with their position in its primary key, as PRAGMA table_info lists them.

Definition at line 100 of file SQLiteFormatter.hpp.

◆ OutgoingForeignKeys

constexpr auto Lightweight::SqliteCatalog::OutgoingForeignKeys
inlineconstexpr
Initial value:
=
std::string_view { R"(SELECT "id", "seq", "table", "from", "to", "on_update", "on_delete", "match")"
R"( FROM pragma_foreign_key_list(?1, ?2))" }

The foreign keys of a table, as PRAGMA foreign_key_list lists them.

Definition at line 104 of file SQLiteFormatter.hpp.

◆ Queries

constexpr auto Lightweight::SqliteCatalog::Queries
inlineconstexpr
Initial value:
= SqlCatalogQueries {
.defaultSchema = DefaultSchema,
.schemaNamed = SchemaNamed,
.tables = Tables,
.tablesLike = TablesLike,
.searchPatternEscape = SearchPatternEscape,
.columns = Columns,
.statistics = Statistics,
.uniqueStatistics = UniqueStatistics,
.foreignKeysTo = ForeignKeysTo,
.primaryKeyColumns = PrimaryKeyColumns,
.outgoingForeignKeys = OutgoingForeignKeys,
}
constexpr auto PrimaryKeyColumns
The columns of a table with their position in its primary key, as PRAGMA table_info lists them.
constexpr auto TablesLike
As Tables, narrowed to the names matching a LIKE pattern (case-insensitive, as SQLite's LIKE is).
constexpr auto UniqueStatistics
As Statistics, unique indexes only.
constexpr auto SearchPatternEscape
The escape character of TablesLike's pattern.
constexpr auto Columns
The columns of a table, without generated columns (hidden <> 0).
constexpr auto DefaultSchema
The schema read when none is named: main, so that a temporary table shadows no table of it.
constexpr auto OutgoingForeignKeys
The foreign keys of a table, as PRAGMA foreign_key_list lists them.

The whole SQL catalog.

Definition at line 109 of file SQLiteFormatter.hpp.