File: intro.txt

package info (click to toggle)
cppdb 0.3.1%2Bdfsg-9
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 676 kB
  • sloc: cpp: 7,373; sh: 133; ansic: 72; makefile: 6
file content (53 lines) | stat: -rw-r--r-- 1,880 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//-----------------------------------------------------------

/*! \page intro Quick Start Guide

\section codesmaple The Code

The best is to start from this example

\include example1.cpp


First we connect to the database using \ref connstr "cppdb connection string". Then
we execute a simple sql query.

When you write

\code
	sql << "DROP TABLE IF EXISTS test" << cppdb::exec;
\endcode

\section codedesc Description


You actually first prepare a statement (using first operator "<<") and then execute it using a cppdb::exec manipulator.
In the same way we create the table we need.

Then we create a statement that we will use multiple times. At first we prepare a statement using
operator "<<" and then we bind parameters to it. Note, the string is passed as is without escaping
it in any way. Then we execute a statement calling stat.exec(). Note it could be done using
manipulator as well in previous line, but this is just a more verbose way and probably more clean way
to do it.

Then calling stat.last_insert_id() and stat.affected() we fetch the data about last executed statement.

We can use our statement again after calling cppdb::statement::reset() function. In the next
statement execution we would use more "verbose" variant of binding parameters - using bind()
functions of statement, and then executing it.


Then fetch the results we created. We prepare a query and assign it into \a res variable
efficiently fetching the query result.

Then we iterate over result's rows using res.next(), for each row we fetch the data using
operator ">>".

In the next query we select several values into a single row.  We prepare a statement,
bind a key 1 for the placeholder "?" and then we check if the row was actually fetched
and we fetch values. We can fetch values using operator ">>" as above, however we can
also fetch them using column names or indexes.


*/