Kea: isc::db::MySqlConnection Class Reference

| Kea 3.2.0-git

isc::db::MySqlConnection Class Reference

Common MySQL Connector Pool. More...

`#include <mysql_connection.h>`

Inheritance diagram for isc::db::MySqlConnection:
[legend]

## Public Types
typedef std::function< void(MySqlBindingCollection &)> | ConsumeResultFun
| Function invoked to process fetched row.
Public Types inherited from isc::db::DatabaseConnection
typedef std::map< std::string, std::string > | ParameterMap
| Database configuration parameter map.

## Public Member Functions
| MySqlConnection (const ParameterMap &parameters, IOServiceAccessorPtr io_accessor=IOServiceAccessorPtr(), DbCallback callback=DbCallback())
| Constructor.
virtual | ~MySqlConnection ()
| Destructor.
template<typename StatementIndex>
void | checkError (const int status, const StatementIndex &index, const char *what)
| Check Error and Throw Exception.
void | commit ()
| Commits current transaction.
template<typename StatementIndex>
MYSQL_STMT * | getStatement (StatementIndex index) const
| Returns a prepared statement by an index.
bool | getTls () const
| Get the TLS flag.
std::string | getTlsCipher ()
| Get the TLS cipher.
template<typename StatementIndex>
void | insertQuery (const StatementIndex &index, const MySqlBindingCollection &in_bindings)
| Executes INSERT prepared statement.
bool | isTransactionStarted () const
| Checks if there is a transaction in progress.
void | openDatabase ()
| Open Database.
void | prepareStatement (uint32_t index, const char *text)
| Prepare Single Statement.
void | prepareStatements (const TaggedStatement *start_statement, const TaggedStatement *end_statement)
| Prepare statements.
void | rollback ()
| Rollbacks current transaction.
template<typename StatementIndex>
void | selectQuery (const StatementIndex &index, const MySqlBindingCollection &in_bindings, MySqlBindingCollection &out_bindings, ConsumeResultFun process_result)
| Executes SELECT query using prepared statement.
void | startRecoverDbConnection ()
| The recover connection.
void | startTransaction ()
| Starts new transaction.
template<typename StatementIndex>
uint64_t | updateDeleteQuery (const StatementIndex &index, const MySqlBindingCollection &in_bindings)
| Executes UPDATE or DELETE prepared statement and returns the number of affected rows.
Public Member Functions inherited from isc::db::DatabaseConnection
| DatabaseConnection (const ParameterMap &parameters, DbCallback callback=DbCallback())
| Constructor.
virtual | ~DatabaseConnection ()
| Destructor.
void | checkUnusable ()
| Throws an exception if the connection is not usable.
bool | configuredReadOnly () const
| Convenience method checking if database should be opened with read only access.
std::string | getParameter (const std::string &name) const
| Returns value of a connection parameter.
bool | isUnusable ()
| Flag which indicates if connection is unusable.
virtual void | makeReconnectCtl (const std::string &timer_name, unsigned int id)
| Instantiates a ReconnectCtl based on the connection's reconnect parameters.
util::ReconnectCtlPtr | reconnectCtl ()
| The reconnect settings.

