Wt
4.11.0
|
#include <Wt/Dbo/backend/MySQL.h>
Public Member Functions | |
MySQL (const std::string &db, const std::string &dbuser="root", const std::string &dbpasswd="", const std::string dbhost="localhost", unsigned int dbport=0, const std::string &dbsocket="/var/run/mysqld/mysqld.sock", int fractionalSecondsPart=-1) | |
Opens a new MySQL backend connection. | |
MySQL (const MySQL &other) | |
Copies a MySQL connection. | |
~MySQL () | |
Destructor. | |
virtual std::unique_ptr< SqlConnection > | clone () const override |
Returns a copy of the connection. | |
bool | connect (const std::string &db, const std::string &dbuser="root", const std::string &dbpasswd="", const std::string &dbhost="localhost", unsigned int dbport=0, const std::string &dbsocket="/var/run/mysqld/mysqld.sock") |
Tries to connect. | |
MySQL_impl * | connection () |
Returns the underlying connection. | |
virtual void | executeSql (const std::string &sql) override |
Executes an SQL statement. | |
virtual void | startTransaction () override |
Starts a transaction. | |
virtual void | commitTransaction () override |
Commits a transaction. | |
virtual void | rollbackTransaction () override |
Rolls back a transaction. | |
virtual std::unique_ptr< SqlStatement > | prepareStatement (const std::string &sql) override |
Prepares a statement. | |
int | getFractionalSecondsPart () const |
Returns the supported fractional seconds part. | |
void | setFractionalSecondsPart (int fractionalSecondsPart) |
Set the supported fractional seconds part. | |
Methods that return dialect information | |
virtual std::string | autoincrementSql () const override |
Returns the 'autoincrement' SQL type modifier. | |
virtual std::string | autoincrementType () const override |
Returns the 'autoincrement' SQL type. | |
virtual std::string | autoincrementInsertSuffix (const std::string &id) const override |
Returns the suffix for an 'autoincrement' insert statement. | |
virtual std::vector< std::string > | autoincrementCreateSequenceSql (const std::string &table, const std::string &id) const override |
Returns the SQL statement(s) required to create an id sequence. | |
virtual std::vector< std::string > | autoincrementDropSequenceSql (const std::string &table, const std::string &id) const override |
Returns the SQL statement(s) required to drop an id sequence. | |
virtual const char * | dateTimeType (SqlDateTimeType type) const override |
Returns the date/time type. | |
virtual const char * | blobType () const override |
Returns the blob type. | |
virtual bool | supportAlterTable () const override |
Returns true if the backend support Alter Table. | |
virtual const char * | alterTableConstraintString () const override |
Returns the command used in alter table .. drop constraint .. | |
virtual bool | requireSubqueryAlias () const override |
Returns the true if the database require subquery alias. | |
Public Member Functions inherited from Wt::Dbo::SqlConnection | |
virtual | ~SqlConnection () |
Destructor. | |
virtual void | executeSqlStateful (const std::string &sql) |
Executes a connection-stateful SQL statement. | |
virtual SqlStatement * | getStatement (const std::string &id) const |
Returns the statement with the given id. | |
virtual void | saveStatement (const std::string &id, std::unique_ptr< SqlStatement > statement) |
Saves a statement with the given id. | |
void | setProperty (const std::string &name, const std::string &value) |
Sets a property. | |
std::string | property (const std::string &name) const |
Returns a property. | |
virtual std::string | autoincrementInsertInfix (const std::string &id) const |
Returns the infix for an 'autoincrement' insert statement. | |
virtual void | prepareForDropTables () |
Execute code before dropping the tables. | |
virtual std::string | textType (int size) const |
Returns the text type. | |
virtual std::string | longLongType () const |
Returns the 64-bit integer type. | |
virtual const char * | booleanType () const |
Returns the boolean type. | |
virtual bool | supportUpdateCascade () const |
Returns true if the database supports Update Cascade. | |
virtual bool | usesRowsFromTo () const |
Returns whether the SQL dialect uses 'ROWS ? TO ?', limit or rownum for partial select results. | |
virtual bool | supportDeferrableFKConstraint () const |
Returns true if the backend supports "deferrable initially
deferred" foreign key constraints. | |
A MySQL connection.
This class provides the backend implementation for mariadb databases. It has been tested against MySQL 5.6.
In order to work properly with Wt::Dbo, MySQL must be configured with InnoDB (for MySQL) or XtraDB (for mariadb) as the default database engine - so that the transaction based functionality works.
Wt::Dbo::backend::MySQL::MySQL | ( | const std::string & | db, |
const std::string & | dbuser = "root" , |
||
const std::string & | dbpasswd = "" , |
||
const std::string | dbhost = "localhost" , |
||
unsigned int | dbport = 0 , |
||
const std::string & | dbsocket = "/var/run/mysqld/mysqld.sock" , |
||
int | fractionalSecondsPart = -1 |
||
) |
Opens a new MySQL backend connection.
For the connection parameter description, please refer to the connect() method.
fractionalSecondsPart | The number of fractional units (0 to 6). A value of -1 indicates that the fractional part is not stored. Fractional seconds part are supported for MySQL 5.6.4 http://dev.mysql.com/doc/refman/5.6/en/fractional-seconds.html |
Wt::Dbo::backend::MySQL::~MySQL | ( | ) |
Destructor.
Closes the connection.
Returns the command used in alter table .. drop constraint ..
This method will return "constraint" by default. Default: ALTER TABLE .. DROP CONSTRAINT ..
Reimplemented from Wt::Dbo::SqlConnection.
|
overridevirtual |
Returns the SQL statement(s) required to create an id sequence.
This is used by Session::createTables() to create the id sequence for a table. The table's name and primary key are passed as arguments to this function and can be used to construct an SQL sequence that is unique for the table.
Implements Wt::Dbo::SqlConnection.
|
overridevirtual |
Returns the SQL statement(s) required to drop an id sequence.
This is used by Session::dropTables() to drop the id sequence for a table. The table's name and primary key are passed as arguments to this function and can be used to construct an SQL sequence that is unique for the table.
Implements Wt::Dbo::SqlConnection.
|
overridevirtual |
Returns the suffix for an 'autoincrement' insert statement.
This is appended to the insert
statement, since some back-ends need to be indicated that they should return the autoincrement id.
Implements Wt::Dbo::SqlConnection.
|
overridevirtual |
Returns the 'autoincrement' SQL type modifier.
This is used by Session::createTables() to create the id column.
Implements Wt::Dbo::SqlConnection.
|
overridevirtual |
Returns the 'autoincrement' SQL type.
This is used by Session::createTables() to create the id column.
Implements Wt::Dbo::SqlConnection.
Returns the blob type.
Implements Wt::Dbo::SqlConnection.
|
overridevirtual |
bool Wt::Dbo::backend::MySQL::connect | ( | const std::string & | db, |
const std::string & | dbuser = "root" , |
||
const std::string & | dbpasswd = "" , |
||
const std::string & | dbhost = "localhost" , |
||
unsigned int | dbport = 0 , |
||
const std::string & | dbsocket = "/var/run/mysqld/mysqld.sock" |
||
) |
Tries to connect.
db | The database name. |
dbuser | The username for the database connection - defaults to "root". |
dbpasswd | The password for the database conection - defaults to an empty string. |
dbhost | The hostname of the database - defaults to localhost. |
dbport | The portnumber - defaults to a default port. |
dbsocket | The socket to use. |
Throws an exception if there was a problem, otherwise true.
|
overridevirtual |
Returns the date/time type.
Implements Wt::Dbo::SqlConnection.
Executes an SQL statement.
This is a convenience method for preparing a statement, executing it, and deleting it.
Reimplemented from Wt::Dbo::SqlConnection.
int Wt::Dbo::backend::MySQL::getFractionalSecondsPart | ( | ) | const |
Returns the supported fractional seconds part.
By default return -1: fractional part is not stored. Fractional seconds part is supported for MySQL 5.6.4 http://dev.mysql.com/doc/refman/5.6/en/fractional-seconds.html
|
overridevirtual |
Returns the true if the database require subquery alias.
This method will return false by default.
Reimplemented from Wt::Dbo::SqlConnection.
|
overridevirtual |
Rolls back a transaction.
This function rolls back a transaction.
Implements Wt::Dbo::SqlConnection.
Set the supported fractional seconds part.
The fractional seconds part can be also set in the constructor Fractional seconds part is supported for MySQL 5.6.4 http://dev.mysql.com/doc/refman/5.6/en/fractional-seconds.html
fractionalSecondsPart | Must be in the range 0 to 6. |
|
overridevirtual |
|
overridevirtual |
Returns true if the backend support Alter Table.
This method will return false by default.
Reimplemented from Wt::Dbo::SqlConnection.