blob: 6fcb567871ef8af31a1279f50632b987e53bd85c (
plain)
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
|
#include <iostream>
#include <sstream>
#include <stdio.h>
#include "sqlite3xx/sqlite3xx"
using namespace sqlite3xx;
using namespace std;
int main( ) {
try {
// connection c( "dbname=test" );
connection c( "test1.db" );
//c.trace( stdout );
cout << "Connected to database." << endl;
// << "Backend protocol version: " << c.server_version( ) << endl
// << "Protocol version: " << c.protocol_version( ) << endl
// << "Server PID: " << c.backendpid( ) << endl
// << "Prepared Statements: " << c.supports( c.cap_prepared_statements ) << endl;
work t( c, "test_transaction" );
t.exec( "create table test( a integer, b integer)" );
for( unsigned int i = 0; i < 1000; i++ ) {
ostringstream sql;
sql << "insert into test values( '" << i << "', '" << i << "' )";
t.exec( sql.str( ) );
}
result r( t.exec( "select * from test" ) );
cout << "a\tb" << endl;
for( result::size_type i = 0; i < r.size( ); i++ ) {
cout << r[i]["a"] << "\t" << r[i]["b"] << endl;
}
t.exec( "drop table test" );
t.commit( );
} catch( sql_error& e ) {
cerr << e.what( ) << ": " << e.query( ) << endl;
}
return 0;
}
|