## Static Public Member Functions
static void | ensureSchemaVersion (const ParameterMap &parameters, const DbCallback &cb=DbCallback(), const std::string &timer_name=std::string())
| Retrieve schema version, validate it against the hardcoded version, and attempt to initialize the schema if there is an error during retrieval.
static std::pair< uint32_t, uint32_t > | getVersion (const ParameterMap &parameters, const IOServiceAccessorPtr &ac=IOServiceAccessorPtr(), const DbCallback &cb=DbCallback(), const std::string &timer_name=std::string(), unsigned int id=0)
| Get the schema version.
static void | initializeSchema (const ParameterMap &parameters)
| Initialize schema.
static std::vector< std::string > | toKeaAdminParameters (ParameterMap const &params)
| Convert MySQL library parameters to kea-admin parameters.
static void | convertToDatabaseTime (const time_t input_time, MYSQL_TIME &output_time)
| Convert time_t value to database time.
static void | convertToDatabaseTime (const time_t cltt, const uint32_t valid_lifetime, MYSQL_TIME &expire)
| Convert Lease Time to Database Times.
static void | convertFromDatabaseTime (const MYSQL_TIME &expire, uint32_t valid_lifetime, time_t &cltt)
| Convert Database Time to Lease Times.
Static Public Member Functions inherited from isc::db::DatabaseConnection
static isc::asiolink::IOServicePtr & | getIOService ()
| Returns pointer to the IO service.
static bool | invokeDbFailedCallback (const util::ReconnectCtlPtr &db_reconnect_ctl)
| Invokes the connection's restore failed connectivity callback.
static bool | invokeDbLostCallback (const util::ReconnectCtlPtr &db_reconnect_ctl)
| Invokes the connection's lost connectivity callback.
static bool | invokeDbRecoveredCallback (const util::ReconnectCtlPtr &db_reconnect_ctl)
| Invokes the connection's restored connectivity callback.
static ParameterMap | parse (const std::string &dbaccess)
| Parse database access string.
static std::string | redactedAccessString (const ParameterMap &parameters)
| Redact database access string.
static void | setIOService (const isc::asiolink::IOServicePtr &io_service)
| Sets IO service to be used by the database backends.
static isc::data::ElementPtr | toElement (const ParameterMap &params)
| Unparse a parameter map.
static isc::data::ElementPtr | toElementDbAccessString (const std::string &dbaccess)
| Unparse an access string.

## Public Attributes
isc::asiolink::IOServicePtr | io_service_
| IOService object, used for all ASIO operations.
IOServiceAccessorPtr | io_service_accessor_
| Accessor function which returns the IOService that can be used to recover the connection.
MySqlHolder | mysql_
| MySQL connection handle.
std::vector< std::string > | text_statements_
| Raw text of statements.
bool | tls_
| TLS flag (true when TLS was required, false otherwise).
int | transaction_ref_count_
| Reference counter for transactions.

## Static Public Attributes
static std::string | KEA_ADMIN_ = KEA_ADMIN
| Holds location to kea-admin.
Static Public Attributes inherited from isc::db::DatabaseConnection
static DbCallback | db_failed_callback_ = 0
| Optional callback function to invoke if an opened connection recovery failed.
static DbCallback | db_lost_callback_ = 0
| Optional callback function to invoke if an opened connection is lost.
static DbCallback | db_recovered_callback_ = 0
| Optional callback function to invoke if an opened connection recovery succeeded.
static const time_t | MAX_DB_TIME = 2147483647
| Defines maximum value for time that can be reliably stored.
static bool | retry_ = false
| Flag which indicates if the database connection should be retried on fail.
static bool | test_mode_ = false
| Test mode flag (default false).

## Additional Inherited Members
Protected Member Functions inherited from isc::db::DatabaseConnection
void | markUnusable ()
| Sets the unusable flag to true.
Protected Attributes inherited from isc::db::DatabaseConnection
DbCallback | callback_
| The callback used to recover the connection.

## Detailed Description

Common MySQL Connector Pool.

This class provides common operations for MySQL database connection used by both MySqlLeaseMgr and MySqlHostDataSource. It manages connecting to the database and preparing compiled statements. Its fields are public, because they are used (both set and retrieved) in classes that use instances of MySqlConnection.

Definition at line 235 of file mysql_connection.h.

## Member Typedef Documentation

## ◆ ConsumeResultFun

typedef std::function<void(MySqlBindingCollection&)> isc::db::MySqlConnection::ConsumeResultFun

Function invoked to process fetched row.

Definition at line 239 of file mysql_connection.h.

## Constructor & Destructor Documentation

## ◆ MySqlConnection()

isc::db::MySqlConnection::MySqlConnection | ( | const ParameterMap & | parameters,
|  | IOServiceAccessorPtr | io_accessor = IOServiceAccessorPtr(),
|  | DbCallback | callback = DbCallback() )
| inline

Constructor.

Initialize MySqlConnection object with parameters needed for connection.

Parameters

  parameters | Specify the connection details.
  io_accessor | The IOService accessor function.
  callback | The connection recovery callback.

Definition at line 248 of file mysql_connection.h.

References isc::db::DatabaseConnection::DatabaseConnection(), io_service_, io_service_accessor_, tls_, and transaction_ref_count_.

