home *** CD-ROM | disk | FTP | other *** search
/ Programmer's ROM - The Computer Language Library / programmersrom.iso / ada / sql / sqlspc.txt < prev    next >
Encoding:
Text File  |  1988-05-03  |  137.0 KB  |  3,441 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.                               Proposed Binding
  11.  
  12.                         Ada to Database Language SQL
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.                                  March 1986
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.                                 Prepared for
  33.  
  34.                                 WIS JPMO/ADT
  35.                          Washington, D.C. 20330-6600
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.                                  Prepared by
  45.  
  46.                         RACOM Computer Professionals
  47.                              7321 Franklin Road
  48.                              Annandale, VA 22003
  49.                                (703) 560-6799
  50.  
  51.                                      and
  52.  
  53.                        Institute for Defense Analyses
  54.                           1801 N. Beauregard Street
  55.                             Alexandria, VA 22311
  56.                                (703) 824-5515
  57.  
  58. INTRODUCTION
  59.  
  60.      This  document  defines the Ada procedure language access to  the  draft
  61. proposed  American  National Standard (dpANS) "Database  Language  SQL",  ISO 
  62. document  TC97/SC21/WG3-N96 and ANSI document X3H2-86-2,  dated January 1986. 
  63. A  native  language approach is used in defining embedded Ada  SQL  programs,
  64. such  that  standard,  validated Ada compilers may be used to  translate  Ada
  65. programs containing embedded SQL.  This is accomplished by slightly adjusting
  66. SQL  syntax  so that the resulting "Ada/SQL" conforms  to  Ada  syntax.   SQL
  67. operations, as well as database names, are subprogram calls in Ada/SQL.  This
  68. document defines how Ada/SQL syntax differs from the dpANS syntax.
  69.  
  70.      As used herein,  an "implementation" consists of two parts:  (1) a data-
  71. base management system (DBMS) providing the functions required for SQL access
  72. to data, and (2) an interface enabling Ada programs to access data controlled
  73. by the DBMS.
  74.  
  75. INTRODUCTORY DIFFERENCES
  76.  
  77.      The  introductory section of the dpANS applies to this Standard as well,
  78. except as noted below (section numbers are from the dpANS):
  79.  
  80. 1.7(2) - An implementation conforming to this Standard must implement  embed- 
  81. ded  SQL  Ada  ("<embedded SQL Ada program>") and the Ada  schema  definition
  82. language ("<schema>").
  83.  
  84. 1.7(3) - A MIL-STD implementation conforming to this Standard must conform to 
  85. Level 2 of the dpANS.   An ANSI standard implementation may conform to either
  86. Level 1 or Level 2.
  87.  
  88. 1.7(5) - An implementation conforming to this Standard may not allow embedded 
  89. SQL Ada options not specified by this Standard or the dpANS.
  90.                                                                               
  91. CONCEPTS
  92.  
  93.      The  concepts  section  of the dpANS applies to this Standard  as  well,
  94. except as noted below (section numbers are from the dpANS):
  95.  
  96. 2.2(4)  - A non-null value may be of any Ada data type,  other than access or 
  97. task,  i.e.,  the  value of any non-access,  non-task program object  may  be
  98. stored  within a database column.   For the purpose of this  definition,  any 
  99. composite  type  containing  an access or task type component shall  also  be
  100. considered  an  access or task type.   Types which use pointers to  refer  to
  101. external objects,  such as files,  shall likewise be considered to be  access
  102. types.
  103.  
  104. 2.2.2  - This  section  shall apply to all Ada scalar  types  -- enumeration, 
  105. integer, floating point, and fixed point.  The dpANS concept of "exact numer- 
  106. ic value" applies to Ada integer types,  while the dpANS concept of "approxi-
  107. mate  numeric value" corresponds to both Ada floating and fixed point  types.
  108. The interface must cause enumeration types to be stored by the DBMS such that
  109. DBMS and Ada comparison operators return consistent results.   Assignment  is
  110. only  permitted between comparable objects.   The Ada/SQL concept of  compar- 
  111. ability is defined in section 3.9.                                            
  112.  
  113. 2.2.3  - This  is a new section for Ada record and array types.   Record  and 
  114. array objects of the same type are comparable.   SQL operations on array  and
  115. record types are described in sections 4.7(3.6) and 4.7(3.7) of this manual.  
  116.  
  117. 2.3(2)  - See  Ada data definition language (section 4) for  column  descrip- 
  118. tions.
  119.  
  120. 2.5(2)  - The  UNIQUE_ERROR exception will be raised following  an  operation 
  121. violating  a UNIQUE constraint,  and the NULL_ERROR exception will be  raised 
  122. following  an operation violating a NOT NULL constraint.   An  implementation 
  123. may  select  which exception to raise if more than one error occurs within  a 
  124. single operation;  programs relying on any particular exception in this  case 
  125. are erroneous.
  126.  
  127. 2.10.1 Status in Ada/SQL is returned by raising the appropriate exception  on 
  128. error.   The following exceptions are defined,  based on similar error condi- 
  129. tions defined in the dpANS:                                                   
  130.  
  131.      UNIQUE_ERROR    : exception;                                             
  132.      NULL_ERROR      : exception;                                             
  133.      NOT_FOUND_ERROR : exception;                                             
  134.  
  135. Additional exceptions will be defined in a later version of this standard.    
  136.  
  137. 2.11  - This  Standard specifies the actions of Ada/SQL  statements  embedded 
  138. within  legal  Ada programs.   A "legal Ada program"  meets  the  conformance
  139. criteria  of  the Ada Programming Language Military  Standard  (ANSI/MIL-STD-
  140. 1815A), hereafter referred to as the Language Reference Manual (LRM).
  141.  
  142. 2.12(2)  - The  <module>  concept is not relevant to Ada/SQL,  since  SQL  is 
  143. embedded within Ada programs rather than contained within separate <module>s.
  144. A  cursor is created by execution of a <declare cursor>,  and  not  destroyed 
  145. until the program defining it terminates.                                     
  146.  
  147. 2.14(1)  - An  <embedded SQL Ada program> uses exact Ada syntax that  may  be 
  148. compiled by any standard, validated Ada compiler.  The embedded SQL syntax is
  149. adjusted to conform to Ada syntax.
  150.  
  151. 2.15(4) - A <schema> has a single <authorization identifier>.  It may, howev- 
  152. er, be defined within one or more <schema package declaration>s.  Each schema
  153. package  declaration is an Ada package.   The SQL syntax (see 3.4 for  excep- 
  154. tions)                                                                        
  155.  
  156.      <table name> ::= <authorization identifier> . <table identifier>         
  157.  
  158. may be used to select a specific table, but the Ada syntax of
  159.  
  160.      <package name> . <subprogram name>
  161.  
  162. may  also be used,  where <package name> selects the <schema package  declara-
  163. tion> and <subprogram name> selects the table within that package.
  164.  
  165. 2.15(5)  - The applicable <schema package declaration> and corresponding  SQL 
  166. <authorization identifier> are selected according to Ada visibility rules for
  167. table  names without an explicitly stated authorization identifier or package
  168. name prefix.
  169.  
  170. 2.16 - Valid execution of any Ada/SQL data manipulation statement other  than 
  171. <declare cursor> initiates a transaction for the executing program, if one is 
  172. not already in progress.   A transaction in progress upon program termination 
  173. is automatically terminated as if a <rollback statement> had been issued.     
  174.  
  175. COMMON ELEMENTS
  176.  
  177.      The  first  five common elements of the dpANS apply to this Standard  as
  178. well, except as noted below (section numbers are from the dpANS).
  179.  
  180. 3.2 - <literal>s,  since they are compiled by an Ada compiler, must be speci-
  181. fied with Ada syntax (syntactic elements other than <literal> as in LRM):
  182.  
  183.      <literal> ::= numeric_literal     -- integer, floating and fixed point   
  184.                   enumeration_literal -- enumeration                         |
  185.                   string_literal      -- array of character (STRING)         |
  186.                   aggregate           -- record, array                       |
  187.  
  188. 3.3 - Lexical units in Ada/SQL are as in Ada.   Ada reserved words can  obvi-
  189. ously not be used as identifiers (SQL database names),  and Ada/SQL key words 
  190. should  also not be used as program and database variables,  to avoid  confu-
  191. sion.   There are,  however, no specific restrictions beyond those imposed by
  192. Ada.
  193.  
  194. 3.4.SR(1)  - In  most  contexts where an <authorization identifier>  is  used 
  195. within a <table name>,  the <authorization identifier> is separated from  the 
  196. <table  identifier> by a period.   There are,  however,  isolated occurrences 
  197. where the separator character is an underscore (see section 3.20) or a hyphen 
  198. (see sections 4.5a and 6.7).                                                  
  199.  
  200. 3.4.SR(2) - Ada visibility rules determine the <authorization identifier>  of 
  201. an unqualified <table name>.
  202.  
  203. 3.4.SR(7)  - <correlation  name>s must be explicitly declared to  pertain  to 
  204. specific tables,  as described in section 3.20.   The same <correlation name> 
  205. may be reused within different scopes of the same statement, although it must 
  206. refer to (different instances of) the same table.                             
  207.  
  208. 3.4.SR(9) - <module name> is not used for embedded language.
  209.  
  210. 3.4.SR(11) - <procedure name> is not used for embedded language.
  211.  
  212. 3.4.SR(12) - <parameter name> is not used for embedded language.
  213.  
  214. 3.5 Any Ada data type may be declared within a schema,  except for access and
  215. task  types,  and  composite types containing access or  task  subcomponents.
  216. Type  declarations  follow standard Ada syntax.   Expressions  used  in  type
  217. declarations must be static or record discriminants.   Additional description
  218. of data types is provided in Section 4.
  219.  
  220. REMAINING SYNTACTIC/SEMANTIC DIFFERENCES
  221.  
  222. The  Ada/SQL  equivalents of the remaining dpANS syntactic/semantic  sections
  223. are now given.  The following aspects are discussed for each section:
  224.  
  225. FUNCTION  - A  concise description of the function of language  element  dis-
  226. cussed
  227.  
  228. EXAMPLE  - Examples  of use within Ada/SQL programs.   The data  manipulation
  229. examples use the following table:
  230.  
  231.   type ANALYST is
  232.     record
  233.       NAME    : ANALYST_NAME_NOT_NULL_UNIQUE;
  234.       SALARY  : ANALYST_SALARY;
  235.       MANAGER : ANALYST_NAME;
  236.     end record;
  237.  
  238. FORMAT  - BNF and commentary description of the syntactic use of the language
  239. element within Ada/SQL programs
  240.  
  241. 3.6 <value specification>
  242.  
  243. FUNCTION:
  244.  
  245. (1)  Indicate values of embedded variables,  (2) indicate whether or not  the
  246. values are null, (3) implement the keyword USER.
  247.  
  248. EXAMPLE:
  249.  
  250.   NEW_EMPLOYEE_NAME   : ANALYST_NAME;
  251.   NEW_EMPLOYEE_SALARY : ANALYST_SALARY;
  252.   SALARY_KNOWN        : INDICATOR_VARIABLE;
  253.   CURRENT_MANAGER     : MANAGER_NAME;
  254.   CURSOR              : CURSOR_NAME; -- see section 6.1
  255.   . . .
  256.   INSERT_INTO ( ANALYST ( NAME & SALARY & MANAGER ),
  257.         VALUES <= NEW_EMPLOYEE_NAME                           -- 1            
  258.               and INDICATOR(NEW_EMPLOYEE_SALARY,SALARY_KNOWN) -- 2            
  259.               and USER );                                     -- 3
  260.  
  261.   DECLAR ( CURSOR , CURSOR_FOR =>
  262.     SELEC  ( '*',
  263.     FROM  => ANALYST,
  264.     WHERE => EQ ( MANAGER , INDICATOR(CURRENT_MANAGER) ) -- 4                 
  265.     AND      SALARY > 25_000.00 ) );                     -- 5
  266.  
  267. FORMAT:
  268.  
  269. <value specification> ::=
  270.      <variable specification>
  271.     <literal>
  272.     USER
  273.  
  274. <parameter  specification>s  are  not used within Ada/SQL since  an  embedded
  275. language,  rather than a module language, is supported.  The keyword USER may
  276. be specified; it is an Ada function (see example 3).
  277.  
  278. <variable specification> ::=
  279.       <Ada program expression>                                                
  280.      INDICATOR ( <Ada program expression> [ , <indicator variable> ] )       |
  281.  
  282. <Ada program expression> ::= program expression of type appropriate for data- 
  283.      base column being accessed                                               
  284.  
  285. <indicator variable> ::= program variable of type  INDICATOR_VARIABLE,  which
  286.      is an enumeration type with values NULL_VALUE and NOT_NULL
  287.  
  288. Unlike  SQL <embedded variable name>s,  program variables within Ada/SQL  ex- 
  289. pressions are not preceded with colons (see example 1).   Also,  general pro- 
  290. gram  expressions  may be used as <variable specification>s in  Ada/SQL;  SQL 
  291. permits only host variable names.   Where an <indicator variable> is desired, 
  292. it is necessary to have a function in order to combine both the value and the
  293. indicator into a single syntactic element.  This function is called INDICATOR 
  294. (see example 2).   For convenience in certain contexts,  the <indicator vari- 
  295. able>  may be omitted from the call to INDICATOR,  and defaults  to  NOT_NULL 
  296. (see  example 4,  where CURRENT_MANAGER could also have been used by  itself,
  297. without the surrounding call to INDICATOR).                                   
  298.  
  299. <literal> ::= see section 3.2
  300.  
  301. Ada literals are program expressions,  so no special syntax is required  (see 
  302. example 5).
  303.  
  304. 3.7 <column specification>
  305.  
  306. FUNCTION:
  307.  
  308. Indicate values of database columns.                                          
  309.  
  310. EXAMPLE:
  311.  
  312.   package E is new ANALYST_CORRELATION_NAME; -- employees \ see section 3.20  
  313.   package M is new ANALYST_CORRELATION_NAME; -- managers  /                   
  314.  
  315.   CURSOR : CURSOR_NAME; -- see section 6.1
  316.   . . .
  317.                                                                               
  318.   DECLAR ( CURSOR , CURSOR_FOR =>
  319.     SELEC  ( '*',
  320.     FROM  => ANALYST,
  321.     WHERE => SALARY > 25_000.00 ) );                -- 1
  322.  
  323.   DECLAR ( CURSOR , CURSOR_FOR =>
  324.     SELEC  ( '*',
  325.     FROM  => ANALYST,
  326.     WHERE => ANALYST.SALARY > 25_000.00 ) );        -- 2
  327.  
  328.   DECLAR ( CURSOR , CURSOR_FOR =>
  329.     SELEC  ( E.NAME & E.SALARY & M.NAME & M.SALARY, -- 3
  330.      FROM  => E.ANALYST & M.ANALYST, -- see section 3.20                      
  331.      WHERE => EQ ( E.MANAGER , M.NAME )             -- 3
  332.      AND      E.SALARY > M.SALARY ) );              -- 3
  333.  
  334. FORMAT:
  335.  
  336. No syntax changes required.  Example 1 shows a <column specification> without 
  337. a  <qualifier>,  example 2 shows a <table name> used as  a  <qualifier>,  and 
  338. example 3 shows <correlation name>s used as <qualifier>s.                     
  339.  
  340. 3.8 <set function specification>
  341.  
  342. FUNCTION:
  343.  
  344. Compute aggregate functions on database values.
  345.  
  346. EXAMPLE:
  347.  
  348.   NUMBER  : DATABASE.INT; -- see 4.7(3.5.4)                                   
  349.   AVERAGE : ANALYST_SALARY;
  350.   . . .
  351.   SELEC ( COUNT('*'),              -- 1
  352.   FROM => ANALYST );
  353.   INTO(NUMBER);
  354.  
  355.   SELEC ( COUNT_DISTINCT(MANAGER), -- 2
  356.   FROM => ANALYST );
  357.   INTO(NUMBER);
  358.  
  359.   SELEC ( AVG(SALARY),             -- 3
  360.   FROM => ANALYST );
  361.   INTO(AVERAGE);
  362.  
  363.   SELEC ( AVG_ALL(SALARY),         -- 4
  364.   FROM => ANALYST );
  365.   INTO(AVERAGE);
  366.  
  367. FORMAT:
  368.  
  369. <set function specification> ::=
  370.      COUNT ( '*' )  <distinct set function> | <all set function>
  371.  
  372. An  asterisk by itself cannot be used as an argument to an Ada  function,  so
  373. Ada/SQL encloses it in quotes to make it a character literal (see example 1).
  374.  
  375. <distinct set function> ::=
  376.      { AVG_DISTINCT  MAX_DISTINCT | MIN_DISTINCT | SUM_DISTINCT |
  377.           COUNT_DISTINCT } ( <column specification> )
  378.  
  379. <column specification> ::= see section 3.7
  380.  
  381. The DISTINCT cannot stand by itself,  so it is included in the function  name
  382. (see example 2).
  383.  
  384. <all set function> ::=
  385.      { AVG  MAX | MIN | SUM | AVG_ALL | MAX_ALL | MIN_ALL | SUM_ALL }
  386.         ( <value expression> )
  387.  
  388. <value expression> ::= see section 3.9
  389.  
  390. The  ALL can likewise not stand by itself,  and is brought into the  function
  391. name (see examples 3 and 4).
  392.  
  393. The  value returned by a set function,  other than a count set  function,  is 
  394. typed  the same as the <column specification> or <value expression>  argument 
  395. of  the set function.   The value returned by a count set function is of type 
  396. INT defined in the DATABASE package, as described in section 4.7(3.5.4).      
  397.  
  398. 3.9 <value expression>
  399.  
  400. FUNCTION:
  401.  
  402. Specify a (possibly) computed value.
  403.  
  404. EXAMPLE:
  405.  
  406.   NUMBER : DATABASE.INT; -- see section 4.7(3.5.4)                            
  407.   . . .
  408.   SELEC  ( COUNT('*') ,
  409.   FROM  => ANALYST ,
  410.   WHERE => ( SALARY + 1000.00 ) / 2080.0 < + 3.85 );
  411.   INTO(NUMBER);
  412.  
  413. FORMAT:
  414.  
  415. No syntax changes required; Ada/SQL supports all SQL operators with virtually 
  416. the same precedences.  The only difference is that SQL permits monadic "+" or 
  417. "-"  operators before any <primary> used within a  <value  expression>.   The 
  418. corresponding  Ada  unary_adding_operators may be applied only to  an  entire 
  419. simple_expression.   Furthermore,  a leading Ada unary_adding_operator is ap- 
  420. plied  to the entire first term within a simple_expression,  while a  leading 
  421. SQL  monadic operator in a similar <value expression> would be applied to the 
  422. first <factor> within the <term>.  Expressions written in Ada/SQL are  inter- 
  423. preted according to Ada rules.  Due to the nature of the operations, however, 
  424. the  arithmetic  results will be the same as if SQL interpretation  had  been 
  425. applied.   Furthermore, any SQL <value expression> may be equivalently stated 
  426. in  Ada,  using parentheses or depending on the properties of the  arithmetic 
  427. operators, even though the Ada syntax is more restrictive.                    
  428.  
  429. Arithmetic  operators  may be applied only to  scalar  numeric  types.   Both 
  430. arguments must be of comparable types.   In Ada/SQL, two database columns are 
  431. comparable  if they each contain values of the same Ada type,  and a database 
  432. column and a program value are comparable if the Ada program value is of  the 
  433. same type as the values contained within the database column.                 
  434.  
  435. 3.10 <predicate>
  436.  
  437. FUNCTION:
  438.  
  439. Specify  a condition that can be evaluated to give a truth value  of  "true",
  440. "false", or "unknown".
  441.  
  442. EXAMPLE:
  443.  
  444. See discussions on individual predicate types.
  445.  
  446. FORMAT:
  447.  
  448. No syntax changes required; all types of predicate are supported by Ada/SQL.
  449.  
  450. 3.11 <comparison predicate>
  451.  
  452. FUNCTION:
  453.  
  454. Specify a comparison of two values.
  455.  
  456. EXAMPLE:
  457.  
  458.   package E is new ANALYST_CORRELATION_NAME; -- see section 3.20              
  459.  
  460.   CURSOR : CURSOR_NAME; -- see section 6.1
  461.   . . .
  462.                                                                               
  463.   DECLAR ( CURSOR , CURSOR_FOR =>
  464.     SELEC  ( '*',
  465.     FROM  => E.ANALYST, -- see section 3.20                                   
  466.     WHERE => SALARY >                       -- 1
  467.       SELEC  ( AVG(SALARY),
  468.       FROM  => ANALYST,
  469.       WHERE => EQ(MANAGER,E.MANAGER) ) ) ); -- 2
  470.  
  471. FORMAT:
  472.  
  473. <comparison predicate> ::=
  474.      <equality operator> ( <value expression> , <right comparison operand> )
  475.     <value expression> <ordering operator> <right comparison operand>
  476.  
  477. Although  Ada  supports  all the SQL comparison  operators,  restrictions  on
  478. overloading  =  and /= prevent them from being  used  in  Ada/SQL.   Instead,
  479. functions  EQ and NE are defined for these <equality operator>s.   The  other
  480. <ordering  operator>s  are expressed in their natural  notation.   Example  2
  481. shows  an <equality operator> function;  example 1 shows an <ordering  opera-
  482. tor>.   <equality operators> are available for all user-defined types.   <or-
  483. dering operators> are available for all scalar types and for character arrays
  484. with a single integer index (represented in SQL as strings).
  485.  
  486. <equality operator> ::=
  487.      EQ  NE
  488.  
  489. <ordering operator> ::=
  490.      <  > | <= | >=
  491.  
  492. <value expression> ::= see section 3.9
  493.  
  494. <right comparison operand> ::=
  495.      <value expression>  <sub-query>
  496.  
  497. The  right  operand of a comparison predicate may be either a (possibly  com-
  498. puted) value (see example 2) or a <sub-query> (see example 1).
  499.  
  500. <sub-query> ::= see section 3.24
  501.  
  502. 3.12 <between predicate>
  503.  
  504. FUNCTION:
  505.  
  506. Specify a range comparison.
  507.  
  508. EXAMPLE:
  509.  
  510.   CURSOR : CURSOR_NAME; -- see section 6.1
  511.   . . .
  512.   DECLAR ( CURSOR , CURSOR_FOR =>
  513.     SELEC  ( '*',
  514.     FROM  => ANALYST,
  515.     WHERE => BETWEEN(SALARY,20_000.00 AND 30_000.00) ) );
  516.  
  517.              -- variations: NOT BETWEEN
  518.  
  519. FORMAT:
  520.  
  521. <between predicate> ::=
  522.      [ NOT ] BETWEEN ( <value expression> ,
  523.                                   <value expression> AND <value expression> )
  524.  
  525. BETWEEN cannot be written as an infix operator in Ada;  it is instead made  a
  526. function  of two parameters.   The first parameter is the value to be tested,
  527. the second parameter is the range,  with the keyword AND joining the endpoint
  528. <value  expression>s.   No special function is required to implement the  NOT
  529. option, the same overloaded NOT operator used with <search condition>s can be
  530. used  to  negate a BETWEEN test.   The BETWEEN function is only  defined  for
  531. types on which the <ordering operator>s are defined (see section 3.11).
  532.  
  533. <value expression> ::= see section 3.9
  534.  
  535. 3.13 <in predicate>
  536.  
  537. FUNCTION:
  538.  
  539. Specify a quantified comparison.
  540.  
  541. EXAMPLE:
  542.  
  543.   PRIMARY_MANAGER,
  544.   ALTERNATE_MANAGER : MANAGER_NAME;
  545.   CURSOR            : CURSOR_NAME; -- see section 6.1
  546.   . . .
  547.   DECLAR ( CURSOR , CURSOR_FOR =>
  548.     SELEC  ( '*',
  549.     FROM  => ANALYST,
  550.     WHERE => IS_IN ( MANAGER , PRIMARY_MANAGER or ALTERNATE_MANAGER ) ) );
  551.  
  552.   DECLAR ( CURSOR , CURSOR_FOR =>
  553.     SELEC  ( '*',
  554.     FROM  => ANALYST,
  555.     WHERE NOT_IN ( MANAGER ,
  556.       SELEC     ( MANAGER,
  557.       FROM     => ANALYST,
  558.       GROUP_BY => MANAGER,
  559.       HAVING   => AVG(SAL) > 20_000.00 ) ) ) );
  560.  
  561. FORMAT:
  562.  
  563. <in predicate> ::=
  564.    { IS_IN  NOT_IN }
  565.       ( <value expression> , { <sub-query>  <in value list> } )
  566.  
  567. The Ada "in" operator cannot be overloaded,  so IS_IN is used instead of  the
  568. SQL  IN,  and  NOT  IN becomes NOT_IN.   These new operators then  cannot  be
  569. expressed in infix notation, so they become functions of two parameters.  The
  570. first parameter is the <value expression> to be tested for set membership  or
  571. non-membership,  and  the second parameter is the specification of the set to
  572. be tested.   Parentheses are not required around the <in value list>  because
  573. (1) the number of closing parentheses would get cumbersome, since the closing
  574. parenthesis for the function must follow the <in value list> anyway,  and (2)
  575. they  are  not required by Ada syntax,  so the compiler cannot check  whether
  576. they are used or not.
  577.  
  578. <value expression> ::= see section 3.9
  579.  
  580. <sub-query> ::= see section 3.24
  581.  
  582. <in value list> ::=
  583.   <value specification> [ { or <value specification> } ... ]
  584.  
  585. Items in a value list cannot be separated by commas, so "or" is used instead.
  586. This  corresponds  to the semantics that a record is selected if  its  <value
  587. expression> equals the first <value specification> OR the second one, etc.
  588.  
  589. <value specification> ::= see section 3.6
  590.  
  591. 3.14 <like predicate>
  592.  
  593. FUNCTION:
  594.  
  595. Specify a pattern-match comparison.
  596.  
  597. EXAMPLE:
  598.  
  599.   LAST_NAME : ANALYST_NAME;
  600.   CURSOR    : CURSOR_NAME; -- see section 6.1
  601.   . . .
  602.   DECLAR ( CURSOR , CURSOR_FOR =>
  603.     SELEC  ( '*',
  604.     FROM  => ANALYST,
  605.     WHERE => LIKE ( NAME , "%" & LAST_NAME ) ) ); -- variation: NOT LIKE
  606.   . . .                                                                       
  607.   DECLAR ( CURSOR , CURSOR_FOR =>                                             
  608.     SELEC  ( '*',                                                             
  609.     FROM  => ANALYST,                                                         
  610.     WHERE => LIKE ( NAME , "%" & LAST_NAME , ESCAPE => "^" ) ) );             
  611.  
  612. FORMAT:
  613.  
  614. <like predicate> ::=
  615.      [ NOT ] LIKE ( <column specification> , <pattern>                        
  616.                   [ , ESCAPE => <escape character> ] )                        
  617.  
  618. LIKE  cannot  be written as an infix operator in Ada;  it is instead  made  a
  619. function  of three parameters.   The first parameter is the specification  of 
  620. the  column  to  be tested,  the second parameter is an array  of  characters
  621. containing the appropriate pattern matching characters.   No special function
  622. is  required to implement the NOT option,  the same overloaded  NOT  operator
  623. used  with  <search condition>s can be used to negate a LIKE test.   LIKE  is
  624. only defined for arrays of characters with a single integer index (represent-
  625. ed in SQL as strings),  with all parameters of the same type.   To be useful, 
  626. the  component type must include the pattern matching characters,  which  are
  627. '_' and '%'.
  628.  
  629. The third parameter to LIKE is named ESCAPE, to implement the SQL keyword for 
  630. the escape character.   This parameter is optional, and defaults to no escape 
  631. character  specified.   If an escape character is specified,  it must  be  an 
  632. array of length 1, of the same type as the pattern.                           
  633.  
  634. <column specification> ::= see section 3.7
  635.  
  636. <pattern> ::= <value specification>                                           
  637.  
  638. <escape character> ::= <value specification>                                  
  639.  
  640. <value specification> ::= see section 3.6
  641.  
  642. 3.15 <null predicate>
  643.  
  644. FUNCTION:
  645.  
  646. Specify a test for a null value.
  647.  
  648. EXAMPLE:
  649.  
  650.   CURSOR : CURSOR_NAME; -- see section 6.1
  651.   . . .
  652.   DECLAR ( CURSOR , CURSOR_FOR =>
  653.     SELEC  ( '*',
  654.     FROM  => ANALYST,
  655.     WHERE => IS_NULL(MANAGER) ) ); -- variation: IS_NOT_NULL
  656.  
  657. FORMAT:
  658.  
  659. <null predicate> ::=
  660.    { IS_NULL  IS_NOT_NULL } ( <column specification> )
  661.  
  662. IS  NULL and IS NOT NULL cannot be written as postfix operators in Ada,  they
  663. are instead made functions IS_NULL and IS_NOT_NULL.    The functions take  as
  664. their parameter the specification of the column to be tested.
  665.  
  666. <column specification> ::= see section 3.7
  667.  
  668. 3.16 <quantified predicate>
  669.  
  670. FUNCTION:
  671.  
  672. Specify a quantified comparison.
  673.  
  674. EXAMPLE:
  675.  
  676.   package E is new ANALYST_CORRELATION_NAME; -- see section 3.20              
  677.  
  678.   CURSOR : CURSOR_NAME; -- see section 6.1
  679.   . . .
  680.                                                                               
  681.   DECLAR ( CURSOR , CURSOR_FOR =>
  682.     SELEC  ( '*',
  683.     FROM  => E.ANALYST, -- see section 3.20                                   
  684.     WHERE => SALARY >= ALLL (      -- 1
  685.       SELEC  ( SALARY,
  686.       FROM  => ANALYST,
  687.       WHERE => EQ(MANAGER,E.MANAGER) ) ) ) );
  688.  
  689.   DECLAR ( CURSOR , CURSOR_FOR =>
  690.     SELEC  ( '*',
  691.     FROM  => ANALYST,
  692.     WHERE => EQ ( NAME , ANY (     -- 2      variation: SOME
  693.       SELEC  ( MANAGER,
  694.       FROM  => ANALYST ) ) ) ) );
  695.  
  696. FORMAT:
  697.  
  698. <quantified predicate> ::=
  699.      <equality operator> ( <value expression> , <quantified sub-query> )
  700.     <value expression> <ordering operator> <quantified sub-query>
  701.  
  702. The syntax and considerations for <quantified predicate>s are the same as for
  703. <comparison predicate>s (see section 3.11), where <quantified sub-query>s are
  704. used instead of <sub-queries>.
  705.  
  706. <equality operator> ::= see section 3.11
  707.  
  708. <ordering operator> ::= see section 3.11
  709.  
  710. <value expression> ::= see section 3.9
  711.  
  712. <quantified sub-query> ::=
  713.      <quantifier> ( <sub-query> )
  714.  
  715. The  <quantifier> cannot stand by itself in Ada;  it is made into a  function
  716. with the <sub-query> being its parameter.
  717.  
  718. <quantifier> ::=
  719.      <all>  <some>
  720.  
  721. <all> ::= ALLL
  722.  
  723. ALL is an Ada reserved word, ALLL is used instead.
  724.  
  725. <some> ::= SOME  ANY
  726.  
  727. <sub-query> ::= see section 3.24
  728.  
  729. 3.17 <exists predicate>
  730.  
  731. FUNCTION:
  732.  
  733. Specify a test for an empty set.
  734.  
  735. EXAMPLE:
  736.  
  737.   package E is new ANALYST_CORRELATION_NAME; -- see section 3.20              
  738.  
  739.   CURSOR : CURSOR_NAME; -- see section 6.1
  740.   . . .
  741.   DECLAR ( CURSOR , CURSOR_FOR =>
  742.     SELEC  ( '*',
  743.     FROM  => E.ANALYST, -- see section 3.20                                   
  744.     WHERE => EXISTS (
  745.       SELEC  ( '*',
  746.       FROM  => ANALYST,
  747.       WHERE => EQ(MANAGER,E.NAME) ) ) ) );
  748.  
  749. FORMAT:
  750.  
  751. <exists predicate> ::=
  752.      EXISTS ( <sub-query> )
  753.  
  754. EXISTS is an Ada function, with the <sub-query> being its parameter.
  755.  
  756. <sub-query> ::= see section 3.24
  757.  
  758. 3.18 <search condition>
  759.  
  760. FUNCTION:
  761.  
  762. Specify  a condition that is "true",  "false",  or "unknown" depending on the
  763. result of applying boolean operators to specified conditions.
  764.  
  765. EXAMPLE:
  766.  
  767.   PRIMARY_MANAGER,
  768.   ALTERNATE_MANAGER : MANAGER_NAME;
  769.   CURSOR            : CURSOR_NAME; -- see section 6.1
  770.   . . .
  771.   DECLAR ( CURSOR , CURSOR_FOR =>
  772.     SELEC  ( '*',
  773.     FROM  => ANALYST,
  774.     WHERE => NOT BETWEEN ( SALARY , 20_000.00 AND 30_000.00 )
  775.     AND    ( EQ(MANAGER,PRIMARY_MANAGER)
  776.     OR       EQ(MANAGER,ALTERNATE_MANAGER) ) ) );
  777.  
  778. FORMAT:
  779.  
  780. <search condition> ::=
  781.      <boolean factor> [ { AND <boolean factor> } ... ]
  782.     <boolean factor> [ { OR  <boolean factor> } ... ]
  783.  
  784. <boolean factor> ::=
  785.      [ NOT ] <boolean primary>
  786.  
  787. <boolean primary> ::=
  788.      <predicate>  ( <search condition> )
  789.  
  790. <predicate> ::= see section 3.10
  791.  
  792. The Ada AND,  OR, and NOT operators correspond to those of SQL.  However, Ada
  793. requires  that combinations of ANDs and ORs be parenthesized to clearly  show
  794. order  of evaluation,  whereas SQL provides precedence of AND over  OR.   The
  795. extra  parentheses  required  by Ada are permitted by SQL,  so  a  legal  Ada
  796. <search  condition>  will still correspond to a valid SQL one,  and  will  be
  797. interpreted in a consistent fashion.
  798.  
  799. 3.19 <table expression>
  800.  
  801. FUNCTION:
  802.  
  803. Specify a table or a grouped table.
  804.  
  805. EXAMPLE:
  806.  
  807. Examples in other sections include use of <table expression>s.
  808.  
  809. FORMAT:
  810.  
  811. <table expression> ::=
  812.      <from clause>
  813.    [ , <where clause> ]
  814.    [ , <group by clause> ]
  815.    [ , <having clause> ]
  816.  
  817. The  various SQL clauses are parameters to Ada/SQL subprograms.   Each clause 
  818. is therefore separated from the one before it with a comma.   The syntax  for
  819. the  <from  clause> does not show the preceding comma because <table  expres-
  820. sion> is preceded with a comma wherever it is used in the grammar.
  821.  
  822. <from clause> ::= see section 3.20
  823.  
  824. <where clause> ::= see section 3.21
  825.  
  826. <group by clause> ::= see section 3.22
  827.  
  828. <having clause> ::= see section 3.23
  829.  
  830. 3.20 <from clause>
  831.  
  832. FUNCTION:
  833.  
  834. Specify a table derived from one or more named tables.
  835.  
  836. EXAMPLE:
  837.  
  838. Examples in other sections include use of <from clause>s.
  839.  
  840. FORMAT:
  841.  
  842. <from clause> ::=
  843.      FROM => <table reference> [ { & <table reference> } ... ]
  844.  
  845. The <table reference>s cannot be separated from each other by commas in  Ada,
  846. so ampersands are used instead.  Since the <from clause> is actually a param-
  847. eter  to  a function,  the named parameter association symbol => follows  the
  848. keyword FROM.
  849.  
  850. <table reference> ::=
  851.      [ <correlation name> . ] <table name>                                    
  852.  
  853. In Ada/SQL,  <correlation name>s are actually Ada packages.  The <correlation 
  854. name>,  if  used,  must therefore precede the <table name>,  with the  <table 
  855. name> being a function selected from the <correlation name> package.   Appro- 
  856. priate  functions  are also generated so that the <table name> may be  refer- 
  857. enced without the optional <correlation name>.                                
  858.  
  859. <table  name>  ::= the name of a database table,  defined  as  an  overloaded
  860.      function  within the database-specific portion of the underlying Ada/SQL
  861.      definitions
  862.  
  863. <correlation name> ::= a package instantiated from the generic package speci- 
  864.      fic to each <table name>.   The generic packages are produced by the SQL 
  865.      function generator.  In order to define a <correlation name>, the appro- 
  866.      priate generic package must be instantiated, in one of the two following 
  867.      ways:                                                                    
  868.  
  869.           package <correlation name> is new                                   
  870.             <table identifier>_CORRELATION_NAME;                              
  871.  
  872.           package <correlation name> is new                                   
  873.             <authorization identifier>_<table identifier>_CORRELATION_NAME;   
  874.  
  875.      Note   that  the  generic  packages  are,   in  general,   named  <table 
  876.      name>_CORRELATION_NAME,  except that an <authorization identifier>  used 
  877.      within  a  <table name> is separated from the <table identifier>  by  an 
  878.      underscore instead of a period as in SQL.  This is an exception; Ada/SQL 
  879.      syntax  for  <table  name>s is identical to that of  SQL,  except  where 
  880.      otherwise noted.                                                         
  881.  
  882.      Although  <correlation  name>s are specifically declared to  pertain  to 
  883.      specific tables,  the same <correlation name> may be reused within  dif- 
  884.      ferent scopes of the same statement,  to refer to different instances of 
  885.      the same table.                                                          
  886.  
  887.      See section 3.7 for an example of using <correlation name>s.
  888.  
  889. 3.21 <where clause>
  890.  
  891. FUNCTION:
  892.  
  893. Specify  a  table derived by the application of a <search condition>  to  the
  894. result of the preceding <from clause>.
  895.  
  896. EXAMPLE:
  897.  
  898. Examples in other sections include use of <where clause>s.
  899.  
  900. FORMAT:
  901.  
  902. <where clause> ::=
  903.      WHERE => <search condition>
  904.  
  905. Since  the  <where clause> is actually a parameter to a function,  the  named
  906. parameter association symbol => follows the keyword WHERE.
  907.  
  908. <search condition> ::= see section 3.18
  909.  
  910. 3.22 <group by clause>
  911.  
  912. FUNCTION:
  913.  
  914. Specify  a grouped table derived by the application of the <group by  clause>
  915. to the result of the previously specified clause.
  916.  
  917. EXAMPLE:
  918.  
  919. See section 3.13 for an example using a <group by clause>
  920.  
  921. FORMAT:
  922.  
  923. <group by clause> ::=
  924.      GROUP_BY => <column specification> [ { & <column specification> } ... ]
  925.  
  926. Since the <group by clause> is actually a parameter to a function,  the named
  927. parameter association symbol => follows the keyword GROUP_BY,  which requires
  928. the underscore to make it a single lexical symbol to Ada.  <column specifica-
  929. tion>s cannot be separated by commas; ampersands are used instead.
  930.  
  931. <column specification> ::= see section 3.7
  932.  
  933. 3.23 <having clause>
  934.  
  935. FUNCTION:
  936.  
  937. Specify a grouped table derived by the application of the <having clause>  to
  938. the result of the previously specified clause.
  939.  
  940. EXAMPLE:
  941.  
  942. See section 3.13 for an example using a <having clause>
  943.  
  944. FORMAT:
  945.  
  946. <having clause> ::=
  947.      HAVING => <search condition>
  948.  
  949. Since  the <having clause> is actually a parameter to a function,  the  named
  950. parameter association symbol => follows the keyword HAVING.
  951.  
  952. <search condition> ::= see section 3.18
  953.  
  954. 3.24 <sub-query>
  955.  
  956. FUNCTION:
  957.  
  958. Specify  a  multi-set of values derived from the result of a  <table  expres-
  959. sion>.
  960.  
  961. EXAMPLE:
  962.  
  963. Examples in other sections include use of <sub-query>s.
  964.  
  965. FORMAT:
  966.  
  967. <sub-query> ::=
  968.    [ SELEC  SELECT_ALL | SELECT_DISTINCT ]
  969.        ( <sub-query result specification> , <table expression> )
  970.  
  971. SELECT  used  as  a <sub-query> is an Ada function.   It is not  possible  to
  972. specify  the  ALL or DISTINCT keywords separately,  so they are part  of  the
  973. function name if used.   The name of the function is SELEC if neither keyword
  974. is  used,  since SELECT is an Ada reserved word.   The <sub-query>  functions
  975. have five parameters which must,  of course, be surrounded by parentheses and
  976. separated by commas.  Any or all of the last three parameters may be omitted,
  977. since  named  associations  are used for them and they  have  default  values
  978. indicating  their  omission.   The first parameter is the  <sub-query  result
  979. specification>,  while  the  second through fifth parameters  are  the  FROM,
  980. WHERE,  GROUP BY,  and HAVING clauses from the <table expression>, and so are
  981. named FROM,  WHERE,  GROUP_BY, and HAVING, respectively.  Parentheses are not
  982. required around the <sub-query> because (1) the number of closing parentheses
  983. would get cumbersome,  since the function call itself also provides a closing
  984. parenthesis,  (2)  a  <sub-query> is often an argument to a  function,  which
  985. causes it to be surrounded by parentheses anyway, and (3) parentheses are not
  986. required by Ada syntax, so the compiler cannot check whether they are used or
  987. not.
  988.  
  989. <sub-query result specification> ::=
  990.      <value expression>
  991.     '*'
  992.  
  993. An  asterisk cannot stand alone by itself as an argument to an Ada  function,
  994. so it is enclosed in quotes to make it a character literal.
  995.  
  996. <value expression> ::= see section 3.9
  997.  
  998. <table expression> ::= see section 3.19
  999.  
  1000. 3.25 <query specification>
  1001.  
  1002. FUNCTION:
  1003.  
  1004. Specify a table derived from the result of a <table expression>.
  1005.  
  1006. EXAMPLE:
  1007.  
  1008. Examples in other sections include use of <query specification>s.
  1009.  
  1010. FORMAT:
  1011.  
  1012. <query specification> ::=
  1013.    [ SELEC  SELECT_ALL | SELECT_DISTINCT ]
  1014.        ( <select list> , <table expression> )
  1015.  
  1016. The syntax and interpretation of a <query specification> is the same as for a
  1017. <sub-query>,  except that a <sub-query> retrieves only one column of  values,
  1018. while a <query specification> may retrieve more than one column.
  1019.  
  1020. <select list> ::=
  1021.      <value expression> [ { & <value expression> } ... ]
  1022.     '*'
  1023.  
  1024. The <value expression>s cannot be separated by commas, so ampersands are used
  1025. instead.  <value expression>s containing Ada binary_adding_operators may have 
  1026. to  be  enclosed  in parentheses to enforce the correct precedence  of  their 
  1027. operators over the Ada/SQL ampersand connectives.   An asterisk cannot  stand 
  1028. alone  by  itself  as an argument to an Ada function,  so it is  enclosed  in
  1029. quotes to make it a character literal.
  1030.  
  1031. <value expression> ::= see section 3.9
  1032.  
  1033. <table expression> ::= see section 3.19
  1034.  
  1035. 4.1 <schema>
  1036.  
  1037. FUNCTION:
  1038.  
  1039. Ada/SQL schemas perform three functions: (1) Provide the Ada type definitions
  1040. necessary for programs to declare variables to hold database values, (2) form
  1041. input  to a schema translator that converts Ada/SQL schemas into SQL  schemas
  1042. for creating database structures, and (3) form input to a SQL function gener-
  1043. ator that produces the functions and type definitions necessary to use schema
  1044. database names within the Ada/SQL data manipulation language.  The interrela- 
  1045. tion  and automation of these functions provides program consistency checking
  1046. within  Ada/SQL.   Ada/SQL schemas also contain sufficient information to  be
  1047. used  as input to a test data generator to produce test data  for  populating
  1048. databases defined by them.
  1049.  
  1050. EXAMPLE:
  1051.  
  1052. - -- This package defines the ADMINISTRATION authorization identifier.
  1053. - -- Authorization packages are used for two purposes:
  1054. - -- (1) The authorization function defined (ADMINISTRATION in this example) is
  1055. - --      referenced from a schema package to indicate the schema authorization
  1056. - --      identifier, e.g., a schema package including the definition
  1057. - --        SCHEMA_AUTHORIZATION : IDENTIFIER := ADMINISTRATION;
  1058. - --      where ADMINISTRATION is the function defined herein, will be
  1059. - --      considered part of the ADMINISTRATION schema.                         
  1060. - -- (2) Other schemas reference the authorization function to grant privileges
  1061. - --      to that authorization identifier.  The ADMINISTRATION function is
  1062. - --      called in the body of COMPANYDB_TABLES_SCHEMA (below) for this
  1063. - --      purpose.
  1064. - -- Note how the ADMINISTRATION authorization package is independent of any
  1065. - --  ADMINISTRATION schema that might be defined.  This is done by design to
  1066. - --  minimize the number of recompilations required by changes to schemas.
  1067. - --  Suppose, for example, that there were an ADMINISTRATION schema.  If the
  1068. - --  schema is changed, must any other schemas granting privileges to
  1069. - --  ADMINISTRATION be recompiled?  No, because they "with" only the
  1070. - --  ADMINISTRATION authorization package, not any of the schema packages.
  1071. - --  (Packages referencing tables within the ADMINISTRATION schema may, of
  1072. - --  course, require recompilation.)
  1073. - -- AUTHORIZATION_IDENTIFIER is a generic function defined within
  1074. - --  SCHEMA_DEFINITION.  IDENTIFIER is a type defined within SCHEMA_-
  1075. - --  DEFINITION.
  1076. - -- The SCHEMA_DEFINITION package also includes the functions and procedures
  1077. - --  necessary to define views and grant privileges.
  1078.  
  1079. with SCHEMA_DEFINITION;
  1080.   use SCHEMA_DEFINITION;
  1081.  
  1082. package ADMINISTRATION_AUTHORIZATION is
  1083.  
  1084.   function ADMINISTRATION is new AUTHORIZATION_IDENTIFIER;
  1085.  
  1086. end ADMINISTRATION_AUTHORIZATION;
  1087. - -----------------------------------------------------------------------------
  1088. - -- This is the authorization package for the PERSONNEL authorization
  1089. - --  identifier.
  1090.  
  1091. with SCHEMA_DEFINITION;
  1092.   use SCHEMA_DEFINITION;
  1093.  
  1094. package PERSONNEL_AUTHORIZATION is
  1095.  
  1096.   function PERSONNEL is new AUTHORIZATION_IDENTIFIER;
  1097.  
  1098. end PERSONNEL_AUTHORIZATION;
  1099. - -----------------------------------------------------------------------------
  1100. - -- This is the authorization package for the COMPANYDB authorization
  1101. - --  identifier.
  1102. - -- The COMPANYDB schema is the only schema shown in this example.
  1103.  
  1104. with SCHEMA_DEFINITION;
  1105.   use SCHEMA_DEFINITION;
  1106.  
  1107. package COMPANYDB_AUTHORIZATION is
  1108.  
  1109.   function COMPANYDB is new AUTHORIZATION_IDENTIFIER;
  1110.  
  1111. end COMPANYDB_AUTHORIZATION;
  1112. - -----------------------------------------------------------------------------
  1113. - -- This package defines the data types used within the COMPANYDB schema.  As
  1114. - --  can be seen, data types need not be defined within actual schema pack-
  1115. - --  ages.  The ability to "with" definitions from other packages permits all
  1116. - --  the Ada flexibilities of program organization.  Also, it is logical to
  1117. - --  define types separately from schemas in those instances where some pro-
  1118. - --  grams handle data of those types without accessing a database.  Such pro-
  1119. - --  grams may then "with" only the type definitions, and not the database
  1120. - --  definitions.
  1121.  
  1122. package COMPANYDB_TYPES is
  1123.  
  1124.   type EMPLOYEE_NAME is new STRING(1..15);
  1125.   subtype EMPLOYEE_NAME_NOT_NULL_UNIQUE is EMPLOYEE_NAME;
  1126.  
  1127.   type EMPLOYEE_AGE is range 14..100;
  1128.     -- many other type definitions would also use SQL NUMERIC(3,0)
  1129.  
  1130.   type EMPLOYEE_SAL is delta 0.01 range 0.00..999_999.99;
  1131.     -- many other type definitions would also use SQL DECIMAL(8,2)
  1132.  
  1133.   type DEPT_NAME is new STRING(1..10);
  1134.   subtype DEPT_NAME_NOT_NULL_UNIQUE is DEPT_NAME;
  1135.  
  1136.   type DEPT_LOC is new STRING(1..2);
  1137.   -- an enumeration type might also be used
  1138.  
  1139. end COMPANYDB_TYPES;
  1140. - -----------------------------------------------------------------------------
  1141. - -- This is the classification package for the COMPANYDB_TABLES schema
  1142. - --  package.
  1143. - -- For the MIL-STD, every schema package must have a corresponding
  1144. - --  classification package.  This is not required for the ANSI standard.  A
  1145. - --  classification package defines the security classification of all columns
  1146. - --  in each table defined by the corresponding schema package.
  1147. - -- The CLASSIFICATION_DEFINITION package defines a type CLASSIFICATION, which
  1148. - --  may be adjusted to suit specific environments.  Although not specified
  1149. - --  for our simple example, it might be an enumeration type such as
  1150. - --    type CLASSIFICATION is (UNCLASSIFIED,CONFIDENTIAL,SECRET,TOP_SECRET);
  1151. - --  In more complex environments, CLASSIFICATION might be a record type, with
  1152. - --   components indicating releasability, special handling, and sensitive
  1153. - --   source caveats as well as the standard four levels shown above.
  1154. - -- SECURITY_CLASSIFICATION is a generic function defined in
  1155. - --  CLASSIFICATION_DEFINITION, which is instantiated for the most restrictive
  1156. - --  classification in the package being declared.  The instantiated function
  1157. - --  (COMPANYDB_TABLES in this case) is called from a schema package to
  1158. - --  indicate which classification package applies to it.  Thus,
  1159. - --  COMPANYDB_TABLES_SCHEMA contains the declaration
  1160. - --    SECURITY : CLASSIFICATION := COMPANYDB_TABLES;
  1161. - --  By design, the instantiated function returns the classification with
  1162. - --  which it was instantiated, so that a program referencing
  1163. - --  COMPANYDB_TABLES_SCHEMA.SECURITY can determine the most restrictive
  1164. - --  classification applying to the data.
  1165. - -- A classification package defines record types paralleling those defining
  1166. - --  tables in the corresponding schema -- the records have the same structure
  1167. - --  and component names, but components are of type CLASSIFICATION in a
  1168. - --  classification package.  Default values for the components are used to
  1169. - --  indicate classifications of the columns.  The classification record types
  1170. - --  are all limited private to indicate that classifications may not be
  1171. - --  arbitrarily adjusted by application programs.
  1172. - -- It is by design that classification records parallel database records.  A
  1173. - --  system could store an associated classification record with each data
  1174. - --  record stored, thereby marking each data value with a classification.
  1175. - --  This is not required by the present standard, which assumes that marking
  1176. - --  is at the column level; future standards may include syntax for marking
  1177. - --  individual data values by setting classification records.
  1178.  
  1179. with CLASSIFICATION_DEFINITION;
  1180.   use CLASSIFICATION_DEFINITION;
  1181.  
  1182. package COMPANYDB_TABLES_CLASSIFICATION is
  1183.  
  1184.   function COMPANYDB_TABLES is new SECURITY_CLASSIFICATION(UNCLASSIFIED);
  1185.  
  1186.   type EMPLOYEE is limited private;
  1187.  
  1188.   type DEPT is limited private;
  1189.  
  1190. private
  1191.  
  1192.   type EMPLOYEE is
  1193.     record
  1194.       NAME : CLASSIFICATION := UNCLASSIFIED;
  1195.       AGE  : CLASSIFICATION := UNCLASSIFIED;
  1196.       SAL  : CLASSIFICATION := UNCLASSIFIED;
  1197.       DEPT : CLASSIFICATION := UNCLASSIFIED;
  1198.     end record;
  1199.  
  1200.   type DEPT is
  1201.     record
  1202.       NAME : CLASSIFICATION := UNCLASSIFIED;
  1203.       LOC  : CLASSIFICATION := UNCLASSIFIED;
  1204.     end record;
  1205.  
  1206. end COMPANYDB_TABLES_CLASSIFICATION;
  1207. - -----------------------------------------------------------------------------
  1208. - -- This is one of the two schema packages comprising the COMPANYDB schema.
  1209. - -- The two packages together define the single SQL schema given the COMPANYDB
  1210. - --  authorization identifier.
  1211. - -- By design, several schema packages can be used to define a single SQL
  1212. - --  schema.  This minimizes recompilation in that a change to one schema
  1213. - --  package may not affect the other schema packages for the same schema.
  1214. - --  Programs referencing the schema do not require recompilation unless they
  1215. - --  are dependent on the modified schema package.
  1216. - -- Record type declarations in schema packages also declare database tables.
  1217. - --  The record type name is used for the table name, component names are used
  1218. - --  for the column names, and the component data types define the column data
  1219. - --  types.
  1220. - -- Note the specifications of the schema authorization identifier and securi-
  1221. - --  ty classification definition, as discussed in comments on other packages.
  1222.  
  1223. with SCHEMA_DEFINITION, COMPANYDB_AUTHORIZATION, COMPANYDB_TYPES,
  1224.  CLASSIFICATION_DEFINITION, COMPANYDB_TABLES_CLASSIFICATION;
  1225.   use SCHEMA_DEFINITION, COMPANYDB_AUTHORIZATION, COMPANYDB_TYPES,
  1226.    CLASSIFICATION_DEFINITION, COMPANYDB_TABLES_CLASSIFICATION;
  1227.  
  1228. package COMPANYDB_TABLES_SCHEMA is
  1229.  
  1230.   SCHEMA_AUTHORIZATION : IDENTIFIER := COMPANYDB;
  1231.  
  1232.   SECURITY : CLASSIFICATION := COMPANYDB_TABLES;
  1233.  
  1234.   type EMPLOYEE is
  1235.     record
  1236.       NAME : EMPLOYEE_NAME_NOT_NULL_UNIQUE;
  1237.       AGE  : EMPLOYEE_AGE;
  1238.       SAL  : EMPLOYEE_SAL;
  1239.       DEPT : DEPT_NAME;
  1240.     end record;
  1241.  
  1242.   type DEPT is
  1243.     record
  1244.       NAME : DEPT_NAME_NOT_NULL_UNIQUE;
  1245.       LOC  : DEPT_LOC;
  1246.     end record;
  1247.  
  1248. end COMPANYDB_TABLES_SCHEMA;
  1249. - -----------------------------------------------------------------------------
  1250. - -- This is the body of the first COMPANYDB schema package.
  1251. - -- Views, privileges, and uniqueness constraints may be defined in package    
  1252. - --  bodies.
  1253. - -- This is done by design, to minimize the number of recompilations required
  1254. - --  when adjusting privileges or uniqueness constraints, or changing a view   
  1255. - --  definition without affecting the names or types of the columns returned.
  1256. - -- Any of these changes requires that only the affected package body be       
  1257. - --  recompiled; it is not necessary to recompile the package specification.
  1258. - --  Therefore, no other recompilations are required.
  1259. - -- COMPANYDB_TABLES is the package created by the SQL function generator from
  1260. - --  the package specification of COMPANYDB_TABLES_SCHEMA.  The required
  1261. - --  processing order for a schema package is therefore:
  1262. - --  (1) Compile the specification
  1263. - --  (2) Run the SQL function generator on the specification
  1264. - --  (3) Compile the body (one is required only if views and/or privileges are
  1265. - --       defined, or if it is desired to define uniqueness constraints there) 
  1266. - --  (4) Run the schema translator after all specifications and bodies in a
  1267. - --       schema have been compiled
  1268. - --  Source files must be compiled before being given to the Ada/SQL automated
  1269. - --  tools.
  1270. - -- Functions for database names are generated in COMPANYDB_TABLES.  The DEPT  
  1271. - --  and EMPLOYEE functions referenced here are among them.
  1272. - -- A schema package must have a name of the form X_SCHEMA, so that the pack-
  1273. - --  age generated by the SQL function generator may be named X.  This is the
  1274. - --  only package naming restriction imposed by Ada/SQL.  Schema packages are
  1275. - --  related to authorization and classification packages by calling the
  1276. - --  functions defined in those packages, not by package naming convention.
  1277. - --  It is, however, suggested that the example conventions of using
  1278. - --  X_AUTHORIZATION and X_CLASSIFICATION as package names be continued.
  1279.  
  1280. with SCHEMA_DEFINITION, ADMINISTRATION_AUTHORIZATION,
  1281.  PERSONNEL_AUTHORIZATION, COMPANYDB_TABLES;
  1282.   use SCHEMA_DEFINITION, ADMINISTRATION_AUTHORIZATION,
  1283.    PERSONNEL_AUTHORIZATION, COMPANYDB_TABLES;
  1284.  
  1285. package body COMPANYDB_TABLES_SCHEMA is
  1286. begin
  1287.  
  1288.   GRANT ( SELEC, ON => DEPT,     TO => PUBLIC);
  1289.   GRANT ( ALLL,  ON => DEPT,     TO => ADMINSTRATION);
  1290.   GRANT ( ALLL,  ON => EMPLOYEE, TO => PERSONNEL);
  1291.  
  1292. end COMPANYDB_TABLES_SCHEMA;
  1293. - -----------------------------------------------------------------------------
  1294. - -- This is the classification package for the second COMPANYDB schema
  1295. - --  package.
  1296. - -- This particular schema was segmented into a package for the base tables
  1297. - --  and a package for the views.  This is not a requirement; as many base
  1298. - --  tables and views as desired may be defined within the same schema
  1299. - --  package.
  1300.  
  1301. with CLASSIFICATION_DEFINITION;
  1302.   use CLASSIFICATION_DEFINITION;
  1303.  
  1304. package COMPANYDB_VIEWS_CLASSIFICATION is
  1305.  
  1306.   function COMPANYDB_VIEWS is new SECURITY_CLASSIFICATION(UNCLASSIFIED);
  1307.  
  1308.   type EMPVIEW is limited private;
  1309.  
  1310. private
  1311.  
  1312.   type EMPVIEW is
  1313.     record
  1314.       EMP  : CLASSIFICATION := UNCLASSIFIED;
  1315.       DEPT : CLASSIFICATION := UNCLASSIFIED;
  1316.     end record;
  1317.  
  1318. end COMPANYDB_VIEWS_CLASSIFICATION;
  1319. - -----------------------------------------------------------------------------
  1320. - -- This is the second schema package
  1321. - -- Record type definitions are required for views as well as for base tables.
  1322. - --  Views, however, are also defined in the bodies of schema packages.
  1323.  
  1324. with SCHEMA_DEFINITION, COMPANYDB_AUTHORIZATION, COMPANYDB_TYPES,
  1325.  CLASSIFICATION_DEFINITION, COMPANYDB_VIEWS_CLASSIFICATION;
  1326.   use SCHEMA_DEFINITION, COMPANYDB_AUTHORIZATION, COMPANYDB_TYPES,
  1327.    CLASSIFICATION_DEFINITION, COMPANYDB_VIEWS_CLASSIFICATION;
  1328.  
  1329. package COMPANYDB_VIEWS_SCHEMA is
  1330.  
  1331.   SCHEMA_AUTHORIZATION : IDENTIFIER := COMPANYDB;
  1332.  
  1333.   SECURITY : CLASSIFICATION := COMPANYDB_VIEWS;
  1334.  
  1335.   type EMPVIEW is
  1336.     record
  1337.       EMP  : EMPLOYEE_NAME;
  1338.       DEPT : DEPT_NAME;
  1339.     end record;
  1340.  
  1341. end COMPANYDB_VIEWS_SCHEMA;
  1342. - -----------------------------------------------------------------------------
  1343. - -- The body of the second COMPANYDB schema package with view and privilege
  1344. - --  definitions
  1345. - -- COMPANYDB_TABLES is, as discussed before, generated from
  1346. - --  COMPANYDB_TABLES_SCHEMA
  1347. - -- Likewise, COMPANYDB_VIEWS is generated from the specification of this
  1348. - --  package
  1349. - -- Table and column names defined in COMPANYDB_TABLES and referenced here are
  1350. - --  EMPLOYEE, NAME, and DEPT
  1351. - -- Table and column names defined in COMPANYDB_VIEWS and referenced here are
  1352. - --  EMPVIEW, EMP, and DEPT
  1353. - -- Note that DEPT is defined in both packages, and will produce homographs.
  1354. - -- DEPT is not a homograph when used to define the name of an EMPVIEW column,
  1355. - --  since only COMPANYDB_VIEWS.DEPT can be used as such.  Using the appro-    
  1356. - --  priate definitions, Ada/SQL causes the Ada compiler to require that       
  1357. - --  column names used in a view definition in a package body must have been   
  1358. - --  declared as view columns in the corresponding package specification.      
  1359. - -- DEPT is, however, a homograph when used as an element in a SELEC list,
  1360. - --  since both EMPVIEW.DEPT (defined in COMPANYDB_VIEWS) and EMPLOYEE.DEPT
  1361. - --  (defined in COMPANYDB_TABLES) are valid column names.  Consequently, it
  1362. - --  must be qualified when used as such.  This is a hazard of splitting a
  1363. - --  single schema into several portions -- homographs will arise if the same
  1364. - --  name is defined in more than one schema package.  We have used the SQL-
  1365. - --  style qualification -- EMPLOYEE.DEPT actually selects the component named
  1366. - --  DEPT from the record returned by the function EMPLOYEE defined in
  1367. - --  COMPANYDB_TABLES.  This is a different overloaded version of the EMPLOYEE
  1368. - --  table than is called on the next line.  An Ada-style qualification could
  1369. - --  have also been used -- COMPANYDB_TABLES.DEPT would select the DEPT column
  1370. - --  function from the COMPANYDB_TABLES package.
  1371. - -- Duplicate column names within the same schema package do not cause
  1372. - --  homographs -- only one column function (actually a set of overloaded
  1373. - --  functions) is defined.  Due to the implementation of strong typing,
  1374. - --  however, the use of an unqualified column name in the same expression as
  1375. - --  a literal, universal, or overloaded value may cause an unresolvable
  1376. - --  ambiguity if there exist columns of different types having that same
  1377. - --  name.  The ambiguity can be resolved by qualifying the column name with
  1378. - --  the appropriate table name.  In this example, NAME is such a potentially
  1379. - --  ambiguous column name.  Its use in the SELEC list is, however, not
  1380. - --  ambiguous.  (We are here talking about ambiguity to the Ada compiler.
  1381. - --  Qualification with the table name may be required only to remove the Ada
  1382. - --  ambiguity; the unqualified column name may be unambiguous to SQL.)
  1383.  
  1384. with SCHEMA_DEFINITION, COMPANYDB_TABLES, COMPANYDB_VIEWS;
  1385.   use SCHEMA_DEFINITION, COMPANYDB_TABLES, COMPANYDB_VIEWS;
  1386.  
  1387. package body COMPANYDB_VIEWS_SCHEMA is
  1388. begin
  1389.  
  1390.   CREATE_VIEW ( EMPVIEW ( EMP  & DEPT ),                                      
  1391.           AS => SELEC   ( NAME & EMPLOYEE.DEPT,
  1392.                 FROM   => EMPLOYEE ) );
  1393.  
  1394.   GRANT ( SELEC, ON => EMPVIEW, TO => PUBLIC);
  1395.  
  1396. end COMPANYDB_VIEWS_SCHEMA;
  1397.  
  1398. Note:  This  example  demonstrates  a  possible  Ada/SQL  definition  of  the
  1399. illustrative  database  used  within the paper "Proposed Language  Access  to
  1400. Draft Proposed American National Standard Database Language SQL",  ANSC  X3H2
  1401. (Database), March 1985, which is defined in SQL as:
  1402.  
  1403. SCHEMA
  1404. AUTHORIZATION COMPANYDB
  1405. TABLE EMPLOYEE
  1406.   (NAME  CHARACTER(15)  NOT NULL UNIQUE,
  1407.    AGE   NUMERIC(3,0),
  1408.    SAL   DECIMAL(8,2),
  1409.    DEPT  CHARACTER(10))
  1410. TABLE DEPT
  1411.   (NAME  CHARACTER(10)  NOT NULL UNIQUE,
  1412.    LOC   CHARACTER (2))
  1413. VIEW EMPVIEW (EMP, DEPT)
  1414.    AS SELECT  NAME, DEPT   FROM  EMPLOYEE
  1415. GRANT SELECT  ON  DEPT  TO  PUBLIC
  1416. GRANT SELECT  ON  EMPVIEW  TO  PUBLIC
  1417. GRANT ALL  ON  DEPT  TO  ADMINISTRATION
  1418. GRANT ALL  ON  EMPLOYEE  TO  PERSONNEL
  1419.  
  1420. FORMAT:
  1421.  
  1422. <schema> ::= <compilation unit> ...
  1423.  
  1424. Several  Ada  compilation units,  all packages,  combine together to  form  a
  1425. schema.   Building a single schema out of several packages adheres to the Ada
  1426. modular program philosophy,  and allows parts of schemas to be modified with-
  1427. out necessarily requiring recompilation of all programs using the schema.
  1428.  
  1429. <compilation unit> ::=
  1430.      <context clause> <library unit>  <context clause> <secondary unit>
  1431.  
  1432. <context clause> ::= as in Ada, except that only packages may be named
  1433.  
  1434. The  packages  comprising  a schema can "with" and "use"  other  packages  as
  1435. required for visibility.
  1436.  
  1437. <library unit> ::=
  1438.      <authorization package declaration>
  1439.     <classification package declaration>
  1440.     <schema package declaration>
  1441.  
  1442. <secondary unit> ::= <library unit body>
  1443.  
  1444. <library unit body> ::= <schema package body>
  1445.  
  1446. Four types of compilation units are used within schemas:
  1447.  
  1448. (1) Authorization packages declare authorization identifiers,
  1449.  
  1450. (2) Classification packages declare the classification of all columns defined
  1451. within the corresponding schema package declaration,
  1452.  
  1453. (3) Schema packages declare database tables and columns, and
  1454.  
  1455. (4) The bodies of schema packages declare views,  grant privileges,  and  may 
  1456. set uniqueness constraints.                                                   
  1457.  
  1458. <authorization package declaration> ::= see section 4.1a
  1459.  
  1460. <classification package declaration> ::= see section 4.6a
  1461.  
  1462. <schema package declaration> ::= see section 4.1b
  1463.  
  1464. <schema package body> ::= see section 4.5
  1465.  
  1466. 4.1a <schema> - <authorization package declaration>
  1467.  
  1468. FUNCTION:
  1469.  
  1470. Each  authorization  package declares a different  authorization  identifier.
  1471. This  authorization identifier may be used as a schema authorization  identi-
  1472. fier and/or as a target identifier for granting privileges.
  1473.  
  1474. EXAMPLE:
  1475.  
  1476. with SCHEMA_DEFINITION;
  1477.   use SCHEMA_DEFINITION;
  1478.  
  1479. package ADMINISTRATION_AUTHORIZATION is
  1480.  
  1481.   function ADMINISTRATION is new AUTHORIZATION_IDENTIFIER;
  1482.  
  1483. end ADMINISTRATION_AUTHORIZATION;
  1484.  
  1485. FORMAT:
  1486.  
  1487. <authorization package declaration> ::=
  1488.      <authorization package specification> ;
  1489.  
  1490. <authorization package specification> ::=
  1491.      package <identifier> is
  1492.        function <authorization identifier> is new AUTHORIZATION_IDENTIFIER;
  1493.      end [ <package simple name> ]
  1494.  
  1495. <identifier> ::= any valid name for a library package
  1496.  
  1497. <authorization  identifier> ::= the identifier that will be used for granting
  1498.      privileges and/or as a schema authorization identifier
  1499.  
  1500. <package simple name> ::= must match the package <identifier> if used
  1501.  
  1502. To define the generic function AUTHORIZATION_IDENTIFIER,  the context  clause
  1503. of an authorization package must read:
  1504.  
  1505.   with SCHEMA_DEFINITION; use SCHEMA_DEFINITION;
  1506.  
  1507. The  sole function of an authorization package is to define an  authorization
  1508. identifier.  Authorization packages do not have bodies.
  1509.  
  1510. 4.1b <schema> - <schema package declaration>
  1511.  
  1512. FUNCTION:
  1513.  
  1514. Schema  package  declarations  define  the table and column  names  within  a
  1515. schema.
  1516.  
  1517. EXAMPLE:
  1518.  
  1519. with SCHEMA_DEFINITION, COMPANYDB_AUTHORIZATION, COMPANYDB_TYPES,
  1520.  CLASSIFICATION_DEFINITION, COMPANYDB_VIEWS_CLASSIFICATION;
  1521.   use SCHEMA_DEFINITION, COMPANYDB_AUTHORIZATION, COMPANYDB_TYPES,
  1522.    CLASSIFICATION_DEFINITION, COMPANYDB_VIEWS_CLASSIFICATION;
  1523.  
  1524. package COMPANYDB_VIEWS_SCHEMA is
  1525.  
  1526.   SCHEMA_AUTHORIZATION : IDENTIFIER := COMPANYDB;
  1527.  
  1528.   SECURITY : CLASSIFICATION := COMPANYDB_VIEWS;
  1529.  
  1530.   type EMPVIEW is
  1531.     record
  1532.       EMP  : EMPLOYEE_NAME;
  1533.       DEPT : DEPT_NAME;
  1534.     end record;
  1535.  
  1536. end COMPANYDB_VIEWS_SCHEMA;
  1537.  
  1538. FORMAT:
  1539.  
  1540. <schema package declaration> ::= <schema package specification> ;
  1541.  
  1542. <schema package specification> ::=
  1543.      package <identifier> is
  1544.        <schema authorization clause>
  1545.      [ <schema classification clause> ]
  1546.      [ <schema declaration element> ... ]
  1547.      end [ <package simple name> ]
  1548.  
  1549. A <schema classification clause> is only required by the MIL-STD,  not by the
  1550. ANSI standard.   If all tables declared within the schema package are  views,
  1551. then  a  <schema  classification clause> is optional.   In the absence  of  a
  1552. classification  specification for a view,  the classification of each  column
  1553. defaults to the most restrictive classification on the data used to material-
  1554. ize that column.
  1555.  
  1556. <identifier> ::= a valid name for a library package, that must be of the form
  1557.      X_SCHEMA to permit the package generated from this one to be named X  by
  1558.      the SQL function generator
  1559.  
  1560. <package simple name> ::= must match the package <identifier> if used
  1561.  
  1562. <schema authorization clause> ::=
  1563.      SCHEMA_AUTHORIZATION : [ SCHEMA_DEFINITION . ] IDENTIFIER
  1564.           := <schema authorization identifier> ;
  1565.  
  1566. <schema authorization identifier> ::= <authorization identifier>
  1567.  
  1568. <authorization identifier> ::= as defined within an authorization package (see
  1569.      section 4.1a)
  1570.  
  1571. The  SQL <schema authorization identifier> for the schema is taken to be  the
  1572. <authorization identifier> used here.   The appropriate authorization package
  1573. must,  of course, be named within the context clause of the schema package in
  1574. order  to  make the instantiated function for the <authorization  identifier>
  1575. visible.   The  full  name of the <authorization identifier> may be  used  if
  1576. visibility  is  desired by selection;  only the simple name is  used  as  the
  1577. <authorization identifier>.   SCHEMA_DEFINITION must also be named within the
  1578. context clause to make the type IDENTIFIER visible.  As indicated, IDENTIFIER
  1579. may  be  visible either directly or by selection.   The  same  <authorization
  1580. identifier>  may be referenced from several schema packages;  the tables  de-
  1581. clared in those packages are all placed in the same SQL schema.
  1582.  
  1583. <schema classification clause> ::=
  1584.      SECURITY : [ CLASSIFICATION_DEFINITION . ] CLASSIFICATION
  1585.           := <classification identifier> ;
  1586.  
  1587. <classification  identifier>  ::= as defined within a classification  package
  1588.      (see section 4.6a)
  1589.  
  1590. The appropriate classification package must,  of course,  be named within the
  1591. context clause of the schema package in order to make the instantiated  func-
  1592. tion  for  the  <classification identifier> visible.   The full name  of  the
  1593. <classification  identifier> may be used if visibility is desired  by  selec-
  1594. tion.  CLASSIFICATION_DEFINITION must also be named within the context clause
  1595. to make the type CLASSIFICATION visible.  As indicated, CLASSIFICATION may be
  1596. visible either directly or by selection.
  1597.  
  1598. <schema declaration element> ::=
  1599.      <basic declarative item>  <table definition>
  1600.  
  1601. <basic  declarative item> ::= an Ada basic declarative item,  subject to  the
  1602.      interpretations and restrictions discussed in section 4.7
  1603.  
  1604. <table definition> ::= see section 4.2
  1605.  
  1606. Declarations  within  schema  packages are not limited to the  definition  of
  1607. database tables; types, etc. may also be defined as required.
  1608.  
  1609. 4.2 <table definition>
  1610.  
  1611. FUNCTION:
  1612.  
  1613. Define  the name of a database table,  as well as the column names  and  data
  1614. types.   Unlike SQL, table definitions must be given for both base tables and
  1615. views.  A view is distinguished from a base table by having a view definition
  1616. in the body of the schema package in which the corresponding table definition
  1617. appears.
  1618.  
  1619. EXAMPLE:
  1620.  
  1621.   type EMPVIEW is
  1622.     record
  1623.       EMP  : EMPLOYEE_NAME;
  1624.       DEPT : DEPT_NAME;
  1625.    end record;
  1626.  
  1627. FORMAT:
  1628.  
  1629. <table definition> ::=
  1630.      type <table name> [ <discriminant part> ] is
  1631.        record
  1632.          <component list>
  1633.        end record ;
  1634.  
  1635. <table name> ::= a valid Ada record type name,  which is also taken to be the
  1636.      name of the database table being declared
  1637.  
  1638. Within a schema package,  the declaration of a record type that is not refer-
  1639. enced  from another record type also declares a database table.   The name of
  1640. the table is taken to be the name of the record type,  and the columns of the
  1641. table  are given by the components of the record type.   "Columns" may be  of
  1642. composite  types,  so lowest level subcomponents become actual database  col-
  1643. umns.   Ada/SQL does,  however, permit access to data as logically structured
  1644. and  grouped by composite types.   The runtime system will translate  between
  1645. Ada composite structures and the simpler underlying database  representation.
  1646. Subcolumns  may also be accessed by using indexing or component selection for
  1647. array and record columns, respectively.
  1648.  
  1649. <discriminant part> ::=
  1650.      ( <discriminant table element>
  1651.           [ { ; <discriminant table element> } ... ] )                        
  1652.  
  1653. <discriminant table element> ::= <table element>
  1654.  
  1655. <component list> ::=
  1656.      <table element> ; [ { <table element> ; } ... ]
  1657.     [ { <table element> ; } ... ] <variant part>
  1658.     null ;
  1659.  
  1660. Both  discriminant parts and component lists declare record  components,  and
  1661. hence table columns.   In Ada,  a discriminant specification   (<discriminant
  1662. table  element> here) looks essentially like a component declaration  (<table
  1663. element>  here),  with the following restrictions:  (1) The type/subtype of a
  1664. discriminant  may  only be given by a type mark,  not by  a  general  subtype
  1665. indication,  and (2) discriminants must be discrete.  These restrictions must
  1666. be  remembered  when reading the following discussion of <table element>s  --
  1667. they will be enforced by the Ada compiler and by the Ada/SQL automated tools.
  1668.  
  1669. No  corresponding  database table is defined for the declaration  of  a  null
  1670. record.
  1671.  
  1672. <variant part> ::=
  1673.      case <discriminant simple name> is
  1674.           <variant>
  1675.         [ <variant> ... ]
  1676.      end case ;
  1677.  
  1678. <discriminant simple name> ::= as in Ada
  1679.  
  1680. <variant> ::=
  1681.      when <choice> [ {  <choice> } ... ] =>
  1682.        <component list>
  1683.  
  1684. <choice> ::= as in Ada
  1685.  
  1686. Accessing a column within a variant part restricts the rows that are  consid-
  1687. ered  to  be within the table.   In particular,  only those rows  that  would
  1688. contain the column,  based on the Ada meaning of the discriminant value,  are
  1689. accessed.
  1690.  
  1691. <table element> ::=
  1692.      <column definition>
  1693.     <single column unique constraint definition>                             |
  1694.  
  1695. <column definition> ::= see section 4.3
  1696.  
  1697. <single column unique constraint definition> ::= see section 4.4              
  1698.  
  1699. 4.3 <column definition>
  1700.  
  1701. FUNCTION:
  1702.  
  1703. Define the names,  data types,  null value possibilities,  and uniqueness re-
  1704. quirements for database columns.
  1705.  
  1706. EXAMPLE:
  1707.  
  1708.   NAME : EMPLOYEE_NAME_NOT_NULL_UNIQUE;
  1709.   AGE  : EMPLOYEE_AGE;
  1710.  
  1711. FORMAT:
  1712.  
  1713. <column definition> ::=
  1714.      <column name list> : <data type> [ _NOT_NULL [ _UNIQUE ] ]
  1715.           [ <constraint> ] [ := <expression> ]
  1716.  
  1717. <column  name list> := an Ada identifier list -- the Ada syntax for discrimi-
  1718.      nant  specifications and component declarations permits several  columns
  1719.      to be defined within the same <column definition>.   The component names
  1720.      and data types are used for the column names and data types.
  1721.  
  1722. <data type>  ::= an Ada type mark.   The type mark may include  the  suffixes
  1723.      _NOT_NULL  or _NOT_NULL_UNIQUE,  which causes the appropriate constraint
  1724.      to be defined for the database.
  1725.  
  1726. <constraint> ::= an Ada constraint,  permitted only if a component other than
  1727.      a discriminant is being defined.   The constraint must be static, unless
  1728.      it  depends on a discriminant,  in which case discriminant names may  be
  1729.      the only non-static items in the constraint.
  1730.  
  1731. <expression>  ::=  an  Ada expression that provides default  values  for  the
  1732.      record  components  and also for the database columns.   When  inserting
  1733.      rows with unspecified values for columns that have defaults, the default
  1734.      values  are stored in the columns.   Null values are stored  in  columns
  1735.      with  neither specified values nor defaults,  with an error occurring if
  1736.      any of those columns do not permit null values.  The default values used
  1737.      for a table are the same as would be used by Ada when creating an object
  1738.      of  the  record type corresponding to the table,  at the  point  in  the
  1739.      program of the insert operation.   Default expressions must be static in
  1740.      Ada/SQL,  since they are processed at compile time, except that the name
  1741.      of a discriminant may be used.
  1742.  
  1743. 4.4 <unique constraint definition>
  1744.  
  1745. FUNCTION:
  1746.  
  1747. Specify that a column or a group of columns is to contain only unique data.   
  1748.  
  1749. EXAMPLE:
  1750.  
  1751.   NAME : DEPT_NAME_NOT_NULL_UNIQUE; -- 1                                      
  1752.  
  1753.   CONSTRAINTS ( EMPLOYEE , UNIQUE ( SAL & DEPT ) ); -- 2                      
  1754.  
  1755. FORMAT:
  1756.  
  1757. <unique constraint definition> ::=                                            
  1758.      <single column unique constraint definition>                             
  1759.     <multiple column unique constraint definition>                           |
  1760.  
  1761. A <single column unique constraint definition> is used to apply a  uniqueness 
  1762. constraint  to  a  single column,  directly as the column is defined  in  its 
  1763. enclosing  <table definition> (see section 4.2).   Applying a <single  column 
  1764. unique  constraint  definition> to a composite column  defines  a  uniqueness 
  1765. constraint  over  several underlying database columns.   A  <multiple  column 
  1766. unique  constraint  definition> is used to apply a uniqueness  constraint  on 
  1767. several Ada/SQL columns.  (It may also be used with single columns.)          
  1768.  
  1769. <single column unique constraint definition> ::= <column definition>          
  1770.  
  1771. <column definition> ::= see section 4.3
  1772.  
  1773. No special Ada/SQL <single column uniqueness constraint definition> syntax is 
  1774. required -- Ada/SQL column definitions provide all the capabilities necessary
  1775. to  define single column uniqueness constraints.   Suffixing a column's  data
  1776. type  with  _NOT_NULL_UNIQUE defines a uniqueness  constraint,  as  shown  in 
  1777. example 1.  If the column is a composite column, the uniqueness constraint is 
  1778. actually  over a group of underlying database columns,  which is part of  the 
  1779. capability  provided by SQL <unique constraint definition>s.   The  remaining 
  1780. capability provided by SQL <unique constraint definition>s, that of including 
  1781. the  same  database  column in several <unique  constraint  definition>s,  is 
  1782. provided by <multiple column unique constraint definition>s in Ada/SQL.       
  1783.  
  1784. <multiple column unique constraint definition> ::=                            
  1785.      CONSTRAINTS ( <table name> , UNIQUE ( <unique column list> ) ) ;         
  1786.  
  1787. A <multiple column unique constraint definition>,  as shown in example 2,  is 
  1788. placed  in  the <schema package body> (see section 4.5) corresponding to  the 
  1789. <schema package declaration> in which the referenced <table name> is defined. 
  1790. Its  effect is to cause CONSTRAINTS UNIQUE(<unique column list>) to be  added 
  1791. to the SQL <table definition> for the <table name>.   Consequently, it may be 
  1792. applied only to a base table.                                                 
  1793.  
  1794. <table  name>  ::= the name of a table defined in  the  corresponding  schema 
  1795.      package  declaration.   The functions for the table name are defined  in 
  1796.      the  package  produced  by the SQL function generator  from  the  schema 
  1797.      package declaration, as are the table-specific CONSTRAINTS procedure and 
  1798.      UNIQUE function.                                                         
  1799.  
  1800. <unique column list> ::=                                                      
  1801.      <column name> [ { & <column name> } ... ]                                
  1802.  
  1803. SQL  uses commas to separate the elements of a <unique column list>;  Ada/SQL 
  1804. uses ampersands.   The ampersand functions are defined specifically for  each 
  1805. table by the SQL function generator.                                          
  1806.  
  1807. <column  name> ::= a name of a column defined for the table.   The  functions 
  1808.      for the column names are defined by the SQL function generator.          
  1809.  
  1810. 4.5 <schema package body>
  1811.  
  1812. FUNCTION:
  1813.  
  1814. Views,  privileges,  and  multiple column uniqueness constraints are  defined 
  1815. within the bodies of schema packages.
  1816.  
  1817. EXAMPLE:
  1818.  
  1819. package body COMPANYDB_VIEWS_SCHEMA is
  1820. begin
  1821.  
  1822.   CREATE_VIEW ( EMPVIEW ( EMP  & DEPT ),                                      
  1823.           AS => SELEC   ( NAME & EMPLOYEE.DEPT,
  1824.                 FROM   => EMPLOYEE ) );
  1825.  
  1826.   GRANT ( SELEC, ON => EMPVIEW, TO => PUBLIC);
  1827.  
  1828. end COMPANYDB_VIEWS_SCHEMA;
  1829.  
  1830. FORMAT:
  1831.  
  1832. <schema package body> ::=
  1833.      package body <package simple name> is
  1834.        [ <declarative part> ]
  1835.      begin
  1836.        <schema body element> ...
  1837.      end [ <package simple name> ] ;
  1838.  
  1839. <package simple name> ::= the package identifier of the corresponding  schema
  1840.      package  declaration.   Schema packages that do not define views,  grant 
  1841.      privileges,  or  require multiple column uniqueness constraints are  not 
  1842.      required to have bodies.
  1843.  
  1844. <declarative part> ::= as in Ada, except that the only declarations permitted
  1845.      are static constant object declarations,  number declarations,  renaming
  1846.      declarations,  and use clauses.   In short,  only declarations that will
  1847.      add  to  the convenience of defining  views,  privileges,  and  multiple 
  1848.      column uniqueness constraints are permitted.                             
  1849.  
  1850. <schema body element> ::=
  1851.      <view definition>  <privilege definition>
  1852.     <multiple column unique constraint definition>                           |
  1853.  
  1854. <view definition> ::= see section 4.5a
  1855.  
  1856. <privilege definition> ::= see section 4.6
  1857.  
  1858. <multiple column unique constraint definition> ::= see section 4.4            
  1859.  
  1860. For every view definition or multiple column unique constraint definition  in 
  1861. a schema package body,  there must be a corresponding table definition in the
  1862. corresponding schema package declaration.
  1863.  
  1864. 4.5a <view definition>
  1865.  
  1866. FUNCTION:
  1867.  
  1868. Define a viewed table.
  1869.  
  1870. EXAMPLE:
  1871.  
  1872.   CREATE_VIEW ( EMPVIEW ( EMP  & DEPT ),                                      
  1873.           AS => SELEC   ( NAME & EMPLOYEE.DEPT,
  1874.                 FROM   => EMPLOYEE ) );
  1875.  
  1876. FORMAT:
  1877.  
  1878. <view definition> ::=
  1879.      CREATE_VIEW ( <table name> [ ( <view column list> ) ] ,                  
  1880.              AS => <query specification> [ ,
  1881.              WITH_CHECK_OPTION => ENABLED ] ) ;
  1882.  
  1883. The two SQL keywords CREATE and VIEW are linked into a single Ada  identifier 
  1884. with an underscore.  The CREATE_VIEW procedure is defined within SCHEMA_DEFI- 
  1885. NITION.
  1886.  
  1887. <table  name>  ::=  the name of a table defined in the  corresponding  schema
  1888.      package  declaration.   The functions for the table name are defined  in
  1889.      the  package  produced  by the SQL function generator  from  the  schema
  1890.      package  declaration.   If  a <view column list> is  included,  and  the 
  1891.      <table  name> includes an <authorization identifier>,  then  the  <table 
  1892.      name>  must be expressed as <authorization identifier>-<table  identifi- 
  1893.      er>,  instead  of as <authorization identifier>.<table  identifier>,  as 
  1894.      used most elsewhere within Ada/SQL.                                      
  1895.  
  1896. <view column list> ::=
  1897.      <column name> [ { & <column name> } ... ]
  1898.  
  1899. <column name> ::= a name of a column defined for the table.  If a view column 
  1900.      list is given,  the column names must agree precisely,  in  order,  with
  1901.      those  defined  for the table in the schema  package  declaration.   The
  1902.      functions  for the column names are also defined in the package produced
  1903.      by the SQL function generator from the schema package declaration.
  1904.  
  1905. <query  specification> ::= see section 3.25.   The number of columns  defined
  1906.      for  the view must be the same as the degree of the table  specified  by
  1907.      the <query specification>.  Furthermore, the data type of each column of
  1908.      the <query specification> must be capable of being converted, via an Ada
  1909.      type  conversion,  to the data type of the corresponding column  defined
  1910.      for the view.
  1911.  
  1912. 4.6 <privilege definition>
  1913.  
  1914. FUNCTION:
  1915.  
  1916. Define privileges.
  1917.  
  1918. EXAMPLE:
  1919.  
  1920.   GRANT ( SELEC, ON => EMPVIEW, TO => PUBLIC);
  1921.   GRANT ( ALLL,  ON => DEPT,    TO => ADMINISTRATION);
  1922.  
  1923. FORMAT;
  1924.  
  1925. <privilege definition> ::=
  1926.      GRANT ( <privileges> ,
  1927.        ON => <table name> ,
  1928.        TO => <grantee> [ { & <grantee> } ... ] [ ,
  1929.        WITH_GRANT_OPTION => ENABLED ] ) ;
  1930.  
  1931. GRANT  procedures and ancillary functions for each table defined in a  schema 
  1932. package  declaration  are  defined in the package produced from  that  schema 
  1933. package declaration by the SQL function generator.   Ancillary functions that 
  1934. are not table-specific are defined in SCHEMA_DEFINITION.   Each clause in the 
  1935. GRANT  statement  is a parameter to the  GRANT  procedure.   Parameter  names 
  1936. retain  the SQL keywords.   WITH_GRANT_OPTION differs slightly from SQL to be
  1937. more Ada-like, and is an optional last parameter.  The grantee list is linked
  1938. together with ampersands; in SQL there are no operators between the grantees.
  1939.  
  1940. <privileges> ::=
  1941.      ALLL  ALL_PRIVILEGES
  1942.     <action> [ { & <action> } ... ]
  1943.  
  1944. ALL  is  an Ada reserved word and so cannot be used,  and ALL  PRIVILEGES  is
  1945. connected with an underscore.  In SQL the action list is separated by commas,
  1946. Ada/SQL uses ampersands as elsewhere.   ALLL and ALL_PRIVILEGES are functions
  1947. defined in SCHEMA_DEFINITION.
  1948.  
  1949. <action> ::=
  1950.      SELEC  INSERT | DELETE
  1951.     UPDATE [ ( <grant column list> ) ]
  1952.  
  1953. SQL uses SELECT;  Ada/SQL uses SELEC because SELECT is an Ada reserved  word.
  1954. The SELEC,  INSERT,  DELETE, and UPDATE functions, as they apply to privilege
  1955. definitions, are defined in the appropriate generated package.                
  1956.  
  1957. <grant column list> ::=
  1958.      <column name> [ { & <column name> } ... ]
  1959.  
  1960. The  column names are linked together with ampersands rather than commas,  as
  1961. is customary within Ada/SQL.
  1962.  
  1963. <column name> ::= the name of a column in the table for which privileges  are
  1964.      being granted.  Functions defining column names are produced from schema
  1965.      package declarations by the SQL function generator.
  1966.  
  1967. <grantee> ::=
  1968.      PUBLIC  <authorization identifier>
  1969.  
  1970. <authorization  identifier>  ::= as defined within an  authorization  package
  1971.      (see section 4.1a)
  1972.  
  1973. A  function defining PUBLIC is declared in SCHEMA_DEFINITION.   Authorization
  1974. identifiers are defined in the applicable authorization packages,  which must
  1975. be named within the context clause of the schema package body in order to  be
  1976. used.
  1977.  
  1978. 4.6a <classification package declaration>
  1979.  
  1980. FUNCTION:
  1981.  
  1982. Classification package declarations are used to define the classifications of
  1983. all columns of the database.   Each schema package declaring base tables must
  1984. have  a corresponding classification package.   The classification package is
  1985. "with"ed into the schema package,  and a <schema classification clause>  (see
  1986. section  4.1b) is used to indicate the relation of the classification package
  1987. to the schema package.  Classification packages are required only by the MIL-
  1988. STD, not by the ANSI standard.
  1989.  
  1990. EXAMPLE:
  1991.  
  1992. package COMPANYDB_VIEWS_CLASSIFICATION is
  1993.  
  1994.   function COMPANYDB_VIEWS is new SECURITY_CLASSIFICATION(UNCLASSIFIED);
  1995.  
  1996.   type EMPVIEW is limited private;
  1997.  
  1998. private
  1999.  
  2000.   type EMPVIEW is
  2001.     record
  2002.       EMP  : CLASSIFICATION := UNCLASSIFIED;
  2003.       DEPT : CLASSIFICATION := UNCLASSIFIED;
  2004.     end record;
  2005.  
  2006. end COMPANYDB_VIEWS_CLASSIFICATION;
  2007.  
  2008. FORMAT:
  2009.  
  2010. <classification package declaration> ::=
  2011.      <classification package specification> ;
  2012.  
  2013. <classification package specification> ::=
  2014.      package <identifier> is
  2015.        function <classification identifier> is new
  2016.          [ CLASSIFICATION_DEFINITION . ] SECURITY_CLASSIFICATION
  2017.              ( <classification> ) ;
  2018.        <private type declaration> ...
  2019.      private
  2020.        <table definition> ...
  2021.      end [ <package simple name> ]
  2022.  
  2023. The  <classification  identifier>  is defined by  instantiating  the  generic
  2024. SECURITY_CLASSIFICATION function which is defined within CLASSIFICATION_DEFI-
  2025. NITION.   As  indicated,  SECURITY_CLASSIFICATION can be made visible  either
  2026. directly or by selection.
  2027.  
  2028. <identifier> ::= any valid name for a library package
  2029.  
  2030. <package simple name> ::= must match the package <identifier> if used
  2031.  
  2032. <classification  identifier>  ::=  the identifier that will be  used  in  the
  2033.      <schema classification clause> of a schema package to indicate that this
  2034.      classification  package  declaration is applicable to  it  (see  section
  2035.      4.1b)
  2036.  
  2037. <classification>  ::=  a value of type CLASSIFICATION,  indicating  the  most
  2038.      restrictive  classification  applied within this classification  package
  2039.      declaration.  Type CLASSIFICATION is defined within CLASSIFICATION_DEFI-
  2040.      NITION,  and  may  be tailored for the specific environment  to  include
  2041.      basic classification,  releasability,  special handling,  and  sensitive
  2042.      source information.
  2043.  
  2044. <private type declaration> ::= as in Ada, with a limited private type declar-
  2045.      ation for each table definition in the schema package that will use this
  2046.      classification package declaration.   The names and discriminants of the
  2047.      limited  private types are the same as those of the corresponding record
  2048.      types.   (This duplication of record type names is the reason that sepa-
  2049.      rate  classification packages are required.)  All discriminants  are  of
  2050.      type CLASSIFICATION, however.  An additional discriminant, called TABLE,
  2051.      may  be  defined  if it is desired to specify a classification  for  the
  2052.      entire table.  In the absence of the special TABLE discriminant, a table
  2053.      is  given  the most restrictive classification defined for  all  of  its
  2054.      columns.   Each discriminant must be given a default value,  which indi-
  2055.      cates the classification of the corresponding column.
  2056.  
  2057. <table definition> ::= see section 4.2.  Corresponding full type declarations
  2058.      must be provided for all limited private types declared.   The full type
  2059.      declarations must have components named the same,  in the same order, as
  2060.      the corresponding table definitions to which they apply.  All components
  2061.      are  of type CLASSIFICATION,  however.   Default values must be provided
  2062.      for all components,  to indicate the classification of the corresponding
  2063.      database  columns.   It should be noted that composite columns have  but
  2064.      one classification; later versions of this standard may address separate
  2065.      classifications for subcolumns.
  2066.  
  2067. 4.7 Special Considerations
  2068.  
  2069. This  section  describes special considerations that apply  to  data  defined
  2070. within  Ada/SQL schemas.   Subsections are organized according to the section
  2071. numbering and notational conventions of the Ada Programming Language Military
  2072. Standard (ANSI/MIL-STD-1815A),  hereafter referred to as the Language  Refer-
  2073. ence Manual (LRM).
  2074.  
  2075. 4.7 Special Considerations - LRM section 2.3 - identifier
  2076.  
  2077. FUNCTION:
  2078.  
  2079. Identifiers  perform their usual Ada functions within schemas,  but are  also
  2080. used to name SQL authorization identifiers, tables, and columns.
  2081.  
  2082. EXAMPLE:
  2083.  
  2084. CITY                 -- columns of type/subtype CITY may contain null and/or
  2085.                      --  duplicate values
  2086. CITY_NOT_NULL        -- columns of this type/subtype may not contain null
  2087.                      --  values, but may contain duplicate values
  2088. CITY_NOT_NULL_UNIQUE -- columns of this type/subtype may not contain nulls
  2089.                      --  and also may not contain duplicate values
  2090.  
  2091. FORMAT:
  2092.  
  2093. identifier ::= as in Ada
  2094.  
  2095. Any  legal Ada identifiers may be used within schemas.   Identifiers used  as
  2096. SQL authorization identifiers, table names, or column names may not be passed
  2097. verbatim to the database management system,  however, because (1) SQL identi-
  2098. fiers  may include only upper case characters (case is not significant in Ada
  2099. anyway),  (2) SQL identifiers may not be longer than 18 characters,  (3)  SQL
  2100. identifiers  may not be identical to SQL key words,  and (4) certain  Ada/SQL
  2101. data definitions may cause underlying database tables to have duplicate table
  2102. and/or  column  names unless the names are qualified by selection in the  Ada
  2103. sense.   Ada/SQL  maps Ada identifiers (and full names,  where  necessary  to
  2104. avoid  duplicates) to appropriate underlying SQL identifiers,  with an algor-
  2105. ithm  that  attempts  to maintain as much semantic content  within  names  as
  2106. possible.                                                                     
  2107.  
  2108. Identifiers used as type and subtype names may include the suffixes _NOT_NULL
  2109. or  _NOT_NULL_UNIQUE.   Database columns defined by record  subcomponents  of
  2110. types/subtypes  named with these suffixes will be given the corresponding SQL
  2111. constraints.
  2112.  
  2113. A  restriction  on  the use of the _NOT_NULL  and  _NOT_NULL_UNIQUE  suffixes
  2114. ensures  that only closely related types/subtypes have similar simple  names.
  2115. Two  identifiers  are considered similar if they differ only in  the  use  or
  2116. nonuse  of the _NOT_NULL and _NOT_NULL_UNIQUE suffixes.   If A and B are  two
  2117. directly  visible types/subtypes with similar simple names,  then one of  the
  2118. following  definitions must hold,  where C is another type,  not  necessarily
  2119. directly visible, with simple name similar to those of A and B:
  2120.  
  2121.   (1) subtype A is B;       (3) subtype C is A;       (4) subtype C is B;
  2122.   (2) subtype B is A;           subtype B is C;           subtype A is C;
  2123.  
  2124. 4.7 Special Considerations - LRM section 3.1 - declaration
  2125.  
  2126. FUNCTION:
  2127.  
  2128. Declare the tables and columns of a database, as well as the types of data to
  2129. be stored within the database.
  2130.  
  2131. EXAMPLE:
  2132.  
  2133.   SECURITY_MARKING_LENGTH : constant := 12; -- a number declaration
  2134.  
  2135.   type SECURITY_CLASSIFICATION is (U,C,S,T); -- type declarations
  2136.   type SECURITY_MARKING is new STRING(1..SECURITY_MARKING_LENGTH);
  2137.  
  2138.   MINIMUM_CLASSIFICATION : constant SECURITY_CLASSIFICATION := C;
  2139.     -- an object declaration
  2140.  
  2141.   MINCLASS : SECURITY_CLASSIFICATION renames MINIMUM_CLASSIFICATION;
  2142.     -- a renaming declaration
  2143.  
  2144.   subtype CLASSIFICATION_LEVEL is SECURITY_CLASSIFICATION
  2145.     range MINIMUM_CLASSIFICATION..SECURITY_CLASSIFICATION'LAST;
  2146.       -- a subtype declaration
  2147.  
  2148.   type MARKING_TABLE is                -- a record type declaration that also
  2149.     record                             --  serves to declare a database table
  2150.       CLASS : SECURITY_CLASSIFICATION; --  and its columns (the table in this
  2151.       MARK  : SECURITY_MARKING;        --  example is rather trivial and
  2152.     end record;                        --  unnecessary)
  2153.  
  2154. FORMAT:
  2155.  
  2156. basic_declaration ::= as in Ada,  except that the only declarations permitted
  2157.      within  schema  packages are object declarations (see LRM section  3.2),
  2158.      number  declarations (see LRM section 3.2),  type declarations (see  LRM
  2159.      section 3.3.1),  subtype declarations (see LRM section 3.3.2) and renam-
  2160.      ing declarations (see LRM section 8.5).
  2161.  
  2162. The  only declarations that are permitted within a schema package  are  those
  2163. that  apply directly to the data definition function.   Further  restrictions
  2164. are  placed  on  the various declarations,  as discussed in  the  appropriate
  2165. sections following.   Packages named in the context clause of schema packages
  2166. may contain arbitrary declarations, if they are not also schema packages.
  2167.  
  2168. 4.7 Special Considerations - LRM section 3.2 - constant object
  2169.      and named number
  2170.  
  2171. FUNCTION:
  2172.  
  2173. Define named constants (of arbitrary type) and numbers (of numeric type)
  2174.  
  2175. EXAMPLE:
  2176.  
  2177.   LIMIT     : constant INTEGER := 10_000;    -- taken from LRM section 3.2.1
  2178.   LOW_LIMIT : constant INTEGER := LIMIT/10;  -- in that example, TOLERANCE is
  2179.                                              --  not static and hence may not
  2180.   PI            : constant := 3.14159_26536; --  be used in a schema
  2181.   TWO_PI        : constant := 2.0*PI;        -- number declaration examples
  2182.   MAX           : constant := 500;           --  are taken from LRM section
  2183.   POWER_16      : constant := 2**16;         --  3.2.2
  2184.   ONE, UN, EINS : constant := 1;
  2185.  
  2186. FORMAT:
  2187.  
  2188. object_declaration ::= as in Ada,  except that only constants may be declared
  2189.      in a schema package.  Likewise, objects referenced from schema packages,
  2190.      except for discriminants, must be constants.
  2191.  
  2192. number_declaration ::= as in Ada
  2193.  
  2194. The purpose of a schema package is to declare database objects,  not  program
  2195. objects.  Hence, the declaration of arbitrary objects is not permitted within
  2196. schema packages.   Constants and named numbers are,  however,  permitted as a
  2197. convenience,  to allow meaningful names to be given to important values.  All
  2198. entities  used  within expressions in schema packages,  except for  discrimi-
  2199. nants,  must  be  static,  because all Ada/SQL automated tool  processing  is
  2200. performed at compile time.
  2201.  
  2202. 4.7 Special Considerations - LRM section 3.3.1 - type declaration
  2203.  
  2204. FUNCTION:
  2205.  
  2206. Declare  types  of program and database values.   Also,  indicate  names  and
  2207. columns of database tables.
  2208.  
  2209. EXAMPLE:
  2210.  
  2211.   type DIGIT_CHARACTER is ('0','1','2','3','4','5','6','7','8','9');
  2212.     -- an enumeration type
  2213.  
  2214.   type DIGIT_VALUE is range 0..9; -- an integer type
  2215.  
  2216.   type MONEY is delta 0.01 range 0.00..1_000_000.00; -- a real type
  2217.  
  2218.   type PHONE_NUMBER is array(1..10) of DIGIT_CHARACTER; -- an array type
  2219.  
  2220.   type PHONE_BILL is -- a record type (also a database table in this example)
  2221.     record
  2222.       NUMBER : PHONE_NUMBER;
  2223.       DUE    : MONEY;
  2224.     end record;
  2225.  
  2226.   type OVERDUE_PHONE_BILL is new PHONE_BILL;
  2227.     -- a derived type (also a database table in this example)
  2228.  
  2229. FORMAT:
  2230.  
  2231. type_declaration  ::= as in Ada,  except that incomplete  type  declarations,
  2232.      private type declarations, access type definitions, and task type decla-
  2233.      rations  are not permitted within schema packages.   The following types
  2234.      may therefore be declared within schema packages:  enumeration (see  LRM
  2235.      section 3.5.1),  integer (see LRM section 3.5.4),  real (see LRM section
  2236.      3.5.6),  array (see LRM section 3.6),  record (see LRM section 3.7), and
  2237.      derived (see LRM sectin 3.4).
  2238.  
  2239. Access and task types may not be declared within schema packages.  Subcompon-
  2240. ents  of composite types declared or used within schema packages may also not
  2241. be of an access or task type.   As a result, incomplete type declarations are
  2242. not necessary, and may not be used, within schema packages.
  2243.  
  2244. Private types may not be declared within schema packages, since their declar-
  2245. ation  would  normally also require the declaration of  subprograms  defining
  2246. operations  on  the types.   And subprogram declarations  are  not  permitted
  2247. within  schema packages,  in order to restrict package text to that  required
  2248. specifically  for the data definition function.   However,  subcomponents  of
  2249. record  and  array types may be of a private type (defined in  other  library
  2250. units  used by the schema),  providing that the corresponding full type would
  2251. be permitted to be used for the subcomponents.
  2252.  
  2253. The  Ada/SQL operations available on a database column of a private type  are
  2254. limited to the following:
  2255.  
  2256. (1) Equality (EQ) and inequality (NE) comparisons,  including within <quanti-
  2257. fied predicate>s,                                                             
  2258.  
  2259. (2) Use as the argument of a COUNT_DISTINCT set function,
  2260.  
  2261. (3) IS_IN and NOT_IN comparisons,
  2262.  
  2263. (4) IS_NULL and IS_NOT_NULL tests (a composite column is null if and only  if
  2264. all subcolumns are null),
  2265.  
  2266. (5) Use in a GROUP_BY clause,
  2267.  
  2268. (6)  Use  in the SELEC clause of a  <sub-query>,  <query  specification>,  or
  2269. <select statement>,
  2270.  
  2271. (7) Use in the <insert column list> of an INSERT_INTO statement,
  2272.  
  2273. (8)  Use within a <set clause> of either type of UPDATE statement,  as either 
  2274. the <object column> or the <value expression>,                                
  2275.  
  2276. (9) Use within a <grant column list> of a GRANT statement, and
  2277.  
  2278. (10) Selection of components that are discriminants.
  2279.  
  2280. Further  restriction  of  SQL operations to develop an  analogue  to  limited
  2281. private types is not fruitful;  hence,  limited private types may not be used
  2282. for database columns.
  2283.  
  2284. There are some other considerations that apply to the various classes of type
  2285. declaration within schemas; these are discussed within the referenced section
  2286. for  each  class  of type.   Any type that may be declared  within  a  schema
  2287. package can be used as the type of a database column,  and no other types may
  2288. be so used.
  2289.  
  2290. 4.7 Special Considerations - LRM section 3.3.2 - subtype declaration
  2291.  
  2292. FUNCTION:
  2293.  
  2294. Declare  Ada  subtypes.   Subtypes may be used in their  Ada  sense,  and  to
  2295. indicate _NOT_NULL and _NOT_NULL_UNIQUE constraints.   Although not a part of
  2296. this  standard,  the  way in which subtypes relate to each other can also  be
  2297. used to guide test data generation.
  2298.  
  2299. EXAMPLE:
  2300.  
  2301.   type EMPLOYEE_NUMBER is range 1000..9999;
  2302.  
  2303.   subtype EMPLOYEE_NUMBER_NOT_NULL_UNIQUE is EMPLOYEE_NUMBER;
  2304.  
  2305. FORMAT:
  2306.  
  2307. subtype_declaration  ::= as in Ada,  except that it must be static,  and  may
  2308.      only define a subtype that would be permitted for a database column
  2309.  
  2310. Because the Ada/SQL automated tools will process schemas at compile time, all
  2311. subtypes defined must be static.   Furthermore,  only subtypes that would  be
  2312. legal for database columns may be defined within a schema.
  2313.  
  2314. A subtype of a _NOT_NULL or _NOT_NULL_UNIQUE type or subtype does not inherit
  2315. these properties;  they are determined solely based on the suffix of the type
  2316. or subtype name.
  2317.  
  2318. 4.7 Special Considerations - LRM section 3.4 - derived type definition
  2319.  
  2320. FUNCTION:
  2321.  
  2322. Define a new type with characteristics derived from another type.
  2323.  
  2324. EXAMPLE:
  2325.  
  2326.   type PROMOTION_LIST_MEMBER is new EMPLOYEE_NUMBER;
  2327.     -- derived from the example on LRM section 3.3.2, above                   
  2328.  
  2329. FORMAT:
  2330.  
  2331. derived_type_definition ::= as in Ada, except that it must be static, and may
  2332.      only define a subtype that would be permitted for a database column
  2333.  
  2334. The  type  mark  in the subtype indication of a derived type  definition  may
  2335. include the suffix _NOT_NULL or _NOT_NULL_UNIQUE.   However, these properties
  2336. do not carry over to the derived type;  they are only conveyed by the  suffix 
  2337. on a type or subtype name.
  2338.  
  2339. If the derived type is a record type,  then the derived type declaration also
  2340. declares  a  database table according to the same rules as for  other  record
  2341. types:  The  derived type declaration also declares a database table  if  and
  2342. only  if  the name of the derived type (or any subtype with a name  differing
  2343. only in the _NOT_NULL or _NOT_NULL_UNIQUE suffix) is not used as the type  of
  2344. a  subcomponent  within  another record declaration within  the  same  schema
  2345. package.   A  derived  database table is assumed to be a base table unless  a
  2346. view definition is given for it.
  2347.  
  2348. Type representation clauses, as they affect database representation, apply to
  2349. derived types as with Ada:  A type representation clause for the parent  type
  2350. applies  to the derived type if and only if it appears before the declaration
  2351. of the derived type.
  2352.  
  2353. 4.7 Special Considerations - LRM section 3.5 - range constraint
  2354.  
  2355. FUNCTION:
  2356.  
  2357. Specify the legal range of values for a type or subtype
  2358.  
  2359. EXAMPLE:
  2360.  
  2361.   type COLUMN is range 1..72; -- from LRM section 3.3.1
  2362.   subtype RAINBOW is COLOR range RED..BLUE; -- from LRM section 3.3.2
  2363.   subtype PROBABILITY is REAL range 0.0..1.0; -- from LRM section 3.5.7
  2364.   type VOLT is delta 0.125 range 0.0..255.0; -- from LRM section 3.5.9
  2365.  
  2366.   type T is array(POSITIVE range MIN..MAX) of COMPONENT;
  2367.     -- from LRM section 3.6                                                   
  2368.  
  2369.   type DATE is -- from LRM section 3.7
  2370.     record
  2371.       DAY   : INTEGER range 1..31;
  2372.       MONTH : MONTH_NAME;
  2373.       YEAR  : INTEGER range 0..4000;
  2374.     end record;
  2375.  
  2376. FORMAT:
  2377.  
  2378. range_constraint ::= as in Ada, except that it must be static
  2379.  
  2380. A  database  column  of a type or subtype having a null  range  must  not  be
  2381. declared  as _NOT_NULL or _NOT_NULL_UNIQUE -- only null values may be  stored
  2382. within it.  (The usefulness of such a column would be extremely limited.)
  2383.  
  2384. 4.7 Special Considerations - LRM section 3.5.1 - enumeration type definition
  2385.  
  2386. FUNCTION:
  2387.  
  2388. Define an enumeration type and its values.
  2389.  
  2390. EXAMPLE:
  2391.  
  2392.   type DAY    is (MON, TUE, WED, THU, FRI, SAT, SUN); -- examples taken from
  2393.   type SUIT   is (CLUBS, DIAMONDS, HEARTS, SPADES);   --  LRM sections 3.5.1
  2394.   type GENDER is (M, F);                              --  and 3.5.2
  2395.   type LEVEL  is (LOW, MEDIUM, URGENT);
  2396.   type COLOR  is (WHITE, RED, YELLOW, GREEN, BLUE, BROWN, BLACK);
  2397.   type LIGHT  is (RED, AMBER, GREEN);
  2398.  
  2399.   type HEXA   is ('A', 'B', 'C', 'D', 'E', 'F');
  2400.   type MIXED  is ('A', 'B', '*', B, NONE, '?', '%');
  2401.  
  2402.   type ROMAN_DIGIT is ('I', 'V', 'X', 'L', 'C', 'D', 'M');
  2403.  
  2404. FORMAT:
  2405.  
  2406. enumeration_type_definition ::= as in Ada
  2407.  
  2408. The Ada/SQL automated tools will recognize the predefined types CHARACTER and
  2409. BOOLEAN.   The  SQL operations available on enumeration types are the same as
  2410. are available on strings,  except that LIKE is not available for  enumeration
  2411. types.
  2412.  
  2413. SQL  does not directly support enumeration types,  so it is necessary to  map
  2414. Ada enumeration types into other SQL data types.   The mapping process should
  2415. achieve  three objectives:  (1) preserve the ordering of the enumeration val-
  2416. ues,  (2) use explicit representations if requested,  and (3) enable enumera-
  2417. tion  database  values  to be referenced/retrieved by  their  identifiers  or
  2418. character literals, even from non-Ada ways of accessing the database.
  2419.  
  2420. For any database type, subtype, or table T, T_NOT_NULL, or T_NOT_NULL_UNIQUE,
  2421. the SQL function generator defines a named number T_SIZE, of type universal_-
  2422. integer, to be equal to the minimum number of bits that is needed by the DBMS
  2423. implementation to hold any possible object of this type or subtype.   This is
  2424. defined as in Ada,  except considering DBMS storage units and  representation
  2425. instead of those of the host computer.  Values for private types are as would
  2426. be given for the underlying full type.
  2427.  
  2428. 4.7 Special Considerations - LRM section 3.5.4 - integer type definition
  2429.  
  2430. FUNCTION:
  2431.  
  2432. Define the range of values for an integer type.
  2433.  
  2434. EXAMPLE:
  2435.  
  2436.   type PAGE_NUM  is range 1..2_000;  -- taken from LRM section 3.5.4
  2437.   type LINE_SIZE is range 1..MAX_LINE_SIZE;
  2438.  
  2439.   subtype SMALL_INT   is INTEGER   range -10..10;
  2440.   subtype COLUMN_PTR  is LINE_SIZE range 1..10;
  2441.   subtype BUFFER_SIZE is INTEGER   range 0..MAX;
  2442.  
  2443. FORMAT:
  2444.  
  2445. integer_type_definition ::= as in Ada, except that it must be static
  2446.  
  2447. The  Ada/SQL  automated  tools will recognize the  predefined  type  INTEGER.
  2448. Although implementation-specific type names, such as LONG_INTEGER and SHORT_-
  2449. INTEGER,  will  not  be recognized,  range constraints can be used to  define
  2450. types with the corresponding ranges.
  2451.  
  2452. The  range  of integers supported by a database management system may not  be
  2453. the same as that supported by the Ada system used to access that  DBMS.   The
  2454. package  DATABASE provides information about the DBMS being accessed by Ada/-
  2455. SQL.   In particular, the smallest (most negative) integer value supported by
  2456. the DBMS through Ada/SQL is the named number DATABASE.MIN_INT and the largest
  2457. (most positive) value is DATABASE.MAX_INT.   The type DATABASE.INT is defined 
  2458. to  encompass  the maximum range of integers supported by  the  DBMS  through 
  2459. Ada/SQL.                                                                      
  2460.  
  2461. The  DATABASE package also includes the definition of a type  SMALLINT,  with
  2462. range  corresponding  to  that supported by the DBMS  type  SMALLINT  through
  2463. Ada/SQL.   The Ada/SQL automated tools will convert Ada integer data types to
  2464. the  corresponding  DBMS  types as follows:  (1) If the Ada type  or  subtype
  2465. declaration  explicitly references (following a chain of references)  INTEGER
  2466. or DATABASE.INT, then the SQL INTEGER type is used, (2) if the declaration of 
  2467. the Ada type or subtype explicitly references SMALLINT, then the SQL SMALLINT
  2468. type  is used,  (3) if none of these types is referenced in the Ada  declara- 
  2469. tions,  then the SQL SMALLINT type is used if the range of values is  compat-
  2470. ible with it, otherwise the SQL INTEGER type is used.
  2471.  
  2472. If the range of integers supported by the DBMS is smaller than that supported
  2473. by Ada,  then the Ada/SQL automated tools will issue warning diagnostics upon
  2474. encountering explicitly declared ranges that extend beyond the capability  of
  2475. the  DBMS.   The  exception  NUMERIC_ERROR is raised by the execution  of  an
  2476. Ada/SQL operation that would require the DBMS to handle an integer beyond its
  2477. range.
  2478.  
  2479. SQL does not support subtypes,  so database operations may be performed with-
  2480. out  range  checking.   (An implementation may perform range  checking  where
  2481. practical,  however,  raising  CONSTRAINT_ERROR on database  operations  that
  2482. would  violate subtype constraints.)  If range checking is not performed,  it
  2483. is possible for an Ada/SQL statement to cause one or more database columns to
  2484. contain values outside the ranges defined for those columns.   The  exception
  2485. CONSTRAINT_ERROR  will be raised,  however,  when it is attemped to  retrieve
  2486. such  values.   If  the value can be legally stored in the variable  used  to
  2487. retrieve it, then the value will be stored before CONSTRAINT_ERROR is raised.
  2488.  
  2489. 4.7 Special Considerations - LRM section 3.5.6 - real type definition
  2490.  
  2491. FUNCTION:
  2492.  
  2493. Define the range of values and accuracy for real types
  2494.  
  2495. EXAMPLE:
  2496.  
  2497.   type COEFFICIENT is digits 10 range -1.0..1.0; -- a floating point type
  2498.   type VOLT is delta 0.125 range 0.0..255.0; -- a fixed point type
  2499.     -- taken from LRM sections 3.5.7 and 3.5.9
  2500.  
  2501. FORMAT:
  2502.  
  2503. real_type_definition ::= as in Ada, except that it must be static
  2504.  
  2505. The  range  and accuracy of real numbers supported by a  database  management
  2506. system may not be the same as that supported by the Ada system used to access
  2507. that DBMS.  If the range or accuracy of real numbers supported by the DBMS is
  2508. smaller  than  that supported by Ada,  then the Ada/SQL automated tools  will
  2509. issue warning diagnostics upon encountering explicitly declared  characteris-
  2510. tics that extend beyond the capability of the DBMS.   The exception NUMERIC_-
  2511. ERROR  is raised by the execution of an Ada/SQL operation that would  require
  2512. the DBMS to handle a real number beyond its range.   In general, no exception
  2513. is raised if accuracy is lost as a result of database operations.
  2514.  
  2515. The  underlying  DBMS  must support the model numbers (according to  the  Ada
  2516. definition) for types that are successfully processed by the automated tools,
  2517. as  well as safe numbers within the ranges of subtypes.   The DBMS  may  also
  2518. support a wider range of safe numbers.
  2519.  
  2520. The  comments in the previous section on range checking and CONSTRAINT_ERRORs
  2521. for INTEGERs are applicable to real numbers as well.
  2522.  
  2523. 4.7 Special Considerations - LRM section 3.5.7 - floating point constraint
  2524.  
  2525. FUNCTION:
  2526.  
  2527. Define the range of values and accuracy for floating point types
  2528.  
  2529. EXAMPLE:
  2530.  
  2531.   type COEFFICIENT is digits 10 range -1.0..1.0; -- taken from LRM section
  2532.                                                  --  3.5.7
  2533.  
  2534.   type REAL is digits 8;
  2535.   type MASS is digits 7 range 0.0..1.0E35;
  2536.  
  2537.   subtype SHORT_COEFF is COEFFICIENT digits 5;
  2538.   subtype PROBABILITY is REAL range 0.0..1.0;
  2539.  
  2540. FORMAT:
  2541.  
  2542. floating_point_constraint ::= as in Ada, except that it must be static
  2543.  
  2544. The  Ada/SQL automated tools will recognize the predefined type  FLOAT.   Al-
  2545. though  implementation-specific type names,  such as LONG_FLOAT  and  SHORT_-
  2546. FLOAT,  are not recognized,  floating point constraints can be used to define
  2547. types with the corresponding characteristics.
  2548.  
  2549. The DATABASE package defines REAL and DOUBLE_PRECISION types, with ranges and
  2550. accuracies corresponding to those supported by the SQL REAL and DOUBLE PRECI-
  2551. SION types as available from the underlying DBMS through Ada/SQL.   The Ada/-
  2552. SQL  automated tools will convert Ada floating point types to the correspond-
  2553. ing DBMS types as follows:  (1) If the Ada type or subtype declaration expli-
  2554. citly references (following a chain of references) DOUBLE_PRECISION, then the
  2555. SQL DOUBLE PRECISION type is used,  (2) if the declaration of the Ada type or
  2556. subtype explicitly references REAL,  then the SQL REAL type is used,  (3)  if
  2557. neither DOUBLE_PRECISION nor REAL is referenced in the Ada declarations, then
  2558. a SQL FLOAT type with appropriate precision is used if the range and accuracy
  2559. of  values is compatible with it,  otherwise the SQL DOUBLE_PRECISION type is
  2560. used.   Note that the range and accuracy of the Ada FLOAT type may not corre-
  2561. spond to those achievable with the SQL FLOAT type.
  2562.  
  2563. The  maximum number of floating point digits that can be handled  by  Ada/SQL
  2564. through  the  underlying DBMS is given by the system dependent  named  number
  2565. DATABASE.MAX_DIGITS.
  2566.  
  2567. For  each floating point database type or subtype T,  T_NOT_NULL,  or T_NOT_-
  2568. NULL_UNIQUE  referenced  within a schema,  the SQL  function  generator  will
  2569. define named numbers T_SAFE_EMAX, T_SAFE_SMALL, and T_SAFE_LARGE, correspond-
  2570. ing to the similarly named attributes of T (or T_NOT_NULL, T_NOT_NULL_UNIQUE,
  2571. etc.).   The  attributes  of  T yield information on the range  of  exponents
  2572. supported  by the Ada implementation;  the corresponding named numbers  yield
  2573. similar information for the DBMS implementation.  The DBMS itself may support
  2574. a  wider  or  a  narrower  range,  which  will  be  accurately  reflected  in
  2575. T_SAFE_EMAX.   However,  T_SAFE_SMALL  and T_SAFE_LARGE will not  exceed  the
  2576. range of the Ada implementation.  As already noted, the DBMS will support all
  2577. model  numbers of a type that is successfully processed by the Ada/SQL  auto-
  2578. mated tools,  so the values returned by the DIGITS,  MANTISSA, EPSILON, EMAX,
  2579. SMALL, and LARGE attributes of T are applicable to the DBMS as well as to the
  2580. Ada implementation.  The SQL function generator will also produce the follow-
  2581. ing  definitions,  corresponding  to the machine-dependent attributes  of  T,
  2582. except with values applicable to the DBMS implementation:
  2583.  
  2584.      Type                Generated_Name           Corresponding_Attribute
  2585.      constant BOOLEAN    T_DATABASE_ROUNDS        T'MACHINE_ROUNDS
  2586.      constant BOOLEAN    T_DATABASE_OVERFLOWS     T'MACHINE_OVERFLOWS
  2587.      named number        T_DATABASE_RADIX         T'MACHINE_RADIX
  2588.      named number        T_DATABASE_MANTISSA      T'MACHINE_MANTISSA
  2589.      named number        T_DATABASE_EMAX          T'MACHINE_EMAX
  2590.      named number        T_DATABASE_EMIN          T'MACHINE_EMIN
  2591.  
  2592. 4.7 Special Considerations - LRM section 3.5.9 - fixed point constraint
  2593.  
  2594. FUNCTION:
  2595.  
  2596. Define the range of values and accuracy for fixed point types
  2597.  
  2598. EXAMPLE:
  2599.  
  2600.   type VOLT is delta 0.125 range 0.0..255.0; -- taken from LRM section 3.5.9
  2601.   subtype ROUGH_VOLTAGE is VOLT delta 1.0;
  2602.  
  2603.   DEL : constant := 1.0/2**(WORD_LENGTH - 1);
  2604.   type FRACTION is delta DEL range -1.0..1.0 - DEL;
  2605.  
  2606. FORMAT:
  2607.  
  2608. fixed_point_constraint ::= as in Ada, except that it must be static
  2609.  
  2610. SQL  has no data type directly corresponding to Ada fixed point  types.   The
  2611. database  representation used for Ada fixed point values is system dependent,
  2612. depending  on the ranges and accuracies desired versus that supported by  the
  2613. various  database types,  and the efficiencies of processing  with  different
  2614. database  types.   The  database representation of any fixed point type  must
  2615. support  the model numbers of that type,  including the required accuracy  of
  2616. operations.   The largest possible number of binary digits in the mantissa of
  2617. fixed point model numbers that can be handled by Ada/SQL through the underly-
  2618. ing DBMS is given by the system dependent named number DATABASE.MAX_MANTISSA.
  2619. Likewise,  the  smallest  delta that can be supported in a fixed  point  con-
  2620. straint  that has the range constraint -1.0..1.0 is given by  DATABASE.FINE_-
  2621. DELTA.
  2622.  
  2623. For each fixed point database type or subtype T,  T_NOT_NULL, or T_NOT_NULL_-
  2624. UNIQUE,  referenced within a schema,  the SQL function generator will  define
  2625. named  numbers T_SAFE_SMALL and T_SAFE_LARGE,  corresponding to the similarly
  2626. named attributes of T (or T_NOT_NULL,  T_NOT_NULL_UNIQUE,  etc.).  The attri-
  2627. butes  of  T  yield information on the accuracy and range  used  by  the  Ada
  2628. implementation; the corresponding named numbers yield similar information for
  2629. the  DBMS  implementation.   The DBMS itself may support a greater or  lesser
  2630. accuracy and range (for the underlying base type;  it must adequately support
  2631. the  accuracy  and range of T),  but the named numbers will  not  exceed  the
  2632. accuracy or range of the Ada implementation.  The SQL function generator will
  2633. also  produce  the BOOLEAN constants T_DATABASE_ROUNDS  and  T_DATABASE_OVER-
  2634. FLOWS,  corresponding  to the attributes T'MACHINE_ROUNDS and T'MACHINE_OVER-
  2635. FLOWS, except with values applicable to the DBMS implementation.
  2636.  
  2637. 4.7 Special Considerations - LRM section 3.6 - array type definition
  2638.  
  2639. FUNCTION:
  2640.  
  2641. Define array types
  2642.  
  2643. EXAMPLE:
  2644.  
  2645.   type VECTOR     is array(INTEGER range <>) of REAL; -- taken from LRM 3.6
  2646.   type MATRIX     is array(INTEGER range <>, INTEGER range <>) of REAL;
  2647.   type BIT_VECTOR is array(POSITIVE range <>) of BOOLEAN;
  2648.   type ROMAN      is array(POSITIVE range <>) of ROMAN_DIGIT;
  2649.  
  2650.   type TABLE    is array(1..10) of INTEGER;
  2651.   type SCHEDULE is array(DAY) of BOOLEAN;
  2652.   type LINE     is array(1..MAX_LINE_SIZE) of CHARACTER;
  2653.  
  2654. FORMAT:
  2655.  
  2656. array_type_definition ::= as in Ada,  except that all subtype indications and
  2657.      ranges used must either be static or depend on a discriminant.  Further-
  2658.      more,  the component subtype must be permitted as the type of a database
  2659.      column.
  2660.  
  2661. Two classes of arrays are supported by Ada/SQL:
  2662.  
  2663. (1)  Arrays  with  components of a character type (not  necessarily  the  Ada
  2664. CHARACTER  type)  that  includes only the ASCII characters  represented  with
  2665. their usual codes,  and with a single index of an integer type.   Such arrays
  2666. are  represented within the database as SQL strings,  and so  are  considered
  2667. scalar by Ada/SQL.  The Ada/SQL automated tools will recognize the predefined
  2668. types CHARACTER and STRING.
  2669.  
  2670. (2) All other arrays, which are composite objects in both Ada and Ada/SQL.
  2671.  
  2672. Ada/SQL  operations  available on string arrays correspond to the SQL  opera-
  2673. tions on strings.  Operations available on other arrays are the same as those
  2674. available on private types (see LRM section 3.3.1),  except that selection of
  2675. discriminants is replaced with indexing.   Slicing is also available on  non-
  2676. string arrays with a single index.  Indexing and slicing are not available on
  2677. string arrays, since SQL provides no substring capability.
  2678.  
  2679. The schema translator will determine the maximum index range of an array used
  2680. as  a database column for the purpose of allocating database storage as  fol-
  2681. lows:
  2682.  
  2683. (1)  For a constrained array type/subtype that does not depend on a discrimi-
  2684. nant, the bounds are given by the index constraint.
  2685.  
  2686. (2)  An  index constraint must be specified (by Ada semantics) for  a  record
  2687. component that is of an unconstrained array type.   If either bound does  not
  2688. depend on a discriminant,  then that value is used as the corresponding data-
  2689. base bound.   If the lower bound depends on a discriminant of type/subtype D,
  2690. then  the  database  lower bound is taken as the maximum of D'FIRST  and  the
  2691. lower  bound  of the index type/subtype.   If the upper bound  depends  on  a
  2692. discriminant of type/subtype D, then the database upper bound is taken as the
  2693. minimum of D'LAST and the upper bound of the index type/subtype.
  2694.  
  2695. (3) If a null range is determined from either (1) or (2) above,  as appropri-
  2696. ate,  then  the type/subtype of the column must permit null  values,  because
  2697. Ada/SQL will only permit nulls to be stored within such a column, which would
  2698. not be very useful.
  2699.  
  2700. Consideration must be given to the index ranges that will be used to allocate
  2701. database storage for arrays.   The Ada/SQL system will determine a mapping of
  2702. arrays  onto  the underlying database storage,  and larger index  ranges  may
  2703. require  greater database resources.   Excessively large index ranges may not
  2704. even be supportable by the underlying DBMS,  in which case the Ada/SQL  auto-
  2705. mated  tools  will issue diagnostics.   For example,  the components  in  the
  2706. following  declarations  could each contain as many as POSITIVE'LAST  charac-
  2707. ters:
  2708.  
  2709.   type PHONE_BOOK(NAME_LENGTH   : POSITIVE := 30;
  2710.                   NUMBER_LENGTH : POSITIVE := 12) is
  2711.     record
  2712.       NAME   : STRING(1..NAME_LENGTH);
  2713.       NUMBER : STRING(1..NUMBER_LENGTH);
  2714.     end record;
  2715.  
  2716. Instead,  the definitions should limit the ranges of the discriminants or the
  2717. possible bounds of the arrays.   The hybrid example below shows the discrimi-
  2718. nant  range limited for the NAME component and the array length  limited  for
  2719. the NUMBER component:
  2720.  
  2721.   subtype PHONE_NAME_LENGTH is POSITIVE range 1..30;
  2722.   subtype PHONE_NUMBER_LENGTH is POSITIVE range 1..12;
  2723.  
  2724.   type PHONE_NUMBER is array(PHONE_NUMBER_LENGTH range <>) of CHARACTER;
  2725.  
  2726.   type PHONE_BOOK
  2727.        (NAME_LENGTH   : PHONE_NAME_LENGTH := PHONE_NAME_LENGTH'LAST;
  2728.         NUMBER_LENGTH : POSITIVE := PHONE_NUMBER_LENGTH'LAST) is
  2729.     record
  2730.       NAME   : STRING(1..NAME_LENGTH);
  2731.       NUMBER : PHONE_NUMBER(1..NUMBER_LENGTH);
  2732.     end record;
  2733.  
  2734. 4.7 Special Considerations - LRM section 3.7 - record types
  2735.  
  2736. FUNCTION:
  2737.  
  2738. Record  type declarations are used within schemas to declare database  tables
  2739. and  also to indicate groupings of fields into subrecords for convenience and
  2740. uniqueness constraints.
  2741.  
  2742. EXAMPLE:
  2743.  
  2744.   type DATE is                     -- taken from LRM section 3.7, not a
  2745.     record                         --  database table due to its later use
  2746.       DAY   : INTEGER range 1..31; --  as a component of another record type
  2747.       MONTH : MONTH_NAME;
  2748.       YEAR  : INTEGER range 0..4000;
  2749.     end record;
  2750.  
  2751.   type STOCK_TRANSACTION is         -- a database table that includes the
  2752.     record                          --  above subrecord
  2753.       TRADE_DATE  : DATE;           -- component types are assumed to be
  2754.       ACCOUNT     : ACCOUNT_NUMBER; --  defined appropriately
  2755.       COMPANY     : COMPANY_NAME;
  2756.       SHARES      : SHARE_COUNT;
  2757.       TRANSACTION : BOUGHT_OR_SOLD;
  2758.       PRICE       : STOCK_PRICE;
  2759.     end record;
  2760.  
  2761. FORMAT:
  2762.  
  2763. record_type_definition ::= as in Ada,  except that types/subtypes and expres-
  2764.      sions  must either be static or depend on a discriminant of the  record.
  2765.      Record components must be of types/subtypes that are legal for  database
  2766.      columns.
  2767.  
  2768. The declaration of a record type also declares a database table,  of the same
  2769. name as the record type, if:
  2770.  
  2771. (1) It occurs within a schema package, and
  2772.  
  2773. (2)  The  record  type name is not used as the type mark of  a  component  of
  2774. another  record declared within the same schema package.   For the purpose of
  2775. this determination, a subtype name differing only in the use of the _NOT_NULL
  2776. or _NOT_NULL_UNIQUE suffixes is considered to be the same name.
  2777.  
  2778. Each component of a record declaring a database table defines a column within
  2779. that table.   The column names are the same as the component names,  and  the
  2780. SQL  types  of the columns are as discussed with each class of type  declara-
  2781. tion.   Columns defined as record or array types are composite columns,  with
  2782. the underlying database columns being the non-composite subcomponents of  the
  2783. types.   Composite  columns may be given the constraints _NOT_NULL or  _NOT_-
  2784. NULL_UNIQUE  only if all subcomponents are constrained to prohibit null  val-
  2785. ues.   Within  the data manipulation language,  composite columns may be used
  2786. wherever  private  types may be used,  as discussed for  LRM  section  3.3.1,
  2787. except  that discriminant selection should be replaced with selection of  any
  2788. component for record columns and indexing for array columns.
  2789.  
  2790. There  is no way to indicate whether subcolumns not depending on a  discrimi-
  2791. nant are null when referencing composite columns, although the entire compos-
  2792. ite  column  may be specified as null by using an indicator  variable.   When
  2793. writing to the database or specifying values for comparison,  such subcolumns
  2794. are taken to be non-null unless the entire composite column is null.   A null
  2795. value denoted by an indicator variable causes all subcolumns, including those
  2796. which would otherwise be non-null based on discriminant values, to be consid-
  2797. ered null.   When reading from the database, the indicator variable is set to
  2798. indicate null if and only if all subcolumns are null.   If any subcolumns not
  2799. depending  on  a  discriminant are null in a composite  column  that  is  not
  2800. completely  null,  then the NULL_ERROR exception will be raised as if a  null 
  2801. value  had  been retrieved without an indicator variable specified (see  com-
  2802. ments on dpANS section 6.6).   For program variables of a composite type used
  2803. to  retrieve composite columns,  component values not depending on  discrimi-
  2804. nants  are  left  undefined if the corresponding subcolumn  contains  a  null
  2805. value.  If the individual null status of subcolumns not depending on discrim-
  2806. inants is important, then all subcolumns should be referenced individually.
  2807.  
  2808. When adding rows to a table with INSERT_INTO statements,  it is not necessary
  2809. to  specify  values for all columns.   SQL uses null values  for  unspecified
  2810. columns,  but Ada/SQL uses the default expressions given for the record  com-
  2811. ponents  used  to define the table,  if such defaults are  provided.   Nested
  2812. levels  of subrecords may give rise to conflicting default  expressions;  the
  2813. default values used are those that would be used by Ada for an object of  the
  2814. record  type whose declaration also declared the database table to which rows
  2815. are  being added.   In short,  outer defaults take precedence over inner  de-
  2816. faults.   When inserting a new row into a table, null values are used for all
  2817. columns without explicit or default values.   It is an SQL error, returned in
  2818. the standard fashion of the data manipulation language,  to attempt to insert
  2819. a  null  value into a column not permitting null  values.   In  other  words,
  2820. INSERT_INTO  statements  must specify values for all non-null columns of  the
  2821. table  in question,  either by explicit reference or by  default  expressions
  2822. obtained from the declarations of the applicable record types.
  2823.  
  2824. 4.7 Special Considerations - LRM section 3.7.1 - discriminants
  2825.  
  2826. FUNCTION:
  2827.  
  2828. As in Ada,  define subrecords containing variable-length arrays.  Also define 
  2829. variant parts of records.                                                     
  2830.  
  2831. EXAMPLE:
  2832.  
  2833.   type SHIP_NAME_LENGTH is range 1..20;
  2834.  
  2835.   type SHIP_NAME_STRING is new STRING;
  2836.  
  2837.   type SHIP_NAME(LENGTH : SHIP_NAME_LENGTH := SHIP_NAME_LENGTH'LAST) is
  2838.     record
  2839.       NAME : SHIP_NAME_STRING(1..LENGTH);
  2840.     end record;
  2841.  
  2842. FORMAT:
  2843.  
  2844. discriminant_part  ::=  as in Ada,  except that all type  marks  and  default
  2845.      expressions used must either be static or depend on a discriminant
  2846.  
  2847. Null  values  are not permitted in discriminant columns,  regardless  of  the
  2848. type/subtype  name of the discriminant.   In keeping with Ada  philosophy,  a
  2849. database  discriminant  value may be modified only by  updating  all  columns
  2850. defined  by the record type containing the discriminant.   Discriminants  may 
  2851. also be used to choose variant parts within records.  When updating discrimi- 
  2852. nant  values,  values need not and may not be specified for variant parts not 
  2853. chosen by the discriminant values.                                            
  2854.  
  2855. 4.7 Special Considerations - LRM section 8.5 - renaming declaration
  2856.  
  2857. FUNCTION:
  2858.  
  2859. Provide alternate names for entities.
  2860.  
  2861. EXAMPLE:
  2862.  
  2863.   MAXLEN : INTEGER renames SHIP_NAME_MAXIMUM_LENGTH; -- renaming an object
  2864.   package SHIPS renames SHIP_DATA_DEFINITION_PACKAGE; -- renaming a package
  2865.  
  2866. FORMAT:
  2867.  
  2868. renaming_declaration ::= as in Ada,  except that only constants and  packages
  2869.      may be renamed within schema packages
  2870.  
  2871. Renaming  declarations  permitted  within schema packages are  restricted  to
  2872. those that rename entities that may be declared or referenced within schemas.
  2873. Hence, only constants and packages may be renamed.
  2874.  
  2875. 4.7 Special Considerations - LRM section 13.1 - representation clause
  2876.  
  2877. FUNCTION:
  2878.  
  2879. Within schemas, specify how enumeration types are to be represented.
  2880.  
  2881. EXAMPLE:
  2882.  
  2883.   type CLASSIFICATION is (UNCLASSIFIED, CONFIDENTIAL, SECRET, TOP_SECRET);
  2884.  
  2885.   for CLASSIFICATION use (1,2,4,8); -- an enumeration representation clause
  2886.  
  2887. FORMAT:
  2888.  
  2889. representation_clause ::= as in Ada
  2890.  
  2891. All types of representation clauses may be used within schemas, as they apply
  2892. to the types and objects that may be declared.   The Ada/SQL automated  tools
  2893. will  ignore all representation clauses other than enumeration representation
  2894. clauses, however.  Enumeration representation clauses will, if possible, have
  2895. the effect of changing the database representation for enumeration types.
  2896.  
  2897. 5.1 - 5.3 Module Language
  2898.  
  2899. There  are  no corresponding sections within the Ada/SQL  standard.   Ada/SQL
  2900. uses  an embedded language,  and therefore does not require the  module  lan-
  2901. guage.
  2902.  
  2903. 6.1 <close statement>
  2904.  
  2905. FUNCTION:
  2906.  
  2907. Close a cursor.
  2908.  
  2909. EXAMPLE:
  2910.  
  2911.   CURSOR : CURSOR_NAME;
  2912.   . . .
  2913.   CLOSE(CURSOR);
  2914.  
  2915. FORMAT:
  2916.  
  2917. <close statement> ::=
  2918.      CLOSE ( <cursor name> ) ;
  2919.  
  2920. The <close statement> is an Ada procedure.
  2921.  
  2922. <cursor name> ::= a program variable of type CURSOR_NAME,  which is a private
  2923.      type defined by the implementation
  2924.  
  2925. 6.2 <commit statement>
  2926.  
  2927. FUNCTION:
  2928.  
  2929. Terminate the current transaction with commit.                                
  2930.  
  2931. EXAMPLE:
  2932.  
  2933.   COMMIT_WORK;
  2934.  
  2935. FORMAT:
  2936.  
  2937. <commit statement> ::=
  2938.      COMMIT_WORK ;
  2939.  
  2940. The <commit statement> is an Ada procedure.
  2941.  
  2942. 6.3 <declare cursor>
  2943.  
  2944. FUNCTION:
  2945.  
  2946. Define a cursor.
  2947.  
  2948. EXAMPLE:
  2949.  
  2950.   CURSOR : CURSOR_NAME;
  2951.  
  2952.   package E is new ANALYST_CORRELATION_NAME; -- employees \ see section 3.20  
  2953.   package M is new ANALYST_CORRELATION_NAME; -- managers  /                   
  2954.   . . .
  2955.                                                                               
  2956.   DECLAR ( CURSOR , CURSOR_FOR =>
  2957.     SELEC     ( NAME & SALARY & MANAGER,
  2958.     FROM     => ANALYST ),
  2959.     ORDER_BY => MANAGER & DESC(SALARY) );
  2960.  
  2961.     -- variations: ORDER_BY => 3 & DESC(2)
  2962.     --             ORDER_BY => ASC(3) & DESC(SALARY), etc.
  2963.  
  2964.   DECLAR ( CURSOR , CURSOR_FOR =>
  2965.         SELEC  ( NAME & SALARY & MANAGER,
  2966.         FROM  => ANALYST,
  2967.         WHERE => SALARY > 25_000.00 )
  2968.     & UNION (
  2969.         SELEC  ( E.NAME & E.SALARY & E.MANAGER,
  2970.         FROM  => E.ANALYST & M.ANALYST, -- see section 3.20                   
  2971.         WHERE => EQ ( E.MANAGER , M.NAME )
  2972.         AND      E.SALARY > M.SALARY ) ) );
  2973.  
  2974.       -- variations: UNION_ALL
  2975.  
  2976. FORMAT:
  2977.  
  2978. <declare cursor> ::=
  2979.      DECLAR ( <cursor name> , CURSOR_FOR =>
  2980.        <cursor specification> ) ;
  2981.  
  2982. The  <declare  cursor>  statement is an Ada procedure named DECLAR  (the  SQL
  2983. keyword DECLARE is an Ada reserved word).   Its first parameter is the cursor
  2984. to be declared.   Its second parameter is named CURSOR_FOR to retain the  SQL
  2985. keyword,  and  is  a  specification of the retrieval to be performed  by  the
  2986. cursor.  The third parameter (discussed below as part of the <cursor specifi-
  2987. cation>) is named ORDER_BY to handle the <order by clause>.
  2988.  
  2989. <cursor name> ::= see section 6.1
  2990.  
  2991. <cursor specification> ::=
  2992.      <query expression> [ ,
  2993.      <order by clause> ]
  2994.  
  2995. The  <order  by  clause> is optional.   Since it is the  third  parameter  to
  2996. DECLAR, a comma must separate it from the <query expression>.
  2997.  
  2998. <query expression> ::=
  2999.        <query term>
  3000.       <query expression> & { UNION | UNION_ALL } ( <query term> )
  3001.       <query expression> & { UNION | UNION_ALL }   <query term>
  3002.  
  3003. Since  UNION and UNION_ALL cannot be made infix operators,  the ampersand  is
  3004. used to connect the two items being UNIONed.   UNION and UNION_ALL are  func-
  3005. tions  on <query term>s that are used to keep the SQL keywords in the  opera-
  3006. tion and that return an indication of whether or not the ALL option was used.
  3007. Parentheses  are required around UNION and UNION_ALL's parameter by Ada  syn-
  3008. tax;  they  are shown as optional here because they may be supplied from  the
  3009. next production, which is used within SQL to show precedence of UNIONs.
  3010.  
  3011. <query term> ::=
  3012.      <query specification>  ( <query expression> )
  3013.  
  3014. <query specification> ::= see section 3.25.
  3015.  
  3016. <order by clause> ::=
  3017.      ORDER_BY => <sort specification> [ { & <sort specification> } ... ]
  3018.  
  3019. As noted above,  the third parameter to DECLAR is named ORDER_BY.   The <sort
  3020. specification>s cannot be joined by commas in Ada; so ampersands are used.
  3021.  
  3022. <sort specification> ::=
  3023.               <sort column specification>
  3024.       ASC  ( <sort column specification> )
  3025.       DESC ( <sort column specification> )
  3026.  
  3027. Ascending (default) and descending sorts cannot be indicated by appending the
  3028. ASC  or DESC keyword to the column indicator;  ASC and DESC are instead  made
  3029. Ada functions.
  3030.  
  3031. <sort column specification> ::=
  3032.      <column number>  <column specification>
  3033.  
  3034. <column number> ::= a positive integer of type COLUMN_NUMBER
  3035.  
  3036. Ada's typing is used to define a <column number>.
  3037.  
  3038. <column specification> ::= see section 3.7
  3039.  
  3040. 6.4 <delete statement: positioned>
  3041.  
  3042. FUNCTION:
  3043.  
  3044. Delete a row of a table based on the current position of a cursor.
  3045.  
  3046. EXAMPLE:
  3047.  
  3048.   CURSOR : CURSOR_NAME;
  3049.   . . .
  3050.   DELETE_FROM ( ANALYST,
  3051.   WHERE_CURRENT_OF => CURSOR );
  3052.  
  3053. FORMAT:
  3054.  
  3055. <delete statement: positioned> ::=
  3056.      DELETE_FROM ( <table name> ,
  3057.      WHERE_CURRENT_OF => <cursor name> ) ;
  3058.  
  3059. The <delete statement: positioned> is an Ada procedure.
  3060.  
  3061. <table name> ::= see section 3.20
  3062.  
  3063. <cursor name> ::= see section 6.1
  3064.  
  3065. 6.5 <delete statement: searched>
  3066.  
  3067. FUNCTION:
  3068.  
  3069. Delete rows of a table based on a search criterion.
  3070.  
  3071. EXAMPLE:
  3072.  
  3073.   DELETE_FROM ( ANALYST,
  3074.   WHERE      => SALARY > 25_000.00 );
  3075.  
  3076.   DELETE_FROM ( ANALYST );
  3077.  
  3078. FORMAT:
  3079.  
  3080. <delete statement: searched> ::=
  3081.      DELETE_FROM ( <table name> [ ,
  3082.      WHERE      => <search condition> ] ) ;
  3083.  
  3084. The  <delete  statement:  searched> is an Ada procedure.   The WHERE  keyword
  3085. names the second parameter.  The WHERE parameter may be omitted.
  3086.  
  3087. <table name> ::= see section 3.20
  3088.  
  3089. <search condition> ::= see section 3.18
  3090.  
  3091. 6.6 <fetch statement>
  3092.  
  3093. FUNCTION:
  3094.  
  3095. Position a cursor on the next row of a table and assign values in that row to
  3096. program variables.
  3097.  
  3098. EXAMPLE:
  3099.  
  3100.   CURRENT_EMPLOYEE : ANALYST_NAME;
  3101.   HIS_SALARY       : ANALYST_SALARY;
  3102.   HIS_MANAGER      : MANAGER_NAME;
  3103.   CURSOR           : CURSOR_NAME;
  3104.   LAST             : NATURAL;
  3105.   IND_VAR          : INDICATOR_VARIABLE;                                      
  3106.   . . .
  3107.   DECLAR ( CURSOR , CURSOR_FOR =>
  3108.     SELEC ( NAME & SALARY & MANAGER,
  3109.     FROM => ANALYST ) );
  3110.   FETCH ( CURSOR );
  3111.   INTO ( CURRENT_EMPLOYEE , LAST );
  3112.   INTO ( HIS_SALARY , IND_VAR );         -- variation: INTO ( HIS_SALARY );   
  3113.   INTO ( HIS_MANAGER, LAST, IND_VAR );                                        
  3114.  
  3115. FORMAT:
  3116.  
  3117. <fetch statement> ::=
  3118.      FETCH ( <cursor name> ) ;
  3119.      INTO ( <result specification> [ , <cursor name> ] ) ;                    
  3120.  [ { INTO ( <result specification> [ , <cursor name> ] ) ; } ... ]            
  3121.  
  3122. It  is  not  possible to string the result variables together  as  with  SQL.
  3123. Consequently,  a FETCH procedure call is followed by as many calls to INTO as
  3124. are  required  to retrieve the values of each column in the row.   Each  INTO
  3125. returns one column value.   The NOT_FOUND_ERROR exception will be raised if a 
  3126. FETCH is performed on a cursor for which all rows (if any) have already  been 
  3127. returned.   If  several tasks within the same program are simultaneously per- 
  3128. forming  database  retrievals,  the <cursor name> used in the FETCH  must  be 
  3129. specified  as  the final parameter to INTO procedures  for  that  FETCH.   If 
  3130. simultaneous  database retrievals are not being performed,  the <cursor name> 
  3131. parameter may be omitted from the INTO calls.                                 
  3132.  
  3133. <cursor name> ::= see section 6.1
  3134.  
  3135. <result specification> ::=
  3136.     <result program variable>
  3137.       [ , <last variable> ] [ , <indicator variable> ]
  3138.  
  3139. <result  program  variable> ::= program variable to obtain column value  from
  3140.      database,  which must be of a type comparable with that of the  database
  3141.      column  being  retrieved.   Program variables within <result  specifica- 
  3142.      tion>s may also be expressed as type conversions,  as would be legal for 
  3143.      any Ada out actual parameter.                                            
  3144.  
  3145. <last variable>  ::= program variable to obtain the value of the  last  index
  3146.      position  used  in  retrieving array values.   Used when and  only  when
  3147.      <result program variable> is of type array.  For one dimensional arrays,
  3148.      <last variable> is of the same type as the array index.   For arrays  of
  3149.      higher  dimensionality,  <last  variable>  is a record  with  components
  3150.      corresponding to each array index type.   The record type, named A_LAST,
  3151.      where A, A_NOT_NULL, or A_NOT_NULL_UNIQUE is the name of the array type,
  3152.      is  defined by the SQL function generator for all schema  packages  con-
  3153.      taining a database column or subcolumn of the array type.  Components of
  3154.      the record are named LAST_1, LAST_2, etc.
  3155.  
  3156. <indicator  variable> ::= optional program variable of  type  INDICATOR_VARI-
  3157.      ABLE, set to NULL_VALUE if the database column retrieved contains a null 
  3158.      value,  else  set  to NOT_NULL.   If a null value is retrieved from  the
  3159.      database but no <indicator variable> is specified, the NULL_ERROR excep- 
  3160.      tion will be raised.                                                     
  3161.  
  3162. 6.7 <insert statement>
  3163.  
  3164. FUNCTION:
  3165.  
  3166. Create new rows in a table.
  3167.  
  3168. EXAMPLE:
  3169.  
  3170.   NEW_EMPLOYEE : ANALYST_NAME;
  3171.   HIS_SALARY   : ANALYST_SALARY;
  3172.   HIS_MANAGER  : MANAGER_NAME;
  3173.   . . .
  3174.   INSERT_INTO ( ANALYST ( EMPLOYEE & SALARY & MANAGER ) ,
  3175.     VALUES <= NEW_EMPLOYEE and HIS_SALARY and HIS_MANAGER );                  
  3176.  
  3177.   INSERT_INTO ( ANALYST ,
  3178.     SELEC ( '*',
  3179.     FROM => NEW_ANALYST_FILE ) );
  3180.  
  3181.   -- assume NEW_ANALYST_FILE is another database table structured identically
  3182.   --   to the ANALYST table
  3183.  
  3184. FORMAT:
  3185.  
  3186. <insert statement> ::=
  3187.      INSERT_INTO ( <table name> [ ( <insert column list> ) ] ,
  3188.    { VALUES <= <insert value list> }  <query specification> ) ;              |
  3189.  
  3190. The  INSERT  INTO statement is a function with  two  parameters.   The  first
  3191. parameter  indicates the table and (optionally) columns to be  affected.   If 
  3192. the <insert column list> is specified,  then the <table name> is expressed as
  3193. a  function with one parameter (the <insert column list>).   The  parentheses 
  3194. around the Ada function parameter exactly match the SQL parentheses.   If the
  3195. <insert  column list> is not specified,  then the <table name> is a  function
  3196. with  no  parameters.   A  comma separates the first and second  argument  to
  3197. INSERT_INTO.  The second argument can be either an explicit list of values or
  3198. a <query specification>.   For the explicit list of values,  the SQL  keyword 
  3199. VALUES  is  followed  by an Ada/SQL "gets" operator (<=),  then the  list  of 
  3200. values.   The SQL parenthesis notation is not used.   A <query specification> 
  3201. is indicated by a call to the SELEC function (see section 3.25).
  3202.  
  3203. <table  name> ::= see section 3.20.   If an <insert column list> is used  and 
  3204.      the <table name> includes an <authorization identifier>, then the syntax 
  3205.      for  the <table name> is <authorization identifier>-<table  identifier>. 
  3206.      This  is  one  of the three contexts within Ada/SQL where  <table  name> 
  3207.      syntax is not the usual <authorization identifier>.<table identifier>.   
  3208.  
  3209. <insert column list> ::=
  3210.      <column name> [ { & <column name> } ... ]
  3211.  
  3212. SQL  uses commas to separate the column names,  Ada/SQL uses  ampersands  in-
  3213. stead.
  3214.  
  3215. <column name> ::= an unqualified column name
  3216.  
  3217. <insert value list> ::=
  3218.      <insert value> [ { and <insert value> } ... ]
  3219.  
  3220. SQL  uses  commas to separate the insert values,  Ada/SQL uses an  overloaded
  3221. "and" operator.
  3222.  
  3223. <insert value> ::=
  3224.      <value specification>  NULL_VALUE
  3225.  
  3226. SQL uses NULL, which is an Ada reserved word.
  3227.  
  3228. <value specification> ::= see section 3.6
  3229.  
  3230. <query specification> ::= see section 3.25
  3231.  
  3232. 6.8 <open statement>
  3233.  
  3234. FUNCTION:
  3235.  
  3236. Open a cursor.
  3237.  
  3238. EXAMPLE:
  3239.  
  3240.   CURSOR : CURSOR_NAME;
  3241.   . . .
  3242.   OPEN(CURSOR);
  3243.  
  3244. FORMAT:
  3245.  
  3246. <open statement> ::=
  3247.      OPEN ( <cursor name> ) ;
  3248.  
  3249. The <open statement> is an Ada procedure.
  3250.  
  3251. <cursor name> ::= a program variable of type CURSOR_NAME
  3252.  
  3253. Note  that SQL evaluates program variables used to declare a cursor when  the 
  3254. cursor is opened.  In Ada/SQL, these program variables are evaluated when the 
  3255. cursor is declared.                                                           
  3256.  
  3257. 6.9 <rollback statement>
  3258.  
  3259. FUNCTION:
  3260.  
  3261. Terminate the current transaction with rollback.                              
  3262.  
  3263. EXAMPLE:
  3264.  
  3265.   ROLLBACK_WORK;
  3266.  
  3267. FORMAT:
  3268.  
  3269. <rollback statement> ::=
  3270.      ROLLBACK_WORK ;
  3271.  
  3272. The <rollback statement> is an Ada procedure.
  3273.  
  3274. 6.10 <select statement>
  3275.  
  3276. FUNCTION:
  3277.  
  3278. Specify  a  table  and assign the values in the single row of that  table  to
  3279. program variables.
  3280.  
  3281. EXAMPLE:
  3282.  
  3283.   DESIRED_EMPLOYEE : ANALYST_NAME;
  3284.   HIS_SALARY       : ANALYST_SALARY;
  3285.   HIS_MANAGER      : MANAGER_NAME;
  3286.   LAST             : NATURAL;
  3287.   . . .
  3288.   SELEC  ( SALARY & MANAGER ,           -- variations: SELECT_ALL,
  3289.   FROM  => ANALYST,                     --             SELECT_DISTINCT
  3290.   WHERE => EQ(NAME,DESIRED_EMPLOYEE) );
  3291.   INTO(HIS_SALARY);
  3292.   INTO(HIS_MANAGER,LAST);
  3293.  
  3294. FORMAT:
  3295.  
  3296. <select statement> ::=
  3297.    [ SELEC  SELECT_ALL | SELECT_DISTINCT ] ( <select list> ,
  3298.      <table expression> ) ;
  3299.      INTO ( <result specification> ) ;
  3300.  [ { INTO ( <result specification> ) ; } ... ]
  3301.  
  3302. The SELECT INTO statement is an Ada procedure.  It is not possible to specify
  3303. the  ALL or DISTINCT keywords separately,  so they are part of the  procedure
  3304. name if used.  The name of the procedure is SELEC if neither keyword is used,
  3305. since SELECT is an Ada reserved word.   The SELECT INTO procedures have three
  3306. parameters which must,  of course, be surrounded by parentheses and separated
  3307. by  commas.   The first is the <select list>,  as described in section  3.25.
  3308. The  second  and  third parameters are the FROM and WHERE  clauses  from  the
  3309. <table expression>, and so are named FROM and WHERE, respectively.  (SQL does
  3310. not  permit GROUP BY and HAVING clauses in <select statement>s.   <table  ex-
  3311. pression>s  are  discussed in section 3.19;  when used within <select  state-
  3312. ment>s the optional <group by clause> and <having clause> must be omitted.)
  3313.  
  3314. The INTO keyword cannot be embedded within the SELECT INTO statement in  Ada,
  3315. nor  can result variables be listed together,  separated by  commas.   Conse-
  3316. quently, one INTO call for each column retrieved is made following the SELECT
  3317. INTO  statement,  with the exact same format and meaning as described in sec-
  3318. tion  6.6  for the FETCH statement,  except that a <cursor name> may  not  be 
  3319. specified.   Consequently,  tasks within a program must not perform more than 
  3320. one  simultaneous <select statement>.   If multiple retrievals must  be  per- 
  3321. formed  simultaneously,  FETCH  statements  must be used to  avoid  erroneous 
  3322. results.   The  NOT_FOUND_ERROR exception will be raised if the  SELECT  INTO 
  3323. statement retrieved no rows,  and UNIQUE_ERROR will be raised if it retrieved 
  3324. more than one.  The values returned by the INTO statements are undefined when
  3325. called directly following errors.
  3326.  
  3327. <select list> ::= see section 3.25
  3328.  
  3329. <table expression> ::= see section 3.19
  3330.  
  3331. <result specification> ::= see section 6.6
  3332.  
  3333. 6.11 <update statement: positioned>
  3334.  
  3335. FUNCTION:
  3336.  
  3337. Modify a row of a table based on a cursor's current position.
  3338.  
  3339. EXAMPLE:
  3340.  
  3341.   CURSOR : CURSOR_NAME;
  3342.   . . .
  3343.   UPDATE ( ANALYST ,
  3344.   SET   => SALARY  <= 2.0*SALARY
  3345.        and MANAGER <= NULL_VALUE ,                                            
  3346.   WHERE_CURRENT_OF => CURSOR );
  3347.  
  3348. FORMAT:
  3349.  
  3350. <update statement: positioned> ::=
  3351.      UPDATE ( <table name> ,
  3352.      SET   => <set clause> [ { and <set clause> } ... ] ,                     
  3353.      WHERE_CURRENT_OF => <cursor name> ) ;
  3354.  
  3355. The  Ada UPDATE procedure has three parameters:  the name of the table to  be
  3356. updated,  a  list  of columns and values to be set,  and the cursor  used  to 
  3357. determine  the  current row.   Named associations on the last two  parameters 
  3358. serve  to get the SQL keywords into the Ada program.   The <set clause>s  are
  3359. separated by "and"s in Ada/SQL, instead of commas as in SQL.                  
  3360.  
  3361. <table name> ::= see section 3.20
  3362.  
  3363. <set clause> ::=
  3364.      <object column> <= { <value expression>  NULL_VALUE }                   |
  3365.  
  3366. <object column> ::= <column name>                                             
  3367.  
  3368. <column name> ::= an unqualified column name                                  
  3369.  
  3370. <value expression> ::= see section 3.9                                        
  3371.  
  3372. The  = operator cannot be overloaded for use in a <set  clause>,  so  Ada/SQL
  3373. uses <= instead, to be indicative of the direction of the assignment.  NULL_-
  3374. VALUE is used instead of NULL, which is an Ada reserved word.
  3375.  
  3376. <cursor name> ::= see section 6.1
  3377.  
  3378. 6.12 <update statement: searched>
  3379.  
  3380. FUNCTION:
  3381.  
  3382. Update rows of a table based on a search condition.
  3383.  
  3384. EXAMPLE:
  3385.  
  3386.   GENEROUS_BOSS : MANAGER_NAME;
  3387.   . . .
  3388.   UPDATE ( ANALYST ,
  3389.   SET   => SALARY <= 1.2*SALARY ,
  3390.   WHERE => EQ(MANAGER,GENEROUS_BOSS) );
  3391.  
  3392.   UPDATE ( ANALYST,
  3393.   SET   => SALARY <= 1.05*SALARY ); -- cost of living raise
  3394.  
  3395. FORMAT:
  3396.  
  3397. <update statement: searched> ::=
  3398.      UPDATE ( <table name> ,
  3399.      SET   => <set clause> [ { and <set clause> } ... ] [ ,                   
  3400.      WHERE => <search condition> ] ) ;
  3401.  
  3402. This  version of the Ada UPDATE procedure has three parameters:  the name  of
  3403. the  table  to be updated,  a list of columns and values to be set,  and  the 
  3404. search condition used to determine which rows are to be updated.   The search 
  3405. condition is optional.   Named associations on the last two parameters  serve
  3406. to get the SQL keywords into the Ada program.  The <set clause>s are separat-
  3407. ed by "and"s instead of by commas as in SQL.                                  
  3408.  
  3409. <table name> ::= see section 3.20
  3410.  
  3411. <set clause> ::= see section 6.11
  3412.  
  3413. <search condition> ::= see section 3.18
  3414.  
  3415. Appendix A. <embedded SQL host program>
  3416.  
  3417. The definition is extended to include
  3418.  
  3419.      <embedded SQL host program> ::= <embedded SQL Ada program>
  3420.  
  3421. An  <embedded  SQL  Ada program> consists of an Ada  program  which  includes
  3422. Ada/SQL  data  manipulation statements as defined in  Section  6.   No  other
  3423. special embedded notation (such as EXEC SQL, etc., used with other languages)
  3424. is  required,  since  an <embedded SQL Ada program> conforms to  precise  Ada
  3425. syntax  and  may be directly processed by the Ada compiler rather than  being
  3426. precompiled.  This also means that program variables are used directly within
  3427. Ada/SQL statements, without the leading colon:
  3428.  
  3429.      <embedded variable name> ::= <host identifier>
  3430.  
  3431. Program  variables may be of user-defined data types as discussed in  section 
  3432. 2.2.   Operations  on database and program values must be between  comparable 
  3433. data types, as defined in section 3.9.                                        
  3434.  
  3435. Appendix B. <embedded exception declaration>
  3436.  
  3437. Error conditions in Ada/SQL always raise exceptions,  that are then processed 
  3438. in  the  normal Ada manner.   Exceptions may not be  "turned  off",  nor  may 
  3439. program  control  be  transferred in any manner other than the  standard  Ada 
  3440. exception handlers.                                                           
  3441.