GRASS 8 Programmer's Manual 8.6.0dev(2026)-56a9afeb9f
Loading...
Searching...
No Matches
db.c
Go to the documentation of this file.
1/*!
2 * \file db/dbmi_client/db.c
3 *
4 * \brief DBMI Library (client) - open/close driver/database connection
5 *
6 * (C) 1999-2009 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 <grass/dbmi.h>
16#include <grass/glocale.h>
17#include "macros.h"
18
19/*!
20 \brief Open driver/database connection
21
22 \param drvname driver name
23 \param dbname database name
24
25 \return pointer to dbDriver structure
26 \return NULL on failure
27 */
28dbDriver *db_start_driver_open_database(const char *drvname, const char *dbname)
29{
30 dbHandle handle;
32
33 G_debug(3, "db_start_driver_open_database(): drvname='%s', dbname='%s'",
34 drvname, dbname);
35
36 db_init_handle(&handle);
37
39 if (driver == NULL) {
40 G_warning(_("Unable to start driver <%s>"), drvname);
41 return NULL;
42 }
43 db_set_handle(&handle, dbname, NULL);
44 if (db_open_database(driver, &handle) != DB_OK) {
45 G_warning(_("Unable to open database <%s> by driver <%s>"), dbname,
46 drvname);
48 return NULL;
49 }
50
51 return driver;
52}
53
54/*!
55 \brief Close driver/database connection
56
57 \param driver db driver
58
59 \return DB_OK or DB_FAILED
60 */
62{
63 int status;
64
65 status = db_close_database(driver);
66 G_debug(2, "db_close_database() result: %d (%d means success)", status,
67 DB_OK);
68
69 if (db_shutdown_driver(driver) != 0) {
70 status = DB_FAILED;
71 G_debug(2, "db_shutdown_driver() failed");
72 }
73
74 return status;
75}
#define NULL
Definition ccmath.h:32
dbDriver * db_start_driver_open_database(const char *drvname, const char *dbname)
Open driver/database connection.
Definition db.c:28
int db_close_database_shutdown_driver(dbDriver *driver)
Close driver/database connection.
Definition db.c:61
Main header of GRASS DataBase Management Interface.
#define DB_FAILED
Definition dbmi.h:72
#define DB_OK
Definition dbmi.h:71
int db_shutdown_driver(dbDriver *)
Closedown the driver, and free the driver structure.
Definition shutdown.c:36
int db_open_database(dbDriver *, dbHandle *)
Open database connection.
Definition c_opendb.c:27
int db_set_handle(dbHandle *, const char *, const char *)
Set handle (database and schema name)
Definition handle.c:39
int db_close_database(dbDriver *)
Close database connection.
Definition c_closedb.c:26
dbDriver * db_start_driver(const char *)
Initialize a new dbDriver for db transaction.
Definition start.c:51
void db_init_handle(dbHandle *)
Initialize handle (i.e database/schema)
Definition handle.c:23
void G_warning(const char *,...) __attribute__((format(printf
int G_debug(int, const char *,...) __attribute__((format(printf
#define _(str)
Definition glocale.h:10