Referenced by getVersion().

Here is the call graph for this function:

## ◆ ~MySqlConnection()

isc::db::MySqlConnection::~MySqlConnection | ( |  | ) |
| virtual

Destructor.

Definition at line 589 of file mysql_connection.cc.

References text_statements_.

## Member Function Documentation

## ◆ checkError()

template<typename StatementIndex>

void isc::db::MySqlConnection::checkError | ( | const int | status,
|  | const StatementIndex & | index,
|  | const char * | what )
| inline

Check Error and Throw Exception.

Virtually all MySQL functions return a status which, if non-zero, indicates an error. This function centralizes the error checking code.

It is used to determine whether or not the function succeeded, and in the event of failures, decide whether or not those failures are recoverable.

If the error is recoverable, the function will throw a DbOperationError. If the error is deemed unrecoverable, such as a loss of connectivity with the server, the function will call startRecoverDbConnection() which will start the connection recovery.

If the invocation returns true, this indicates the calling layer will attempt recovery, and the function throws a DbOperationError to allow the caller to error handle the failed db access attempt.

Parameters

  status | Status code: non-zero implies an error
  index | Index of statement that caused the error
  what | High-level description of the error

Template Parameters

  Enumeration | representing index of a statement to which an error pertains.

Exceptions

  isc::db::DbOperationError | An operation on the open database has failed.

Definition at line 697 of file mysql_connection.h.

References isc::db::DB_LOG< log_type >::arg(), isc_throw, isc::db::DatabaseConnection::markUnusable(), mysql_, isc::db::MYSQL_FATAL_ERROR, startRecoverDbConnection(), and text_statements_.

Referenced by insertQuery(), selectQuery(), and updateDeleteQuery().

Here is the call graph for this function:

## ◆ commit()

void isc::db::MySqlConnection::commit | ( |  | ) |

Commits current transaction.

Commits all pending database operations. On databases that don't support transactions, this is a no-op.

When this method is called for a nested transaction it decrements the transaction reference counter incremented during the call to `startTransaction`.

Exceptions

  DbOperationError | If the commit failed.

Definition at line 656 of file mysql_connection.cc.

References isc::db::DatabaseConnection::checkUnusable(), isc::db::DB_DBG_TRACE_DETAIL, isc_throw, mysql_, isc::db::MYSQL_COMMIT, and transaction_ref_count_.

Here is the call graph for this function:

## ◆ convertFromDatabaseTime()

void isc::db::MySqlConnection::convertFromDatabaseTime | ( | const MYSQL_TIME & | expire,
|  | uint32_t | valid_lifetime,
|  | time_t & | cltt )
| static

Convert Database Time to Lease Times.

Within the database, time is stored as "expire" (time of expiry of the lease) and valid lifetime. In the DHCP server, the information is stored client last transmit time and valid lifetime. These are related by the equation:

- client last transmit time = expire - valid_lifetime

This method converts from the times in the database into times able to be inserted into the lease object.

Parameters

  expire | Reference to MYSQL_TIME object from where the expiry time of the lease is taken.
  valid_lifetime | lifetime of the lease.
  cltt | Reference to location where client last transmit time is put.

Definition at line 627 of file mysql_connection.cc.

References isc::db::MySqlBinding::convertFromDatabaseTime().

Here is the call graph for this function:

## ◆ convertToDatabaseTime() [1/2]

void isc::db::MySqlConnection::convertToDatabaseTime | ( | const time_t | cltt,
|  | const uint32_t | valid_lifetime,
|  | MYSQL_TIME & | expire )
| static

Convert Lease Time to Database Times.

Within the DHCP servers, times are stored as client last transmit time and valid lifetime. In the database, the information is stored as valid lifetime and "expire" (time of expiry of the lease). They are related by the equation:

- expire = client last transmit time + valid lifetime

This method converts from the times in the lease object into times able to be added to the database.

Parameters

  cltt | Client last transmit time
  valid_lifetime | Valid lifetime
  expire | Reference to MYSQL_TIME object where the expiry time of the lease will be put.

Exceptions

  isc::BadValue | if the sum of the calculated expiration time is greater than the value of `LeaseMgr::MAX_DB_TIME`.

