Module Sqml (.ml)


module Sqml: sig .. end
Parsing SQL select and union queries.


Abstract syntax



Abstract Syntax for Queries


type query = query_exp * ordering list 
type query_exp = [ `select of select
| `union of query_exp * query_exp
| `unionall of query_exp * query_exp ]
type select = [ `all | `distinct | `nomod ] * selection * from *
where option * group_by option * having option
type selection = [ `list of exp list | `star ] 
type from = [ `table of string | `tableas of string * string ] list 
type where = condition 
type group_by = column list 
type column = [ `ref of string | `refdotref of string * string ] 
type having = condition 
type condition = [ `cand of condition * condition
| `cnot of condition
| `cor of condition * condition
| `p of predicate ]
type predicate = [ `allorany of exp * comparison * [ `all | `some ] * select
| `between of bool * exp * exp * exp
| `comparisonexp of exp * comparison * exp
| `comparisonselect of exp * comparison * select
| `exists of select
| `in_atom_list of bool * exp * atom list
| `in_select of bool * exp * select
| `iscolnull of bool * column
| `like of bool * exp * atom * atom option ]
type comparison = [ `eq | `gt | `gte | `lt | `lte | `neq ] 
type exp = [ `atom of atom
| `binop of [ `div | `minus | `plus | `times ] * exp * exp
| `column of column
| `functioncall of functioncall
| `uminus of exp ]
type atom = [ `float of int * int * float
| `floattoomuch of string
| `int of int
| `inttoomuch of string
| `parameter of parameter
| `string of string
| `user ]
type functioncall = function_label *
[ `distinct of column | `exp of [ `all | `nomod ] * exp | `star ]
type function_label = [ `avg | `count | `max | `min | `other of string | `sum ] 
type parameter = [ `couple of string * string
| `indicator of string * string
| `single of string ]

Abstract Syntax for Insert


type insert = string * string list *
[ `select of select | `values of [ `atom of atom | `null ] list ]

Abstract Syntax for Schemas


type cmd = [ `manip of manipulative_statement
| `moduledef of moddef
| `privdef of privdef
| `schemadef of schemadef
| `tabledef of tabledef
| `viewdef of viewdef
| `when_not_found of when_action
| `whenever_sqlerror of when_action ]
type schemadef = string * schema_element list 
type schema_element = [ `privdef of privdef
| `tabledef of tabledef
| `viewdef of viewdef ]

Abstract Syntax for create table


type tabledef = string * table_element list 
type table_element = [ `columndef of columndef | `tblcnstr of tblcnstr ] 
type columndef = string * data_type * column_opt list 
type data_type = [ `char of int option
| `decimal of [ `default | `length of int | `lengthdec of int * int ]
| `doubleprecision
| `float of int option
| `int
| `numeric of [ `default | `length of int | `lengthdec of int * int ]
| `real
| `smallint ]
type literal = [ `int of int | `inttoomuch of string | `string of string ] 
type column_opt = [ `check of condition
| `default of literal
| `default_null
| `default_user
| `not_null
| `not_null_primary_key
| `not_null_unique
| `references of string * string list ]
type tblcnstr = [ `check of condition
| `foreignkey of string list * string * string list
| `primkey of string list
| `unique of string list ]

Abstract Syntax for create view


type viewdef = string * string list * select * [ `check | `nocheck ] 

Abstract Syntax for grant


type privdef = privilege * string * grantee list *
[ `grantoption | `nograntoption ]
type privilege = [ `all | `some of operation list ] 
type operation = [ `delete
| `insert
| `references of string list
| `select
| `update of string list ]
type grantee = [ `public | `user of string ] 

Abstract Syntax for modules


type moddef = string option * lang * string * cursor_def list *
procedure_def list
type lang = [ `ada | `c | `cobol | `fortran | `ocaml | `pascal | `pli ] 
type cursor_def = string * query_exp * ordering list 
type ordering = [ `column of column | `numcolumn of int ] * [ `asc | `desc ] option 
type procedure_def = string * parameter_def list * manipulative_statement list 
type parameter_def = [ `par of string * data_type | `sqlcode ] 
type manipulative_statement = [ `close of string
| `commit
| `delete_pos of string * string
| `delete_where of string * condition option
| `fetch of string * parameter list
| `insert of insert
| `opencursor of string
| `rollback
| `select of select * parameter list
| `update_pos of string * assignment list * string
| `update_where of string * assignment list * condition option ]
type assignment = [ `column_exp of string * exp | `column_null of string ] 
type when_action = [ `continue | `goto of string ] 

Parsing


exception Syntax_error = Sqml_sqlstx.Syntax_error
val parse_full_select : Lexing.lexbuf -> Sqml_sqlstx.select * Sqml_sqlstx.ordering list
val parse_query : Lexing.lexbuf -> Sqml_sqlstx.query
val parse_command : Lexing.lexbuf -> Sqml_sqlstx.cmd
val parse_command_list : Lexing.lexbuf -> Sqml_sqlstx.cmd list
val query_of_string : string -> Sqml_sqlstx.query