EasyQtSql_NonQueryResult.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #ifndef EASYQTSQL_NONQUERYRESULT_H
  2. #define EASYQTSQL_NONQUERYRESULT_H
  3. /*
  4. * The MIT License (MIT)
  5. * Copyright 2018 Alexey Kramin
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining
  8. * a copy of this software and associated documentation files (the
  9. * "Software"), to deal in the Software without restriction, including
  10. * without limitation the rights to use, copy, modify, merge, publish,
  11. * distribute, sublicense, and/or sell copies of the Software, and to
  12. * permit persons to whom the Software is furnished to do so, subject to
  13. * the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be
  16. * included in all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  19. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  21. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  22. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  23. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  24. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. *
  26. */
  27. #ifndef EASY_QT_SQL_MAIN
  28. #include <QtSql>
  29. #endif
  30. /*!
  31. * \brief QSqlQuery wrapper for non-select query results reading
  32. */
  33. class NonQueryResult
  34. {
  35. friend class Database;
  36. friend class Transaction;
  37. friend class InsertQuery;
  38. friend class UpdateQuery;
  39. friend class DeleteQuery;
  40. public:
  41. /*!
  42. \brief Returns reference on wrapped QSqlQuery.
  43. */
  44. QSqlQuery &unwrappedQuery()
  45. {
  46. return m_query;
  47. }
  48. /*!
  49. \brief Returns the number of rows affected by the result's SQL statement, or -1 if it cannot be determined.
  50. Wrapper over QSqlQuery::numRowsAffected()
  51. */
  52. int numRowsAffected() const
  53. {
  54. return m_query.numRowsAffected();
  55. }
  56. /*!
  57. \brief Returns the object ID of the most recent inserted row if the database supports it.
  58. Wrapper over QSqlQuery::lastInsertId()
  59. */
  60. QVariant lastInsertId() const
  61. {
  62. return m_query.lastInsertId();
  63. }
  64. /*!
  65. \brief Returns error information about the last error (if any) that occurred with this query.
  66. Wrapper over QSqlQuery::lastError()
  67. */
  68. QSqlError lastError() const
  69. {
  70. return m_query.lastError();
  71. }
  72. /*!
  73. \brief Returns the text of the current query being used, or an empty string if there is no current query text.
  74. Wrapper over QSqlQuery::lastQuery()
  75. */
  76. QString lastQuery() const
  77. {
  78. return m_query.lastQuery();
  79. }
  80. /*!
  81. \brief Returns the last query that was successfully executed.
  82. Wrapper over QSqlQuery::executedQuery()
  83. */
  84. QString executedQuery() const
  85. {
  86. return m_query.executedQuery();
  87. }
  88. private:
  89. explicit NonQueryResult(const QSqlQuery &q)
  90. : m_query(q)
  91. { }
  92. QSqlQuery m_query;
  93. };
  94. #endif // EASYQTSQL_NONQUERYRESULT_H