Definition at line 620 of file mysql_connection.cc.

References isc::db::MySqlBinding::convertToDatabaseTime().

Here is the call graph for this function:

## ◆ convertToDatabaseTime() [2/2]

void isc::db::MySqlConnection::convertToDatabaseTime | ( | const time_t | input_time,
|  | MYSQL_TIME & | output_time )
| static

Convert time_t value to database time.

The following methods are used to convert between times and time intervals stored in the Lease object, and the times stored in the database. The reason for the difference is because in the DHCP server, the cltt (Client Time Since Last Transmission) is the natural data; in the lease file - which may be read by the user - it is the expiry time of the lease.

Parameters

  input_time | A time_t value representing time.
  output_time | Reference to MYSQL_TIME object where converted time will be put.

Definition at line 614 of file mysql_connection.cc.

References isc::db::MySqlBinding::convertToDatabaseTime().

Here is the call graph for this function:

## ◆ ensureSchemaVersion()

void isc::db::MySqlConnection::ensureSchemaVersion | ( | const ParameterMap & | parameters,
|  | const DbCallback & | cb = DbCallback(),
|  | const std::string & | timer_name = std::string() )
| static

Retrieve schema version, validate it against the hardcoded version, and attempt to initialize the schema if there is an error during retrieval.

Properly handles retrying of the database connection.

Parameters

  parameters | A data structure relating keywords and values concerned with the database.
  cb | The dbReconnect callback.
  timer_name | The DB reconnect timer name.

Exceptions

  isc::db::ScehamInitializationFailed | if the initialization fails

Definition at line 411 of file mysql_connection.cc.

References isc::db::DB_LOG< log_type >::arg(), isc::db::DatabaseConnection::getIOService(), getVersion(), initializeSchema(), isc_throw, isc::db::MYSQL_INITIAL_CONNECTION_FAIL, isc::db::MYSQL_SCHEMA_VERSION_MAJOR, isc::db::MYSQL_SCHEMA_VERSION_MINOR, and isc::db::DatabaseConnection::test_mode_.

Here is the call graph for this function:

## ◆ getStatement()

template<typename StatementIndex>

MYSQL_STMT * isc::db::MySqlConnection::getStatement | ( | StatementIndex | index | ) | const
| inline

Returns a prepared statement by an index.

Template Parameters

  StatementIndex | Type of the statement index enum.

Parameters

  index | Statement index.

Returns
  Pointer to the prepared statement.

Exceptions

  isc::db::DbConnectionUnusable | when the `mysql` pointer in the returned statement is NULL; it may be the result of the database connectivity loss.

Definition at line 356 of file mysql_connection.h.

References isc_throw.

Referenced by insertQuery(), selectQuery(), and updateDeleteQuery().

## ◆ getTls()

bool isc::db::MySqlConnection::getTls | ( |  | ) | const
| inline

Get the TLS flag.

Returns
  True if TLS was required, false otherwise.

Definition at line 760 of file mysql_connection.h.

References tls_.

## ◆ getTlsCipher()

std::string isc::db::MySqlConnection::getTlsCipher | ( |  | ) |
| inline

Get the TLS cipher.

This method is used to check if required TLS was setup.

Definition at line 767 of file mysql_connection.h.

References mysql_.

## ◆ getVersion()

std::pair< uint32_t, uint32_t > isc::db::MySqlConnection::getVersion | ( | const ParameterMap & | parameters,
|  | const IOServiceAccessorPtr & | ac = IOServiceAccessorPtr(),
|  | const DbCallback & | cb = DbCallback(),
|  | const std::string & | timer_name = std::string(),
|  | unsigned int | id = 0 )
| static

Get the schema version.

Parameters

  parameters | A data structure relating keywords and values concerned with the database.
  ac | An IOServiceAccessor object.
  cb | The dbReconnect callback.
  timer_name | The DB reconnect timer name.
  id | the ID of the manager.

Returns
  Version number as a pair of unsigned integers. "first" is the major version number, "second" the minor number.

Exceptions

  isc::db::DbOperationError | An operation on the open database has failed.

Definition at line 328 of file mysql_connection.cc.

