AddFileRelationship.xml 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
  4. <sect1 id="AddFileRelationship">
  5. <title>AddFileRelationship</title>
  6. <para><emphasis role="bold">STD.File.AddFileRelationship<indexterm>
  7. <primary>STD.File.AddFileRelationship</primary>
  8. </indexterm><indexterm>
  9. <primary>File.AddFileRelationship</primary>
  10. </indexterm><indexterm>
  11. <primary>AddFileRelationship</primary>
  12. </indexterm>(</emphasis> <emphasis> primary, secondary,</emphasis>
  13. <emphasis> primaryfields, secondaryfields, </emphasis> <emphasis
  14. role="bold"> [ </emphasis> <emphasis>relationship </emphasis> <emphasis
  15. role="bold">]</emphasis> <emphasis>, cardinality, payload </emphasis>
  16. <emphasis role="bold"> [</emphasis> <emphasis>, description </emphasis>
  17. <emphasis role="bold">] );</emphasis></para>
  18. <informaltable colsep="1" frame="all" rowsep="1">
  19. <tgroup cols="2">
  20. <colspec colwidth="80.50pt" />
  21. <colspec />
  22. <tbody>
  23. <row>
  24. <entry><emphasis>primary</emphasis></entry>
  25. <entry>A null-terminated string containing the logical filename of
  26. the primary file.</entry>
  27. </row>
  28. <row>
  29. <entry><emphasis>secondary</emphasis></entry>
  30. <entry>A null-terminated string containing the logical filename of
  31. the secondary file.</entry>
  32. </row>
  33. <row>
  34. <entry><emphasis>primaryfields</emphasis></entry>
  35. <entry>A null-terminated string containing the name of the primary
  36. key field for the <emphasis>primary</emphasis> file. The value
  37. “__fileposition__” indicates the <emphasis>secondary</emphasis> is
  38. an INDEX that must use FETCH to access non-keyed fields.</entry>
  39. </row>
  40. <row>
  41. <entry><emphasis>secondaryfields</emphasis></entry>
  42. <entry>A null-terminated string containing the name of the foreign
  43. key field relating to the <emphasis>primary</emphasis> file.</entry>
  44. </row>
  45. <row>
  46. <entry><emphasis>relationship</emphasis></entry>
  47. <entry>A null-terminated string containing either “link” or “view”
  48. indicating the type of relationship between the
  49. <emphasis>primary</emphasis> and <emphasis>secondary</emphasis>
  50. files. If omitted, the default is “link.”</entry>
  51. </row>
  52. <row>
  53. <entry><emphasis>cardinality</emphasis></entry>
  54. <entry>A null-terminated string containing the kind of relationship
  55. between the <emphasis>primary</emphasis> and
  56. <emphasis>secondary</emphasis> files. The format is X:Y where X
  57. indicates the <emphasis>primary</emphasis> and Y indicates the
  58. <emphasis>secondary</emphasis>. Valid values for X and Y are “1” or
  59. ‘M’.</entry>
  60. </row>
  61. <row>
  62. <entry><emphasis>payload</emphasis></entry>
  63. <entry>A BOOLEAN value indicating whether the
  64. <emphasis>primary</emphasis> or <emphasis>secondary</emphasis> are
  65. payload INDEXes.</entry>
  66. </row>
  67. <row>
  68. <entry><emphasis>description</emphasis></entry>
  69. <entry>A null-terminated string containing the relationship
  70. description.</entry>
  71. </row>
  72. </tbody>
  73. </tgroup>
  74. </informaltable>
  75. <para>The <emphasis role="bold">AddFileRelationship</emphasis> function
  76. defines the relationship between two files. These may be DATASETs or
  77. INDEXes. Each record in the <emphasis>primary</emphasis> file should be
  78. uniquely defined by the <emphasis>primaryfields</emphasis> (ideally),
  79. preferably efficiently.</para>
  80. <para>The <emphasis>primaryfields</emphasis> and
  81. <emphasis>secondaryfields</emphasis> parameters can have the same format as
  82. the column mappings for a file (see the SetColumnMappings function
  83. documentation) , although they will often be just a list of fields.</para>
  84. <para>They are currently used in two different ways:</para>
  85. <para>First, the roxie browser needs a way of determining which indexes are
  86. built from which files. A “view” relationship should be added each time an
  87. index is built from a file, like this:</para>
  88. <programlisting>STD.File.AddFileRelationship(DG_FlatFileName, DG_IndexFileName,
  89. '', '', 'view', '1:1', false);</programlisting>
  90. <para>To implement the roxie browser there is no need to define the
  91. <emphasis>primaryfields</emphasis> or <emphasis>secondaryfields</emphasis>,
  92. so passing blank strings is recommended.</para>
  93. <para>Second, the browser needs a way of finding all the original
  94. information from the file from an index.</para>
  95. <para>This stage depends on the nature of the index:</para>
  96. <para>a) If the index contains all the relevant data from the original file
  97. you don't need to do anything.</para>
  98. <para>b) If the index uses a fileposition field to FETCH extra data from the
  99. original file then add a relationship between the original file and the
  100. index, using a special value of __fileposition__ to indicate the record is
  101. retrieved using a FETCH.</para>
  102. <programlisting>STD.File.AddFileRelationship('fetch_file',
  103. 'new_index',
  104. '__fileposition__',
  105. 'index_filepos_field',
  106. 'link',
  107. '1:1',
  108. true);</programlisting>
  109. <para>The original file is the primary, since the rows are uniquely
  110. identified by the fileposition (also true of the index), and the retrieval
  111. is efficient.</para>
  112. <para>c) If the index uses a payload field which needs to be looked up in
  113. another index to provide the information, then you need to define a
  114. relationship between the new index and the index that provides the extra
  115. information. The index providing the extra information is the
  116. primary.</para>
  117. <programlisting>STD.File.AddFileRelationship('related_index',
  118. 'new_index',
  119. 'related_key_fields',
  120. 'index_filepos_field',
  121. 'link',
  122. '1:M',
  123. true);</programlisting>
  124. <para>The <emphasis>payload </emphasis>flag is there so that the roxie
  125. browser can distinguish this link from a more general relationship between
  126. two files.</para>
  127. <para>You should ensure any super-file names are expanded if the relation is
  128. defined between the particular sub-files.</para>
  129. <para>While going through all the attributes it may be worth examining
  130. whether it makes sense to add relationships for any other combinations of
  131. files. It won’t have any immediate beneficial effect, but would once we add
  132. an ER diagram to the system. A couple of examples may help illustrate the
  133. syntax.</para>
  134. <para>For a typical example, datasets with a household and person file, the
  135. following defines a relationship linking by house hold id (hhid):</para>
  136. <programlisting>STD.File.AddFileRelationship('HHFile','PersonFile', 'hhid','hhid', 'link', '1:M', false);</programlisting>
  137. <para>Here's a more hypothetical example—a file query with firstname,
  138. lastname related to an index with phonetic names you might have:</para>
  139. <programlisting>STD.File.AddFileRelationship('names', 'inquiries','plastname{set(phonetic)},
  140. pfirstname{set(phonetic)}',
  141. 'lastname{set(fail)},firstname{set(fail)}','link', '1:M', false);</programlisting>
  142. <para>Note, the fail mapping indicates that you can use the phonetic mapping
  143. from inquiries to names, but there is no way of mapping from names to
  144. inquiries. There could equally be get(fail) attributes on the index
  145. fields.</para>
  146. <para>Example:</para>
  147. <programlisting format="linespecific">Maps := STD.File.GetColumnMapping('Thor::in::SomeFile');
  148. </programlisting>
  149. </sect1>