BltInFunc-LIBRARY.xml 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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="LIBRARY">
  5. <title>LIBRARY</title>
  6. <para><emphasis role="bold">LIBRARY<indexterm>
  7. <primary>LIBRARY</primary>
  8. </indexterm><indexterm>
  9. <primary>LIBRARY function</primary>
  10. </indexterm>(</emphasis><emphasis> </emphasis><emphasis
  11. role="bold">INTERNAL<indexterm>
  12. <primary>INTERNAL</primary>
  13. </indexterm>( </emphasis><emphasis>module </emphasis><emphasis
  14. role="bold">)</emphasis><emphasis>, interface </emphasis><emphasis
  15. role="bold">[</emphasis><emphasis> (</emphasis><emphasis role="bold">
  16. </emphasis><emphasis>parameters) </emphasis><emphasis role="bold">]
  17. )</emphasis><emphasis role="bold"></emphasis></para>
  18. <para><emphasis role="bold">LIBRARY(</emphasis><emphasis> module , interface
  19. </emphasis><emphasis role="bold">[</emphasis><emphasis>
  20. (</emphasis><emphasis role="bold"> </emphasis><emphasis>parameters)
  21. </emphasis><emphasis role="bold">] )</emphasis></para>
  22. <informaltable colsep="1" frame="all" rowsep="1">
  23. <tgroup cols="2">
  24. <colspec colwidth="86.10pt" />
  25. <colspec />
  26. <tbody>
  27. <row>
  28. <entry><emphasis role="bold">INTERNAL</emphasis></entry>
  29. <entry>Optional. Specifies the module is an attribute, not an
  30. external library (created by the BUILD action).</entry>
  31. </row>
  32. <row>
  33. <entry><emphasis>module</emphasis></entry>
  34. <entry>The name of the query library. When INTERNAL, this is the
  35. name of the MODULE attribute that implements the query library. If
  36. not INTERNAL, this is a string expression containing the name of the
  37. workunit that compiled the query library (typically defined with
  38. #WORKUNIT).</entry>
  39. </row>
  40. <row>
  41. <entry><emphasis>interface</emphasis></entry>
  42. <entry>The name of the INTERFACE structure that defines the query
  43. library.</entry>
  44. </row>
  45. <row>
  46. <entry><emphasis>parameters</emphasis></entry>
  47. <entry>Optional. The values to pass to the INTERFACE, if defined to
  48. receive parameters.</entry>
  49. </row>
  50. <row>
  51. <entry>Return:</entry>
  52. <entry>LIBRARY results in a MODULE that can be used to reference the
  53. exported attributes from the specified module.</entry>
  54. </row>
  55. </tbody>
  56. </tgroup>
  57. </informaltable>
  58. <para>The <emphasis role="bold">LIBRARY </emphasis>function defines an
  59. instance of a query library—the <emphasis>interface</emphasis> as
  60. implemented by the <emphasis>module</emphasis> when passed the specified
  61. <emphasis>parameters. </emphasis><emphasis role="bold">Query libraries are
  62. only used by hthor and Roxie.</emphasis></para>
  63. <para>INTERNAL libraries are typically used when developing queries, while
  64. external libraries are best for production queries. An INTERNAL library
  65. generates the library code as a separate unit, but then includes that unit
  66. within the query workunit. It doesn't have the advantage of reducing compile
  67. time or memory usage in Roxie that an external library would have, but it
  68. does retain the library structure, and means that changes to the code cannot
  69. affect anyone else using the system.</para>
  70. <para>External libraries are created by the BUILD action and use the "name"
  71. form of #WORKUNIT to specify the external name of the library. An external
  72. library is pre-compiled and therefore reduces compile time for queries that
  73. use it. They also reduce memory usage in Roxie</para>
  74. <para>Example:</para>
  75. <programlisting>NamesRec := RECORD
  76. INTEGER1 NameID;
  77. STRING20 FName;
  78. STRING20 LName;
  79. END;
  80. NamesTable := DATASET([ {1,'Doc','Holliday'},
  81. {2,'Liz','Taylor'},
  82. {3,'Mr','Nobody'},
  83. {4,'Anywhere','but here'}],
  84. NamesRec);
  85. FilterLibIface1(DATASET(namesRec) ds, STRING search) := INTERFACE
  86. EXPORT DATASET(namesRec) matches;
  87. EXPORT DATASET(namesRec) others;
  88. END;
  89. FilterDsLib1(DATASET(namesRec) ds, STRING search) :=
  90. MODULE,LIBRARY(FilterLibIface1)
  91. EXPORT matches := ds(Lname = search);
  92. EXPORT others := ds(Lname != search);
  93. END;
  94. // Run this to create the 'Ppass.FilterDsLib' external library
  95. // #WORKUNIT('name','Ppass.FilterDsLib')
  96. // BUILD(FilterDsLib1);
  97. lib1 := LIBRARY(INTERNAL(FilterDsLib1),
  98. FilterLibIface1(NamesTable, 'Holliday'));
  99. lib2 := LIBRARY('Ppass.FilterDsLib',
  100. FilterLibIface1(NamesTable, 'Holliday'));
  101. IFilterArgs := INTERFACE
  102. EXPORT DATASET(namesRec) ds;
  103. EXPORT STRING search;
  104. END;
  105. FilterLibIface2(IFilterArgs args) := INTERFACE
  106. EXPORT DATASET(namesRec) matches;
  107. EXPORT DATASET(namesRec) others;
  108. END;
  109. FilterDsLib2(IFilterArgs args) := MODULE,LIBRARY(FilterLibIface2)
  110. EXPORT matches := args.ds(Lname = args.search);
  111. EXPORT others := args.ds(Lname != args.search);
  112. END;
  113. // Run this to create the 'Ipass.FilterDsLib' external library
  114. // #WORKUNIT('name','Ipass.FilterDsLib')
  115. // BUILD(FilterDsLib2);
  116. SearchArgs := MODULE(IFilterArgs)
  117. EXPORT DATASET(namesRec) ds := NamesTable;
  118. EXPORT STRING search := 'Holliday';
  119. END;
  120. lib3 := LIBRARY(INTERNAL(FilterDsLib2),
  121. FilterLibIface2(SearchArgs));
  122. lib4 := LIBRARY('Ipass.FilterDsLib',
  123. FilterLibIface2(SearchArgs));
  124. OUTPUT(lib1.matches,NAMED('INTERNAL_matches_straight_parms'));
  125. OUTPUT(lib1.others, NAMED('INTERNAL_nonmatches_straight_parms'));
  126. OUTPUT(lib2.matches,NAMED('EXTERNAL_matches_straight_parms'));
  127. OUTPUT(lib2.others, NAMED('EXTERNAL_nonmatches_straight_parms'));
  128. OUTPUT(lib3.matches,NAMED('INTERNAL_matches_interface_parms'));
  129. OUTPUT(lib3.others, NAMED('INTERNAL_nonmatches_interface_parms'));
  130. OUTPUT(lib4.matches,NAMED('EXTERNAL_matches_interface_parms'));
  131. OUTPUT(lib4.others, NAMED('EXTERNAL_nonmatches_interface_parms'));
  132. </programlisting>
  133. </sect1>