summaryrefslogtreecommitdiffstats
path: root/server/test/test_mult-db-open.cc
blob: b80302600e122545019b868eee54e1bbfb9428cf (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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
* This file is part of rasdaman community.
*
* Rasdaman community is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Rasdaman community is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with rasdaman community.  If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
rasdaman GmbH.
*
* For more information please see <http://www.rasdaman.org>
* or contact Peter Baumann via <baumann@rasdaman.com>.
*/
/*************************************************************
 *
 *
 * PURPOSE:
 *
 *
 * COMMENTS:
 *
 ************************************************************/

static const char rcsid[] = "@(#)exportutils,ExportData: $Id: exporttif.cc,v 1.1 2003/12/27 21:44:18 rasdev Exp $";

#ifndef RMANVERSION
#error "Please specify RMANVERSION variable!"
#endif

#ifndef COMPDATE
#error "Please specify the COMPDATE variable!"
/*
COMPDATE=`date +"%d.%m.%Y %H:%M:%S"`

and -DCOMPDATE="\"$(COMPDATE)\"" when compiling
*/
#endif


#ifdef EARLY_TEMPLATE
#define __EXECUTABLE__
#ifdef __GNUG__
#include "raslib/template_inst.hh"
#endif
#endif

#include <iostream>
#include <cstdio>
#include <cctype>

using std::vector;
using std::iterator;
 
#if defined(SOLARIS)
#	include <strings.h>
#else
#	include <cstring>
#endif

#include "mymalloc/mymalloc.h"

// here is the main prog for allocating debug macro vars
#define DEBUG_MAIN
#include "debug.hh"

#include "rasodmg/transaction.hh"
#include "rasodmg/database.hh"


// global variables and default settings
// -------------------------------------

r_Database db;
r_Transaction ta;

const char* server          = DEFAULT_SERV;
unsigned int port           = DEFAULT_PORT;
const char* database        = DEFAULT_DB;
const char* user            = DEFAULT_USER;
const char* passwd          = DEFAULT_PASSWD;


void
openDatabase() throw (r_Error)
{
        ENTER( "openDatabase" );

	if (! dbIsOpen)
	{
		cout << "Opening database " <<  database  << " at " << server << ":" << port << "..." << flush;
        	db.set_servername(server, port);
        	db.set_useridentification( user, passwd);
        	TALK( "database was closed, opening database=" <<  database  << ", server=" << server << ", port=" << port << ", user=" <<  user << ", passwd=" << passwd << "..." );
        	db.open( database );
		TALK( "done" );
		dbIsOpen = true;
		cout << "ok" << endl << flush;
	}

        LEAVE( "openDatabase" );
}

void
closeDatabase() throw (r_Error)
{
        ENTER( "closeDatabase" );

	if (dbIsOpen)
	{
        	TALK( "database was open, closing it" );
		db.close();
		dbIsOpen = false;
	}

        LEAVE( "closeDatabase" );
        return;
}


int main(int argc, char** argv)
{
	SET_OUTPUT( false );		// inhibit unconditional debug output, await cmd line evaluation

	int retval = EXIT_FAILURE;

	cout << argv[0] << ": rasdaman test 'failure upon multiple db open' for rasdaman v" << RMANVERSION/1000 << " -- generated on " << COMPDATE << endl;

	try
	{
		openDatabase();

		closeDatabase();

		retval = EXIT_SUCCESS;
	}
	catch (ExportError& e)
	{
		cout << argv[0] << ": " << e.what() << endl;
		retval = EXIT_FAILURE;
	}
	catch (const r_Error& e)
	{
		cout << argv[0] << ": rasdaman error " << e.get_errorno() << ": " << e.what() << endl;
		retval = EXIT_FAILURE;
	}
	catch (...)
	{
		cout << argv[0] << ": panic: unexpected internal exception." << endl;
		retval = EXIT_FAILURE;
	}

	cout << argv[0] << " done." << endl;

	return retval;
}