mysql_connection.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*
  2. * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License, version 2.0, as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is also distributed with certain software (including
  9. * but not limited to OpenSSL) that is licensed under separate terms,
  10. * as designated in a particular file or component or in included license
  11. * documentation. The authors of MySQL hereby grant you an
  12. * additional permission to link the program and your derivative works
  13. * with the separately licensed software that they have included with
  14. * MySQL.
  15. *
  16. * Without limiting anything contained in the foregoing, this file,
  17. * which is part of MySQL Connector/C++, is also subject to the
  18. * Universal FOSS Exception, version 1.0, a copy of which can be found at
  19. * http://oss.oracle.com/licenses/universal-foss-exception.
  20. *
  21. * This program is distributed in the hope that it will be useful, but
  22. * WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  24. * See the GNU General Public License, version 2.0, for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program; if not, write to the Free Software Foundation, Inc.,
  28. * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  29. */
  30. #ifndef _MYSQL_CONNECTION_H_
  31. #define _MYSQL_CONNECTION_H_
  32. #include "cppconn/connection.h"
  33. #include <boost/shared_ptr.hpp>
  34. #include <boost/scoped_ptr.hpp>
  35. namespace sql
  36. {
  37. namespace mysql
  38. {
  39. class MySQL_Savepoint : public sql::Savepoint
  40. {
  41. sql::SQLString name;
  42. public:
  43. MySQL_Savepoint(const sql::SQLString &savepoint);
  44. virtual ~MySQL_Savepoint() {}
  45. int getSavepointId();
  46. sql::SQLString getSavepointName();
  47. private:
  48. /* Prevent use of these */
  49. MySQL_Savepoint(const MySQL_Savepoint &);
  50. void operator=(MySQL_Savepoint &);
  51. };
  52. class MySQL_DebugLogger;
  53. struct MySQL_ConnectionData; /* PIMPL */
  54. class MySQL_Statement;
  55. namespace NativeAPI
  56. {
  57. class NativeConnectionWrapper;
  58. }
  59. class CPPCONN_PUBLIC_FUNC MySQL_Connection : public sql::Connection
  60. {
  61. MySQL_Statement * createServiceStmt();
  62. public:
  63. MySQL_Connection(Driver * _driver,
  64. ::sql::mysql::NativeAPI::NativeConnectionWrapper & _proxy,
  65. const sql::SQLString& hostName,
  66. const sql::SQLString& userName,
  67. const sql::SQLString& password);
  68. MySQL_Connection(Driver * _driver, ::sql::mysql::NativeAPI::NativeConnectionWrapper & _proxy,
  69. std::map< sql::SQLString, sql::ConnectPropertyVal > & options);
  70. virtual ~MySQL_Connection();
  71. void clearWarnings();
  72. void close();
  73. void commit();
  74. sql::Statement * createStatement();
  75. sql::SQLString escapeString(const sql::SQLString &);
  76. bool getAutoCommit();
  77. sql::SQLString getCatalog();
  78. Driver *getDriver();
  79. sql::SQLString getSchema();
  80. sql::SQLString getClientInfo();
  81. void getClientOption(const sql::SQLString & optionName, void * optionValue);
  82. sql::SQLString getClientOption(const sql::SQLString & optionName);
  83. sql::DatabaseMetaData * getMetaData();
  84. enum_transaction_isolation getTransactionIsolation();
  85. const SQLWarning * getWarnings();
  86. bool isClosed();
  87. bool isReadOnly();
  88. bool isValid();
  89. bool reconnect();
  90. sql::SQLString nativeSQL(const sql::SQLString& sql);
  91. sql::PreparedStatement * prepareStatement(const sql::SQLString& sql);
  92. sql::PreparedStatement * prepareStatement(const sql::SQLString& sql, int autoGeneratedKeys);
  93. sql::PreparedStatement * prepareStatement(const sql::SQLString& sql, int columnIndexes[]);
  94. sql::PreparedStatement * prepareStatement(const sql::SQLString& sql, int resultSetType, int resultSetConcurrency);
  95. sql::PreparedStatement * prepareStatement(const sql::SQLString& sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability);
  96. sql::PreparedStatement * prepareStatement(const sql::SQLString& sql, sql::SQLString columnNames[]);
  97. void releaseSavepoint(Savepoint * savepoint) ;
  98. void rollback();
  99. void rollback(Savepoint * savepoint);
  100. void setAutoCommit(bool autoCommit);
  101. void setCatalog(const sql::SQLString& catalog);
  102. void setSchema(const sql::SQLString& catalog);
  103. sql::Connection * setClientOption(const sql::SQLString & optionName, const void * optionValue);
  104. sql::Connection * setClientOption(const sql::SQLString & optionName, const sql::SQLString & optionValue);
  105. void setHoldability(int holdability);
  106. void setReadOnly(bool readOnly);
  107. sql::Savepoint * setSavepoint();
  108. sql::Savepoint * setSavepoint(const sql::SQLString& name);
  109. void setTransactionIsolation(enum_transaction_isolation level);
  110. virtual sql::SQLString getSessionVariable(const sql::SQLString & varname);
  111. virtual void setSessionVariable(const sql::SQLString & varname, const sql::SQLString & value);
  112. virtual void setSessionVariable(const sql::SQLString & varname, unsigned int value);
  113. virtual sql::SQLString getLastStatementInfo();
  114. private:
  115. /* We do not really think this class has to be subclassed*/
  116. void checkClosed();
  117. void init(std::map< sql::SQLString, sql::ConnectPropertyVal > & properties);
  118. Driver * driver;
  119. boost::shared_ptr< NativeAPI::NativeConnectionWrapper > proxy;
  120. /* statement handle to execute queries initiated by driver. Perhaps it is
  121. a good idea to move it to a separate helper class */
  122. boost::scoped_ptr< ::sql::mysql::MySQL_Statement > service;
  123. boost::scoped_ptr< ::sql::mysql::MySQL_ConnectionData > intern; /* pimpl */
  124. /* Prevent use of these */
  125. MySQL_Connection(const MySQL_Connection &);
  126. void operator=(MySQL_Connection &);
  127. };
  128. } /* namespace mysql */
  129. } /* namespace sql */
  130. #endif // _MYSQL_CONNECTION_H_
  131. /*
  132. * Local variables:
  133. * tab-width: 4
  134. * c-basic-offset: 4
  135. * End:
  136. * vim600: noet sw=4 ts=4 fdm=marker
  137. * vim<600: noet sw=4 ts=4
  138. */