db_res_t.xml 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
  4. <section id="db_res_t" xmlns:xi="http://www.w3.org/2001/XInclude">
  5. <sectioninfo>
  6. <revhistory>
  7. <revision>
  8. <revnumber>$Revision$</revnumber>
  9. <date>$Date$</date>
  10. </revision>
  11. </revhistory>
  12. </sectioninfo>
  13. <title>Type <type>db_res_t</type></title>
  14. <para>
  15. This type represents a result returned by <function>db_query</function>
  16. function (see below). The result can consist of zero or more rows (see
  17. <type>db_row_t</type> description).
  18. </para>
  19. <note>
  20. <para>
  21. A variable of type <type>db_res_t</type> returned by
  22. <function>db_query</function> function uses dynamically allocated
  23. memory, don't forget to call <function>db_free_result</function> if
  24. you don't need the variable anymore. You will encounter memory
  25. leaks if you fail to do this !
  26. </para>
  27. </note>
  28. <para>
  29. In addition to zero or more rows, each <type>db_res_t</type> object
  30. contains also an array of <type>db_key_t</type> objects. The objects
  31. represent keys (names of columns).
  32. </para>
  33. <programlisting>
  34. typedef struct db_res {
  35. struct {
  36. db_key_t* keys; /* Array of column names */
  37. db_type_t* types; /* Array of column types */
  38. int n; /* Number of columns */
  39. } col;
  40. struct db_row* rows; /* Array of rows */
  41. int n; /* Number of rows */
  42. } db_res_t;
  43. </programlisting>
  44. <itemizedlist>
  45. <listitem>
  46. <para>
  47. <function>RES_NAMES(res)</function> Macro.
  48. </para>
  49. <para>
  50. Use this macro if you want to obtain pointer to an array of
  51. cell names.
  52. </para>
  53. <example>
  54. <title>RES_NAMES Macro</title>
  55. <programlisting>
  56. ...
  57. db_key_t* column_names = ROW_NAMES(row);
  58. ...
  59. </programlisting>
  60. </example>
  61. </listitem>
  62. <listitem>
  63. <para>
  64. <function>RES_COL_N(res)</function> Macro.
  65. </para>
  66. <para>
  67. Use this macro if you want to get the number of columns in the result.
  68. </para>
  69. <example>
  70. <title>RES_COL_N Macro</title>
  71. <programlisting>
  72. <![CDATA[
  73. ...
  74. int ncol = RES_COL_N(res);
  75. for(i = 0; i < ncol; i++) {
  76. /* do something with the column */
  77. }
  78. ...
  79. ]]>
  80. </programlisting>
  81. </example>
  82. </listitem>
  83. <listitem>
  84. <para>
  85. <function>RES_ROWS(res)</function> Macro.
  86. </para>
  87. <para>
  88. Use this macro if you need to obtain pointer to array of rows.
  89. </para>
  90. <example>
  91. <title>RES_ROWS Macro</title>
  92. <programlisting>
  93. ...
  94. db_row_t* rows = RES_ROWS(res);
  95. ...
  96. </programlisting>
  97. </example>
  98. </listitem>
  99. <listitem>
  100. <para>
  101. <function>RES_ROW_N(res)</function> Macro.
  102. </para>
  103. <para>
  104. Use this macro if you need to obtain the number of rows in the
  105. result.
  106. </para>
  107. <example>
  108. <title>RES_ROW_N Macro</title>
  109. <programlisting>
  110. ...
  111. int n = RES_ROW_N(res);
  112. ...
  113. </programlisting>
  114. </example>
  115. </listitem>
  116. </itemizedlist>
  117. </section>