| 1 |
//----------------------------------------------------------- |
| 2 |
|
| 3 |
/*! \page intro Quick Start Guide |
| 4 |
|
| 5 |
\section codesmaple The Code |
| 6 |
|
| 7 |
The best is to start from this example |
| 8 |
|
| 9 |
\include example1.cpp |
| 10 |
|
| 11 |
|
| 12 |
First we connect to the database using \ref connstr "cppdb connection string". Then |
| 13 |
we execute a simple sql query. |
| 14 |
|
| 15 |
When you write |
| 16 |
|
| 17 |
\code |
| 18 |
sql << "DROP TABLE IF EXISTS test" << cppdb::exec; |
| 19 |
\endcode |
| 20 |
|
| 21 |
\section codedesc Description |
| 22 |
|
| 23 |
|
| 24 |
You actually first prepare a statement (using first operator "<<") and then execute it using a cppdb::exec manipulator. |
| 25 |
In the same way we create the table we need. |
| 26 |
|
| 27 |
Then we create a statement that we will use multiple times. At first we prepare a statement using |
| 28 |
operator "<<" and then we bind parameters to it. Note, the string is passed as is without escaping |
| 29 |
it in any way. Then we execute a statement calling stat.exec(). Note it could be done using |
| 30 |
manipulator as well in previous line, but this is just a more verbose way and probably more clean way |
| 31 |
to do it. |
| 32 |
|
| 33 |
Then calling stat.last_insert_id() and stat.affected() we fetch the data about last executed statement. |
| 34 |
|
| 35 |
We can use our statement again after calling cppdb::statement::reset() function. In the next |
| 36 |
statement execution we would use more "verbose" variant of binding parameters - using bind() |
| 37 |
functions of statement, and then executing it. |
| 38 |
|
| 39 |
|
| 40 |
Then fetch the results we created. We prepare a query and assign it into \a res variable |
| 41 |
efficiently fetching the query result. |
| 42 |
|
| 43 |
Then we iterate over result's rows using res.next(), for each row we fetch the data using |
| 44 |
operator ">>". |
| 45 |
|
| 46 |
In the next query we select several values into a single row. We prepare a statement, |
| 47 |
bind a key 1 for the placeholder "?" and then we check if the row was actually fetched |
| 48 |
and we fetch values. We can fetch values using operator ">>" as above, however we can |
| 49 |
also fetch them using column names or indexes. |
| 50 |
|
| 51 |
|
| 52 |
*/ |
| 53 |
|