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();

Destroys the SessionImpl.

Member Functions

autoCommit

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

Sets autocommit property for the session.

begin

void begin();

Starts a transaction

canTransact inline

bool canTransact() const;

Returns true if session has transaction capabilities.

close

void close();

Closes the connection.

commit

void commit();

Commits and ends a transaction

connectorName inline

const std::string & connectorName() const;

Returns the name of the connector.

createStatementImpl

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

Returns an MySQL StatementImpl

getConnectionTimeout inline

std::size_t getConnectionTimeout() const;

Returns the session connection timeout value.

getFailIfInnoReadOnly inline

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

Returns the state of the "failIfInnoReadOnly" feature.

getInsertId inline

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

Get insert id

getLastError inline

int getLastError() const;

Returns the last set error code.

getTransactionIsolation

Poco::UInt32 getTransactionIsolation() const;

Returns the transaction isolation level.

handle inline

SessionHandle & handle();

hasTransactionIsolation

bool hasTransactionIsolation(
    Poco::UInt32 ti
) const;

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;

Returns true if connected, false otherwise.

isGood

bool isGood() const;

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 inline

bool isTransaction() const;

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

isTransactionIsolation inline

bool isTransactionIsolation(
    Poco::UInt32 ti
) const;

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

open

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

Opens a connection to the database.

reset

void reset();

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

rollback

void rollback();

Aborts a transaction

setConnectionTimeout

void setConnectionTimeout(
    std::size_t timeout
);

Sets the session connection timeout value.

setFailIfInnoReadOnly inline

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

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

setInsertId inline

void setInsertId(
    const std::string & param31,
    const Poco::Any & param32
);

Try to set insert id - do nothing.

setLastError inline

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
);

Sets the transaction isolation level.

Variables

MYSQL_READ_COMMITTED static

static const std::string MYSQL_READ_COMMITTED;

MYSQL_READ_UNCOMMITTED static

static const std::string MYSQL_READ_UNCOMMITTED;

MYSQL_REPEATABLE_READ static

static const std::string MYSQL_REPEATABLE_READ;

MYSQL_SERIALIZABLE static

static const std::string MYSQL_SERIALIZABLE;