References MySqlConnection(), isc_throw, isc::db::DatabaseConnection::makeReconnectCtl(), mysql_, isc::db::MysqlExecuteStatement(), openDatabase(), and version().

Referenced by ensureSchemaVersion().

Here is the call graph for this function:

## ◆ initializeSchema()

void isc::db::MySqlConnection::initializeSchema | ( | const ParameterMap & | parameters | ) |
| static

Initialize schema.

Parameters

  parameters | A data structure relating keywords and values concerned with the database.

Exceptions

  isc::db::ScehamInitializationFailed | if the initialization fails

Definition at line 467 of file mysql_connection.cc.

References isc::db::DB_LOG< log_type >::arg(), isc::asiolink::ProcessSpawn::getCommandLine(), isc::asiolink::ProcessSpawn::getExitStatus(), isc_throw, isc::util::file::isFile(), isc::asiolink::ProcessSpawn::isRunning(), KEA_ADMIN_, isc::db::MYSQL_INITIALIZE_SCHEMA, isc::db::MYSQL_NO_INIT_NO_ADMIN, isc::db::MYSQL_NO_INIT_READONLY, isc::asiolink::ProcessSpawn::spawn(), isc::asiolink::ProcessSpawn::SYNC, and toKeaAdminParameters().

Referenced by ensureSchemaVersion().

Here is the call graph for this function:

## ◆ insertQuery()

template<typename StatementIndex>

void isc::db::MySqlConnection::insertQuery | ( | const StatementIndex & | index,
|  | const MySqlBindingCollection & | in_bindings )
| inline

Executes INSERT prepared statement.

The statement index must point to an existing prepared statement associated with the connection. The `in_bindings` size must match the number of placeholders in the prepared statement.

This method executes prepared statement using provided bindings to insert data into the database.

Template Parameters

  StatementIndex | Type of the statement index enum.

Parameters

  index | Index of the query to be executed.
  in_bindings | Input bindings holding values to substitue placeholders in the query.

Definition at line 562 of file mysql_connection.h.

References checkError(), isc::db::DatabaseConnection::checkUnusable(), getStatement(), isc_throw, mysql_, and isc::db::MysqlExecuteStatement().

Here is the call graph for this function:

## ◆ isTransactionStarted()

bool isc::db::MySqlConnection::isTransactionStarted | ( |  | ) | const

Checks if there is a transaction in progress.

Returns
  true if a transaction has been started, false otherwise.

Definition at line 651 of file mysql_connection.cc.

References transaction_ref_count_.

## ◆ openDatabase()

void isc::db::MySqlConnection::openDatabase | ( |  | ) |

Open Database.

Opens the database using the information supplied in the parameters passed to the constructor.

Exceptions

  NoDatabaseName | Mandatory database name not given
  DbOpenError | Error opening the database

Definition at line 63 of file mysql_connection.cc.

References isc::data::DefaultCredentials::check(), isc::db::DatabaseConnection::getParameter(), isc_throw, isc::util::file::isDir(), isc::db::DatabaseConnection::markUnusable(), isc::db::MLM_FALSE, mysql_, isc::db::MYSQL_DEFAULT_CONNECTION_TIMEOUT, isc::db::DatabaseConnection::reconnectCtl(), isc::db::DatabaseConnection::retry_, startRecoverDbConnection(), and tls_.

Referenced by getVersion().

Here is the call graph for this function:

## ◆ prepareStatement()

void isc::db::MySqlConnection::prepareStatement | ( | uint32_t | index,
|  | const char * | text )

Prepare Single Statement.

Creates a prepared statement from the text given and adds it to the statements_ vector at the given index.

Parameters

  index | Index into the statements_ vector into which the text should be placed. The vector must be big enough for the index to be valid, else an exception will be thrown.
  text | Text of the SQL statement to be prepared.

Exceptions

  isc::db::DbOperationError | An operation on the open database has failed.
  isc::InvalidParameter | 'index' is not valid for the vector.

Definition at line 548 of file mysql_connection.cc.

References isc_throw, mysql_, and text_statements_.

Referenced by prepareStatements().

## ◆ prepareStatements()

void isc::db::MySqlConnection::prepareStatements | ( | const TaggedStatement * | start_statement,
|  | const TaggedStatement * | end_statement )

