summaryrefslogtreecommitdiff
path: root/tests/psql/test1.cpp
blob: 140f419a8ca7d7ad77165b55763574fa6315d131 (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
#include <iostream>
#include <sstream>
#include <stdio.h>

#include "pqxx/pqxx"

using namespace pqxx;
using namespace PGSTD;
using namespace std;

int main( ) {
	connection c( "dbname=test" );

	//c.trace( stdout );

	cout << "Conntected to database." << endl
	     << "Backend protocol version: " << c.server_version( ) << endl
	     << "Protocol version: " << c.protocol_version( ) << 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( );

	return 0;
}