File: main.page

package info (click to toggle)
tntdb 1.4-2
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 1,632 kB
  • sloc: cpp: 15,806; makefile: 261; ansic: 260; sql: 158; sh: 11
file content (88 lines) | stat: -rw-r--r-- 1,939 bytes parent folder | download | duplicates (7)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/** \mainpage Easy to use database abstraction layer

\section intro Introduction

Tntdb is database abstraction layer for C++.

The goals are:
 - easy and safe to use
 - automatic resource management
 - database independent
 - thin layer for best performance
 - no SQL-abstraction
 - use modern C++ with exceptions and STL
 - support for multithreaded applications

A example, which lists the the content of a table:

\code
#include <iostream>
#include <tntdb/connect.h>
#include <tntdb/statement.h>
#include <tntdb/row.h>

int main(int argc, char* argv[])
{
  try
  {
    tntdb::Connection conn = tntdb::connect("sqlite:mydatabase.db");

    tntdb::Statement stmt = conn.prepare(
        "select FIRST_NAME, LAST_NAME"
        "  from ADDRESS");

    for (tntdb::Statement::const_iterator cur = stmt.begin();
         cur != stmt.end(); ++cur)
    {
      tntdb::Row row = *cur;
      std::cout << row[0].getString() << '\t' << row[1].getString() << std::endl;
    }
  }
  catch (const std::exception& e)
  {
    std::cerr << e.what() << std::endl;
  }
}
\endcode

Example: modify data:

\code
#include <iostream>
#include <tntdb/connect.h>
#include <tntdb/statement.h>
#include <tntdb/row.h>

int main(int argc, char* argv[])
{
  try
  {
    tntdb::Connection conn = tntdb::connect("sqlite:mydatabase.db");

    tntdb::Transaction trans;  // start a transaction here

    tntdb::Statement stmt = conn.prepare(
        "insert into ADDRESS (ID, FIRST_NAME, LAST_NAME)"
        "  values (:id, :firstName, :lastName)");

    stmt.set("id", 34)
        .set("firstName", "Tommi")
        .set("lastName", "Makitalo")
        .execute();

    stmt.set("id", 35)
        .set("firstName", "Linus")
        .set("lastName", "Torvalds")
        .execute();

    // if no explicit commit is executed, then rollback is done
    trans.commit();
  }
  catch (const std::exception& e)
  {
    std::cerr << e.what() << std::endl;
  }
}
\endcode

*/