Prepare statements.

Creates the prepared statements for all of the SQL statements used by the MySQL backend.

Parameters

  start_statement | Pointer to the first statement in range of the statements to be compiled.
  end_statement | Pointer to the statement marking end of the range of statements to be compiled. This last statement is not compiled.

Exceptions

  isc::db::DbOperationError | An operation on the open database has failed.
  isc::InvalidParameter | 'index' is not valid for the vector. This represents an internal error within the code.

Definition at line 573 of file mysql_connection.cc.

References prepareStatement(), and text_statements_.

Here is the call graph for this function:

## ◆ rollback()

void isc::db::MySqlConnection::rollback | ( |  | ) |

Rollbacks current transaction.

Rolls back all pending database operations. On databases that don't support transactions, this is a no-op.

When this method is called for a nested transaction it decrements the transaction reference counter incremented during the call to `startTransaction`.

Exceptions

  DbOperationError | If the rollback failed.

Definition at line 674 of file mysql_connection.cc.

References isc::db::DatabaseConnection::checkUnusable(), isc::db::DB_DBG_TRACE_DETAIL, isc_throw, mysql_, isc::db::MYSQL_ROLLBACK, and transaction_ref_count_.

Here is the call graph for this function:

## ◆ selectQuery()

template<typename StatementIndex>

void isc::db::MySqlConnection::selectQuery | ( | const StatementIndex & | index,
|  | const MySqlBindingCollection & | in_bindings,
|  | MySqlBindingCollection & | out_bindings,
|  | ConsumeResultFun | process_result )
| inline

Executes SELECT query using prepared statement.

The statement index must point to an existing prepared statement associated with the connection. The `in_bindings` size must match the number of placeholders in the prepared statement. The size of the `out_bindings` must match the number of selected columns. The output bindings must be created and must encapsulate values of the appropriate type, e.g. string, uint32_t etc.

This method executes prepared statement using provided bindings and calls `process_result` function for each returned row. The `process_result` function is implemented by the caller and should gather and store each returned row in an external data structure prior to returning because the values in the `out_bindings` will be overwritten by the values of the next returned row when this function is called again.

Template Parameters

  StatementIndex | Type of the statement index enum.

Parameters

  | index | Index of the query to be executed.
  | in_bindings | Input bindings holding values to substitue placeholders in the query.
  [out] | out_bindings | Output bindings where retrieved data will be stored.
  | process_result | Pointer to the function to be invoked for each retrieved row. This function consumes the retrieved data from the output bindings.

Definition at line 482 of file mysql_connection.h.

References checkError(), isc::db::DatabaseConnection::checkUnusable(), getStatement(), isc_throw, isc::db::MLM_MYSQL_FETCH_FAILURE, isc::db::MLM_MYSQL_FETCH_SUCCESS, isc::db::MysqlExecuteStatement(), and text_statements_.

Here is the call graph for this function:

## ◆ startRecoverDbConnection()

void isc::db::MySqlConnection::startRecoverDbConnection | ( |  | ) |
| inline

The recover connection.

This function starts the recover process of the connection.

Note
  The recover function must be run on the IO Service thread.

Definition at line 744 of file mysql_connection.h.

References isc::db::DatabaseConnection::callback_, io_service_, io_service_accessor_, and isc::db::DatabaseConnection::reconnectCtl().

Referenced by checkError(), and openDatabase().

Here is the call graph for this function:

## ◆ startTransaction()

void isc::db::MySqlConnection::startTransaction | ( |  | ) |

Starts new transaction.

This function begins a new transaction by sending the START TRANSACTION statement to the database. The transaction should be explicitly committed by calling `commit()` or rolled back by calling `rollback()`. MySQL does not support nested transactions, and it implicitly commits a current transaction when the new transaction begins. Therefore, this function checks if a transaction has already started and does not start a new transaction. However, it increments a transaction reference counter which is later decremented when `commit()` or `rollback()` is called. When this mechanism is used properly, it guarantees that nested transactions are not attempted, thus avoiding implicit (unexpected) commits of the pending transaction.

Definition at line 633 of file mysql_connection.cc.

