Skip to main content

TableInfo

Struct TableInfo 

Source
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: usize

Which attached database it belongs to.

§root: u32

The 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: bool

Whether the table is WITHOUT ROWID.

§strict: bool

Whether the table is STRICT.

§autoincrement: bool

Whether 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: TableKind

What 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

Source

pub fn column_position(&self, folded: &[u8]) -> Option<u16>

Returns the position of a column by its folded name.

Source

pub fn column(&self, position: u16) -> Option<&ColumnInfo>

Returns a column by position.

Source

pub fn has_rowid(&self) -> bool

Returns whether the table has a rowid a query may refer to.

Source

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

Source

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.

Source

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.

Source

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.

Source

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).

Source

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.

Trait Implementations§

Source§

impl Clone for TableInfo

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TableInfo

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for TableInfo

Source§

impl PartialEq for TableInfo

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for TableInfo

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.