ODBCResult.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #include "../../Core/Variant.h"
  5. #include <nanodbc/nanodbc.h>
  6. namespace Urho3D
  7. {
  8. /// %Database query result.
  9. class URHO3D_API DbResult
  10. {
  11. friend class DbConnection;
  12. public:
  13. /// Default constructor constructs an empty result object.
  14. DbResult() :
  15. numAffectedRows_(-1)
  16. {
  17. }
  18. /// Return number of columns in the resultset or 0 if there is no resultset.
  19. unsigned GetNumColumns() const { return columns_.Size(); }
  20. /// Return number of rows in the resultset or 0 if the number of rows is not available.
  21. unsigned GetNumRows() const { return rows_.Size(); }
  22. /// Return number of affected rows by the DML query or -1 if the number of affected rows is not available.
  23. long GetNumAffectedRows() const { return numAffectedRows_; }
  24. /// Return the underlying implementation result object.
  25. const nanodbc::result& GetResultImpl() const { return resultImpl_; }
  26. /// Return the column headers string collection.
  27. const StringVector& GetColumns() const { return columns_; }
  28. /// Return fetched rows collection. Filtered rows are not included in the collection.
  29. const Vector<VariantVector>& GetRows() const { return rows_; }
  30. private:
  31. /// The underlying implementation connection object.
  32. nanodbc::result resultImpl_;
  33. /// Column headers from the resultset.
  34. StringVector columns_;
  35. /// Fetched rows from the resultset.
  36. Vector<VariantVector> rows_;
  37. /// Number of affected rows by recent DML query.
  38. long numAffectedRows_;
  39. };
  40. }