Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

122 рядки
3.0 KiB

  1. #pragma once
  2. #include <memory>
  3. #include <cppmariadb/config.h>
  4. #include <cppmariadb/impl/handle.h>
  5. namespace cppmariadb
  6. {
  7. /**
  8. * @brief Basic result type containing all rows and data from a query.
  9. */
  10. struct result :
  11. public __impl::handle<MYSQL_RES*>
  12. {
  13. private:
  14. bool _is_initialized; //!< Indicates if the result is initialized or not.
  15. std::unique_ptr<row> _row; //!< Current data row of the result.
  16. mutable column_vector _columns; //!< Column information that belongs to this result.
  17. unsigned long long _rowindex; //!< Index of the current row.
  18. public:
  19. /**
  20. * @brief Constructor. Create object from the mariadb handle.
  21. */
  22. inline result(MYSQL_RES* h);
  23. /**
  24. * @brief Destructor.
  25. */
  26. virtual ~result();
  27. /**
  28. * @brief Get the number of columns.
  29. */
  30. inline unsigned int columncount() const;
  31. /**
  32. * @brief Get the columns that belong to this result.
  33. */
  34. inline const column_vector& columns() const;
  35. /**
  36. * @brief Get the next row of the result or nullptr
  37. * if no more rows are stored in the result.
  38. */
  39. row* next();
  40. /**
  41. * @brief Get the current row.
  42. */
  43. inline row* current() const;
  44. /**
  45. * @brief Get the current row index.
  46. */
  47. inline unsigned long long rowindex() const;
  48. /**
  49. * @brief Free the result.
  50. */
  51. inline void free();
  52. protected:
  53. /**
  54. * @brief Set the index of the current row.
  55. */
  56. inline void rowindex(unsigned long long value);
  57. private:
  58. /**
  59. * @brief Fetch the column information from the database.
  60. */
  61. void update_columns() const;
  62. };
  63. /**
  64. * @brief The stored result is a special kind of the result
  65. * that stores all result rows on the client.
  66. */
  67. struct result_stored
  68. : public result
  69. {
  70. using result::rowindex;
  71. /**
  72. * @brief Constructor. Create a new object from the mariadb handle.
  73. */
  74. inline result_stored(MYSQL_RES* h);
  75. /**
  76. * @brief Set the index of the current row.
  77. */
  78. inline void rowindex(unsigned long long index);
  79. /**
  80. * @brief Get the number of rows soted in this result.
  81. */
  82. inline unsigned long long rowcount() const;
  83. };
  84. /**
  85. * @brief The used result is a special kind of the result
  86. * that fetches only the needed rows from the database.
  87. */
  88. struct result_used
  89. : public result
  90. {
  91. /**
  92. * @brief Constructor. Create a new object from the mariadb handle.
  93. */
  94. inline result_used(MYSQL_RES* h);
  95. /**
  96. * @brief Destructor.
  97. */
  98. virtual ~result_used() override;
  99. };
  100. }