nontransaction.hxx 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /** Definition of the pqxx::nontransaction class.
  2. *
  3. * pqxx::nontransaction provides nontransactional database access
  4. *
  5. * DO NOT INCLUDE THIS FILE DIRECTLY; include pqxx/nontransaction instead.
  6. *
  7. * Copyright (c) 2000-2019, Jeroen T. Vermeulen.
  8. *
  9. * See COPYING for copyright license. If you did not receive a file called
  10. * COPYING with this source code, please notify the distributor of this mistake,
  11. * or contact the author.
  12. */
  13. #ifndef PQXX_H_NONTRANSACTION
  14. #define PQXX_H_NONTRANSACTION
  15. #include "pqxx/compiler-public.hxx"
  16. #include "pqxx/compiler-internal-pre.hxx"
  17. #include "pqxx/connection_base.hxx"
  18. #include "pqxx/result.hxx"
  19. #include "pqxx/transaction_base.hxx"
  20. // Methods tested in eg. test module test01 are marked with "//[t01]".
  21. namespace pqxx
  22. {
  23. /// Simple "transaction" class offering no transactional integrity.
  24. /**
  25. * @ingroup transaction
  26. *
  27. * nontransaction, like transaction or any other transaction_base-derived class,
  28. * provides access to a database through a connection. Unlike its siblings,
  29. * however, nontransaction does not maintain any kind of transactional
  30. * integrity. This may be useful eg. for read-only access to the database that
  31. * does not require a consistent, atomic view on its data; or for operations
  32. * that are not allowed within a backend transaction, such as creating tables.
  33. *
  34. * For queries that update the database, however, a real transaction is likely
  35. * to be faster unless the transaction consists of only a single record update.
  36. *
  37. * Also, you can keep a nontransaction open for as long as you like. Actual
  38. * back-end transactions are limited in lifespan, and will sometimes fail just
  39. * because they took too long to execute or were left idle for too long. This
  40. * will not happen with a nontransaction (although the connection may still time
  41. * out, e.g. when the network is unavailable for a very long time).
  42. *
  43. * Any query executed in a nontransaction is committed immediately, and neither
  44. * commit() nor abort() has any effect.
  45. *
  46. * Database features that require a backend transaction, such as cursors or
  47. * large objects, will not work in a nontransaction.
  48. */
  49. class PQXX_LIBEXPORT nontransaction : public transaction_base
  50. {
  51. public:
  52. /// Constructor.
  53. /** Create a "dummy" transaction.
  54. * @param C Connection that this "transaction" will operate on.
  55. * @param Name Optional name for the transaction, beginning with a letter
  56. * and containing only letters and digits.
  57. */
  58. explicit nontransaction( //[t14]
  59. connection_base &C,
  60. const std::string &Name=std::string{}) :
  61. namedclass{"nontransaction", Name}, transaction_base{C} { Begin(); }
  62. virtual ~nontransaction(); //[t14]
  63. private:
  64. virtual void do_begin() override {} //[t14]
  65. virtual result do_exec(const char C[]) override; //[t14]
  66. virtual void do_commit() override {} //[t14]
  67. virtual void do_abort() override {} //[t14]
  68. };
  69. } // namespace pqxx
  70. #include "pqxx/compiler-internal-post.hxx"
  71. #endif