References isc::db::DatabaseConnection::checkUnusable(), isc::db::DB_DBG_TRACE_DETAIL, isc_throw, mysql_, isc::db::MYSQL_START_TRANSACTION, and transaction_ref_count_.

Here is the call graph for this function:

## ◆ toKeaAdminParameters()

vector< string > isc::db::MySqlConnection::toKeaAdminParameters | ( | ParameterMap const & | params | ) |
| static

Convert MySQL library parameters to kea-admin parameters.

Parameters

  params | input MySQL parameters

Returns
  vector of kea-admin parameters

Definition at line 503 of file mysql_connection.cc.

Referenced by initializeSchema().

## ◆ updateDeleteQuery()

template<typename StatementIndex>

uint64_t isc::db::MySqlConnection::updateDeleteQuery | ( | const StatementIndex & | index,
|  | const MySqlBindingCollection & | in_bindings )
| inline

Executes UPDATE or DELETE prepared statement and returns the number of affected rows.

The statement index must point to an existing prepared statement associated with the connection. The `in_bindings` size must match the number of placeholders in the prepared statement.

Template Parameters

  StatementIndex | Type of the statement index enum.

Parameters

  index | Index of the query to be executed.
  in_bindings | Input bindings holding values to substitute placeholders in the query.

Returns
  Number of affected rows.

Definition at line 606 of file mysql_connection.h.

References checkError(), isc::db::DatabaseConnection::checkUnusable(), getStatement(), isc_throw, mysql_, and isc::db::MysqlExecuteStatement().

Here is the call graph for this function:

## Member Data Documentation

## ◆ io_service_

isc::asiolink::IOServicePtr isc::db::MySqlConnection::io_service_

IOService object, used for all ASIO operations.

Definition at line 821 of file mysql_connection.h.

Referenced by MySqlConnection(), and startRecoverDbConnection().

## ◆ io_service_accessor_

IOServiceAccessorPtr isc::db::MySqlConnection::io_service_accessor_

Accessor function which returns the IOService that can be used to recover the connection.

This accessor is used to lazy retrieve the IOService when the connection is lost. It is useful to retrieve it at a later time to support hook libraries which create managers on load and set IOService later on by using the dhcp4_srv_configured and dhcp6_srv_configured hooks.

Definition at line 818 of file mysql_connection.h.

Referenced by MySqlConnection(), and startRecoverDbConnection().

## ◆ KEA_ADMIN_

std::string isc::db::MySqlConnection::KEA_ADMIN_ = KEA_ADMIN
| static

Holds location to kea-admin.

By default, it points to kea-admin from installation. In tests, it points to kea-admin from sources.

Definition at line 836 of file mysql_connection.h.

Referenced by initializeSchema().

## ◆ mysql_

MySqlHolder isc::db::MySqlConnection::mysql_

MySQL connection handle.

This field is public, because it is used heavily from MySqlConnection and will be from MySqlHostDataSource.

Definition at line 809 of file mysql_connection.h.

Referenced by checkError(), commit(), getTlsCipher(), getVersion(), insertQuery(), openDatabase(), prepareStatement(), rollback(), startTransaction(), and updateDeleteQuery().

## ◆ text_statements_

std::vector<std::string> isc::db::MySqlConnection::text_statements_

Raw text of statements.

This field is public, because it is used heavily from MySqlConnection and will be from MySqlHostDataSource.

Definition at line 803 of file mysql_connection.h.

Referenced by ~MySqlConnection(), checkError(), prepareStatement(), prepareStatements(), and selectQuery().

## ◆ tls_

bool isc::db::MySqlConnection::tls_

TLS flag (true when TLS was required, false otherwise).

Definition at line 832 of file mysql_connection.h.

Referenced by MySqlConnection(), getTls(), and openDatabase().

## ◆ transaction_ref_count_

int isc::db::MySqlConnection::transaction_ref_count_

Reference counter for transactions.

It precludes starting and committing nested transactions. MySQL implicitly commits current transaction when new transaction is started. We want to not start new transactions when one is already in progress.

Definition at line 829 of file mysql_connection.h.

Referenced by MySqlConnection(), commit(), isTransactionStarted(), rollback(), and startTransaction().

The documentation for this class was generated from the following files:

- mysql_connection.h
- mysql_connection.cc