\section{Updates and Procedures}


In this section we briefly consider how bulk updates and
procedures can be integrated into the language,
 
\subsection{Assignment}
 
The semantics of an assignment $l \; := \; r$ assumes that the
left-hand side evaluates to an l-value, and the right-hand side
evaluates to an r-value; the r-value is assigned as the new
value associated with the l-value.
 
Our approach to assignment as a general operation generalizes
the {\em update} statement of SQL.  The general  syntax is $ q_1
:= q_2$.  It can be combined with previous queries in the form $
q.(q_1 := q_2)$.  To understand the issues in using such an
operation, consider\vsmall\\
\hsmall$ (EMP \; where \; SAL > 1800).\\ \hhh (WORKS\_IN \; := \; (DEPT
\; where \; DNAME = "Toy")) $\vtiny\\
The first part of the query terminates with $\{i_1, i_5\}$
on the top of $QRES$. The `.' evaluation starts streams, pushing
the corresponding scopes on $ES$.  Consider the stream for
$i_5$.  
The first argument of the assignment evaluates to an l-value,
i.e., to $i_8$. The second argument evaluates to the identifier
$i_{13}$. The assignment updates the object $<i_8, WORKS\_IN,
i_{17}>$ to $<i_8, WORKS\_IN, i_{13}>$.  Note that it is crucial
here that $WORKS\_IN$ returns a l-value for a $WORKS\_IN$
objects ($i_8$), not its r-value ($i_{17}$).

The example illustrates an issue that needs to be resolved for
bulk updates to be well defined. To avoid semantic ambiguity we
assume that each of parallel streams prepares only an intention
list of updates to be performed, relying on a state before the
updating, common to all parallel streams. When streams are
merged, their lists are merged. During merging inconsistences
can be discovered, e.g. more than one stream attempted to update
the same object.  To take into account a more complex case of
nested updates (i.e.  when the update is of the form $q.p$,
where $q$ is a query and p is an arbitrary updating program) we
must assume the transactional semantics: each parallel stream
can see only own updates, and any inconsistency or conflict
between parallel stream reverts the database to the initial
state.

We can easily do multiple updates in a single stream (`;'
denotes sequencing):
%++++++++++++++++++++++++++++ Example ++++++++++++++++++++
\begin{examp}
$ $\vsmall\\
\hsmall $(EMP \; where \; JOB = "clerk").(SAL :=
SAL+100; \; JOB := "officer" )$
\end{examp}
 
\subsection{Procedures}
 
Since the semantics of procedures is also defined by using a
stack, we can easily incorporate procedures into our framework.
There are, nevertheless, many issues to be considered, e.g.
methods of parameter transmission. For lack of space, we only
illustrate the essential idea. A procedure can introduce local
objects, which are removed when the procedure is terminated.
Parameters are treated similarly. We assume static scoping,
i.e., if $p_1$ calls $p_2$ then local objects of $p_1$ are not
visible from the inside of $p_2$. Local objects can be easily
implemented by storing them as volatile named objects, and
storing the identifiers on a new cell of $ES$.  When the cell
containing an identifier is popped, the object is gone. Output
from functional procedures is pushed onto $QRES$.
 
