Commit 2902a8b4 authored by MARCHE Claude's avatar MARCHE Claude

sqlite3 db for the manager

parent 671f8248
......@@ -64,8 +64,8 @@ endif
INCLUDES = -I src/core -I src/util -I src/driver -I src/parser -I src/printer \
-I src/transform -I src/programs -I src
BFLAGS = -w Aelz -dtypes -g $(INCLUDES) @INCLUDEGTK2@ -I +threads @OCAMLGRAPHLIB@ str.cma unix.cma $(DYNLINKBFLAGS)
-I src/transform -I src/programs -I src/manager -I src
BFLAGS = -w Aelz -dtypes -g $(INCLUDES) @INCLUDEGTK2@ -I +threads -I +sqlite3 @OCAMLGRAPHLIB@ str.cma unix.cma $(DYNLINKBFLAGS)
# no -warn-error because some do not compile all files (e.g. those linked to APRON)
OFLAGS = -w Aelz -dtypes $(INCLUDES) @INCLUDEGTK2@ -I +threads @OCAMLGRAPHLIB@ str.cmxa unix.cmxa $(DYNLINKOFLAGS)
......@@ -116,6 +116,21 @@ include Version
doc/version.tex src/version.ml: Version version.sh config.status
BINDIR=$(BINDIR) LIBDIR=$(LIBDIR) COQVER=$(COQVER) ./version.sh
src/orm/sql_orm_header.ml: src/orm/sql_access.ml src/orm/convert.ml
ocaml src/orm/convert.ml $< $@
ORM_CMO := printer_utils.cmo sql_orm_header.cmo sql_orm.cmo
ORM_CMO := $(addprefix src/orm/,$(ORM_CMO))
src/manager/db.ml: $(ORM_CMO) src/manager/orm_schema.ml
ocaml -I src/orm src/manager/orm_schema.ml
src/orm/%.cmo: src/orm/%.ml
ocamlc -c -I src/orm -I +sqlite3 $<
src/manager/orm_schema.ml: $(ORM_CMO)
# why
#####
......@@ -163,6 +178,13 @@ bin/why.static: $(CMX) src/why.cmx
bin/top: $(CMO)
ocamlmktop $(BFLAGS) -o $@ nums.cma $^
MANAGER_CMO := db.cmo
MANAGER_CMO := $(addprefix src/manager/,$(MANAGER_CMO))
bin/manager.byte: $(MANAGER_CMO)
$(if $(QUIET),@echo 'Linking $@' &&) $(OCAMLC) $(BFLAGS) \
sqlite3.cma -o $@ $^
# test targets
##############
......@@ -413,7 +435,7 @@ doc/main.html: doc/main.tex doc/version.tex
APIDOCSRC = $(UTIL_CMO:.cmo=.mli) $(CORE_CMO:.cmo=.mli) \
src/driver/call_provers.mli \
src/driver/driver.mli \
manager/db.mli
src/manager/state.mli
.PHONY: apidoc
......
(** {1 Proof manager database} *)
(** {2 proof attempts and transformations} *)
(** status of an external proof attempt *)
type proof_attempt_status =
| Running (** external proof attempt is in progress *)
| Success (** external proof attempt succeeded *)
| Timeout (** external proof attempt was interrupted *)
| Unknown (** external prover answered ``don't know'' or equivalent *)
| HighFailure (** external prover call failed *)
(** a proof attempt by some external provers *)
type external_proof =
{ prover : Driver.driver; (** prover driver *)
timelimit : int; (** CPU limit given in seconds *)
status : proof_attempt_status; (** the current state *)
result_time : float ; (** CPU time for that run *)
trace : string;
(** any kind of trace returned by the prover.
when redoing the same attempt, the former trace is sent again *)
obsolete : bool;
(** when true, goal as changed after that proof attempt *)
}
type transf = Task.task Register.tlist_reg
(** an proof attempt is either an external proof or a transformation
into subtasks *)
type attempt =
| External of external_proof
| Transf of transf
(** {2 proof goals in a proof project} *)
type loc
type explain
type identifier
type goal_origin =
| Goal of Decl.prsymbol
| VCfun of loc * explain * identifier
| Subgoal of goal
and goal =
{
task : Task.task;
task_checksum: string;
origin : goal_origin;
mutable attempts : attempt list;
mutable proved : bool;
(** invariant: g.proved == true iff
exists attempts a in g.attempts, a.obsolete == false and
(a = External e and e.result == Valid or
a = Transf(gl) and forall g in gl, g.proved)
*)
mutable observers: (bool -> unit) list;
(** observers that wants to be notified by any changes of the proved status *)
}
(** {2 database for a proof project} *)
type loc_record_in_db =
{ file : string;
line : int;
cbegin : int;
cend : int;
}
type goal_record_in_db =
{
task_checksum : string;
parent : transf_in_db option;
name : string; (* qualified proposition name *)
origin : loc_record_in_db option;
external_proofs : external_proof_in_db list;
transformations : transf_in_db list;
proved : bool;
}
and external_proof_in_db =
{
prover : string; (** prover identifier *)
timelimit : int; (** CPU limit given in seconds *)
memlimit : int; (** VM limit given in megabytes *)
status : int; (** enum{proof_attempt_status}; the current state *)
result_time : float ; (** CPU time for that run in seconds *)
trace : string option;
(** any kind of trace returned by an automatic prover,
or any kind of proof script for an interactive prover *)
obsolete : bool;
}
and transf_in_db =
{
name : string; (** transformation name *)
obsolete : bool;
}
val read_db_from_file : unit -> goal list
(** returns the set of root goals *)
(** {2 attempts to solve goals} *)
exception AlreadyAttempted
val try_prover :
timelimit:int -> ?memlimit:int -> goal -> Driver.driver -> unit
(** attempts to prove goal with the given prover. This function adds
a new corresponding attempt for that goal, sets its current
status to Running, launches the prover in a separate process and
returns immediately.
Upon termination of the external process, the prover's answer is
retrieved and database is updated. The [proved] field of the
database is updated, and also these of any goal affected, according
to invariant above. Goal observers are notified of any change
of goal statuses.
@param timelimit CPU time limit given for that attempt, must be positive
@raise AlreadyAttempted if there already exists a non-obsolete
external proof attempt with the same driver and time limit, or
with a different time limit and a result different from Timeout
*)
val add_transformation: goal -> transf -> unit
(** adds a transformation on the goal. This function adds a new
corresponding attempt for that goal, computes the subgoals and
and them in the database. In the case where no subgoal is
genereated, the [proved] field is updated, and those of parent
goals.
if this transformation has already been attempted but is markes
as obsolete, it is retried, and the new lists of goals is
carefully matched with the older subgoals, so that if some
subgoals are identical to older ones, then the proof is kept.
Notice that no old proof attempts should be lost in this
process, e.g if the old trans formation produced 3 subgoals
A,B,C, C was proved interactively, and the new transformations
produces only 2 goals, the interactive proof of C is keep in an
extra dummy goal "true"
@raise AlreadyAttempted if this transformation has already been attempted
and is not obsolete
*)
(** TODO: removal of attempts *)
(* {2 goal updates} *)
val add_or_replace_goal: goal -> unit
(** updates the database with the new goal. If a goal with the same
origin already exists, it is checked whether the task to
prove is different or not. If it is the same, proof attempts are
preserved. If not the same, former proof attempts are marked as
obsolete.
IMPORTANT: this kills every running prover tasks
(* autogenerated by sql_orm *)
(** Use the [[Init]] module to open a new database handle. Each object type has its own module with functions to create, modify, save and destroy objects of that type into the SQLite database
*)
(** TODO: full update, removing goals that are not pertinent anymore *)
module Init : sig
type t
type transaction_mode = [`Exclusive |`Deferred |`Immediate ]
(** Database handle which can be used to create and retrieve objects
*)
val t :
?busyfn:(Sqlite3.db -> unit) -> ?mode:transaction_mode ->
string -> t
(** [t db_name] open a Sqlite3 database with filename [db_name] and create any tables if they are missing. @return a database handle which can be used to create and retrieve objects in the database.
@raise Sql_error if a database error is encountered
*)
val db: t -> Sqlite3.db
(** [db handle] @return the underlying Sqlite3 database handle for the connection, for advanced queries.
*)
end
module Challenge : sig
type t = <
id : int64 option;
set_id : int64 option -> unit;
log : int64;
set_log : int64 -> unit;
input : string;
set_input : string -> unit;
answer : string option;
set_answer : string option -> unit;
time : float;
set_time : float -> unit;
correct : int64;
set_correct : int64 -> unit;
save: int64; delete: unit
>
(** An object which can be stored in the database with the [save] method call, or removed by calling [delete]. Fields can be accessed via the approriate named method and set via the [set_] methods. Changes are not committed to the database until [save] is invoked.
*)
val t :
?id:int64 option ->
log:int64 ->
input:string ->
?answer:string option ->
time:float ->
correct:int64 ->
Init.t -> t
(** Can be used to construct a new object. If [id] is not specified, it will be automatically assigned the first time [save] is called on the object. The object is not committed to the database until [save] is invoked. The [save] method will also return the [id] assigned to the object.
@raise Sql_error if a database error is encountered
*)
val get :
?id:int64 option ->
?log:int64 option ->
?input:string option ->
?answer:string option ->
?time:float option ->
?correct:int64 option ->
?custom_where:string * Sqlite3.Data.t list -> Init.t -> t list
(** Used to retrieve objects from the database. If an argument is specified, it is included in the search criteria (all fields are ANDed together).
@raise Sql_error if a database error is encountered
*)
end
module Log_entry : sig
type t = <
id : int64 option;
set_id : int64 option -> unit;
attempt : int64;
set_attempt : int64 -> unit;
successful : int64;
set_successful : int64 -> unit;
starting_date : float;
set_starting_date : float -> unit;
end_date : float;
set_end_date : float -> unit;
challenges : Challenge.t list;
set_challenges : Challenge.t list -> unit;
save: int64; delete: unit
>
(** An object which can be stored in the database with the [save] method call, or removed by calling [delete]. Fields can be accessed via the approriate named method and set via the [set_] methods. Changes are not committed to the database until [save] is invoked.
*)
val t :
?id:int64 option ->
attempt:int64 ->
successful:int64 ->
starting_date:float ->
end_date:float ->
challenges:Challenge.t list ->
Init.t -> t
(** Can be used to construct a new object. If [id] is not specified, it will be automatically assigned the first time [save] is called on the object. The object is not committed to the database until [save] is invoked. The [save] method will also return the [id] assigned to the object.
@raise Sql_error if a database error is encountered
*)
val get :
?id:int64 option ->
?attempt:int64 option ->
?successful:int64 option ->
?starting_date:float option ->
?end_date:float option ->
?custom_where:string * Sqlite3.Data.t list -> Init.t -> t list
(** Used to retrieve objects from the database. If an argument is specified, it is included in the search criteria (all fields are ANDed together).
@raise Sql_error if a database error is encountered
*)
end
module Attempts : sig
type t = <
id : int64 option;
set_id : int64 option -> unit;
solution : int64;
set_solution : int64 -> unit;
log_entries : Log_entry.t list;
set_log_entries : Log_entry.t list -> unit;
save: int64; delete: unit
>
(** An object which can be stored in the database with the [save] method call, or removed by calling [delete]. Fields can be accessed via the approriate named method and set via the [set_] methods. Changes are not committed to the database until [save] is invoked.
*)
val t :
?id:int64 option ->
solution:int64 ->
log_entries:Log_entry.t list ->
Init.t -> t
(** Can be used to construct a new object. If [id] is not specified, it will be automatically assigned the first time [save] is called on the object. The object is not committed to the database until [save] is invoked. The [save] method will also return the [id] assigned to the object.
@raise Sql_error if a database error is encountered
*)
val get :
?id:int64 option ->
?solution:int64 option ->
?custom_where:string * Sqlite3.Data.t list -> Init.t -> t list
(** Used to retrieve objects from the database. If an argument is specified, it is included in the search criteria (all fields are ANDed together).
@raise Sql_error if a database error is encountered
*)
end
module Solution : sig
type t = <
id : int64 option;
set_id : int64 option -> unit;
user : string;
set_user : string -> unit;
problem_id : int64;
set_problem_id : int64 -> unit;
solved : int64;
set_solved : int64 -> unit;
attempts : Attempts.t list;
set_attempts : Attempts.t list -> unit;
save: int64; delete: unit
>
(** An object which can be stored in the database with the [save] method call, or removed by calling [delete]. Fields can be accessed via the approriate named method and set via the [set_] methods. Changes are not committed to the database until [save] is invoked.
*)
val t :
?id:int64 option ->
user:string ->
problem_id:int64 ->
solved:int64 ->
attempts:Attempts.t list ->
Init.t -> t
(** Can be used to construct a new object. If [id] is not specified, it will be automatically assigned the first time [save] is called on the object. The object is not committed to the database until [save] is invoked. The [save] method will also return the [id] assigned to the object.
@raise Sql_error if a database error is encountered
*)
val get :
?id:int64 option ->
?user:string option ->
?problem_id:int64 option ->
?solved:int64 option ->
?custom_where:string * Sqlite3.Data.t list -> Init.t -> t list
(** Used to retrieve objects from the database. If an argument is specified, it is included in the search criteria (all fields are ANDed together).
@raise Sql_error if a database error is encountered
*)
end
module Problems : sig
type t = <
id : int64 option;
set_id : int64 option -> unit;
number : int64;
set_number : int64 -> unit;
short_descr : string;
set_short_descr : string -> unit;
description : string;
set_description : string -> unit;
solved_by : int64;
set_solved_by : int64 -> unit;
save: int64; delete: unit
>
(** An object which can be stored in the database with the [save] method call, or removed by calling [delete]. Fields can be accessed via the approriate named method and set via the [set_] methods. Changes are not committed to the database until [save] is invoked.
*)
val t :
?id:int64 option ->
number:int64 ->
short_descr:string ->
description:string ->
solved_by:int64 ->
Init.t -> t
(** Can be used to construct a new object. If [id] is not specified, it will be automatically assigned the first time [save] is called on the object. The object is not committed to the database until [save] is invoked. The [save] method will also return the [id] assigned to the object.
@raise Sql_error if a database error is encountered
*)
val get :
?id:int64 option ->
?number:int64 option ->
?short_descr:string option ->
?description:string option ->
?solved_by:int64 option ->
?custom_where:string * Sqlite3.Data.t list -> Init.t -> t list
(** Used to retrieve objects from the database. If an argument is specified, it is included in the search criteria (all fields are ANDed together).
@raise Sql_error if a database error is encountered
*)
end
module User : sig
type t = <
id : int64 option;
set_id : int64 option -> unit;
username : string;
set_username : string -> unit;
password : string;
set_password : string -> unit;
email : string;
set_email : string -> unit;
allow_contact : int64;
set_allow_contact : int64 -> unit;
nationality : string option;
set_nationality : string option -> unit;
preferred_language : string option;
set_preferred_language : string option -> unit;
score : int64;
set_score : int64 -> unit;
solutions : Solution.t list;
set_solutions : Solution.t list -> unit;
save: int64; delete: unit
>
(** An object which can be stored in the database with the [save] method call, or removed by calling [delete]. Fields can be accessed via the approriate named method and set via the [set_] methods. Changes are not committed to the database until [save] is invoked.
*)
val t :
?id:int64 option ->
username:string ->
password:string ->
email:string ->
allow_contact:int64 ->
?nationality:string option ->
?preferred_language:string option ->
score:int64 ->
solutions:Solution.t list ->
Init.t -> t
(** Can be used to construct a new object. If [id] is not specified, it will be automatically assigned the first time [save] is called on the object. The object is not committed to the database until [save] is invoked. The [save] method will also return the [id] assigned to the object.
@raise Sql_error if a database error is encountered
*)
val get :
?id:int64 option ->
?username:string option ->
?password:string option ->
?email:string option ->
?allow_contact:int64 option ->
?nationality:string option ->
?preferred_language:string option ->
?score:int64 option ->
?custom_where:string * Sqlite3.Data.t list -> Init.t -> t list
(** Used to retrieve objects from the database. If an argument is specified, it is included in the search criteria (all fields are ANDed together).
@raise Sql_error if a database error is encountered
*)
end
This diff is collapsed.
(* autogenerated by sql_orm *)
(** Use the [[Init]] module to open a new database handle. Each object type has its own module with functions to create, modify, save and destroy objects of that type into the SQLite database
*)
module Init : sig
type t
type transaction_mode = [`Exclusive |`Deferred |`Immediate ]
(** Database handle which can be used to create and retrieve objects
*)
val t :
?busyfn:(Sqlite3.db -> unit) -> ?mode:transaction_mode ->
string -> t
(** [t db_name] open a Sqlite3 database with filename [db_name] and create any tables if they are missing. @return a database handle which can be used to create and retrieve objects in the database.
@raise Sql_error if a database error is encountered
*)
val db: t -> Sqlite3.db
(** [db handle] @return the underlying Sqlite3 database handle for the connection, for advanced queries.
*)
end
module Challenge : sig
type t = <
id : int64 option;
set_id : int64 option -> unit;
log : int64;
set_log : int64 -> unit;
input : string;
set_input : string -> unit;
answer : string option;
set_answer : string option -> unit;
time : float;
set_time : float -> unit;
correct : int64;
set_correct : int64 -> unit;
save: int64; delete: unit
>
(** An object which can be stored in the database with the [save] method call, or removed by calling [delete]. Fields can be accessed via the approriate named method and set via the [set_] methods. Changes are not committed to the database until [save] is invoked.
*)
val t :
?id:int64 option ->
log:int64 ->
input:string ->
?answer:string option ->
time:float ->
correct:int64 ->
Init.t -> t
(** Can be used to construct a new object. If [id] is not specified, it will be automatically assigned the first time [save] is called on the object. The object is not committed to the database until [save] is invoked. The [save] method will also return the [id] assigned to the object.
@raise Sql_error if a database error is encountered
*)
val get :
?id:int64 option ->
?log:int64 option ->
?input:string option ->
?answer:string option ->
?time:float option ->
?correct:int64 option ->
?custom_where:string * Sqlite3.Data.t list -> Init.t -> t list
(** Used to retrieve objects from the database. If an argument is specified, it is included in the search criteria (all fields are ANDed together).
@raise Sql_error if a database error is encountered
*)
end
module Log_entry : sig
type t = <
id : int64 option;
set_id : int64 option -> unit;
attempt : int64;
set_attempt : int64 -> unit;
successful : int64;
set_successful : int64 -> unit;
starting_date : float;
set_starting_date : float -> unit;
end_date : float;
set_end_date : float -> unit;
challenges : Challenge.t list;
set_challenges : Challenge.t list -> unit;
save: int64; delete: unit
>
(** An object which can be stored in the database with the [save] method call, or removed by calling [delete]. Fields can be accessed via the approriate named method and set via the [set_] methods. Changes are not committed to the database until [save] is invoked.
*)
val t :
?id:int64 option ->
attempt:int64 ->
successful:int64 ->
starting_date:float ->
end_date:float ->
challenges:Challenge.t list ->
Init.t -> t
(** Can be used to construct a new object. If [id] is not specified, it will be automatically assigned the first time [save] is called on the object. The object is not committed to the database until [save] is invoked. The [save] method will also return the [id] assigned to the object.
@raise Sql_error if a database error is encountered
*)
val get :
?id:int64 option ->
?attempt:int64 option ->
?successful:int64 option ->
?starting_date:float option ->
?end_date:float option ->
?custom_where:string * Sqlite3.Data.t list -> Init.t -> t list
(** Used to retrieve objects from the database. If an argument is specified, it is included in the search criteria (all fields are ANDed together).
@raise Sql_error if a database error is encountered
*)
end
module Attempts : sig
type t = <
id : int64 option;
set_id : int64 option -> unit;
solution : int64;
set_solution : int64 -> unit;
log_entries : Log_entry.t list;
set_log_entries : Log_entry.t list -> unit;