1 /*!
2  * \file db/dbmi_driver/d_opendb.c
3  *
4  * \brief DBMI Library (driver) - open database connection
5  *
6  * (C) 1999-2008 by the GRASS Development Team
7  *
8  * This program is free software under the GNU General Public
9  * License (>=v2). Read the file COPYING that comes with GRASS
10  * for details.
11  *
12  * \author Joel Jones (CERL/UIUC), Radim Blazek
13  */
14 
15 #include <stdlib.h>
16 #include <grass/dbmi.h>
17 #include "macros.h"
18 #include "dbstubs.h"
19 
20 /*!
21   \brief Open database connection
22 
23   \return DB_OK on success
24   \return DB_FAILED on failure
25  */
db_d_open_database(void)26 int db_d_open_database(void)
27 {
28     dbHandle handle;
29     int stat;
30 
31     /* get the arg(s) */
32     db_init_handle(&handle);
33     DB_RECV_HANDLE(&handle);
34 
35     /* see if there is a database already open */
36     if (db__test_database_open()) {
37 	db_error("Multiple open databases not allowed");
38 	DB_SEND_FAILURE();
39 	return DB_OK;
40     }
41 
42     /* call the procedure */
43     stat = db_driver_open_database(&handle);
44 
45     /* send the return code */
46     if (stat != DB_OK) {
47 	db_free_handle(&handle);
48 	DB_SEND_FAILURE();
49 	return DB_OK;
50     }
51     DB_SEND_SUCCESS();
52 
53     /* record the open in the driver state */
54     db__mark_database_open(db_get_handle_dbname(&handle),
55 			   db_get_handle_dbschema(&handle));
56     /* DO NOT free the handle since we saved the pointers to the name,path */
57 
58     /* no results */
59     return DB_OK;
60 }
61