home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / CONTRIB / MBASE / MBASE50.TAR / mbase / dox / build.dox < prev    next >
Encoding:
Text File  |  1992-10-28  |  10.7 KB  |  230 lines

  1. Build Documentation                                               MetalBase 5.0
  2. -------------------------------------------------------------------------------
  3.  
  4.                                   Function
  5.  
  6. Relations are built from schema files, which decribe the relation in a more
  7. human-friendly syntax.  Schema for MetalBase 4.0 and up relations take the
  8. following form (Words in brackets are optional syntax, words enclosed in <>
  9. are sample entries):
  10.  
  11.         [relation] <equipment>
  12.  
  13.         field <customer>         [type] <string> [length/*] <5> ;
  14.         field <num_purchased>    [type] <ushort> ;
  15.         field <part_number>      [type] <char>   [length/*] <4> ;
  16.         field <shop_address>     [type] <char>   [length/*] <11> ;
  17.         field <price_code>       [type] <money> ;
  18.         field <transaction>      [type] <serial> [<start 100>] ;
  19.  
  20.         index customer [on] customer                 [<with duplicates>] ;
  21.         index part     [on] part_number,price_code   [with duplicates] ;
  22.         index ix_price [on] price_code               [<with duplicates>] ;
  23.  
  24.         [<typedef <equ> >] ;
  25.  
  26.         end
  27.  
  28. Ah, but note:  4.1 and up expect to find SEMICOLONS after every line save
  29. "Relation..." and "End"!  It's okay if they're not there, but better get
  30. in the habit, 'cause report and form will choke heavily without their
  31. semicolons.
  32.  
  33. Build is the program which reads these schema and creates MetalBase-format
  34. relations from them; in addition, build released with mbase 4.0 and up can
  35. create C-style header files for interface with metalbase routines; these look
  36. somewhat like this:
  37.  
  38.    #ifndef EQUIPMENT_H
  39.    #define EQUIPMENT_H
  40.  
  41.    /*
  42.     * This file was created by MetalBase version 5.0 to reflect the structure
  43.     * of the relation "equipment".
  44.     *
  45.     * MetalBase 5.0 released October 1992 by virtual!richid@owlnet.rice.edu
  46.     *
  47.     */
  48.  
  49.    typedef struct
  50.     { char    customer[5];          /* field customer type string length 5   */
  51.       ushort  num_purch;            /* field num_purch type ushort           */
  52.       char    part_numb[4];         /* field part_numb type string length 4  */
  53.       char    shop_addr[11];        /* field shop_addr type string length 11 */
  54.       double  price_code;           /* field price_code type money           */
  55.       long    trans;                /* field trans type serial start 100     */
  56.       } equipment_str;
  57.  
  58.    #ifndef MODULE
  59.       equipment_str equipment_rec;
  60.    #else
  61.       extern equipment_str equipment_rec;
  62.    #endif
  63.  
  64.    #endif
  65.  
  66. The headers created by build include actual data (the reference to
  67.       equipment_str equipment_rec
  68. above), that should be local to only one module of a multiple .c-program
  69. executable; all the others should have the headers' variables declared as
  70. external.  So the headers use #ifdefs and check for the definition of MODULE--
  71. if it's there, variables are declared external, if not, they're declared local.
  72. That way, variables always go in this one piece of .c code.
  73.  
  74.  
  75.                              Command-Line Options
  76.  
  77. Build's command line is rather simple:
  78.       build [-q] [-h] schemaname
  79.    Where
  80.       -q indicates no output should be sent; all questions are assumed to
  81.          be answered by their defaults.
  82.       -h indiciates the header file should be created.  When used with -q,
  83.          this overrides the "No" default answer for build's question; when
  84.          used without, the header will be created without the user being
  85.          asked interactively.
  86.  
  87. The schemaname may optionally be terminated in .s; if it is missing, it is
  88. added by build.  MetalBase requires that schema be terminated in .s, and
  89. relations in .rel.
  90.  
  91.  
  92.                                    Format
  93.  
  94. The build utility released with versions 3.1 and higher supports comments at
  95. the end of the "field" and "index" lines, and that's it--that's totally
  96. pathetic.  5.0 accepts comments anywhere, like a makefile--anything after a
  97. # is ignored.  Likewise are form and report.  Empty lines are ignored.
  98.  
  99.         # Comments
  100.  
  101.         [relation] <equipment>   # Another comment.
  102.  
  103.         field <custo...
  104.  
  105.     The first line of a schema simply tells the computer what to call the new
  106. relation.  The word 'relation' is optional, as is all text enclosed in
  107. brackets in the description way up above.
  108.     The second section of a schema describes the fields of which every record
  109. in the relation will be composed.  The word immediately following 'field' is
  110. simply a name for the field.  Fields may be any of twelve types:
  111.  
  112.        string/char/character    short             unsigned short
  113.        long                     unsigned long     float
  114.        double                   money             time
  115.        date                     serial            phone
  116.  
  117.    MetalBase 4.0 and up surpass 3.2 in that they understand the following
  118.    fields that 3.2 just didn't know about:
  119.       phone  - This corresponds to the typedef mb_phone, which is actually
  120.                20 characters.  Fields stored in this type of field are parsed
  121.                before writing into the database, and sorted correctly
  122.                regardless of missing or extra pieces of data (extensions,
  123.                area codes, etc).
  124.       money  - Fields of this type are actually doubles which are automatically
  125.                rounded by MetalBase before adding them to a relation.  There
  126.                is no typedef to support this--use double.
  127.       time   - MetalBase uses a long to contain a 24-hour clock (including
  128.                precision to microseconds, though the built-in date-n-time
  129.                routines only go to seconds), and sorts and stores these
  130.                appropriately.  There is a typedef (mb_time) for these fields.
  131.       date   - MetalBase uses a long to contain a date, with range from the
  132.                year -4096 to 4096, and precision down to the day.  Routines
  133.                are also included to obtain the current date and time, and
  134.                to manipulate these formats.  There is a typedef (mb_date) for
  135.                these fields... use mb_date and mb_time fields as if they were
  136.                longs, for purposes of returning and passing values.
  137.       serial - Something that has really been missing from MetalBase.  Each
  138.                relation now has a counter, and every time a new record is
  139.                added, the counter goes up--it never goes back down.  If the
  140.                relation has a serial field, it is automatically filled in by
  141.                the system--set to this counter's value at the time of addition.
  142.                In this way, each record can be stamped with a serial code for
  143.                reference--guaranteed to be unique, record to record (and
  144.                appropriately, any index containing a serial field as part of
  145.                itself is automatically marked 'no duplicates allowed').  Serial
  146.                numbers start at zero unless the parameter "start xxx" is
  147.                specified in the schema.  Serials are represented as longs;
  148.                there is no typedef.
  149.  
  150.    The next point of interest is the number after 'length' or '*' in a
  151. character field... this number indicates the number of characters in that
  152. field.  MetalBase will allow any positive integer here your computer can
  153. handle, and if any length, or the sum of all lengths, is indeed large, _build_
  154. will prompt you to add certain lines to the beginning of your code to warn the
  155. system of excessive-length records.
  156.  
  157.     After all fields have been declared, indicies are placed on fields and
  158. combinations of fields.  MetalBase requires that you have at least one index
  159. in any relation (this is only logical--a database without indicies is nothing
  160. more than a text file).  After the word 'index' in each line, the index must
  161. be given a name (whether or not it is used it up to the programmer), followed
  162. by names of fields to be indexed, separated by commas (note that this is VERY
  163. DIFFERENT from previous versions of MetalBase.  Because version 4.0 and up read
  164. records directly into structures, the vertical bar ("|") is no longer used at
  165. all).  If more than one field name appears, MetalBase will declare that index
  166. composite.
  167.  
  168.     Occasionally certain data should not be repeated... for instance, a
  169. person obviously cannot visit a physician's office twice at the same time.  In
  170. this case, were a relation defined as consisting of the fields "name" and
  171. "visit_time", an index would be declared on "name,time" WITHOUT including the
  172. words 'with duplicates', as seen above.  If such a relation were built,
  173. MetalBase would not allow the space-time continuum to be stretched, as
  174. described previously.  Including the words 'with duplicates' after the
  175. definition of an index removes this error-catching system, for that index
  176. alone.  Use of the duplicate-catching system is entirely a case-to-case
  177. decision... there is little difference in the amount of time used between
  178. implementing and not implementing it.
  179.  
  180.     If the schema described previously exists as "/usr/joe/equip.s", the
  181. command BUILD, a utility included for use with MetalBase, will create a
  182. relation called "equipment.rel" under the directory "/usr/joe".  A sample
  183. output of BUILD is as follows:
  184.  
  185.         % build /usr/joe/equip.s
  186.         Building relation equipment under current directory
  187.  
  188.         Fields___________________________________________________
  189.         customer [char *5]            num_purchased [ushort]
  190.         part_number [char *4]         shop_address [char *11]
  191.         price_code [money]            transaction [serial @100]
  192.  
  193.         Indicies_________________________________________________
  194.         customer.....customer................Duplicates allowed
  195.         part.........part_number,price_code..Duplicates not allowed
  196.         ix_price.....price_code..............Duplicates allowed
  197.  
  198.         Continue with the creation of the relation [Y/n] ? <y>
  199.         Create header file for this relation       [y/N] ? <y>
  200.  
  201.         Header file created.
  202.         Relation created--zero entries.
  203.  
  204.         % ls -C /usr/joe
  205.         equip.s         equipment.rel       equipment.h
  206.         %
  207.  
  208.     Once a relation has been built, it contains no entries, and is ready for
  209. use.  BUILD's sole use is the creation of relations... other utilities
  210. (discussed later) must be used for maintenance of relations (if needed).
  211.  
  212.     A recent addition to build's operation is its ability to create header
  213. files for your programs.  When interacting with MetalBase routines, you must
  214. pass pointers to structures where data can be placed--build now creates these
  215. structures for you, removing chances for error along with mindless tedium.
  216. Note that, as in the above example, the line 'typedef equ' has caused the
  217. structure to be named as:
  218.  
  219.          typedef struct { ... } equ;
  220.          equ  equ_rec;
  221.  
  222. If this line (typedef equ) were not present in the schema, the structure
  223. would have been named with:
  224.  
  225.          typedef struct { ... } equipment_str;
  226.          equipment_str  equipment_rec;
  227.  
  228. That is, the relation name appended with "_str".
  229.  
  230.