Something went wrong. Try again.
SQLite file format and SQL engine in pure OCaml
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465(*--------------------------------------------------------------------------- Copyright (c) 2026 Thomas Gazagnaire. All rights reserved. SPDX-License-Identifier: ISC ---------------------------------------------------------------------------*)
(** Record transfers.
[INSERT INTO t SELECT * FROM s] copies the records of [s] into [t] whole, and the entries of each index of [s] into the matching index of [t], where the two tables are compatible: sqlite3's transfer optimisation (insert.c, xferOptimization), with its conditions. No column is decoded, and no constraint is checked that the conditions already guarantee. *)
type t = { src : Model.generic_table; (** The table the records come from. *) keep_rowids : bool; (** [true] if each record keeps the rowid it has in the source: the target has an [INTEGER PRIMARY KEY] or an index. Otherwise each takes the target's next rowid, as an [INSERT] naming none does. *) check_rowids : bool; (** [true] if a kept rowid the target already holds is a violation: the target has an [INTEGER PRIMARY KEY]. *) needs_empty : bool; (** [true] if the transfer is only valid into a target that holds no row; one that holds a row takes the ordinary path. *) conflict : Sql.Ast.insert_conflict; (** The resolution a violation takes: [ABORT] or [ROLLBACK] wherever one can occur. *) indexes : (Model.index * Model.index) list; (** Each index of the target with the index of the source its entries are copied from. *)}(** The type for transfers into a table, the target. *)
val pp : t Fmt.t(** [pp] formats a transfer: its source, whether the rowids are kept, the resolution of a violation and the number of indexes copied. *)
val source : Sql.Ast.insert -> string option(** [source i] is the table [s] if [i] is [INSERT INTO t SELECT * FROM s] with no column list, no [WITH], [WHERE], [GROUP BY], [HAVING], [ORDER BY], [LIMIT], compound or [DISTINCT], no upsert and no [RETURNING]; and [None] otherwise. *)
val plan : fk_enforce:bool -> triggers:bool -> conflict:Sql.Ast.insert_conflict -> dst:Model.generic_table -> Model.generic_table -> t option(** [plan ~fk_enforce ~triggers ~conflict ~dst src] is the transfer of the rows of [src] into [dst] under the statement's [conflict] resolution, or [None] if sqlite3 would not transfer them: [dst] has [INSERT] triggers ([triggers]), or foreign keys while [fk_enforce]; the tables are the same, or differ in having a rowid, in their number of columns, in their [INTEGER PRIMARY KEY] or in [STRICT]-ness (a [STRICT] [dst] takes a [STRICT] [src] whose types fit); a column differs in affinity, collating sequence, generated expression or, past the first, [DEFAULT] text, or is [NOT NULL] in [dst] alone; the [CHECK] constraints of [dst] are not those of [src], or read the rowid where the copy renumbers the rows; or an index of [dst] has no index of [src] over the same keys, orders, uniqueness, conflict resolution and [WHERE]. A table whose [CREATE] text does not parse is not transferred. *)