Skip to main content

Context

Struct Context 

Source
pub struct Context {
    pub limit: usize,
    pub null: String,
    /* private fields */
}
Expand description

Where a command runs: the database, and the limits placed on it.

Fields§

§limit: usize

How many rows a command hands back when it was not told.

§null: String

What to print where a value is null.

Implementations§

Source§

impl Context

Source

pub fn open( path: &str, mode: OpenMode, root: Option<PathBuf>, ) -> Result<Context, Failed>

Opens a context on a database.

@param path - the file, or an in-memory name @param readonly - whether writes are refused @param root - the directory paths are confined to, if any

Source

pub fn open_for( path: &str, mode: OpenMode, root: Option<PathBuf>, may_create: bool, ) -> Result<Context, Failed>

Opens a database for one command, which may or may not make the file.

@param path - the database to open @param mode - whether writes are refused @param root - the directory every file is confined to, when there is one @param may_create - whether this caller is allowed to make the file

Source

pub fn use_database(&mut self, path: &str) -> Result<(), Failed>

Points this context at a different file, reopening only if it moved.

One open database at a time, and that is a decision rather than a simplification. One file is one buffer pool, and a server holding four of them holds four pools whose sizes nobody asked about. A caller that alternates pays a reopen; a caller that does not pays nothing.

@param path - the file to use

Source

pub fn refuse_the_world(&mut self)

Refuses every shell command that reaches outside the database.

Always on over MCP, and there is no flag to turn it off (task-1979, H1). The set is the reference’s -safe: running a program (.shell, .system), loading a shared library (.load), changing the working directory (.cd), handing a file to whatever the system opens it with (.excel, .www), and writing output through a pipe. An MCP server that left it off handed an agent a shell on the host, whatever --root said - and a child spawned that way inherits the server’s standard output, which is the JSON-RPC channel, so its output landed in the middle of a reply and the client could not match one to its id.

A flag was the alternative and was rejected: an operator who forgets it hands an agent a shell, and there is no case for an MCP server with safe mode off.

Source

pub fn recovery(&self) -> Recovery

Returns what opening this context’s database did to it.

See Outcome::with_recovery for what the command surface does with it.

Source

pub fn stray_log_segments(&self) -> &[u64]

Returns the strays this context’s open found. See Context::strays_beside.

Source

pub fn cancel_flag(&self) -> Arc<AtomicBool> ⓘ

Returns a handle to this session’s cancellation flag.

Setting it stops the statement that is running, at the next batch. It is cleared when the next command is armed, so a cancel that arrives between two calls belongs to the one that has finished and is discarded rather than applied to the one that has not started.

Source

pub fn preserve_cancellation(&self)

Says that this surface clears the cancellation flag itself.

Only inillucent-mcp does, because it is the only one that reads its input on a second thread. See budget::arm_as_it_stands.

Source

pub fn shell(&mut self) -> &mut Shell

Returns the shell commands drive.

Source

pub fn path(&self) -> &str

Returns the file this context is open on.

Source

pub fn readonly(&self) -> bool

Returns whether writes are refused.

Source

pub fn cap_rows(&self, asked: usize) -> Result<usize, Failed>

Refuses a row count past this surface’s ceiling, when it has one.

The command line has no ceiling and the MCP server does, which is the whole distinction: a person running inillucent query against their own database and asking for every row is asking for what they want, and an agent doing the same thing to a served database is the case --root and --readonly already exist for. Zero means every row and is refused where a ceiling is set, because “every row” is precisely the request the ceiling is about.

@param asked - the row count the caller wants

Source

pub fn set_max_rows(&mut self, most: Option<usize>)

Sets the ceiling on how many rows one call hands back.

@param most - the ceiling, or None for the command line’s absence of one

Source

pub fn set_limits(&mut self, limits: StatementLimits)

Sets what one command may spend inside the engine.

@param limits - the budget, or Limits::unbounded for a command line

Source

pub fn limits(&self) -> StatementLimits

Returns what one command on this surface may spend inside the engine.

A verb that runs work outside the executor - a migration reads a remote server and writes rows through a second connection - asks so that it can put itself under the same ceiling rather than beside it.

Source

pub fn confined(&self) -> bool

Returns whether this surface was confined to a directory.

Confinement is about reach, not only about paths. --root exists so that an MCP server can be handed to an agent without handing it the file system, and a verb that dialled a host and a port would be a hole straight through it. A command that can reach something other than a file asks this and refuses.

Source

pub fn confine(&self, path: &str) -> Result<PathBuf, Failed>

Refuses a path outside the root, when a root was set.

The decision is not made here. It is made by inillucent_vfs::confine, which resolves the path through the file system rather than reading its text, and which the VFS consults again at the moment the file is opened. This method exists so that a person reading a refusal is told the path they typed and the directory they confined to, neither of which survives as far as the VFS.

The check this replaced compared normalised path text against the root. A junction below the root passed it and opened a database outside the root.

@param path - the path a caller named

Source

pub fn refuse_if_it_writes(&self, sql: &str) -> Result<(), Failed>

Refuses a statement that changes something, when read-only.

By the statement’s class, in one place shared with the driver (task-1979, section 5.2). The check this replaces asked the engine to EXPLAIN the statement and refused only when the message contained “not a read-only statement” - text compile_explain never produces for an INSERT, a write pragma, an ATTACH or a VACUUM INTO, all of which therefore ran and persisted through --readonly. The class comes from the parser’s own classify_statement; the pragma lists are in inillucent_driver::readonly so this and the driver cannot disagree.

This is the layer that gives the caller a good message. The layer that makes the property true is the commit path, which refuses a write on a connection opened read only whatever reached it.

@param sql - the statement

Source

pub fn collect_output(&mut self, input: &str) -> String

Runs shell input, collecting everything it printed.

@param input - the lines, dot commands included

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V