next up previous contents
Next: Sequences Up: SQL Previous: Queries   Contents

DML

The Ur/Web library also includes an embedding of a fragment of SQL's DML, the Data Manipulation Language, for modifying database tables. Any piece of DML may be executed in a transaction.

\begin{displaymath}\begin{array}{l}
\mathsf{type} \; \mathsf{dml} \\
\mathsf{...
...thsf{dml} \to \mathsf{transaction} \; \mathsf{unit}
\end{array}\end{displaymath}

The function $ \mathsf{Basis.dml}$ will trigger a fatal application error if the command fails, for instance, because a data integrity constraint is violated. An alternate function returns an error message as a string instead.

\begin{displaymath}\begin{array}{l}
\mathsf{val} \; \mathsf{tryDml} : \mathsf{d...
...ransaction} \; (\mathsf{option} \; \mathsf{string})
\end{array}\end{displaymath}

Properly typed records may be used to form $ \mathsf{INSERT}$ commands.

\begin{displaymath}\begin{array}{l}
\mathsf{val} \; \mathsf{insert} : \mathsf{f...
...] \; [] \; []) \; \mathsf{fields}) \to \mathsf{dml}
\end{array}\end{displaymath}

An $ \mathsf{UPDATE}$ command is formed from a choice of which table fields to leave alone and which to change, along with an expression to use to compute the new value of each changed field and a $ \mathsf{WHERE}$ clause. Note that, in the table environment applied to expressions, the table being updated is hardcoded at the name $ \mathsf{T}$ . The parsing extension for $ \mathsf{UPDATE}$ will elaborate all table-free field references to use table variable $ \mathsf{T}$ .

\begin{displaymath}\begin{array}{l}
\mathsf{val} \; \mathsf{update} : \mathsf{u...
...ged}] \; [] \; [] \; \mathsf{bool} \to \mathsf{dml}
\end{array}\end{displaymath}

A $ \mathsf{DELETE}$ command is formed from a table and a $ \mathsf{WHERE}$ clause. The above use of $ \mathsf{T}$ is repeated.

\begin{displaymath}\begin{array}{l}
\mathsf{val} \; \mathsf{delete} : \mathsf{f...
...lds}] \; [] \; [] \; \mathsf{bool} \to \mathsf{dml}
\end{array}\end{displaymath}


next up previous contents
Next: Sequences Up: SQL Previous: Queries   Contents
2014-07-14