The SOCI MySQL backend should in principle work with every version of MySQL 3.x or newer. Some of the features (transactions, stored functions) are not available when MySQL server doesn't support them.
|MySQL version||Operating System||Compiler|
|5.0.45||Linux i686 2.6.23 (Fedora release 7)||g++ 4.1.2|
The SOCI MySQL backend requires MySQL's
Note that the SOCI library itself depends also on
libdl, so the minimum set of libraries needed to compile a basic client program is:
-lsoci_core -lsoci_mysql -ldl -lmysqlclient
To establish a connection to a MySQL server, create a
mysql backend factory together with a connection
session sql(mysql, "db=test user=root password='Ala ma kota'"); // or: session sql("mysql", "db=test user=root password='Ala ma kota'"); // or: session sql("mysql://db=test user=root password='Ala ma kota'");
The set of parameters used in the connection string for MySQL is:
Once you have created a
session object as shown above, you
can use it to access the database, for example:
int count; sql << "select count(*) from invoices", into(count);
The MySQL backend supports the use of the SOCI
which facilitates retrieval of data which type is not known at compile
row::get<T>(), the type you should pass
T depends upon the underlying database type.
For the MySQL backend, this type mapping is:
|MySQL Data Type||SOCI Data Type||
|FLOAT, DOUBLE, DECIMAL and synonyms||
|TINYINT, SMALLINT, INT, BIGINT (provided it's in the range)||
|TIMESTAMP (works only with MySQL >= 5.0), DATE, TIME, DATETIME||
(See the dynamic resultset binding documentation for general information on using the
int id = 7; sql << "select name from person where id = :id", use(id, "id")
It should be noted that parameter binding of any kind is supported only by means of emulation, since the underlying API used by the backend doesn't provide this feature.
The MySQL backend has full support for SOCI's bulk operations interface. This feature is also supported by emulation.
Transactions are also supported by the MySQL backend. Please note, however, that transactions can only be used when the MySQL server supports them (it depends on options used during the compilation of the server; typically, but not always, servers >=4.0 support transactions and earlier versions do not) and only with appropriate table types.
blob interface is not supported by the MySQL backend.
rowid functionality is not supported by the MySQL backend.
Nested statements are not supported by the MySQL backend.
MySQL version 5.0 and later supports two kinds of stored routines: stored procedures and stored functions (for details, please consult the MySQL documentation). Stored functions can be executed by using SOCI's procedure class. There is currently no support for stored procedures.
SOCI provides access to underlying datbabase APIs via several
get_backend() functions, as described in the Beyond SOCI documentation.
The MySQL backend provides the following concrete classes for native API access:
|Accessor Function||Concrete Class|
Copyright © 2004-2009 Maciej Sobczak, Stephen Hutton, Pawel Aleksander Fedorynski