ODBCResult.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //
  2. // Copyright (c) 2008-2017 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "../../Core/Variant.h"
  24. #include <nanodbc/nanodbc.h>
  25. namespace Urho3D
  26. {
  27. /// %Database query result.
  28. class URHO3D_API DbResult
  29. {
  30. friend class DbConnection;
  31. public:
  32. /// Default constructor constructs an empty result object.
  33. DbResult() :
  34. numAffectedRows_(-1)
  35. {
  36. }
  37. /// Return number of columns in the resultset or 0 if there is no resultset.
  38. unsigned GetNumColumns() const { return columns_.Size(); }
  39. /// Return number of rows in the resultset or 0 if the number of rows is not available.
  40. unsigned GetNumRows() const { return rows_.Size(); }
  41. /// Return number of affected rows by the DML query or -1 if the number of affected rows is not available.
  42. long GetNumAffectedRows() const { return numAffectedRows_; }
  43. /// Return the underlying implementation result object.
  44. const nanodbc::result& GetResultImpl() const { return resultImpl_; }
  45. /// Return the column headers string collection.
  46. const StringVector& GetColumns() const { return columns_; }
  47. /// Return fetched rows collection. Filtered rows are not included in the collection.
  48. const Vector<VariantVector>& GetRows() const { return rows_; }
  49. private:
  50. /// The underlying implementation connection object.
  51. nanodbc::result resultImpl_;
  52. /// Column headers from the resultset.
  53. StringVector columns_;
  54. /// Fetched rows from the resultset.
  55. Vector<VariantVector> rows_;
  56. /// Number of affected rows by recent DML query.
  57. long numAffectedRows_;
  58. };
  59. }