A procedure declaration has the usual format, with a header that
contains a formal parameter list. A call has the form\vsmall\\
\hsmall{\em $<$procedure name$>$ ($p_1:q_1;...$ )}, \vtiny\\
where $p_i$ is a name of the i'th formal parameter,  and $q_i$
is a query that provides a value for it.  Local objects (i.e.,
variables) are declared by\vsmall\\
\hsmall{\em create local $<$ specification of the object $>$ }
%++++++++++++++++++++++++++++ Example ++++++++++++++++++++
\begin{examp} A functional procedure `poor' has a list of
jobs as a parameter. It returns pointers to names, salaries, and
department names of employees, who do one of the specified jobs
and earn less than the average.\\\\
\h {\bf procedure} $poor( JOBS )$\\
\hh {\bf begin}\\
\hhh $create \; local \; AVERAGE( avg( EMP.SAL ) );$\\
\hhh (* Creating a set of pointer objects pointing poor EMPs  *)\\
\hhh $create \; local \; pointers \; \\ \hhhh POOR($
          $EMP \; where (JOB \in JOBS \wedge SAL < AVERAGE ));$\\
\hhh $return \; POOR.EMP.((N \la NAME)$\\
            \hhhh \hspace*{3.2cm}$\times (S \la SAL)$ \\
            \hhhh \hspace*{3.2cm}$\times (D \la (WORKS\_IN.DNAME)));$\\
\hh {\bf end} $poor$;\\\\
\noi A query that retrieves  names of poor clerks and
programmers from the department $"Sales"$:\vsmall\\
\hsmall $(poor( JOBS: \{"clerk", "programmer"\}) \; where \; (D = 
"Sales")).N$\\\\
Increase salaries of poor programmers from the department
$"Sales"$ by 100:\\\\
\hsmall $(poor( JOBS: "programmer") \; where \; (D = "Sales")).(
S := S+100)$
\end{examp}
%++++++++++++++++++++++++++++ Example ++++++++++++++++++++
\begin{examp} Define a view $MyView( Dname, AvgSal, Mgr(Name,
Sal) )$ containing information about department names, average
salaries, and manager names and salaries for departments located
in Paris.\\\\
\h {\bf procedure} $MyView( )$\\
\hh {\bf begin}\\
\hhh $return (DEPT \; where \; "Paris" \in LOC).($\\
\hhhh $(Dname \la DNAME) \times$ \\
\hhhh $(AvgSal \la avg(EMPLOYS.EMP.SAL)) \times$ \\
\hhhh $(Mgr \la (MANAGER.EMP.$\\
\hhhh \hspace*{1.6cm}$( (Name \la NAME) \times (Sal \la
SAL)))))$\\
\hh {\bf end} $MyView$;\\\\
\noi A query on the view: Give manager name for the department
with the highest average salary:\\\\
\hsmall $(MyView \; where \; AvgSal = max( MyView.AvgSal
)).Mgr.Name$\\\\ 
An update through the view: Increase by 200 the salary of the
manager of the Sales department:\vsmall\\
\hsmall $(MyView \; where \; Dname = "Sales").Mgr.(Sal :=
Sal+200)$
\end{examp}
 
\section{Conclusions}
 
We have presented an approach to query languages based on a
modification of concepts that are well known in programming
languages. It makes possible to build query languages for
variety of data models, including relational and object-oriented
models. The approach supports pragmatic universality,
orthogonality, and precision of specification of semantics. We
have shown that a modified stack-based mechanism can be used to
define and process declarative queries, and that it makes
possible seamless integration of query constructs with
imperative constructs and programming abstractions.

For space limit, we do not discuss many issues relevant to this
approach, in particular, static polymorphic typing, object
orientation, general transitive closures, ordering, processing
of null values and variants, various procedural constructs,
methods of parameter transmission in procedures, optimization,
active rules and event-driven programming. Many of them are
implemented in LOQIS and they will be subjects of subsequent
papers.

 
%**************************************************************
\begin{thebibliography}{99}
 
\bibitem{ACO85} A.~Albano, L.~Cardelli, R.~Orsini.
\newblock Galileo: A Strongly-Typed, Interactive Conceptual
Language.
\newblock ACM Transactions on Database Systems, Vol.10, No 2,
1985, pp.230-260
 
\bibitem{Beer89}C.~Beeri. Formal Models for
Object-Oriented Databases. Proc. 1st DOOD Conf., Kyoto,
pp.370-395, 1989.
 
\bibitem{BrMo92} A.I.~Brown, R.~Morrison.
\newblock A Generic Persistent Object Store. 
\newblock FIDE, ESPRIT BRA Project 3070, Technical Report
Series, FIDE/92/39, 1992

\bibitem{Ingr90} Language Reference Manual for
INGRES/Windows 4GL for the UNIX and VMS Operating Systems.
\newblock  INGRES Release 6, Ingres Corporation, August 1990.
 
\bibitem{KKS92} M.~Kifer, W.~Kim, Y.~Sagiv.
\newblock Querying Object-Oriented Databases.
\newblock Proc. ACM SIGMOD Conf. pp.393-402, 1992.
 
\bibitem{KL89} Kifer, M. and G. Lausen
\newblock F-Logic: A higher-order language for reasoning about
objects, inheritance, and scheme.
\newblock {\it Proc. SIGMOD Conf.}, June 1989, pp. 134--146.
 
\bibitem{MRSS92a} F.~Matthes, A.~Rudloff, J.W.~Schmidt,
K.~Subieta.
\newblock The Database Programming Language DBPL, User and
System Manual.
\newblock FIDE, ESPRIT BRA Project 3070, Technical Report
Series, FIDE/92/47, 1992
 
\bibitem{MBCD89} R.~Morrison, F.~Brown, R.~Connor,
A.~Dearle.
\newblock The Napier88 Reference Manual.
\newblock Universities of St Andrews and Glasgow, Departments of
Comp. Science, Persistent Programming Report 77, July 1989.
 
\bibitem{Moss90} E.J.~Moss.
\newblock Design of the Mneme Persistent Object Store. ACM
Transactions on Information Systems, Vol.8, No.2, April 1990,
pp.103-139

\bibitem{MBW80} J.~Mylopoulos, P.A.~Bernstein,
H.K.T.~Wong.
\newblock A Language Facility for Designing Database-Intensive
Applications.
\newblock ACM Transactions on Database Systems, Vol.5, No 2,
1980, pp.185-207
 
\bibitem{O2Ma92} The O$_2$ User Manual, Version 4.1.
\newblock O$_2$ Technology, Versailles, France, October 1992

\bibitem{OBB89} A.~Ohori, P.~Buneman, V.~Breazu-Tannen.
\newblock Database Programming in Machiavelli - a Polymorphic
Language with Static Type Inference.
\newblock Proc. of ACM SIGMOD 89 Conf., 1989, pp.46-57
 
\bibitem{Schm77} J.W.~Schmidt.
\newblock Some high level language constructs for data of type
relation.
\newblock ACM Transactions on Database Systems, Vol.2, No 3,
1977, pp.247-261
 
\bibitem{ScMa92} J.W.~Schmidt, F~Matthes.
\newblock The Database Programming Language DBPL, Rationale and
Report.
\newblock FIDE, ESPRIT BRA Project 3070, Technical Report
Series, FIDE/92/46, 1992
 
\bibitem{SRH90} M.~Stonebraker, L.A.~Rowe, and M.~Hirohama.
\newblock The Implementation of POSTGRES.
\newblock IEEE Transactions on Knowledge and Data Engineering,
2:1, pp.125-142, 1990.
 
\bibitem{SRLG+90} M.~Stonebraker, L.A.~Rowe,
B.~Lindsay, J.~Gray, M.~Carey,
M.~Brodie, P.~Bernstein, D.~Beech:
\newblock The Committee for Advanced DBMS Function.
\newblock Third-Generation Data Base System Manifesto.
\newblock ACM SIGMOD Record 19(3), pp.31-44, 1990.
 
\bibitem{Subi91} K.~Subieta.
\newblock LOQIS: The Object-Oriented Database Programming System
\newblock Proc.1st Intl. East/West Database Workshop on Next
Generation Information System Technology, Kiew, USSR 1990
\newblock Springer Lecture Notes in Computer Science, Vol.504,
pp.403-421, 1991.  

\bibitem{SBMS93} K.~Subieta, C.~Beeri, F.~Matthes,
J.W.~Schmidt.
\newblock A Stack-Based Approach to Query Languages. Institute
of Computer Science Polish Academy of Sciences, Report 738,
Warszawa, December 1993.
 
\end{thebibliography}
\end{document}

