@@ -13,7 +13,7 @@ Welcome to Boost.Mysql's tutorial. We will go through the simplest
13
13
possible piece of code using Boost.Mysql: a program that connects
14
14
to the MySQL server and issues the query `SELECT "Hello World!"`.
15
15
16
- This tutorial assumes you have a running MySQL server listening
16
+ To run this tutorial, you need a running MySQL server listening
17
17
in localhost on port 3306 (the default one). You should have
18
18
the credentials of a valid MySQL user (username and password).
19
19
No further setup is needed.
@@ -46,7 +46,8 @@ which accepts two parameters:
46
46
47
47
* The first one specifies the network address of the MySQL server.
48
48
As we are using TCP, this is a [asioreflink ip__tcp/endpoint ip::tcp::endpoint],
49
- identifying the host and port to connect to.
49
+ identifying the host and port to connect to. We will use a `boost::asio::ip::tcp::resolver`
50
+ to convert the string hostname into a `boost::asio::ip::tcp::endpoint`.
50
51
* The second one is a collection of MySQL handshake parameters, including
51
52
username and password. This parameter must be an instance of
52
53
[reflink handshake_params]. You may also set other options like
@@ -65,33 +66,25 @@ which accepts two parameters:
65
66
The next step is to issue the query to the server. We will use
66
67
[reflink2 connection.query tcp_ssl_connection::query],
67
68
which accepts a string containing a single SQL query and instructs
68
- the server to run it. It returns a [reflink tcp_ssl_resultset ]
69
- object, which allows to read the query results :
69
+ the server to run it. It returns a [reflink resultset ]
70
+ object, containing the rows returned by the query:
70
71
71
72
[tutorial_query]
72
73
73
- [heading Reading the results]
74
+ [heading Obtaining the results]
74
75
75
- A [reflink resultset] is an object that represents the result of a query.
76
- Resultsets are not containers, but I/O objects:
77
- they do not contain by themselves the entire result of the query, but allow
78
- the user to read it using several methods. We will use
79
- [reflink2 resultset.read_all tcp_ssl_resultset::read_all], which
80
- reads all the rows in the resultset and places them in a [reflink rows]
81
- object:
76
+ A [reflink resultset] is an object that holds the result of a query in memory.
77
+ To obtain the value we selected, we can write:
82
78
83
- [tutorial_read ]
79
+ [tutorial_resultset ]
84
80
85
- A [reflink rows] object is a matrix-like container of MySQL fields.
86
- Each field is represented as a [reflink field_view], a variant-like class that
87
- can hold any type allowed in MySQL.
88
-
89
- [tutorial_fields]
90
-
91
- The operation `all_rows.at(0)` returns the first row from the `all_rows`
92
- container. From that row, we select the first field using `.at(0)` again.
93
- We finally stream the returned `field_view`
94
- to `std::cout`, which prints the expected phrase to the console.
81
+ Let's break this into steps:
82
+ * [refmem resultset rows] returns all the rows that this resultset contains.
83
+ It returns a [reflink rows_view], which is a matrix-like structure.
84
+ * `result.rows().at(0)` returns the first row in the resultset, represented as a [reflink row_view].
85
+ * `result.rows().at(0).at(0)` returns the first field in the first row. This is a
86
+ [reflink field_view], a variant-like class that can hold any type allowed in MySQL.
87
+ * The obtained `field_view` is streamed to `std::cout`.
95
88
96
89
[heading Closing the connection]
97
90
@@ -104,7 +97,7 @@ we are closing the connection, and thus may fail.
104
97
105
98
[heading Final notes]
106
99
107
- This concludes our __Self__ tutorial! You can now learn more about the
100
+ This concludes our tutorial! You can now learn more about the
108
101
core functionality of this library in the [link mysql.overview overview section].
109
102
You can also look at more complex [link mysql.examples examples].
110
103
0 commit comments