(** Internal write model operations. *) module Engine = Sql.Private.Engine module Resolve = Sql.Private.Resolve module Query = Sql.Private.Query module Ident = Catalog.Ident module Table = Sql.Private.Table module Conflict = Sql.Private.Conflict val ident_equal : Ident.t -> Ident.t -> bool (** Compares SQL identifiers. *) type row_addr = Store.addr = Rowid of int64 | Row of Sql.Ast.value list module Store_reader : Store.S with type t = Handle.t module Rows : module type of Store.Make (Store_reader) val select_source : Handle.t -> Query.catalog -> Sql.Ast.value array -> Query.binding list -> Sql.Ast.select -> f:(Sql.Ast.value list -> unit) -> unit (** The rows an INSERT ... SELECT draws from its source query, each handed over as the query produces it. The source is run by the SELECT executor, which is built above this layer, so the runner arrives through {!install} once it exists. Nothing can reach a write before then: every door onto a handle is the facade's, and the facade installs it as it opens. *) val install : insert_select_iter: (Handle.t -> Query.catalog -> Sql.Ast.value array -> Query.binding list -> Sql.Ast.select -> f:(Sql.Ast.value list -> unit) -> unit) -> unit (** See {!Write.install}. *) val columns : Model.generic_table -> string list (** A table's column names, in declared order: what a row is aligned to, what an OLD/NEW scope binds by, and what an expression over one row resolves against. Read off the schema of the table the statement has already resolved, so a statement of many rows names its table once. *) val target_table : Handle.t -> string -> Model.generic_table (** The table a write acts on. Tables and views share one namespace, so a name a view holds is taken: answering "no such table" would say it is free, which CREATE TABLE then refuses. sqlite3 refuses while preparing. No INSTEAD OF trigger stands behind a view here, so every write onto one is refused. *) val check_returning : Sql.Private.Query.catalog -> Sql.Ast.value array -> table:string -> Model.generic_table -> Sql.Ast.result_col list -> unit (** {!Sql.Private.Write.check_returning} over the row of [gt]. *) val check_statement : Handle.t -> Sql.Private.Query.catalog -> Sql.Ast.stmt -> where:Sql.Ast.expr option -> returning:Sql.Ast.result_col list -> Sql.Ast.expr list -> unit (** {!Sql.Private.Write.check_statement}, outside a trigger: a trigger's step is prepared again at every firing ({!program}), its names were resolved, with the trigger's row, when the trigger was created, and its calls are met at its first row. *) val check_insert_calls : Handle.t -> Sql.Private.Query.catalog -> Sql.Ast.insert -> unit (** {!Sql.Private.Write.check_insert_calls}, outside a trigger, as above. *) val named_rowid : Model.generic_table -> 'a -> 'a option (** The key a row of [gt] is in scope under while a statement's expressions run over it. A rowid table publishes it, so [rowid] and its aliases resolve in a WHERE, a SET expression and RETURNING as in a scan. A WITHOUT ROWID table publishes none, so the spelling reaches nothing and the resolver refuses the statement. The walk still needs a key for every row it visits; this decides only whether the key is a name the statement may spell. *) val program : Handle.t -> (unit -> ?rowid:'a -> 'b -> 'c) -> ?rowid:'a -> 'b -> 'c (** A program over the rows a statement reaches, lowered as the statement is prepared ({!Engine.row_values}), except in a trigger's step: sqlite3 codes a trigger's program once for the statement that fires it, and the step here is prepared again at every firing, so its program is lowered at the first row it reaches, and a firing that reaches none lowers nothing. *) val triggers : Handle.t -> Sql.Ast.create_trigger list (** The parsed triggers declared by the handle schema. *) val vet_triggers : Handle.t -> event:Sql.Private.Trigger.event -> table:string -> unit (** A statement firing [event] on [table] is refused while it is prepared if a trigger it fires names a column nothing binds: sqlite3 codes each trigger's program as it prepares the statement (sqlite3CodeRowTrigger, trigger.c), so the refusal comes before any row is written, whether or not one is. *) module Trigger_reader : Sql.Private.Trigger.S with type t = Handle.t module Trig : module type of Sql.Private.Trigger.Make (Trigger_reader) module Fk_reader : Sql.Private.Foreign_key.S with type t = Handle.t module Fk : module type of Sql.Private.Foreign_key.Make (Fk_reader) val foreign_key_violations : Fk_reader.t -> string list -> Sql.Private.Foreign_key.violation list (** See {!Write.foreign_key_violations}. *) val seek_where : Handle.t -> Model.generic_table -> frame:Ident.t -> Sql.Ast.expr option -> Sql.Ast.expr option (** The predicate [where] as the seeks below read it within a trigger's firing: a rowid equality against a qualified reference to the enclosing row, [rowid = NEW.id], holds the integer the reference has in this firing, as sqlite3 codes NEW.id as a register of the trigger program and seeks OP_SeekRowid. Only the top-level AND conjuncts are read, as {!Fast_path.equalities} reads them; a reference qualified by the statement's own [frame] is the target's column and stays; any other value stays a reference, since an equality against a column of another affinity is not a seek of its value. The rows found are filtered by [where] itself. *) val seeks_rowid : Handle.t -> Model.generic_table -> Sql.Ast.expr option -> bool (** Whether [seek], a WHERE as {!seek_where} reads it within a trigger's firing, pins the target's rowid to an integer, [rowid = NEW.id]. sqlite3 codes that as an OP_SeekRowid of the trigger program, which it compiles once for the statement that fires it; {!indexed_victims} reads the row as directly, where the select {!selected_rows} runs would be prepared, planned and compiled again at every firing. *) val fires_none : Handle.t -> table:string -> Sql.Private.Trigger.event -> bool (** Whether no trigger on [table] fires for [event]. *) val clears : Handle.t -> string -> bool (** sqlite3 clears a table whole for a DELETE with no WHERE where nothing has to see each row go: no DELETE trigger and no foreign key to count (delete.c, sqlite3DeleteFrom, pWhere == 0 and not bComplex). A one-pass DELETE asks the same of its table. *) val drop_deletes : Fk_reader.t -> string -> bool (** See {!Write.drop_deletes}. *) val drop_delete_runs : Fk_reader.t -> string -> bool (** See {!Write.drop_delete_runs}. *) val foreign_key_plan : Handle.t -> Ident.t -> changed:string list option -> string list (** The [EXPLAIN QUERY PLAN] line of each loop over a child table that the foreign keys referencing [table] run when a row of it is deleted ([changed] is [None]) or an [UPDATE] assigns [changed] (fkey.c, sqlite3FkCheck's loops, in the order of sqlite3FkReferences): one per key, the newest first, and for an [UPDATE] two passes of the keys whose parent columns it assigns. It is [[]] without foreign keys enforced, and refuses a key whose parent columns are no key of [table]. *)