mirror of
https://github.com/boostorg/mysql.git
synced 2025-05-12 14:11:41 +00:00
5.4 KiB
5.4 KiB
Upgrade instructions to 1.82
This document describes how to upgrade from 0.2.x to 1.82 (please remember that 1.82 is the first stable release in this library, and the versioning follows Boost versioning).
This is a major upgrade, since a lot of changes have been made since the review took place. If you encounter any problems, please file an issue against the repository, and we will be happy to help :)
- The
value
class has been replaced byfield_view
. The generic accessors have been replaced by type-specific functions. Conversions,get_optional
andget_std_optional
have been removed, in favor of an interface more similar tojson::value
. The classfield
has been added to be able to take ownership of afield_view
.- Action: replace
value
byfield_view
.
- Action: replace
- Statements are no longer I/O objects.
connection::prepare_statement
works the same, but execution requires going through the connection.- Action: replace
stmt.execute(...)
byconn.execute_statement(stmt, ...)
,stmt.close()
byconn.close_statement(stmt)
.
- Action: replace
- Resultsets as I/O objects have been removed, and executing queries and statements is now simpler. There are now two ways to run queries or statements:
connection::query
andconnection::execute_statement
now read all rows into memory, into aresults
object (which is similar toresultset
, but is a plain data object and contains all the rows). These functions are equivalent to the oldconnection::query
/statement::execute
plusresultset::read_all
.- Action: if you were using
conn.query(...).read_all()
(or similar), replace it byconn.query(...)
.
- Action: if you were using
connection::start_query
andstatement::start_execution
behave similarly to the oldconnection::query
andstatement::execute
. They use a data structure calledexecution_state
, which is similar to the oldresultset
.- Action: if you were reading rows using
read_one
orread_many
, consider whether your application requires reading row-by-row or not. If it doesn't, apply the point above. If it does, replaceconn.query(...)
byconn.start_query(...)
, andresult.read_one(...)
byconn.read_some_rows(...)
. There is no function to read a single row.
- Action: if you were reading rows using
- Statement parameters are now passed as a
std::tuple
toexecute_statement
, rather than a collection.- Action:
- If you were using
stmt.execute(make_values(a, b), ...)
, replace it byconn.execute_statement(std::make_tuple(a, b), ...)
- If you were using a collection and can't migrate to a
std::tuple
(because the number of parameters is unknown at compile-time), then have a look at this solution.
- If you were using
- Action:
error_info
has been renamed todiagnostics
anderror_info::message()
todiagnostics::server_message()
. The message is no longer included by default in the thrown exceptions'swhat()
. This is because the message may not be UTF-8 compatible.- Action: apply the renames. If you're using exceptions, catch the new
error_with_diagnostics
exception type to retrieve the server message.
- Action: apply the renames. If you're using exceptions, catch the new
- The
date
anddatetime
types are now custom types, instead of aliases forstd::chrono
. This enables them to represent zero and invalid dates.- Action: to get a
time_point
from adate
ordatetime
, useas_time_point
orget_time_point
+valid
.
- Action: to get a
- Binary types (
BLOB
,BINARY
,VARBINARY
,GEOMETRY
) are now represented as a special typeblob_view
/blob
.- Action: if you handle these types in your application, use
is_blob
,get_blob
andas_blob
functions infield_view
.
- Action: if you handle these types in your application, use
- The
collation
enum has been removed in favor of plain integers.- Action: if you were using collations explicitly, replace the enumerator by the collation ID. You can find them in
<boost/mysql/mysql_collations.hpp>
and<boost/mysql/mariadb_collations.hpp>
.
- Action: if you were using collations explicitly, replace the enumerator by the collation ID. You can find them in
connection_params
has been reverted tohandshake_params
.- Action: replace occurrences of
connection_params
byhandshake_params
.
- Action: replace occurrences of
row
is no longer streamable. The stream operation onrow
wasn't a universal agreement.- Action: if you were streaming rows, switch to using a loop and streaming individual
field_view
s, instead.
- Action: if you were streaming rows, switch to using a loop and streaming individual
- Metadata strings is no longer retained by default, to save allocations.
- Action: if your code uses metadata strings (e.g.
metadata::column_name()
, useconn.set_metadata_mode(metadata_mode::full))
before initiating any query/statement execution.
- Action: if your code uses metadata strings (e.g.
- The library now uses
boost::core::string_view
(under the aliasboost::mysql::string_view
) rather thanboost::string_view
.- Action: if you were using
boost::string_view
directly, change it toboost::mysql::string_view
.
- Action: if you were using
errc
has been split intoclient_errc
,server_errc
and server-specific error codes (which don't have an enum).- Action: if you were referencing
errc
values directly, replaceerrc
byclient_errc
orserver_errc
.
- Action: if you were referencing
field_type
has been renamed tocolumn_type
.- Action: apply the rename.
- The following members in
metadata
have been renamed:field_name
=>column_name
original_field_name
=>original_column_name
character_set
=>column_collation
- Action: apply the renames.
connection::next_layer()
has been renamed toconnection::stream()
.- Action: apply the rename.
no_statement_params
has been removed.- Action: replace it by an empty
std::make_tuple()
.
- Action: replace it by an empty