# Poco::Data::MySQL

# class SessionImpl

Library: Data/MySQL
Package: MySQL
Header: Poco/Data/MySQL/SessionImpl.h

## Description

Implements SessionImpl interface

## Inheritance

Direct Base Classes: Poco::Data::AbstractSessionImpl < SessionImpl >

All Base Classes: Poco::Data::AbstractSessionImpl < SessionImpl >

## Member Summary

Member Functions: autoCommit, begin, canTransact, close, commit, connectorName, createStatementImpl, getConnectionTimeout, getFailIfInnoReadOnly, getInsertId, getLastError, getTransactionIsolation, handle, hasTransactionIsolation, isAutoCommit, isConnected, isGood, isTransaction, isTransactionIsolation, open, reset, rollback, setConnectionTimeout, setFailIfInnoReadOnly, setInsertId, setLastError, setTransactionIsolation

## Constructors

### SessionImpl

SessionImpl(
const std::string & connectionString,
std::size_t loginTimeout = LOGIN_TIMEOUT_DEFAULT
);

Creates the SessionImpl. Opens a connection to the database.

Connection string format:

    <str> == <assignment> | <assignment> ';' <str>
    <assignment> == <name> '=' <value>
    <name> == 'host' | 'port' | 'user' | 'password' | 'db' | 'compress' | 'auto-reconnect' | 'reset' | 'fail-readonly'
    <value> == [~;]*

The following settings are supported:

- host: MySQL server hostname or IP address (default: localhost)
- port: MySQL server port number (default: 3306)
- user: MySQL user name
- password: MySQL password
- compress: enable compression (true/false; default: false)
- auto-reconnect: enable automatic reconnect (true/false; default: false)
- secure-auth: use secure authentication (true/false; default: false)
- character-set: connection character set (default: utf8)
- reset: reset connection when returned to SessionPool by calling mysql_reset_connection().
- fail-readonly: if set to true, the session will fail if the database becomes read-only. This corresponds to setFailIfInnoReadOnly(true).

Warning: Due to a bug in MySQL, resetting the connection with mysql_reset_connection() could change the character encoding used for the connection. Therefore the reset option should be used with caution.

## Destructor

### ~SessionImpl

~SessionImpl() override;

Destroys the SessionImpl.

## Member Functions

### autoCommit

void autoCommit(
const std::string & param19,
bool val
);

Sets autocommit property for the session.

### begin

void begin() override;

Starts a transaction

### canTransact

bool canTransact() const override;

Returns true if session has transaction capabilities.

### close

void close() override;

Closes the connection.

### commit

void commit() override;

Commits and ends a transaction

### connectorName

const std::string & connectorName() const override;

Returns the name of the connector.

### createStatementImpl

Poco::SharedPtr < Poco::Data::StatementImpl > createStatementImpl() override;

Returns an MySQL StatementImpl

### getConnectionTimeout

std::size_t getConnectionTimeout() const override;

Returns the session connection timeout value.

### getFailIfInnoReadOnly

bool getFailIfInnoReadOnly(
const std::string & param24
) const;

Returns the state of the "failIfInnoReadOnly" feature.

### getInsertId

Poco::Any getInsertId(
const std::string & param22
) const;

Get insert id

### getLastError

int getLastError() const;

Returns the last set error code.

### getTransactionIsolation

Poco::UInt32 getTransactionIsolation() const override;

Returns the transaction isolation level.

### handle

SessionHandle & handle();

### hasTransactionIsolation

bool hasTransactionIsolation(
Poco::UInt32 ti
) const override;

Returns true iff the transaction isolation level corresponding to the supplied bitmask is supported.

### isAutoCommit

bool isAutoCommit(
const std::string & name = ""
) const;

Returns autocommit property value.

### isConnected

bool isConnected() const override;

Returns true if connected, false otherwise.

### isGood

bool isGood() const override;

Returns true iff the database session is good. For the session to be considered good:

- it must be connected
- and it's last error code must be 0, or mysql_ping() must be okay.

Furthermore, if the "failIfInnoReadOnly" property has been set to true, the innodb_read_only setting must be false. The flag is only checked if the session has a non-zero error code.

### isTransaction

bool isTransaction() const override;

Returns true iff a transaction is a transaction is in progress, false otherwise.

### isTransactionIsolation

bool isTransactionIsolation(
Poco::UInt32 ti
) const override;

Returns true iff the transaction isolation level corresponds to the supplied bitmask.

### open

void open(
const std::string & connection = ""
) override;

Opens a connection to the database.

### reset

void reset() override;

Reset connection with dababase and clears session state, but without disconnecting

### rollback

void rollback() override;

Aborts a transaction

### setConnectionTimeout

void setConnectionTimeout(
std::size_t timeout
) override;

Sets the session connection timeout value.

### setFailIfInnoReadOnly

void setFailIfInnoReadOnly(
const std::string & param23,
bool value
);

Sets the "failIfInnoReadOnly" feature. If set, isGood() will return false if the database is in read-only mode.

### setInsertId

void setInsertId(
const std::string & param20,
const Poco::Any & param21
);

Try to set insert id - do nothing.

### setLastError

void setLastError(
int err
);

Sets an error code. If a non-zero error code is set, the session is considered bad.

### setTransactionIsolation

void setTransactionIsolation(
Poco::UInt32 ti
) override;

Sets the transaction isolation level.

## Variables

### MYSQL_READ_COMMITTED

static const std::string MYSQL_READ_COMMITTED;

### MYSQL_READ_UNCOMMITTED

static const std::string MYSQL_READ_UNCOMMITTED;

### MYSQL_REPEATABLE_READ

static const std::string MYSQL_REPEATABLE_READ;

### MYSQL_SERIALIZABLE

static const std::string MYSQL_SERIALIZABLE;