Warning, /sdk/codevis/thirdparty/soci/docs/backends/mysql.md is written in an unsupported language. File is not indexed.

0001 # MySQL Backend Reference
0002 
0003 SOCI backend for accessing MySQL database.
0004 
0005 ## Prerequisites
0006 
0007 ### Supported Versions
0008 
0009 The SOCI MySQL backend should in principle work with every version of MySQL 5.x.
0010 Some of the features (transactions, stored functions) are not available when MySQL server doesn't support them.
0011 
0012 ### Tested Platforms
0013 
0014 |MySQL|OS|Compiler|
0015 |--- |--- |--- |
0016 |8.0.1|Windows 10|Visual Studio 2017 (15.3.3)|
0017 |5.5.28|OS X 10.8.2|Apple LLVM version 4.2 (clang-425.0.24)|
0018 |5.0.96|Ubuntu 8.04.4 LTS (Hardy Heron)|g++ (GCC) 4.2.4 (Ubuntu 4.2.4-1ubuntu4)|
0019 |5.7.22|macOS High Sierra 10.13.5|AppleClang 9.1.0.9020039|
0020 
0021 ### Required Client Libraries
0022 
0023 The SOCI MySQL backend requires MySQL's `libmysqlclient` client library from the [MySQL Connector/C](https://dev.mysql.com/downloads/connector/c/).
0024 
0025 Note that the SOCI library itself depends also on `libdl`, so the minimum set of libraries needed to compile a basic client program is:
0026 
0027     -lsoci_core -lsoci_mysql -ldl -lmysqlclient
0028 
0029 ## Connecting to the Database
0030 
0031 To establish a connection to a MySQL server, create a `session` object using the `mysql` backend factory together with a connection string:
0032 
0033     session sql(mysql, "db=test user=root password='Ala ma kota'");
0034 
0035     // or:
0036     session sql("mysql", "db=test user=root password='Ala ma kota'");
0037 
0038     // or:
0039     session sql("mysql://db=test user=root password='Ala ma kota'");
0040 
0041 The set of parameters used in the connection string for MySQL is:
0042 
0043 * `dbname` or `db` or `service` (required)
0044 * `user`
0045 * `password` or `pass`
0046 * `host`
0047 * `port`
0048 * `unix_socket`
0049 * `sslca`
0050 * `sslcert`
0051 * `local_infile` - should be `0` or `1`, `1` means `MYSQL_OPT_LOCAL_INFILE` will be set.
0052 * `charset`
0053 * `reconnect` - if set to 1, set `MYSQL_OPT_RECONNECT` to reconnect on connection loss.
0054 * `connect_timeout` - should be positive integer value that means seconds corresponding to `MYSQL_OPT_CONNECT_TIMEOUT`.
0055 * `read_timeout` - should be positive integer value that means seconds corresponding to `MYSQL_OPT_READ_TIMEOUT`.
0056 * `write_timeout` - should be positive integer value that means seconds corresponding to `MYSQL_OPT_WRITE_TIMEOUT`.
0057 
0058 Once you have created a `session` object as shown above, you can use it to access the database, for example:
0059 
0060     int count;
0061     sql << "select count(*) from invoices", into(count);
0062 
0063 (See the [connection](../connections.md) and [data binding](../binding.md) documentation
0064 for general information on using the `session` class.)
0065 
0066 ## SOCI Feature Support
0067 
0068 ### Dynamic Binding
0069 
0070 The MySQL backend supports the use of the SOCI `row` class, which facilitates retrieval of data which type is not known at compile time.
0071 
0072 When calling `row::get<T>()`, the type you should pass as `T` depends upon the underlying database type.
0073 For the MySQL backend, this type mapping is:
0074 
0075 |MySQL Data Type|SOCI Data Type|`row::get<T>` specializations|
0076 |--- |--- |--- |
0077 |FLOAT, DOUBLE, DECIMAL and synonyms|dt_double|double|
0078 |TINYINT, TINYINT UNSIGNED, SMALLINT, SMALLINT UNSIGNED, INT|dt_integer|int|
0079 |INT UNSIGNED|dt_long_long|long long or unsigned|
0080 |BIGINT|dt_long_long|long long|
0081 |BIGINT UNSIGNED|dt_unsigned_long_long|unsigned long long|
0082 |CHAR, VARCHAR, BINARY, VARBINARY, TINYBLOB, MEDIUMBLOB, BLOB,LONGBLOB, TINYTEXT, MEDIUMTEXT, TEXT, LONGTEXT, ENUM|dt_string|std::string|
0083 |TIMESTAMP (works only with MySQL >= 5.0), DATE, TIME, DATETIME|dt_date|std::tm|
0084 
0085 (See the [dynamic resultset binding](../types.md#dynamic-binding) documentation for general information
0086 on using the `Row` class.)
0087 
0088 ### Binding by Name
0089 
0090 In addition to [binding by position](../binding.md#binding-by-position), the MySQL backend supports
0091 [binding by name](../binding.md#binding-by-name), via an overload of the `use()` function:
0092 
0093     int id = 7;
0094     sql << "select name from person where id = :id", use(id, "id")
0095 
0096 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.
0097 
0098 ### Bulk Operations
0099 
0100 ### Transactions
0101 
0102 [Transactions](../transactions.md) 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.
0103 
0104 ### BLOB Data Type
0105 
0106 SOCI `blob` interface is not supported by the MySQL backend.
0107 
0108 Note that this does not mean you cannot use MySQL's `BLOB` types.  They can be selected using the usual SQL syntax and read into `std::string` on the C++ side, so no special interface is required.
0109 
0110 ### RowID Data Type
0111 
0112 The `rowid` functionality is not supported by the MySQL backend.
0113 
0114 ### Nested Statements
0115 
0116 Nested statements are not supported by the MySQL backend.
0117 
0118 ### Stored Procedures
0119 
0120 MySQL version 5.0 and later supports two kinds of stored routines: stored procedures and stored functions (for details, please consult the [Defining Stored Programs](https://dev.mysql.com/doc/refman/5.5/en/stored-programs-defining.html)). Stored functions can be executed by using SOCI's [procedure class](../procedures.md). There is currently no support for stored procedures.
0121 
0122 ## Native API Access
0123 
0124 SOCI provides access to underlying datbabase APIs via several `get_backend()` functions, as described in the [Beyond SOCI](../beyond.md) documentation.
0125 
0126 The MySQL backend provides the following concrete classes for native API access:
0127 
0128 |Accessor Function|Concrete Class|
0129 |--- |--- |
0130 |session_backend * session::get_backend()|mysql_session_backend|
0131 |statement_backend * statement::get_backend()|mysql_statement_backend|
0132 
0133 ## Backend-specific extensions
0134 
0135 None.
0136 
0137 ## Configuration options
0138 
0139 None.