pub struct TableInfo {Show 19 fields
pub name: Vec<u8>,
pub folded: Vec<u8>,
pub database: usize,
pub root: u32,
pub columns: Vec<ColumnInfo>,
pub rowid_alias: Option<u16>,
pub without_rowid: bool,
pub strict: bool,
pub autoincrement: bool,
pub kind: TableKind,
pub create_sql: Vec<u8>,
pub indexes: Vec<IndexInfo>,
pub view: Option<Box<ViewBody>>,
pub triggers: Vec<TriggerInfo>,
pub analysed_rows: Option<i64>,
pub foreign_key_triggers: Vec<ForeignKeyTrigger>,
pub foreign_keys: Vec<ForeignKeyInfo>,
pub checks: Vec<CheckInfo>,
pub module: Option<ModuleRef>,
}Expand description
A table, view or virtual table.
Fields§
§name: Vec<u8>The name as declared.
folded: Vec<u8>The ASCII-folded lookup key.
database: usizeWhich attached database it belongs to.
root: u32The root page of the table B-tree, or zero for a view.
columns: Vec<ColumnInfo>The columns, in declaration order.
rowid_alias: Option<u16>The column that is an alias for the rowid, when there is one.
without_rowid: boolWhether the table is WITHOUT ROWID.
strict: boolWhether the table is STRICT.
autoincrement: boolWhether the rowid alias was declared AUTOINCREMENT.
It changes where a new rowid comes from: an ordinary table reuses the
numbers its deleted rows had, and an AUTOINCREMENT one never does,
because it remembers the largest it has ever handed out in
sqlite_sequence.
kind: TableKindWhat kind of object this is.
create_sql: Vec<u8>The CREATE text as stored in sqlite_schema.
indexes: Vec<IndexInfo>The indexes over this table.
view: Option<Box<ViewBody>>The parsed body, when this is a view.
triggers: Vec<TriggerInfo>The triggers attached to this table or view, in schema order.
analysed_rows: Option<i64>How many rows ANALYZE counted, when it has run.
foreign_key_triggers: Vec<ForeignKeyTrigger>The triggers this table’s writes fire because of a foreign key.
Both directions are here, because both are things that happen when this table is written: the checks its own keys need when a row arrives, and the actions the keys pointing at it need when a row leaves. They are built once when the schema is read rather than once per statement, because generating and parsing them is the same work every time and the schema is what decides them.
foreign_keys: Vec<ForeignKeyInfo>Every foreign key declared on this table, in declaration order.
The child’s side of the relationship, which is the side the table
carries. Finding the keys that point at a table means walking the
database’s tables and asking each one, which is what
CatalogView::foreign_keys_referencing does - and is what SQLite does
too, because nothing in the file records the reverse direction.
checks: Vec<CheckInfo>Every CHECK constraint, as the source text it was written as.
The text rather than a bound expression, for the same reason
default_sql is text: the catalog is below the binder, so it cannot
bind anything, and a constraint that had been half-interpreted on the
way through would be a second source of truth beside the CREATE
statement the file actually stores.
module: Option<ModuleRef>The module a virtual table is implemented by, and its arguments.
The catalog records the question and the session fills in the answer: what columns the table has is the module’s to say, not the file’s, so a virtual table arrives here with a module and no columns and leaves the connection’s schema load with both.
Implementations§
Source§impl TableInfo
impl TableInfo
Sourcepub fn column_position(&self, folded: &[u8]) -> Option<u16>
pub fn column_position(&self, folded: &[u8]) -> Option<u16>
Returns the position of a column by its folded name.
Sourcepub fn column(&self, position: u16) -> Option<&ColumnInfo>
pub fn column(&self, position: u16) -> Option<&ColumnInfo>
Returns a column by position.
Sourcepub fn eponymous(
name: Vec<u8>,
columns: Vec<ColumnInfo>,
module: ModuleRef,
without_rowid: bool,
) -> TableInfo
pub fn eponymous( name: Vec<u8>, columns: Vec<ColumnInfo>, module: ModuleRef, without_rowid: bool, ) -> TableInfo
Returns a table that stands for an eponymous module.
A module reached as a name rather than through CREATE VIRTUAL TABLE -
generate_series, json_each, pragma_table_info - belongs to no
database and has no sqlite_schema row, so everything a stored table
carries is absent and only the module’s declaration remains.
@param name - the module’s name, which is also the table’s @param columns - the columns the module declared @param module - the module reference the executor resolves it by @param without_rowid - whether the module declared no rowid
Sourcepub fn subquery(
name: Vec<u8>,
database: usize,
columns: Vec<ColumnInfo>,
) -> TableInfo
pub fn subquery( name: Vec<u8>, database: usize, columns: Vec<ColumnInfo>, ) -> TableInfo
Returns a table that stands for a nested query’s result.
The column list is the block’s result columns: their names are what a reference to the subquery resolves against, and their affinity and collation are the ones the expressions behind them carry, so a comparison against a subquery column applies the same rules it would have applied one level down.
Sourcepub fn record_slot(&self, column: u16) -> Option<usize>
pub fn record_slot(&self, column: u16) -> Option<usize>
Returns the record slot a column’s value lives in, when it has one.
VIRTUAL generated columns take no slot, so the slots of the columns
after them shift down. Every read of a stored column has to go through
this rather than through the column’s declared position, and a VIRTUAL
column has no slot at all - it is computed.
Sourcepub fn primary_key(&self) -> Vec<u16>
pub fn primary_key(&self) -> Vec<u16>
Returns the primary key’s columns, in key order.
Key order, not declaration order: PRIMARY KEY(b, a) is ordered by b
and then a however the columns were declared, and for a WITHOUT ROWID table that order also decides where in the record they sit.
Sourcepub fn record_order(&self) -> Vec<u16>
pub fn record_order(&self) -> Vec<u16>
Returns the columns a record holds, in the order it holds them.
A rowid table stores its columns as declared. A WITHOUT ROWID table’s
B-tree is an index whose key is the primary key, so its record is the
key columns first, in key order, and then everything else as declared -
verified against a file the pinned build wrote: PRIMARY KEY(b, a) over
(a, b, c) stores (b, a, c).
Sourcepub fn is_rowid_name(&self, folded: &[u8]) -> bool
pub fn is_rowid_name(&self, folded: &[u8]) -> bool
Returns whether a name is one of the rowid’s three spellings and is not shadowed by a real column.
SQLite’s rule is exactly this: rowid, _rowid_ and oid name the
rowid unless the table declares a column with that name, in which case
the column wins. A table without a rowid has none of the three.